Geant4  10.00.p03
G4GlobalFastSimulationManager.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: G4GlobalFastSimulationManager.cc 68056 2013-03-13 14:44:48Z gcosmo $
28 //
29 //
30 //---------------------------------------------------------------
31 //
32 // G4GlobalFastSimulationManager.cc
33 //
34 // Description:
35 // A singleton class which manages the Fast Simulation managers
36 // attached to envelopes. Implementation.
37 //
38 // History:
39 // June 98: Verderi && MoraDeFreitas - "G4ParallelWorld" becomes
40 // "G4FlavoredParallelWorld"; some method name changes;
41 // GetFlavoredWorldForThis now returns a
42 // G4FlavoredParallelWorld pointer.
43 // Feb 98: Verderi && MoraDeFreitas - First Implementation.
44 // March 98: correction to instanciate dynamically the manager
45 // May 07: Move to parallel world scheme
46 //
47 //---------------------------------------------------------------
48 
50 #include "G4ParticleTable.hh"
51 #include "G4ParticleDefinition.hh"
52 #include "G4Material.hh"
53 #include "G4ThreeVector.hh"
54 #include "G4PVPlacement.hh"
57 #include "G4RegionStore.hh"
58 #include "G4ProcessVector.hh"
59 #include "G4ProcessManager.hh"
60 #include "G4PhysicalVolumeStore.hh"
61 
62 
63 // ------------------------------------------
64 // -- static instance pointer initialisation:
65 // ------------------------------------------
67 
68 // --------------------------------------------------
69 // -- static methods to retrieve the manager pointer:
70 // --------------------------------------------------
72 {
75 
77 }
78 
79 
81 {
83 }
84 
85 // ---------------
86 // -- constructor
87 // ---------------
89 {
91 }
92 
93 // -------------
94 // -- destructor
95 // -------------
97 {
100 }
101 
102 // ----------------------
103 // -- management methods:
104 // ----------------------
107 {
108  ManagedManagers.push_back(fsmanager);
109 }
110 
113 {
114  ManagedManagers.remove(fsmanager);
115 }
116 
118 {
119  fFSMPVector.push_back(fp);
120 }
121 
123 {
124  fFSMPVector.remove(fp);
125 }
126 
128 {
129  G4bool result = false;
130  for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
131  result = result || ManagedManagers[ifsm]->
133  if(result)
134  G4cout << "Model " << aName << " activated.";
135  else
136  G4cout << "Model " << aName << " not found.";
137  G4cout << G4endl;
138 }
139 
141 {
142  G4bool result = false;
143  for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
144  result = result || ManagedManagers[ifsm]->
146  if (result) G4cout << "Model " << aName << " inactivated.";
147  else G4cout << "Model " << aName << " not found.";
148  G4cout << G4endl;
149 }
150 
151 
152 // ---------------------------------
153 // -- display fast simulation setup:
154 // ---------------------------------
156 {
157  std::vector<G4VPhysicalVolume*> worldDone;
158  G4VPhysicalVolume* world;
160  // ----------------------------------------------------
161  // -- loop on regions to get the list of world volumes:
162  // ----------------------------------------------------
163  G4cout << "\nFast simulation setup:" << G4endl;
164  for (size_t i=0; i<regions->size(); i++)
165  {
166  world = (*regions)[i]->GetWorldPhysical();
167  G4bool newWorld = true;
168  for (size_t ii=0; ii<worldDone.size(); ii++) if (worldDone[ii] == world) {newWorld = false; break;}
169  if (newWorld)
170  {
171  worldDone.push_back(world);
172  G4Region* worldRegion = world->GetLogicalVolume()->GetRegion();
173  // -- preambule: print physical volume and region names...
174  if (world == G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume())
175  G4cout << "\n * Mass Geometry with ";
176  else
177  G4cout << "\n * Parallel Geometry with ";
178  G4cout << "world volume: `" << world->GetName() << "' [region : `" << worldRegion->GetName() << "']" << G4endl;
179  // -- ... and print G4FSMP(s) attached to this world volume:
180  G4bool findG4FSMP(false);
181  // -- show to what particles this G4FSMP is attached to:
182  std::vector<G4ParticleDefinition*> particlesKnown;
183  for (size_t ip=0; ip<fFSMPVector.size(); ip++)
184  if (fFSMPVector[ip]->GetWorldVolume() == world)
185  {
186  G4cout << " o G4FastSimulationProcess: '" << fFSMPVector[ip]->GetProcessName() << "'" << G4endl;
187  G4cout << " Attached to:";
189  for (G4int iParticle=0; iParticle<particles->entries(); iParticle++)
190  {
191  G4ParticleDefinition* particle = particles->GetParticle(iParticle);
192  G4ProcessVector* processes = particle->GetProcessManager()->GetProcessList();
193  if (processes->contains(fFSMPVector[ip])) {G4cout << " " << particle->GetParticleName(); findG4FSMP = true; particlesKnown.push_back(particle);}
194  }
195  G4cout << G4endl;
196  }
197  if (!findG4FSMP) G4cout << " o G4FastSimulationProcess: (none)" << G4endl;
198  // -- now display the regions in this world volume, with mother<->daughter link shown by indentation:
199  G4cout << " o Region(s) and model(s) setup:" << G4endl;
200  DisplayRegion(worldRegion, 1, particlesKnown);
201  }
202  }
203 }
204 
205 
206 void G4GlobalFastSimulationManager::DisplayRegion(G4Region* region, G4int depth, std::vector<G4ParticleDefinition*>& particlesKnown) const
207 {
208  G4String indent = " ";
209  for (G4int I=0; I<depth; I++) indent += " ";
210  G4cout << indent << "Region: `" << region->GetName() <<"'" << G4endl;
211  G4FastSimulationManager* fastSimManager = region->GetFastSimulationManager();
212  if (fastSimManager)
213  {
214  indent += " ";
215  G4cout << indent << "Model(s):" << G4endl;
216  indent += " ";
217  for (size_t im=0; im<fastSimManager->GetFastSimulationModelList().size(); im++)
218  {
219  G4cout << indent << "`" << (fastSimManager->GetFastSimulationModelList())[im]->GetName() << "'";
220  G4cout << " ; applicable to:";
222  for (G4int iParticle=0; iParticle<particles->entries(); iParticle++)
223  {
224  if ((fastSimManager->GetFastSimulationModelList())[im]->IsApplicable(*(particles->GetParticle(iParticle))))
225  {
226  G4cout << " " << particles->GetParticle(iParticle)->GetParticleName();
227  G4bool known(false);
228  for (size_t l=0; l<particlesKnown.size();l++) if(particlesKnown[l] == particles->GetParticle(iParticle)) {known = true; break;}
229  if (!known) G4cout << "[!!]";
230  }
231  }
232  G4cout << G4endl;
233  }
234  }
235 
236  // -- all that to check mothership of "region"
238  for (size_t ip=0; ip<physVolStore->size(); ip++)
239  {
240  G4VPhysicalVolume* physVol = (*physVolStore)[ip];
241  if (physVol->GetLogicalVolume()->IsRootRegion())
242  if (physVol->GetMotherLogical())
243  {
244  G4Region* thisVolMotherRegion = physVol->GetMotherLogical()->GetRegion();
245  if (thisVolMotherRegion == region)
246  DisplayRegion(physVol->GetLogicalVolume()->GetRegion(), depth+1, particlesKnown);
247  }
248  }
249 }
250 
251 
252 // ----------------------------
253 // -- management methods : list
254 // ----------------------------
255 
257  listType theType)
258 {
259  if (theType == ISAPPLICABLE)
260  {
261  for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) ManagedManagers[ifsm]->ListModels(aName);
262  return;
263  }
264 
265  if(aName == "all")
266  {
267  G4int titled = 0;
268  for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
269  {
270  if(theType == NAMES_ONLY)
271  {
272  if(!(titled++))
273  G4cout << "Current Envelopes for Fast Simulation:\n";
274  G4cout << " ";
275  ManagedManagers[ifsm]->ListTitle();
276  G4cout << G4endl;
277  }
278  else ManagedManagers[ifsm]->ListModels();
279  }
280  }
281  else
282  {
283  for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
284  if(aName == ManagedManagers[ifsm]-> GetEnvelope()->GetName())
285  {
286  ManagedManagers[ifsm]->ListModels();
287  break;
288  }
289  }
290 }
291 
293 {
294  for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
295  ManagedManagers[ifsm]->ListModels(aPD);
296 }
297 
298 
300  const G4VFastSimulationModel* previousFound) const
301 {
302  G4VFastSimulationModel* model = 0;
303  // -- flag used to navigate accross the various managers;
304  bool foundPrevious(false);
305  for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
306  {
307  model = ManagedManagers[ifsm]->
308  GetFastSimulationModel(modelName, previousFound, foundPrevious);
309  if (model) break;
310  }
311  return model;
312 }
void RemoveFSMP(G4FastSimulationManagerProcess *)
G4FastSimulationVector< G4FastSimulationManagerProcess > fFSMPVector
const G4String & GetName() const
G4FastSimulationMessenger * fTheFastSimulationMessenger
void InActivateFastSimulationModel(const G4String &)
G4VFastSimulationModel * GetFastSimulationModel(const G4String &modelName, const G4VFastSimulationModel *previousFound=0) const
void ListEnvelopes(const G4String &aName="all", listType aListType=NAMES_ONLY)
static G4GlobalFastSimulationManager * GetGlobalFastSimulationManager()
G4FastSimulationVector< G4FastSimulationManager > ManagedManagers
void RemoveFastSimulationManager(G4FastSimulationManager *)
G4Region * GetRegion() const
#define G4ThreadLocal
Definition: tls.hh:52
G4ProcessManager * GetProcessManager() const
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
static G4PhysicalVolumeStore * GetInstance()
static G4RegionStore * GetInstance()
static G4ThreadLocal G4GlobalFastSimulationManager * fGlobalFastSimulationManager
G4ParticleDefinition * GetParticle(G4int index) const
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
bool G4bool
Definition: G4Types.hh:79
G4bool IsRootRegion() const
static G4GlobalFastSimulationManager * GetInstance()
G4LogicalVolume * GetMotherLogical() const
static G4TransportationManager * GetTransportationManager()
G4bool contains(G4VProcess *aProcess) const
G4LogicalVolume * GetLogicalVolume() const
static G4ParticleTable * GetParticleTable()
const std::vector< G4VFastSimulationModel * > & GetFastSimulationModelList() const
G4FastSimulationManager * GetFastSimulationManager() const
#define G4endl
Definition: G4ios.hh:61
void DisplayRegion(G4Region *motherRegion, G4int depth, std::vector< G4ParticleDefinition * > &particles) const
T * remove(const T *)
void AddFastSimulationManager(G4FastSimulationManager *)
G4int entries() const
G4ProcessVector * GetProcessList() const
void AddFSMP(G4FastSimulationManagerProcess *)