Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4FastSimulationManager.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28//---------------------------------------------------------------
29//
30// G4FastSimulationManager.cc
31//
32// Description:
33// Manages the Fast Simulation models attached to a envelope.
34//
35// History:
36// Oct 97: Verderi && MoraDeFreitas - First Implementation.
37// ...
38// May 07: Move to parallel world scheme
39//
40//---------------------------------------------------------------
41
44#include "G4PVPlacement.hh"
46
47// --------------------------------------------------
48// Constructor with envelope and IsUnique flag :
49// --------------------------------------------------
50//
53 G4bool IsUnique) :
54 fFastTrack(anEnvelope,IsUnique),fTriggedFastSimulationModel(0),
55 fLastCrossedParticle(0)
56{
57 // Communicates to the region that it becomes a
58 // envelope and with this fast simulation manager.
59 anEnvelope->SetFastSimulationManager(this);
60
61 // Add itself to the GlobalFastSimulationManager
63 AddFastSimulationManager(this);
64}
65
66// -----------
67// Destructor:
68// -----------
70{
71 //
72 // Check out the Envelope about this pointer. If in use,
73 // resets the Logical Volume IsEnvelope flag to avoid clash.
74 //
75 if(fFastTrack.GetEnvelope()->GetFastSimulationManager()==this)
77 // Remove itself from the GlobalFastSimulationManager
79 RemoveFastSimulationManager(this);
80}
81
82// ---------------------------------------
83// Methods to activate/inactivate models
84//----------------------------------------
85
88{
89 G4int iModel;
90
91 // If the model is already active, do nothing.
92 for (iModel=0; iModel<(G4int)ModelList.size(); ++iModel)
93 if(ModelList[iModel]->GetName() == aName)
94 return true;
95
96 // Look for in the fInactivatedModels list, if found push_back it back to
97 // the ModelList
98 for (iModel=0; iModel<(G4int)fInactivatedModels.size(); ++iModel)
99 if(fInactivatedModels[iModel]->GetName() == aName) {
100 ModelList.
101 push_back (fInactivatedModels.removeAt(iModel));
102 // forces the fApplicableModelList to be rebuild
103 fLastCrossedParticle=0;
104 return true;
105 }
106 return false;
107}
108
109G4bool
111{
112 // Look for in the ModelList, if found remove from it and keep the pointer
113 // on the fInactivatedModels list.
114 for (G4int iModel=0; iModel<(G4int)ModelList.size(); ++iModel)
115 if(ModelList[iModel]->GetName() == aName) {
116 fInactivatedModels.push_back (ModelList.removeAt(iModel));
117 // forces the fApplicableModelList to be rebuild
118 fLastCrossedParticle=0;
119 return true;
120 }
121 return false;
122}
123
126 const G4VFastSimulationModel* previousFound,
127 bool &foundPrevious) const
128{
129 G4VFastSimulationModel* model = 0;
130 for (std::size_t iModel=0; iModel<ModelList.size(); ++iModel)
131 {
132 if(ModelList[iModel]->GetName() == modelName)
133 {
134 if (previousFound == 0)
135 {
136 model = ModelList[iModel];
137 break;
138 }
139 else
140 {
141 if (ModelList[iModel] == previousFound)
142 {
143 foundPrevious = true;
144 continue;
145 }
146 if (foundPrevious)
147 {
148 model = ModelList[iModel];
149 break;
150 }
151 }
152 }
153 }
154 return model;
155}
156
158{
159 for (std::size_t iModel=0; iModel<ModelList.size(); ++iModel)
160 {
161 ModelList[iModel]->Flush();
162 }
163}
164
165
166
167//------------------------------------------------------------------
168// Interface trigger method for the G4ParameterisationManagerProcess
169//------------------------------------------------------------------
170// G4bool GetFastSimulationManagerTrigger(const G4Track &);
171//
172// This method is used to interface the G4FastSimulationManagerProcess
173// with the user Fast Simulation Models. It's called when the particle
174// is inside the envelope.
175//
176// It :
177//
178// 1) initialises the private members (fFastTrack and so
179// on);
180// 2) loops on the IsApplicable() methods to find out the
181// ones should be applied.
182// 2) for these, loops on the ModelTrigger() methods to find out
183// perhaps one that must be applied just now.
184//
185// If the a Fast Simulation Model is triggered then it returns
186// true, false otherwise.
187//
188//-----------------------------------------------------------
189G4bool
192 const G4Navigator* theNavigator)
193{
194 std::size_t iModel;
195
196 // If particle type changed re-build the fApplicableModelList.
197 if(fLastCrossedParticle!=track.GetDefinition()) {
198 fLastCrossedParticle=track.GetDefinition();
199 fApplicableModelList.clear();
200 // If Model List is empty, do nothing !
201 if(ModelList.size()==0) return false;
202 for (iModel=0; iModel<ModelList.size(); ++iModel)
203 if(ModelList[iModel]->IsApplicable(*(track.GetDefinition())))
204 fApplicableModelList.push_back (ModelList[iModel]);
205 }
206
207 // If Applicable Model List is empty, do nothing !
208 if(fApplicableModelList.size()==0) return false;
209
210 // -- Register current track
211 fFastTrack.SetCurrentTrack(track,theNavigator);
212
213 // tests if particle are on the boundary and leaving,
214 // in this case do nothing !
215 if(fFastTrack.OnTheBoundaryButExiting()) return false;
216
217 // Loops on the ModelTrigger() methods
218 for (iModel=0; iModel<fApplicableModelList.size(); ++iModel)
219
220 //---------------------------------------------------
221 // Asks the ModelTrigger method if it must be trigged now.
222 //---------------------------------------------------
223
224 if(fApplicableModelList[iModel]->ModelTrigger(fFastTrack)) {
225 //--------------------------------------------------
226 // The model will be applied. Initializes the G4FastStep
227 // with the current state of the G4Track and
228 // same usefull parameters.
229 // In particular it does SetLocalEnergyDeposit(0.0).
230 //--------------------------------------------------
231 fFastStep.Initialize(fFastTrack);
232
233 // Keeps the FastSimulationModel pointer to call the
234 // DoIt() method.
235 fTriggedFastSimulationModel=fApplicableModelList[iModel];
236 return true;
237 }
238
239 //--------------------------------------------
240 // Nobody asks to gain control, returns false
241 //--------------------------------------------
242 return false;
243}
244
246{
247 // const G4FastTrack& parFastTrack=fFastTrack;
248 fTriggedFastSimulationModel->DoIt(fFastTrack,fFastStep);
249 return &fFastStep;
250}
251
252// -------------------------------------------------------------
253// -- Mostly the same as above, in the case of AtRest particles:
254// -------------------------------------------------------------
255G4bool
257 const G4Navigator* theNavigator)
258{
259 std::size_t iModel;
260
261 // If particle type changed re-build the fApplicableModelList.
262 if(fLastCrossedParticle!=track.GetDefinition()) {
263 fLastCrossedParticle=track.GetDefinition();
264 fApplicableModelList.clear();
265 // If Model List is empty, do nothing !
266 if(ModelList.size()==0) return false;
267 for (iModel=0; iModel<ModelList.size(); ++iModel)
268 if(ModelList[iModel]->IsApplicable(*(track.GetDefinition())))
269 fApplicableModelList.push_back (ModelList[iModel]);
270 }
271
272 // If Applicable Model List is empty, do nothing !
273 if(fApplicableModelList.size()==0) return false;
274
275 // -- Register current track
276 fFastTrack.SetCurrentTrack(track,theNavigator);
277
278 // -- (note: compared to the PostStepGetFastSimulationManagerTrigger,
279 // -- the test to see if the particle is on the boundary but leaving
280 // -- is irrelevant here)
281
282 // Loops on the models to see if one of them wants to trigger:
283 for (iModel=0; iModel < fApplicableModelList.size(); ++iModel)
284 if(fApplicableModelList[iModel]->AtRestModelTrigger(fFastTrack))
285 {
286 fFastStep.Initialize(fFastTrack);
287 fTriggedFastSimulationModel=fApplicableModelList[iModel];
288 return true;
289 }
290
291 //--------------------------------------------
292 // Nobody asks to gain control, returns false
293 //--------------------------------------------
294 return false;
295}
296
298{
299 fTriggedFastSimulationModel->AtRestDoIt(fFastTrack,fFastStep);
300 return &fFastStep;
301}
302
303void
305{
306 G4cout << fFastTrack.GetEnvelope()->GetName();
307 // if(GhostPlacements.size()!=0) G4cout << " (ghost)";
309 else G4cout << " (// geom.)";
310
311}
312
313void
315{
316 std::size_t iModel;
317
318 G4cout << "Current Models for the ";
319 ListTitle();
320 G4cout << " envelope:\n";
321
322 for (iModel=0; iModel<ModelList.size(); ++iModel)
323 G4cout << " " << ModelList[iModel]->GetName() << "\n";
324
325 for (iModel=0; iModel<fInactivatedModels.size(); ++iModel)
326 G4cout << " " << fInactivatedModels[iModel]->GetName()
327 << "(inactivated)\n";
328}
329
331{
332 std::size_t iModel;
333 G4int titled = 0;
335
336 // Active Models
337 for ( iModel=0; iModel<ModelList.size(); ++iModel )
338 if( ModelList[iModel]->GetName() == modelName || modelName == "all" )
339 {
340 if( !(titled++) )
341 {
342 G4cout << "In the envelope ";
343 ListTitle();
344 G4cout << ",\n";
345 }
346 G4cout << " the model " << ModelList[iModel]->GetName()
347 << " is applicable for :\n ";
348
349 G4int list_started=0;
350 for ( G4int iParticle = 0; iParticle<theParticleTable->entries(); iParticle++)
351 if( ModelList[iModel] -> IsApplicable( *(theParticleTable->GetParticle(iParticle))) )
352 {
353 if(list_started++) G4cout << ", ";
354 G4cout << theParticleTable->
355 GetParticle(iParticle)->GetParticleName();
356 }
357 G4cout <<G4endl;
358 }
359
360 // Inactive Models
361 for (iModel=0; iModel<fInactivatedModels.size(); ++iModel)
362 if(fInactivatedModels[iModel]->GetName() == modelName || modelName == "all" )
363 {
364 if( !(titled++) )
365 {
366 G4cout << "In the envelope ";
367 ListTitle();
368 G4cout << ",\n";
369 }
370 G4cout << " the model " << fInactivatedModels[iModel]->GetName()
371 << " (inactivated) is applicable for :\n ";
372
373 G4int list_started=0;
374 for ( G4int iParticle=0; iParticle<theParticleTable->entries(); iParticle++ )
375 if( fInactivatedModels[iModel] -> IsApplicable( *(theParticleTable->GetParticle(iParticle))) )
376 {
377 if(list_started++) G4cout << ", ";
378 G4cout << theParticleTable->
379 GetParticle(iParticle)->GetParticleName();
380 }
381 G4cout <<G4endl;
382 }
383}
384
386{
387 std::size_t iModel;
388 G4bool unique = true;
389
390 // Active Models
391 for ( iModel=0; iModel<ModelList.size(); ++iModel )
392 if ( ModelList[iModel]->IsApplicable(*particleDefinition) )
393 {
394 G4cout << "Envelope ";
395 ListTitle();
396 G4cout << ", Model "
397 << ModelList[iModel]->GetName()
398 << "." << G4endl;
399 // -- Verify unicity of model attached to particleDefinition:
400 for ( auto jModel = iModel + 1; jModel < ModelList.size(); jModel++ )
401 if ( ModelList[jModel]->IsApplicable(*particleDefinition) ) unique = false;
402 }
403
404 // Inactive Models
405 for ( iModel=0; iModel<fInactivatedModels.size(); ++iModel )
406 if( fInactivatedModels[iModel]->IsApplicable(*particleDefinition) )
407 {
408 G4cout << "Envelope ";
409 ListTitle();
410 G4cout << ", Model "
411 << fInactivatedModels[iModel]->GetName()
412 << " (inactivated)." << G4endl;
413 }
414
415 if( !unique )
416 {
418 ed << "Two or more active Models are available for the same particle type, in the same envelope/region." << G4endl;
419 G4Exception("G4FastSimulationManager::ListModels(const G4ParticleDefinition* particleDefinition) const",
420 "FastSim001",
421 JustWarning, ed,
422 "Models risk to exclude each other.");
423 }
424 unique=false;
425}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4FastSimulationManager(G4Envelope *anEnvelope, G4bool IsUnique=FALSE)
G4VParticleChange * InvokePostStepDoIt()
G4VParticleChange * InvokeAtRestDoIt()
G4bool PostStepGetFastSimulationManagerTrigger(const G4Track &, const G4Navigator *a=0)
G4bool AtRestGetFastSimulationManagerTrigger(const G4Track &, const G4Navigator *a=0)
G4bool ActivateFastSimulationModel(const G4String &)
G4VFastSimulationModel * GetFastSimulationModel(const G4String &modelName, const G4VFastSimulationModel *previousFound, bool &foundPrevious) const
G4bool InActivateFastSimulationModel(const G4String &)
void Initialize(const G4FastTrack &)
Definition: G4FastStep.cc:53
G4Envelope * GetEnvelope() const
Definition: G4FastTrack.hh:186
G4bool OnTheBoundaryButExiting() const
Definition: G4FastTrack.hh:241
void SetCurrentTrack(const G4Track &, const G4Navigator *a=0)
Definition: G4FastTrack.cc:70
static G4GlobalFastSimulationManager * GetGlobalFastSimulationManager()
G4VPhysicalVolume * GetWorldVolume() const
G4ParticleDefinition * GetParticle(G4int index) const
G4int entries() const
static G4ParticleTable * GetParticleTable()
const G4String & GetParticleName(G4int index) const
G4FastSimulationManager * GetFastSimulationManager() const
Definition: G4Region.cc:140
G4VPhysicalVolume * GetWorldPhysical() const
const G4String & GetName() const
void SetFastSimulationManager(G4FastSimulationManager *fsm)
Definition: G4Region.cc:131
void ClearFastSimulationManager()
Definition: G4Region.cc:434
G4ParticleDefinition * GetDefinition() const
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const
virtual void DoIt(const G4FastTrack &, G4FastStep &)=0
virtual void AtRestDoIt(const G4FastTrack &, G4FastStep &)