ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4RunManagerKernel.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4RunManagerKernel.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 #include "G4RunManagerKernel.hh"
31 
32 #include <vector>
33 
34 #include "G4StateManager.hh"
35 #include "G4ApplicationState.hh"
36 #include "G4ExceptionHandler.hh"
37 #include "G4PrimaryTransformer.hh"
38 #include "G4GeometryManager.hh"
39 #include "G4FieldManagerStore.hh"
41 #include "G4PathFinder.hh"
43 #include "G4VPhysicalVolume.hh"
44 #include "G4LogicalVolume.hh"
45 #include "G4VUserPhysicsList.hh"
46 
47 #include "G4ParticleTable.hh"
48 #include "G4Region.hh"
49 #include "G4RegionStore.hh"
50 #include "G4ProductionCuts.hh"
51 #include "G4ProductionCutsTable.hh"
52 #include "G4SDManager.hh"
54 #include "G4UImanager.hh"
55 #include "G4VVisManager.hh"
56 #include "G4UnitsTable.hh"
57 #include "G4Version.hh"
58 #include "G4ios.hh"
59 #include "G4TiMemory.hh"
60 
61 #include "G4MTRunManager.hh"
62 #include "G4AllocatorList.hh"
63 
64 #include "G4AutoLock.hh"
65 #include "G4RNGHelper.hh"
66 
67 #ifdef G4FPE_DEBUG
68  #include "G4FPEDetection.hh"
69 #endif
70 
71 //The following lines are needed since G4VUserPhysicsList uses a #define theParticleIterator
72 #ifdef theParticleIterator
73 #undef theParticleIterator
74 #endif
75 
77 
79 { return fRunManagerKernel; }
80 
82 : physicsList(0),currentWorld(0),
83  geometryInitialized(false),physicsInitialized(false),
84  geometryToBeOptimized(true),
85  physicsNeedsToBeReBuilt(true),verboseLevel(0),
86  numberOfParallelWorld(0),geometryNeedsToBeClosed(true),
87  numberOfStaticAllocators(0)
88 {
89 #ifdef G4FPE_DEBUG
91 #endif
93  if(allocList) numberOfStaticAllocators = allocList->Size();
96  {
97  G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0001",
98  FatalException,"More than one G4RunManagerKernel is constructed.");
99  }
100  fRunManagerKernel = this;
101 
103  if(particleTable->entries()>0)
104  {
105  // No particle should be registered beforehand
107  ED<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<G4endl;
108  ED<<" G4RunManagerKernel fatal exception"<<G4endl;
109  ED<<" -- Following particles have already been registered"<<G4endl;
110  ED<<" before G4RunManagerKernel is instantiated."<<G4endl;
111  for(int i=0;i<particleTable->entries();i++)
112  { ED<<" "<<particleTable->GetParticle(i)->GetParticleName()<<G4endl; }
113  ED<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<G4endl;
114  G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0002",
115  FatalException,ED);
116  }
117 
118  // construction of Geant4 kernel classes
120 
121  defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
122  defaultRegionForParallelWorld = new G4Region("DefaultRegionForParallelWorld"); // deleted by store
124  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
126  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
127 
129  // set the initial application state
131 
132  // version banner
133  G4String vs = G4Version;
134  vs = vs.substr(1,vs.size()-2);
135  versionString = " Geant4 version ";
136  versionString += vs;
137  versionString += " ";
139  G4cout << G4endl
140  << "**************************************************************" << G4endl
141  << versionString << G4endl
142  << " Copyright : Geant4 Collaboration" << G4endl
143  << " References : NIM A 506 (2003), 250-303" << G4endl
144  << " : IEEE-TNS 53 (2006), 270-278" << G4endl
145  << " : NIM A 835 (2016), 186-225" << G4endl
146  << " WWW : http://geant4.org/" << G4endl
147  << "**************************************************************" << G4endl
148  << G4endl;
149 }
150 
152 : physicsList(0),currentWorld(0),
153 geometryInitialized(false),physicsInitialized(false),
154 geometryToBeOptimized(true),
155 physicsNeedsToBeReBuilt(true),verboseLevel(0),
156 numberOfParallelWorld(0),geometryNeedsToBeClosed(true),
157  numberOfStaticAllocators(0)
158 {
159 //This version of the constructor should never be called in sequential mode!
160 #ifndef G4MULTITHREADED
162  msg<<"Geant4 code is compiled without multi-threading support (-DG4MULTITHREADED is set to off).";
163  msg<<" This type of RunManagerKernel can only be used in mult-threaded applications.";
164  G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)","Run0105",FatalException,msg);
165 #endif
166 
167 #ifdef G4FPE_DEBUG
168  if ( G4Threading::IsMasterThread() ) {
170  }
171 #endif
172 
175  {
176  G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0001",
177  FatalException,"More than one G4RunManagerKernel is constructed.");
178  }
179  fRunManagerKernel = this;
180  // construction of Geant4 kernel classes
182 
183  switch(rmkType)
184  {
185  case masterRMK:
186  //Master thread behvior
187  defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
188  defaultRegionForParallelWorld = new G4Region("DefaultRegionForParallelWorld"); // deleted by store
190  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
192  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
193  break;
194  case workerRMK:
195  //Worker thread behavior
196  defaultRegion = G4RegionStore::GetInstance()->GetRegion("DefaultRegionForTheWorld", true);
198  = G4RegionStore::GetInstance()->GetRegion("DefaultRegionForParallelWorld", true);
199  break;
200  default:
201  defaultRegion = 0;
204  msgx<<" This type of RunManagerKernel can only be used in mult-threaded applications.";
205  G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)","Run0106",FatalException,msgx);
206  }
207  runManagerKernelType = rmkType;
208 
209  // set the initial application state
211 
212  // version banner
213  G4String vs = G4Version;
214  vs = vs.substr(1,vs.size()-2);
215  switch(rmkType)
216  {
217  case masterRMK:
218  versionString = " Geant4 version ";
219  versionString += vs;
220  versionString += " ";
222  G4cout << G4endl
223  << "**************************************************************" << G4endl
224  << versionString << G4endl
225  << " << in Multi-threaded mode >> " << G4endl
226  << " Copyright : Geant4 Collaboration" << G4endl
227  << " References : NIM A 506 (2003), 250-303" << G4endl
228  << " : IEEE-TNS 53 (2006), 270-278" << G4endl
229  << " : NIM A 835 (2016), 186-225" << G4endl
230  << " WWW : http://geant4.org/" << G4endl
231  << "**************************************************************" << G4endl
232  << G4endl;
233  break;
234  default:
235  if(verboseLevel) {
236  versionString = " Local thread RunManagerKernel version ";
237  versionString += vs;
238  G4cout << G4endl
239  << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << G4endl
240  << versionString << G4endl
241  << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << G4endl
242  << G4endl;
243  }
244  }
245 
246 #ifdef G4MULTITHREADED
247  G4UnitDefinition::GetUnitsTable().Synchronize();
248 #endif
249 }
250 
252 {
253  if(runManagerKernelType==workerRMK) return;
254 
255  // Remove old world logical volume from the default region, if exist
257  {
258  if(defaultRegion->GetNumberOfRootVolumes()>size_t(1))
259  {
260  G4Exception("G4RunManager::SetupDefaultRegion",
261  "Run0005",
263  "Default world region should have a unique logical volume.");
264  }
265  std::vector<G4LogicalVolume*>::iterator lvItr
267  defaultRegion->RemoveRootLogicalVolume(*lvItr,false);
268  if(verboseLevel>1) G4cout
269  << "Obsolete world logical volume is removed from the default region." << G4endl;
270  }
271 
272 }
273 
275 {
277  // set the application state to the quite state
278  if(pStateManager->GetCurrentState()!=G4State_Quit)
279  {
280  if(verboseLevel>0) G4cout << "G4 kernel has come to Quit state." << G4endl;
281  pStateManager->SetNewState(G4State_Quit);
282  }
283 
284  // open geometry for deletion
286 
287  // deletion of Geant4 kernel classes
289  if(pwps) delete pwps;
291  if(fSDM)
292  {
293  delete fSDM;
294  if(verboseLevel>1) G4cout << "G4SDManager deleted." << G4endl;
295  }
296  delete eventManager;
297  if(verboseLevel>1) G4cout << "EventManager deleted." << G4endl;
298 
300  if(verboseLevel>1) G4cout << "Units table cleared." << G4endl;
301 
302  // deletion of path-finder field-manager store, geometry and transportation manager
304  if (pFinder) delete pFinder;
306  if (fmStore) delete fmStore;
308  if (gManager) delete gManager;
310  if (tManager)
311  {
312  delete tManager;
313  if(verboseLevel>1) G4cout << "TransportationManager deleted." << G4endl;
314  }
315 
316  // deletion of navigation levels
319 
320  // deletion of G4RNGHelper singleton
322  {
324  if(rngHelper)
325  {
326  delete rngHelper;
327  if(verboseLevel>1) G4cout << "G4RNGHelper object is deleted." << G4endl;
328  }
329  }
330 
331  // deletion of allocators
333  if(allocList)
334  {
336  delete allocList;
337  if(verboseLevel>1) G4cout << "G4Allocator objects are deleted." << G4endl;
338  }
339 
340  G4UImanager* pUImanager = G4UImanager::GetUIpointer();
342  {
343  G4cout << "Thread-local UImanager is to be deleted." << G4endl
344  << "There should not be any thread-local G4cout/G4cerr hereafter."
345  << G4endl;
346  verboseLevel = 0;
347  }
348  if(pUImanager) delete pUImanager;
349  if(verboseLevel>1) G4cout << "UImanager deleted." << G4endl;
350 
351  delete pStateManager;
352  if(verboseLevel>1) G4cout << "StateManager deleted." << G4endl;
354  if(verboseLevel>0) G4cout << "RunManagerKernel is deleted. Good bye :)" << G4endl;
355  fRunManagerKernel = 0;
356 }
357 
359 {
362  G4MTRunManager::masterWorlds_t masterWorlds= masterRM->GetMasterWorlds();
363  G4MTRunManager::masterWorlds_t::iterator itrMW = masterWorlds.begin();
364  for(;itrMW!=masterWorlds.end();itrMW++)
365  {
366  G4VPhysicalVolume* wv = (*itrMW).second;
367  G4VPhysicalVolume* pWorld
369  ->IsWorldExisting(wv->GetName());
370  if(!pWorld)
371  { transM->RegisterWorld(wv); }
372  }
373 }
374 
376  G4bool topologyIsChanged)
377 {
379  G4ApplicationState currentState = stateManager->GetCurrentState();
380  if(currentState!=G4State_Init)
381  {
382  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
383  {
384  G4cout << "Current application state is "
385  << stateManager->GetStateString(currentState) << G4endl;
386  G4Exception("G4RunManagerKernel::DefineWorldVolume",
387  "DefineWorldVolumeAtIncorrectState",
389  "Geant4 kernel is not Init state : Method ignored.");
390  return;
391  } else {
392  //G4Exception("G4RunManagerKernel::DefineWorldVolume",
393  // "DefineWorldVolumeAtIncorrectState",
394  // JustWarning,
395  // "Geant4 kernel is not Init state : Assuming Init state.");
396  //G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state."
397  // <<G4endl;
398  stateManager->SetNewState(G4State_Init);
399  }
400  }
401 
402  currentWorld = worldVol;
405  G4MTRunManager::masterWorlds_t masterWorlds= masterRM->GetMasterWorlds();
406  G4MTRunManager::masterWorlds_t::iterator itrMW = masterWorlds.begin();
407  for(;itrMW!=masterWorlds.end();itrMW++)
408  {
409  if((*itrMW).first == 0)
410  {
411  if((*itrMW).second != currentWorld)
412  {
413  G4Exception("G4RunManagerKernel::WorkerDefineWorldVolume","RUN3091",
414  FatalException,"Mass world is inconsistent");
415  }
416  transM->SetWorldForTracking((*itrMW).second);
417  }
418  else
419  {
420  transM->RegisterWorld((*itrMW).second);
421  }
422  }
423 
424  if(topologyIsChanged) geometryNeedsToBeClosed = true;
425 
426  // Notify the VisManager as well
428  {
430  if(pVVisManager) pVVisManager->GeometryHasChanged();
431  }
432 
433  geometryInitialized = true;
434  stateManager->SetNewState(currentState);
435  if(physicsInitialized && currentState!=G4State_Idle)
436  { stateManager->SetNewState(G4State_Idle); }
437 }
438 
440  G4bool topologyIsChanged)
441 {
443  G4ApplicationState currentState = stateManager->GetCurrentState();
444 
445  if(currentState!=G4State_Init)
446  {
447  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
448  {
449  G4cout << "Current application state is "
450  << stateManager->GetStateString(currentState) << G4endl;
451  G4Exception("G4RunManagerKernel::DefineWorldVolume",
452  "DefineWorldVolumeAtIncorrectState",
454  "Geant4 kernel is not Init state : Method ignored.");
455  return;
456  } else {
457  //G4Exception("G4RunManagerKernel::DefineWorldVolume",
458  // "DefineWorldVolumeAtIncorrectState",
459  // JustWarning,
460  // "Geant4 kernel is not Init state : Assuming Init state.");
461  //G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state."
462  // <<G4endl;
463  stateManager->SetNewState(G4State_Init);
464  }
465  }
466 
467  // The world volume MUST NOT have a region defined by the user
468  if(worldVol->GetLogicalVolume()->GetRegion())
469  {
470  if(worldVol->GetLogicalVolume()->GetRegion()!=defaultRegion)
471  {
473  ED << "The world volume has a user-defined region <"
474  << worldVol->GetLogicalVolume()->GetRegion()->GetName()
475  << ">." << G4endl;
476  ED << "World would have a default region assigned by RunManagerKernel."
477  << G4endl;
478  G4Exception("G4RunManager::DefineWorldVolume",
479  "Run0004", FatalException, ED);
480  }
481  }
482 
484 
485  // Accept the world volume
486  currentWorld = worldVol;
487 
488  // Set the default region to the world
489 
491  worldLog->SetRegion(defaultRegion);
493  if(verboseLevel>1) G4cout << worldLog->GetName()
494  << " is registered to the default region." << G4endl;
495 
496  // Set the world volume, notify the Navigator and reset its state
499  if(topologyIsChanged) geometryNeedsToBeClosed = true;
500 
501  // Notify the VisManager as well
503  {
505  if(pVVisManager) pVVisManager->GeometryHasChanged();
506  }
507 
508  geometryInitialized = true;
509  stateManager->SetNewState(currentState);
510  if(physicsInitialized && currentState!=G4State_Idle)
511  { stateManager->SetNewState(G4State_Idle); }
512 }
513 
515 {
516  physicsList = uPhys;
517 
518  if(runManagerKernelType==workerRMK) return;
519 
520  SetupPhysics();
522  if(verboseLevel>1)
523  {
524  G4cout << "List of instantiated particles ============================================" << G4endl;
526  for(G4int i=0;i<nPtcl;i++)
527  {
529  G4cout << pd->GetParticleName() << " ";
530  if(i%10==9) G4cout << G4endl;
531  }
532  G4cout << G4endl;
533  }
534 }
535 
536 #include "G4IonTable.hh"
538 #include "G4IonConstructor.hh"
539 #include "G4Geantino.hh"
540 
542 {
544 
546 
547  // For sanity reason
550  if(gion)
553 
555  pItr->reset();
556  while( (*pItr)() )
557  {
559  if(!(particle->IsGeneralIon())) particle->SetParticleDefinitionID();
560  }
561 
562  if(gion)
563  {
564  G4int gionId = gion->GetParticleDefinitionID();
565  pItr->reset(false);
566  while( (*pItr)() )
567  {
569  if(particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
570  }
571  }
572 #ifdef G4MULTITHREADED
573  G4UnitDefinition::GetUnitsTable().Synchronize();
574 #endif
575 }
576 
577 namespace {
578  G4Mutex initphysicsmutex = G4MUTEX_INITIALIZER;
579 }
580 
582 {
584  G4ApplicationState currentState = stateManager->GetCurrentState();
585  if(currentState!=G4State_Init)
586  {
587  G4cout << "Current application state is "
588  << stateManager->GetStateString(currentState) << G4endl;
589  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
590  {
591  G4Exception("G4RunManagerKernel::InitializePhysics",
592  "InitializePhysicsIncorrectState",
594  "Geant4 kernel is not Init state : Method ignored.");
595  return;
596  } else {
597  //G4Exception("G4RunManagerKernel::DefineWorldVolume",
598  //"DefineWorldVolumeAtIncorrectState",
599  //JustWarning,
600  //"Geant4 kernel is not Init state : Assuming Init state.");
601  G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state."
602  <<G4endl;
603  stateManager->SetNewState(G4State_Init);
604  }
605  }
606 
607  if(!physicsList)
608  {
609  G4Exception("G4RunManagerKernel::InitializePhysics",
610  "Run0012", FatalException,
611  "G4VUserPhysicsList is not defined");
612  return;
613  }
614 
615  if(verboseLevel>1) G4cout << "physicsList->Construct() start." << G4endl;
618 
619  if(verboseLevel>1) G4cout << "physicsList->CheckParticleList() start." << G4endl;
621  //Cannot assume that SetCuts and CheckRegions are thread safe. We need to mutex
622  //Report from valgrind --tool=drd
623  G4AutoLock l(&initphysicsmutex);
624  if ( G4Threading::IsMasterThread() ) {
625  if(verboseLevel>1) G4cout << "physicsList->setCut() start." << G4endl;
626  physicsList->SetCuts();
627 
628  }
629  CheckRegions();
630  l.unlock();
631 
632 /*******************
633 // static G4bool createIsomerOnlyOnce = false;
634 // if(G4Threading::IsMultithreadedApplication() && G4Threading::IsMasterThread())
635 // {
636 // if(!createIsomerOnlyOnce)
637 // {
638 // createIsomerOnlyOnce = true;
639 // G4ParticleDefinition* gion = G4ParticleTable::GetParticleTable()->GetGenericIon();
640 // if(gion)
641 // {
642 // G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer();
643 // PropagateGenericIonID();
644 // }
645 // }
646 // }
647 *********************/
648 
649  physicsInitialized = true;
650 #ifdef G4MULTITHREADED
651  G4UnitDefinition::GetUnitsTable().Synchronize();
652 #endif
653  stateManager->SetNewState(currentState);
654  if(geometryInitialized && currentState!=G4State_Idle)
655  { stateManager->SetNewState(G4State_Idle); }
656 }
657 
659 {
662  G4ApplicationState currentState = stateManager->GetCurrentState();
663 
664  if(!geometryInitialized)
665  {
666  G4Exception("G4RunManagerKernel::RunInitialization",
667  "Run0021",
668  JustWarning,
669  "Geometry has not yet initialized : method ignored.");
670  return false;
671  }
672 
673  if(!physicsInitialized)
674  {
675  G4Exception("G4RunManagerKernel::RunInitialization",
676  "Run0022",
677  JustWarning,
678  "Physics has not yet initialized : method ignored.");
679  return false;
680  }
681 
682  if( currentState != G4State_Idle )
683  {
684  G4Exception("G4RunManagerKernel::RunInitialization",
685  "Run0023",
686  JustWarning,
687  "Geant4 kernel not in Idle state : method ignored.");
688  return false;
689  }
690 
692 
693  stateManager->SetNewState(G4State_Init);
696  UpdateRegion();
697  BuildPhysicsTables(fakeRun);
698 
700  {
701  ResetNavigator();
702  // CheckRegularGeometry();
703  // Notify the VisManager as well
705  {
707  if(pVVisManager) pVVisManager->GeometryHasChanged();
708  }
709  }
710 
712 
713 #ifdef G4MULTITHREADED
714  G4UnitDefinition::GetUnitsTable().Synchronize();
715 #endif
716  stateManager->SetNewState(G4State_Idle);
717  stateManager->SetNewState(G4State_GeomClosed);
718  return true;
719 }
720 
722 {
724  if(gion)
725  {
726  //G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer();
727  G4int gionId = gion->GetParticleDefinitionID();
729  pItr->reset(false);
730  while( (*pItr)() )
731  {
733  if(particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
734  }
735  }
736 }
737 
739 {
743 }
744 
746 {
748  { geometryNeedsToBeClosed = false; return; }
749 
750  // We have to tweak the navigator's state in case a geometry has been
751  // modified between runs. By the following calls we ensure that navigator's
752  // state is reset properly. It is required the geometry to be closed
753  // and previous optimisations to be cleared.
754 
756  if(verboseLevel>1) G4cout << "Start closing geometry." << G4endl;
757 
758  geomManager->OpenGeometry();
760 
761  geometryNeedsToBeClosed = false;
762 }
763 
765 {
767  G4ApplicationState currentState = stateManager->GetCurrentState();
768  if( currentState != G4State_Init )
769  {
770  G4Exception("G4RunManagerKernel::UpdateRegion",
771  "Run0024",
772  JustWarning,
773  "Geant4 kernel not in Init state : method ignored.");
774  return;
775  }
776 
777  if(runManagerKernelType==workerRMK) return;
778 
779  CheckRegions();
780 
782 
784 }
785 
787 {
790  {
792 #ifdef G4MULTITHREADED
794  {
795  // make sure workers also rebuild physics tables
796  G4UImanager* pUImanager = G4UImanager::GetUIpointer();
797  pUImanager->ApplyCommand("/run/physicsModified");
798  }
799 #endif
802  physicsNeedsToBeReBuilt = false;
803  }
804 
805  if(!fakeRun && verboseLevel>1) DumpRegion();
806  if(!fakeRun && verboseLevel>0) physicsList->DumpCutValuesTable();
808 }
809 
811 {
813  size_t nWorlds = transM->GetNoWorlds();
814  std::vector<G4VPhysicalVolume*>::iterator wItr;
815  for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
816  {
817  G4Region* region = (*(G4RegionStore::GetInstance()))[i];
818 
819  //Let each region have a pointer to the world volume where it belongs to.
820  //G4Region::SetWorld() checks if the region belongs to the given world and set it
821  //only if it does. Thus, here we go through all the registered world volumes.
822  region->SetWorld(0); // reset
823  region->UsedInMassGeometry(false);
824  region->UsedInParallelGeometry(false);
825  wItr = transM->GetWorldsIterator();
826  for(size_t iw=0;iw<nWorlds;iw++)
827  {
828  if(region->BelongsTo(*wItr))
829  {
830  if(*wItr==currentWorld)
831  { region->UsedInMassGeometry(true); }
832  else
833  { region->UsedInParallelGeometry(true); }
834  }
835  region->SetWorld(*wItr);
836  wItr++;
837  }
838 
839  G4ProductionCuts* cuts = region->GetProductionCuts();
840  if(!cuts)
841  {
842  if(region->IsInMassGeometry())
843  {
844  G4cout << "Warning : Region <" << region->GetName()
845  << "> does not have specific production cuts," << G4endl
846  << "even though it appears in the current tracking world." << G4endl;
847  G4cout << "Default cuts are used for this region." << G4endl;
848  }
849 
850  if(region->IsInMassGeometry()||region->IsInParallelGeometry())
851  {
852  region->SetProductionCuts(
854  ->GetDefaultProductionCuts());
855  }
856  }
857  }
858 
859  //
860  // If a parallel world has no region, set default region for parallel world
861  //
862 
863  wItr = transM->GetWorldsIterator();
864  for(size_t iw=0;iw<nWorlds;iw++)
865  {
866  //G4cout << "+++ " << (*wItr)->GetName() << G4endl;
867  if(*wItr!=currentWorld)
868  {
869  G4LogicalVolume* pwLogical = (*wItr)->GetLogicalVolume();
870  if(!(pwLogical->GetRegion()))
871  {
874  //G4cout << "+++++ defaultRegionForParallelWorld is set to "
875  // << (*wItr)->GetName() << " +++++" << G4endl;
876  }
877  }
878  wItr++;
879  }
880 
881 }
882 
883 void G4RunManagerKernel::DumpRegion(const G4String& rname) const
884 {
885  G4Region* region = G4RegionStore::GetInstance()->GetRegion(rname);
886  if(region) DumpRegion(region);
887 }
888 
890 {
891  if(!region)
892  {
893  for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
894  { DumpRegion((*(G4RegionStore::GetInstance()))[i]); }
895  }
896  else
897  {
898  if(G4Threading::IsWorkerThread()) return;
899  G4cout << G4endl;
900  G4cout << "Region <" << region->GetName() << "> -- ";
901  if(region->GetWorldPhysical())
902  {
903  G4cout << " -- appears in <"
904  << region->GetWorldPhysical()->GetName() << "> world volume";
905  }
906  else
907  { G4cout << " -- is not associated to any world."; }
908  G4cout << G4endl;
909  if(region->IsInMassGeometry())
910  { G4cout << " This region is in the mass world." << G4endl; }
911  if(region->IsInParallelGeometry())
912  { G4cout << " This region is in the parallel world." << G4endl; }
913 
914  G4cout << " Root logical volume(s) : ";
915  size_t nRootLV = region->GetNumberOfRootVolumes();
916  std::vector<G4LogicalVolume*>::iterator lvItr = region->GetRootLogicalVolumeIterator();
917  for(size_t j=0;j<nRootLV;j++)
918  { G4cout << (*lvItr)->GetName() << " "; lvItr++; }
919  G4cout << G4endl;
920 
921  G4cout << " Pointers : G4VUserRegionInformation[" << region->GetUserInformation()
922  << "], G4UserLimits[" << region->GetUserLimits()
923  << "], G4FastSimulationManager[" << region->GetFastSimulationManager()
924  << "], G4UserSteppingAction[" << region->GetRegionalSteppingAction() << "]" << G4endl;
925 
926  G4cout << " Materials : ";
927  std::vector<G4Material*>::const_iterator mItr = region->GetMaterialIterator();
928  size_t nMaterial = region->GetNumberOfMaterials();
929  for(size_t iMate=0;iMate<nMaterial;iMate++)
930  {
931  G4cout << (*mItr)->GetName() << " ";
932  mItr++;
933  }
934  G4cout << G4endl;
935  G4ProductionCuts* cuts = region->GetProductionCuts();
936  if(!cuts && region->IsInMassGeometry())
937  {
938  G4cerr << "Warning : Region <" << region->GetName()
939  << "> does not have specific production cuts." << G4endl;
940  G4cerr << "Default cuts are used for this region." << G4endl;
941  region->SetProductionCuts(
942  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
943  }
944  else if(cuts)
945  {
946  G4cout << " Production cuts : "
947  << " gamma "
948  << G4BestUnit(cuts->GetProductionCut("gamma"),"Length")
949  << " e- "
950  << G4BestUnit(cuts->GetProductionCut("e-"),"Length")
951  << " e+ "
952  << G4BestUnit(cuts->GetProductionCut("e+"),"Length")
953  << " proton "
954  << G4BestUnit(cuts->GetProductionCut("proton"),"Length")
955  << G4endl;
956  }
957  }
958 }
959 
960 #include "G4LogicalVolumeStore.hh"
962 {
964  for(G4LogicalVolumeStore::iterator pos=store->begin(); pos!=store->end(); pos++)
965  {
966  if((*pos)&&((*pos)->GetNoDaughters()==1))
967  {
968  if((*pos)->GetDaughter(0)->IsRegularStructure())
969  {
971  return;
972  }
973  }
974  }
975 }
976 
977 #include "G4ParticleTable.hh"
978 #include "G4ParticleDefinition.hh"
979 #include "G4ProcessManager.hh"
980 #include "G4ProcessVector.hh"
981 #include "G4VProcess.hh"
983 {
986  theParticleIterator->reset();
987  while((*theParticleIterator)())
988  {
989  G4ParticleDefinition* pd = theParticleIterator->value();
991  if(pm)
992  {
994  G4VProcess* p = (*pv)[0];
995  return ( (p->GetProcessName()) == "CoupledTransportation" );
996  }
997  }
998  return false;
999 }
1000 
1001 #include "G4ScoreSplittingProcess.hh"
1003 {
1005  G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
1007 
1008  // Ensure that Process is added only once to the particles' process managers
1009  static G4ThreadLocal bool InitSplitter=false;
1010  if( ! InitSplitter ) {
1011  InitSplitter = true;
1012 
1013  theParticleIterator->reset();
1014  while( (*theParticleIterator)() )
1015  {
1016  G4ParticleDefinition* particle = theParticleIterator->value();
1017  G4ProcessManager* pmanager = particle->GetProcessManager();
1018  if(pmanager)
1019  { pmanager->AddDiscreteProcess(pSplitter); }
1020  }
1021 
1022  if(verboseLevel>0)
1023  {
1024  G4cout << "G4RunManagerKernel -- G4ScoreSplittingProcess is appended to all particles." << G4endl;
1025  }
1026  }
1027 }
1028 
1030 {
1031  G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
1033  theParticleIterator->reset();
1034  //loop on particles and get process manager from there list of processes
1035  while((*theParticleIterator)())
1036  {
1037  G4ParticleDefinition* pd = theParticleIterator->value();
1039  if(pm)
1040  {
1041  G4ProcessVector& procs = *(pm->GetProcessList());
1042  for ( std::size_t idx = 0 ; idx<procs.size() ; ++idx)
1043  {
1044  const G4VProcess* masterP = procs[idx]->GetMasterProcess();
1045  if ( ! masterP )
1046  {
1047  //Process does not have an associated shadow master process
1048  //We are in master mode or sequential
1049  procs[idx]->SetMasterProcess(const_cast<G4VProcess*>(procs[idx]));
1050  }
1051  }
1052  }
1053  }
1054 }