ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4GlobalFastSimulationManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4GlobalFastSimulationManager.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 //
31 // G4GlobalFastSimulationManager.cc
32 //
33 // Description:
34 // A singleton class which manages the Fast Simulation managers
35 // attached to envelopes. Implementation.
36 //
37 // History:
38 // June 98: Verderi && MoraDeFreitas - "G4ParallelWorld" becomes
39 // "G4FlavoredParallelWorld"; some method name changes;
40 // GetFlavoredWorldForThis now returns a
41 // G4FlavoredParallelWorld pointer.
42 // Feb 98: Verderi && MoraDeFreitas - First Implementation.
43 // March 98: correction to instanciate dynamically the manager
44 // May 07: Move to parallel world scheme
45 //
46 //---------------------------------------------------------------
47 
49 #include "G4ParticleTable.hh"
50 #include "G4ParticleDefinition.hh"
51 #include "G4Material.hh"
52 #include "G4ThreeVector.hh"
53 #include "G4PVPlacement.hh"
56 #include "G4RegionStore.hh"
57 #include "G4ProcessVector.hh"
58 #include "G4ProcessManager.hh"
59 #include "G4PhysicalVolumeStore.hh"
60 
61 
62 // ------------------------------------------
63 // -- static instance pointer initialisation:
64 // ------------------------------------------
66 
67 // --------------------------------------------------
68 // -- static methods to retrieve the manager pointer:
69 // --------------------------------------------------
71 {
74 
76 }
77 
78 
80 {
82 }
83 
84 // ---------------
85 // -- constructor
86 // ---------------
88 {
90 }
91 
92 // -------------
93 // -- destructor
94 // -------------
96 {
99 }
100 
101 // ----------------------
102 // -- management methods:
103 // ----------------------
106 {
107  ManagedManagers.push_back(fsmanager);
108 }
109 
112 {
113  ManagedManagers.remove(fsmanager);
114 }
115 
117 {
118  fFSMPVector.push_back(fp);
119 }
120 
122 {
123  fFSMPVector.remove(fp);
124 }
125 
127 {
128  G4bool result = false;
129  for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
130  result = result || ManagedManagers[ifsm]->
132  if(result)
133  G4cout << "Model " << aName << " activated.";
134  else
135  G4cout << "Model " << aName << " not found.";
136  G4cout << G4endl;
137 }
138 
140 {
141  G4bool result = false;
142  for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
143  result = result || ManagedManagers[ifsm]->
145  if (result) G4cout << "Model " << aName << " inactivated.";
146  else G4cout << "Model " << aName << " not found.";
147  G4cout << G4endl;
148 }
149 
150 
151 // ---------------------------------
152 // -- display fast simulation setup:
153 // ---------------------------------
155 {
156  std::vector<G4VPhysicalVolume*> worldDone;
159  // ----------------------------------------------------
160  // -- loop on regions to get the list of world volumes:
161  // ----------------------------------------------------
162  G4cout << "\nFast simulation setup:" << G4endl;
163  for (size_t i=0; i<regions->size(); i++)
164  {
165  world = (*regions)[i]->GetWorldPhysical();
166  G4bool newWorld = true;
167  for (size_t ii=0; ii<worldDone.size(); ii++) if (worldDone[ii] == world) {newWorld = false; break;}
168  if (newWorld)
169  {
170  worldDone.push_back(world);
171  G4Region* worldRegion = world->GetLogicalVolume()->GetRegion();
172  // -- preambule: print physical volume and region names...
173  if (world == G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume())
174  G4cout << "\n * Mass Geometry with ";
175  else
176  G4cout << "\n * Parallel Geometry with ";
177  G4cout << "world volume: `" << world->GetName() << "' [region : `" << worldRegion->GetName() << "']" << G4endl;
178  // -- ... and print G4FSMP(s) attached to this world volume:
179  G4bool findG4FSMP(false);
180  // -- show to what particles this G4FSMP is attached to:
181  std::vector<G4ParticleDefinition*> particlesKnown;
182  for (size_t ip=0; ip<fFSMPVector.size(); ip++)
183  if (fFSMPVector[ip]->GetWorldVolume() == world)
184  {
185  G4cout << " o G4FastSimulationProcess: '" << fFSMPVector[ip]->GetProcessName() << "'" << G4endl;
186  G4cout << " Attached to:";
188  for (G4int iParticle=0; iParticle<particles->entries(); iParticle++)
189  {
190  G4ParticleDefinition* particle = particles->GetParticle(iParticle);
191  G4ProcessVector* processes = particle->GetProcessManager()->GetProcessList();
192  if (processes->contains(fFSMPVector[ip])) {G4cout << " " << particle->GetParticleName(); findG4FSMP = true; particlesKnown.push_back(particle);}
193  }
194  G4cout << G4endl;
195  }
196  if (!findG4FSMP) G4cout << " o G4FastSimulationProcess: (none)" << G4endl;
197  // -- now display the regions in this world volume, with mother<->daughter link shown by indentation:
198  G4cout << " o Region(s) and model(s) setup:" << G4endl;
199  DisplayRegion(worldRegion, 1, particlesKnown);
200  }
201  }
202 }
203 
204 
205 void G4GlobalFastSimulationManager::DisplayRegion(G4Region* region, G4int depth, std::vector<G4ParticleDefinition*>& particlesKnown) const
206 {
207  G4String indent = " ";
208  for (G4int I=0; I<depth; I++) indent += " ";
209  G4cout << indent << "Region: `" << region->GetName() <<"'" << G4endl;
210  G4FastSimulationManager* fastSimManager = region->GetFastSimulationManager();
211  if (fastSimManager)
212  {
213  indent += " ";
214  G4cout << indent << "Model(s):" << G4endl;
215  indent += " ";
216  for (size_t im=0; im<fastSimManager->GetFastSimulationModelList().size(); im++)
217  {
218  G4cout << indent << "`" << (fastSimManager->GetFastSimulationModelList())[im]->GetName() << "'";
219  G4cout << " ; applicable to:";
221  for (G4int iParticle=0; iParticle<particles->entries(); iParticle++)
222  {
223  if ((fastSimManager->GetFastSimulationModelList())[im]->IsApplicable(*(particles->GetParticle(iParticle))))
224  {
225  G4cout << " " << particles->GetParticle(iParticle)->GetParticleName();
226  G4bool known(false);
227  for (size_t l=0; l<particlesKnown.size();l++) if(particlesKnown[l] == particles->GetParticle(iParticle)) {known = true; break;}
228  if (!known) G4cout << "[!!]";
229  }
230  }
231  G4cout << G4endl;
232  }
233  }
234 
235  // -- all that to check mothership of "region"
237  for (size_t ip=0; ip<physVolStore->size(); ip++)
238  {
239  G4VPhysicalVolume* physVol = (*physVolStore)[ip];
240  if (physVol->GetLogicalVolume()->IsRootRegion())
241  if (physVol->GetMotherLogical())
242  {
243  G4Region* thisVolMotherRegion = physVol->GetMotherLogical()->GetRegion();
244  if (thisVolMotherRegion == region)
245  DisplayRegion(physVol->GetLogicalVolume()->GetRegion(), depth+1, particlesKnown);
246  }
247  }
248 }
249 
250 
251 // ----------------------------
252 // -- management methods : list
253 // ----------------------------
254 
256  listType theType)
257 {
258  if (theType == ISAPPLICABLE)
259  {
260  for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) ManagedManagers[ifsm]->ListModels(aName);
261  return;
262  }
263 
264  if(aName == "all")
265  {
266  G4int titled = 0;
267  for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
268  {
269  if(theType == NAMES_ONLY)
270  {
271  if(!(titled++))
272  G4cout << "Current Envelopes for Fast Simulation:\n";
273  G4cout << " ";
274  ManagedManagers[ifsm]->ListTitle();
275  G4cout << G4endl;
276  }
277  else ManagedManagers[ifsm]->ListModels();
278  }
279  }
280  else
281  {
282  for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
283  if(aName == ManagedManagers[ifsm]-> GetEnvelope()->GetName())
284  {
285  ManagedManagers[ifsm]->ListModels();
286  break;
287  }
288  }
289 }
290 
292 {
293  for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
294  ManagedManagers[ifsm]->ListModels(aPD);
295 }
296 
297 
299  const G4VFastSimulationModel* previousFound) const
300 {
302  // -- flag used to navigate accross the various managers;
303  bool foundPrevious(false);
304  for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
305  {
306  model = ManagedManagers[ifsm]->
307  GetFastSimulationModel(modelName, previousFound, foundPrevious);
308  if (model) break;
309  }
310  return model;
311 }