Geant4  10.02.p02
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 // $Id: G4FastSimulationManager.cc 68056 2013-03-13 14:44:48Z gcosmo $
28 //
29 //---------------------------------------------------------------
30 //
31 // G4FastSimulationManager.cc
32 //
33 // Description:
34 // Manages the Fast Simulation models attached to a envelope.
35 //
36 // History:
37 // Oct 97: Verderi && MoraDeFreitas - First Implementation.
38 // ...
39 // May 07: Move to parallel world scheme
40 //
41 //---------------------------------------------------------------
42 
45 #include "G4PVPlacement.hh"
47 
48 // --------------------------------------------------
49 // Constructor with envelope and IsUnique flag :
50 // --------------------------------------------------
51 //
54  G4bool IsUnique) :
55  fFastTrack(anEnvelope,IsUnique),fTriggedFastSimulationModel(0),
56  fLastCrossedParticle(0)
57 {
58  // Communicates to the region that it becomes a
59  // envelope and with this fast simulation manager.
60  anEnvelope->SetFastSimulationManager(this);
61 
62  // Add itself to the GlobalFastSimulationManager
64  AddFastSimulationManager(this);
65 }
66 
67 // -----------
68 // Destructor:
69 // -----------
71 {
72  //
73  // Check out the Envelope about this pointer. If in use,
74  // resets the Logical Volume IsEnvelope flag to avoid clash.
75  //
78  // Remove itself from the GlobalFastSimulationManager
80  RemoveFastSimulationManager(this);
81 }
82 
83 // ---------------------------------------
84 // Methods to activate/inactivate models
85 //----------------------------------------
86 
87 G4bool
89 {
90  size_t iModel;
91 
92  // If the model is already active, do nothing.
93  for (iModel=0; iModel<ModelList.size(); iModel++)
94  if(ModelList[iModel]->GetName() == aName)
95  return true;
96 
97  // Look for in the fInactivatedModels list, if found push_back it back to
98  // the ModelList
99  for (iModel=0; iModel<fInactivatedModels.size(); iModel++)
100  if(fInactivatedModels[iModel]->GetName() == aName) {
101  ModelList.
102  push_back (fInactivatedModels.removeAt(iModel));
103  // forces the fApplicableModelList to be rebuild
105  return true;
106  }
107  return false;
108 }
109 
110 G4bool
112 {
113  // Look for in the ModelList, if found remove from it and keep the pointer
114  // on the fInactivatedModels list.
115  for (size_t iModel=0; iModel<ModelList.size(); iModel++)
116  if(ModelList[iModel]->GetName() == aName) {
118  push_back (ModelList.removeAt(iModel));
119  // forces the fApplicableModelList to be rebuild
121  return true;
122  }
123  return false;
124 }
125 
128  const G4VFastSimulationModel* previousFound,
129  bool &foundPrevious) const
130 {
131  G4VFastSimulationModel* model = 0;
132  for (size_t iModel=0; iModel<ModelList.size(); iModel++)
133  {
134  if(ModelList[iModel]->GetName() == modelName)
135  {
136  if (previousFound == 0)
137  {
138  model = ModelList[iModel];
139  break;
140  }
141  else
142  {
143  if (ModelList[iModel] == previousFound)
144  {
145  foundPrevious = true;
146  continue;
147  }
148  if (foundPrevious)
149  {
150  model = ModelList[iModel];
151  break;
152  }
153  }
154  }
155  }
156  return model;
157 }
158 
159 
160 //------------------------------------------------------------------
161 // Interface trigger method for the G4ParameterisationManagerProcess
162 //------------------------------------------------------------------
163 // G4bool GetFastSimulationManagerTrigger(const G4Track &);
164 //
165 // This method is used to interface the G4FastSimulationManagerProcess
166 // with the user Fast Simulation Models. It's called when the particle
167 // is inside the envelope.
168 //
169 // It :
170 //
171 // 1) initialises the private members (fFastTrack and so
172 // on);
173 // 2) loops on the IsApplicable() methods to find out the
174 // ones should be applied.
175 // 2) for these, loops on the ModelTrigger() methods to find out
176 // perhaps one that must be applied just now.
177 //
178 // If the a Fast Simulation Model is triggered then it returns
179 // true, false otherwise.
180 //
181 //-----------------------------------------------------------
182 G4bool
185  const G4Navigator* theNavigator)
186 {
187  size_t iModel;
188 
189  // If particle type changed re-build the fApplicableModelList.
190  if(fLastCrossedParticle!=track.GetDefinition()) {
192  fApplicableModelList.clear();
193  // If Model List is empty, do nothing !
194  if(ModelList.size()==0) return false;
195  for (iModel=0; iModel<ModelList.size(); iModel++)
196  if(ModelList[iModel]->IsApplicable(*(track.GetDefinition())))
197  fApplicableModelList.push_back (ModelList[iModel]);
198  }
199 
200  // If Applicable Model List is empty, do nothing !
201  if(fApplicableModelList.size()==0) return false;
202 
203  // -- Register current track
204  fFastTrack.SetCurrentTrack(track,theNavigator);
205 
206  // tests if particle are on the boundary and leaving,
207  // in this case do nothing !
208  if(fFastTrack.OnTheBoundaryButExiting()) return false;
209 
210  // Loops on the ModelTrigger() methods
211  for (iModel=0; iModel<fApplicableModelList.size(); iModel++)
212 
213  //---------------------------------------------------
214  // Asks the ModelTrigger method if it must be trigged now.
215  //---------------------------------------------------
216 
217  if(fApplicableModelList[iModel]->ModelTrigger(fFastTrack)) {
218  //--------------------------------------------------
219  // The model will be applied. Initializes the G4FastStep
220  // with the current state of the G4Track and
221  // same usefull parameters.
222  // In particular it does SetLocalEnergyDeposit(0.0).
223  //--------------------------------------------------
225 
226  // Keeps the FastSimulationModel pointer to call the
227  // DoIt() method.
229  return true;
230  }
231 
232  //--------------------------------------------
233  // Nobody asks to gain control, returns false
234  //--------------------------------------------
235  return false;
236 }
237 
239 {
240  // const G4FastTrack& parFastTrack=fFastTrack;
242  return &fFastStep;
243 }
244 
245 // -------------------------------------------------------------
246 // -- Mostly the same as above, in the case of AtRest particles:
247 // -------------------------------------------------------------
248 G4bool
250  const G4Navigator* theNavigator)
251 {
252  size_t iModel;
253 
254  // If particle type changed re-build the fApplicableModelList.
255  if(fLastCrossedParticle!=track.GetDefinition()) {
257  fApplicableModelList.clear();
258  // If Model List is empty, do nothing !
259  if(ModelList.size()==0) return false;
260  for (iModel=0; iModel<ModelList.size(); iModel++)
261  if(ModelList[iModel]->IsApplicable(*(track.GetDefinition())))
262  fApplicableModelList.push_back (ModelList[iModel]);
263  }
264 
265  // If Applicable Model List is empty, do nothing !
266  if(fApplicableModelList.size()==0) return false;
267 
268  // -- Register current track
269  fFastTrack.SetCurrentTrack(track,theNavigator);
270 
271  // -- (note: compared to the PostStepGetFastSimulationManagerTrigger,
272  // -- the test to see if the particle is on the boundary but leaving
273  // -- is irrelevant here)
274 
275  // Loops on the models to see if one of them wants to trigger:
276  for (iModel=0; iModel < fApplicableModelList.size(); iModel++)
277  if(fApplicableModelList[iModel]->AtRestModelTrigger(fFastTrack))
278  {
281  return true;
282  }
283 
284  //--------------------------------------------
285  // Nobody asks to gain control, returns false
286  //--------------------------------------------
287  return false;
288 }
289 
291 {
293  return &fFastStep;
294 }
295 
296 void
298 {
300  // if(GhostPlacements.size()!=0) G4cout << " (ghost)";
302  else G4cout << " (// geom.)";
303 
304 }
305 
306 void
308 {
309  size_t iModel;
310 
311  G4cout << "Current Models for the ";
312  ListTitle();
313  G4cout << " envelope:\n";
314 
315  for (iModel=0; iModel<ModelList.size(); iModel++)
316  G4cout << " " << ModelList[iModel]->GetName() << "\n";
317 
318  for (iModel=0; iModel<fInactivatedModels.size(); iModel++)
319  G4cout << " " << fInactivatedModels[iModel]->GetName()
320  << "(inactivated)\n";
321 }
322 
323 void
325 {
326  size_t iModel;
327  G4int titled = 0;
328  G4ParticleTable* theParticleTable=
330 
331  // Active Models
332  for (iModel=0; iModel<ModelList.size(); iModel++)
333  if(ModelList[iModel]->GetName() == aName ||
334  aName == "all" ) {
335  if(!(titled++)){
336  G4cout << "In the envelope ";
337  ListTitle();
338  G4cout << ",\n";
339  }
340  G4cout << " the model " << ModelList[iModel]->GetName()
341  << " is applicable for :\n ";
342 
343  G4int list_started=0;
344  for (G4int iParticle=0; iParticle<theParticleTable->entries();
345  iParticle++)
346  if(ModelList[iModel]->
347  IsApplicable(*(theParticleTable->
348  GetParticle(iParticle)))) {
349  if(list_started++) G4cout << ", ";
350  G4cout << theParticleTable->
351  GetParticle(iParticle)->GetParticleName();
352  }
353  G4cout <<G4endl;
354  }
355 
356  // Inactive Models
357  for (iModel=0; iModel<fInactivatedModels.size(); iModel++)
358  if(fInactivatedModels[iModel]->GetName() == aName ||
359  aName == "all" ) {
360  if(!(titled++)){
361  G4cout << "In the envelope ";
362  ListTitle();
363  G4cout << ",\n";
364  }
365  G4cout << " the model " << fInactivatedModels[iModel]->GetName()
366  << " (inactivated) is applicable for :\n ";
367 
368  G4int list_started=0;
369  for (G4int iParticle=0; iParticle<theParticleTable->entries();
370  iParticle++)
371  if(fInactivatedModels[iModel]->
372  IsApplicable(*(theParticleTable->
373  GetParticle(iParticle)))) {
374  if(list_started++) G4cout << ", ";
375  G4cout << theParticleTable->
376  GetParticle(iParticle)->GetParticleName();
377  }
378  G4cout <<G4endl;
379  }
380 }
381 
382 void
384 {
385  size_t iModel;
386  G4bool unique=true;
387 
388  // Active Models
389  for (iModel=0; iModel<ModelList.size(); iModel++)
390  if(ModelList[iModel]->IsApplicable(*aPD)) {
391  G4cout << "Envelope ";
392  ListTitle();
393  G4cout << ", Model "
394  << ModelList[iModel]->GetName()
395  << "." << G4endl;
396  }
397  // inactive Models
398  for (iModel=0; iModel<fInactivatedModels.size(); iModel++)
399  if(fInactivatedModels[iModel]->IsApplicable(*aPD)) {
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 Models are available for the same particle type, in the same envelope/region." << G4endl;
411  G4Exception("G4FastSimulationManager::ListModels(const G4ParticleDefinition* aPD) const",
412  "FastSim001",
413  JustWarning, ed,
414  "Models risk to exclude each other.");
415  }
416  unique=false;
417 }
G4FastSimulationVector< G4VFastSimulationModel > fApplicableModelList
virtual void AtRestDoIt(const G4FastTrack &, G4FastStep &)
G4ParticleDefinition * GetDefinition() const
const G4String & GetName() const
G4VParticleChange * InvokePostStepDoIt()
G4bool AtRestGetFastSimulationManagerTrigger(const G4Track &, const G4Navigator *a=0)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
const G4String & GetParticleName(G4int index) const
G4bool OnTheBoundaryButExiting() const
Definition: G4FastTrack.hh:243
G4Navigator * GetNavigatorForTracking() const
static G4GlobalFastSimulationManager * GetGlobalFastSimulationManager()
void Initialize(const G4FastTrack &)
Definition: G4FastStep.cc:53
int G4int
Definition: G4Types.hh:78
G4FastSimulationVector< G4VFastSimulationModel > fInactivatedModels
void SetFastSimulationManager(G4FastSimulationManager *fsm)
G4bool ActivateFastSimulationModel(const G4String &)
G4VPhysicalVolume * GetWorldPhysical() const
G4GLOB_DLL std::ostream G4cout
G4VFastSimulationModel * fTriggedFastSimulationModel
bool G4bool
Definition: G4Types.hh:79
virtual void DoIt(const G4FastTrack &, G4FastStep &)=0
void ClearFastSimulationManager()
Definition: G4Region.cc:382
void SetCurrentTrack(const G4Track &, const G4Navigator *a=0)
Definition: G4FastTrack.cc:68
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4TransportationManager * GetTransportationManager()
G4VFastSimulationModel * GetFastSimulationModel(const G4String &modelName, const G4VFastSimulationModel *previousFound, bool &foundPrevious) const
G4VParticleChange * InvokeAtRestDoIt()
static G4ParticleTable * GetParticleTable()
G4FastSimulationManager * GetFastSimulationManager() const
#define G4endl
Definition: G4ios.hh:61
G4ParticleDefinition * fLastCrossedParticle
G4bool InActivateFastSimulationModel(const G4String &)
G4bool PostStepGetFastSimulationManagerTrigger(const G4Track &, const G4Navigator *a=0)
G4FastSimulationManager(G4Envelope *anEnvelope, G4bool IsUnique=FALSE)
G4VPhysicalVolume * GetWorldVolume() const
G4int entries() const
G4Envelope * GetEnvelope() const
Definition: G4FastTrack.hh:188
G4FastSimulationVector< G4VFastSimulationModel > ModelList