ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4FastSimulationManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4FastSimulationManager.cc
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  //
77  // Remove itself from the GlobalFastSimulationManager
79  RemoveFastSimulationManager(this);
80 }
81 
82 // ---------------------------------------
83 // Methods to activate/inactivate models
84 //----------------------------------------
85 
86 G4bool
88 {
89  size_t iModel;
90 
91  // If the model is already active, do nothing.
92  for (iModel=0; iModel<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<fInactivatedModels.size(); iModel++)
99  if(fInactivatedModels[iModel]->GetName() == aName) {
100  ModelList.
101  push_back (fInactivatedModels.removeAt(iModel));
102  // forces the fApplicableModelList to be rebuild
104  return true;
105  }
106  return false;
107 }
108 
109 G4bool
111 {
112  // Look for in the ModelList, if found remove from it and keep the pointer
113  // on the fInactivatedModels list.
114  for (size_t iModel=0; iModel<ModelList.size(); iModel++)
115  if(ModelList[iModel]->GetName() == aName) {
117  push_back (ModelList.removeAt(iModel));
118  // forces the fApplicableModelList to be rebuild
120  return true;
121  }
122  return false;
123 }
124 
127  const G4VFastSimulationModel* previousFound,
128  bool &foundPrevious) const
129 {
131  for (size_t iModel=0; iModel<ModelList.size(); iModel++)
132  {
133  if(ModelList[iModel]->GetName() == modelName)
134  {
135  if (previousFound == 0)
136  {
137  model = ModelList[iModel];
138  break;
139  }
140  else
141  {
142  if (ModelList[iModel] == previousFound)
143  {
144  foundPrevious = true;
145  continue;
146  }
147  if (foundPrevious)
148  {
149  model = ModelList[iModel];
150  break;
151  }
152  }
153  }
154  }
155  return model;
156 }
157 
158 
159 //------------------------------------------------------------------
160 // Interface trigger method for the G4ParameterisationManagerProcess
161 //------------------------------------------------------------------
162 // G4bool GetFastSimulationManagerTrigger(const G4Track &);
163 //
164 // This method is used to interface the G4FastSimulationManagerProcess
165 // with the user Fast Simulation Models. It's called when the particle
166 // is inside the envelope.
167 //
168 // It :
169 //
170 // 1) initialises the private members (fFastTrack and so
171 // on);
172 // 2) loops on the IsApplicable() methods to find out the
173 // ones should be applied.
174 // 2) for these, loops on the ModelTrigger() methods to find out
175 // perhaps one that must be applied just now.
176 //
177 // If the a Fast Simulation Model is triggered then it returns
178 // true, false otherwise.
179 //
180 //-----------------------------------------------------------
181 G4bool
184  const G4Navigator* theNavigator)
185 {
186  size_t iModel;
187 
188  // If particle type changed re-build the fApplicableModelList.
189  if(fLastCrossedParticle!=track.GetDefinition()) {
191  fApplicableModelList.clear();
192  // If Model List is empty, do nothing !
193  if(ModelList.size()==0) return false;
194  for (iModel=0; iModel<ModelList.size(); iModel++)
195  if(ModelList[iModel]->IsApplicable(*(track.GetDefinition())))
196  fApplicableModelList.push_back (ModelList[iModel]);
197  }
198 
199  // If Applicable Model List is empty, do nothing !
200  if(fApplicableModelList.size()==0) return false;
201 
202  // -- Register current track
203  fFastTrack.SetCurrentTrack(track,theNavigator);
204 
205  // tests if particle are on the boundary and leaving,
206  // in this case do nothing !
207  if(fFastTrack.OnTheBoundaryButExiting()) return false;
208 
209  // Loops on the ModelTrigger() methods
210  for (iModel=0; iModel<fApplicableModelList.size(); iModel++)
211 
212  //---------------------------------------------------
213  // Asks the ModelTrigger method if it must be trigged now.
214  //---------------------------------------------------
215 
216  if(fApplicableModelList[iModel]->ModelTrigger(fFastTrack)) {
217  //--------------------------------------------------
218  // The model will be applied. Initializes the G4FastStep
219  // with the current state of the G4Track and
220  // same usefull parameters.
221  // In particular it does SetLocalEnergyDeposit(0.0).
222  //--------------------------------------------------
224 
225  // Keeps the FastSimulationModel pointer to call the
226  // DoIt() method.
228  return true;
229  }
230 
231  //--------------------------------------------
232  // Nobody asks to gain control, returns false
233  //--------------------------------------------
234  return false;
235 }
236 
238 {
239  // const G4FastTrack& parFastTrack=fFastTrack;
241  return &fFastStep;
242 }
243 
244 // -------------------------------------------------------------
245 // -- Mostly the same as above, in the case of AtRest particles:
246 // -------------------------------------------------------------
247 G4bool
249  const G4Navigator* theNavigator)
250 {
251  size_t iModel;
252 
253  // If particle type changed re-build the fApplicableModelList.
254  if(fLastCrossedParticle!=track.GetDefinition()) {
256  fApplicableModelList.clear();
257  // If Model List is empty, do nothing !
258  if(ModelList.size()==0) return false;
259  for (iModel=0; iModel<ModelList.size(); iModel++)
260  if(ModelList[iModel]->IsApplicable(*(track.GetDefinition())))
261  fApplicableModelList.push_back (ModelList[iModel]);
262  }
263 
264  // If Applicable Model List is empty, do nothing !
265  if(fApplicableModelList.size()==0) return false;
266 
267  // -- Register current track
268  fFastTrack.SetCurrentTrack(track,theNavigator);
269 
270  // -- (note: compared to the PostStepGetFastSimulationManagerTrigger,
271  // -- the test to see if the particle is on the boundary but leaving
272  // -- is irrelevant here)
273 
274  // Loops on the models to see if one of them wants to trigger:
275  for (iModel=0; iModel < fApplicableModelList.size(); iModel++)
276  if(fApplicableModelList[iModel]->AtRestModelTrigger(fFastTrack))
277  {
280  return true;
281  }
282 
283  //--------------------------------------------
284  // Nobody asks to gain control, returns false
285  //--------------------------------------------
286  return false;
287 }
288 
290 {
292  return &fFastStep;
293 }
294 
295 void
297 {
299  // if(GhostPlacements.size()!=0) G4cout << " (ghost)";
301  else G4cout << " (// geom.)";
302 
303 }
304 
305 void
307 {
308  size_t iModel;
309 
310  G4cout << "Current Models for the ";
311  ListTitle();
312  G4cout << " envelope:\n";
313 
314  for (iModel=0; iModel<ModelList.size(); iModel++)
315  G4cout << " " << ModelList[iModel]->GetName() << "\n";
316 
317  for (iModel=0; iModel<fInactivatedModels.size(); iModel++)
318  G4cout << " " << fInactivatedModels[iModel]->GetName()
319  << "(inactivated)\n";
320 }
321 
322 void G4FastSimulationManager::ListModels(const G4String& modelName) const
323 {
324  size_t iModel;
325  G4int titled = 0;
327 
328  // Active Models
329  for ( iModel=0; iModel<ModelList.size(); iModel++ )
330  if( ModelList[iModel]->GetName() == modelName || modelName == "all" )
331  {
332  if( !(titled++) )
333  {
334  G4cout << "In the envelope ";
335  ListTitle();
336  G4cout << ",\n";
337  }
338  G4cout << " the model " << ModelList[iModel]->GetName()
339  << " is applicable for :\n ";
340 
341  G4int list_started=0;
342  for ( G4int iParticle = 0; iParticle<theParticleTable->entries(); iParticle++)
343  if( ModelList[iModel] -> IsApplicable( *(theParticleTable->GetParticle(iParticle))) )
344  {
345  if(list_started++) G4cout << ", ";
346  G4cout << theParticleTable->
347  GetParticle(iParticle)->GetParticleName();
348  }
349  G4cout <<G4endl;
350  }
351 
352  // Inactive Models
353  for (iModel=0; iModel<fInactivatedModels.size(); iModel++)
354  if(fInactivatedModels[iModel]->GetName() == modelName || modelName == "all" )
355  {
356  if( !(titled++) )
357  {
358  G4cout << "In the envelope ";
359  ListTitle();
360  G4cout << ",\n";
361  }
362  G4cout << " the model " << fInactivatedModels[iModel]->GetName()
363  << " (inactivated) is applicable for :\n ";
364 
365  G4int list_started=0;
366  for ( G4int iParticle=0; iParticle<theParticleTable->entries(); iParticle++ )
367  if( fInactivatedModels[iModel] -> IsApplicable( *(theParticleTable->GetParticle(iParticle))) )
368  {
369  if(list_started++) G4cout << ", ";
370  G4cout << theParticleTable->
371  GetParticle(iParticle)->GetParticleName();
372  }
373  G4cout <<G4endl;
374  }
375 }
376 
377 void G4FastSimulationManager::ListModels(const G4ParticleDefinition* particleDefinition) const
378 {
379  size_t iModel;
380  G4bool unique = true;
381 
382  // Active Models
383  for ( iModel=0; iModel<ModelList.size(); iModel++ )
384  if ( ModelList[iModel]->IsApplicable(*particleDefinition) )
385  {
386  G4cout << "Envelope ";
387  ListTitle();
388  G4cout << ", Model "
389  << ModelList[iModel]->GetName()
390  << "." << G4endl;
391  // -- Verify unicity of model attached to particleDefinition:
392  for ( auto jModel = iModel + 1; jModel < ModelList.size(); jModel++ )
393  if ( ModelList[jModel]->IsApplicable(*particleDefinition) ) unique = false;
394  }
395 
396  // Inactive Models
397  for ( iModel=0; iModel<fInactivatedModels.size(); iModel++ )
398  if( fInactivatedModels[iModel]->IsApplicable(*particleDefinition) )
399  {
400  G4cout << "Envelope ";
401  ListTitle();
402  G4cout << ", Model "
403  << fInactivatedModels[iModel]->GetName()
404  << " (inactivated)." << G4endl;
405  }
406 
407  if( !unique )
408  {
410  ed << "Two or more active Models are available for the same particle type, in the same envelope/region." << G4endl;
411  G4Exception("G4FastSimulationManager::ListModels(const G4ParticleDefinition* particleDefinition) const",
412  "FastSim001",
413  JustWarning, ed,
414  "Models risk to exclude each other.");
415  }
416  unique=false;
417 }