Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4RunManagerKernel.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// G4RunManagerKernel implementation
27//
28// Author: M.Asai, 1 August 2003
29// --------------------------------------------------------------------
30
31#include <vector>
32
33#include "G4RunManagerKernel.hh"
34
35#include "G4ApplicationState.hh"
36#include "G4ExceptionHandler.hh"
38#include "G4GeometryManager.hh"
39#include "G4LogicalVolume.hh"
41#include "G4PathFinder.hh"
43#include "G4StateManager.hh"
45#include "G4VPhysicalVolume.hh"
46#include "G4VUserPhysicsList.hh"
48
50#include "G4ParticleTable.hh"
51#include "G4ProductionCuts.hh"
53#include "G4Region.hh"
54#include "G4RegionStore.hh"
55#include "G4SDManager.hh"
56#include "G4TiMemory.hh"
57#include "G4UImanager.hh"
58#include "G4UnitsTable.hh"
59#include "G4VVisManager.hh"
60#include "G4Version.hh"
61#include "G4ios.hh"
62
63#include "G4Geantino.hh"
64#include "G4IonConstructor.hh"
65#include "G4IonTable.hh"
68#include "G4ParticleTable.hh"
69#include "G4ProcessManager.hh"
70#include "G4ProcessVector.hh"
71#include "G4VProcess.hh"
73
74#include "G4AllocatorList.hh"
75#include "G4MTRunManager.hh"
76
77#include "G4AutoLock.hh"
78#include "G4RNGHelper.hh"
79
80#ifdef G4BT_DEBUG
81# include "G4Backtrace.hh"
82#endif
83
84#ifdef G4FPE_DEBUG
85# include "G4FPEDetection.hh"
86#endif
87
88// The following lines are needed since G4VUserPhysicsList
89// uses a #define theParticleIterator
90#ifdef theParticleIterator
91# undef theParticleIterator
92#endif
93
95G4RunManagerKernel::fRunManagerKernel = nullptr;
96
97// --------------------------------------------------------------------
99{
100 return fRunManagerKernel;
101}
102
103// --------------------------------------------------------------------
105{
106 #ifdef G4FPE_DEBUG
107 InvalidOperationDetection();
108 #endif
109
110 #ifdef G4BT_DEBUG
111 auto _signals = G4GetEnv<std::string>("G4BACKTRACE", "");
112 if(_signals.empty())
113 {
115 }
116 else
117 {
118 G4Backtrace::Enable(_signals);
119 }
120 #endif
121
123 if(allocList != nullptr)
124 numberOfStaticAllocators = (G4int)allocList->Size();
125
127 {
128 defaultExceptionHandler = new G4ExceptionHandler();
129 }
130 if(fRunManagerKernel != nullptr)
131 {
132 G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0001",
134 "More than one G4RunManagerKernel is constructed.");
135 }
136 fRunManagerKernel = this;
137
139 if(particleTable->entries() > 0)
140 {
141 // No particle should be registered beforehand
143 ED << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << G4endl;
144 ED << " G4RunManagerKernel fatal exception" << G4endl;
145 ED << " -- Following particles have already been registered" << G4endl;
146 ED << " before G4RunManagerKernel is instantiated." << G4endl;
147 for(G4int i = 0; i < particleTable->entries(); ++i)
148 {
149 ED << " " << particleTable->GetParticle(i)->GetParticleName()
150 << G4endl;
151 }
152 ED << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << G4endl;
153 G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0002",
154 FatalException, ED);
155 }
156
157 // construction of Geant4 kernel classes
158 eventManager = new G4EventManager();
159
160 defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
162 new G4Region("DefaultRegionForParallelWorld"); // deleted by store
165 ->GetDefaultProductionCuts());
168 ->GetDefaultProductionCuts());
169
171 // set the initial application state
173
174 // version banner
175 G4String vs = G4Version;
176 vs = vs.substr(1, vs.size() - 2);
177 versionString = " Geant4 version ";
178 versionString += vs;
179 versionString += " ";
180 versionString += G4Date;
181 G4cout << G4endl
182 << "**************************************************************"
183 << G4endl << versionString << G4endl
184 << " Copyright : Geant4 Collaboration" << G4endl
185 << " References : NIM A 506 (2003), 250-303"
186 << G4endl
187 << " : IEEE-TNS 53 (2006), 270-278"
188 << G4endl
189 << " : NIM A 835 (2016), 186-225"
190 << G4endl << " WWW : http://geant4.org/"
191 << G4endl
192 << "**************************************************************"
193 << G4endl << G4endl;
194}
195
196// --------------------------------------------------------------------
198{
199 // This version of the constructor should never be called in sequential mode!
200 #ifndef G4MULTITHREADED
202 msg << "Geant4 code is compiled without multi-threading support "
203 "(-DG4MULTITHREADED is set to off).";
204 msg << " This type of RunManagerKernel can only be used in mult-threaded "
205 "applications.";
206 G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)", "Run0105",
207 FatalException, msg);
208 #endif
209
210 #ifdef G4FPE_DEBUG
212 {
213 InvalidOperationDetection();
214 }
215 #endif
216
217 #ifdef G4BT_DEBUG
218 auto _signals = G4GetEnv<std::string>("G4BACKTRACE", "");
219 if(_signals.empty())
220 {
222 }
223 else
224 {
225 G4Backtrace::Enable(_signals);
226 }
227 #endif
228
229 if(G4StateManager::GetStateManager()->GetExceptionHandler() == nullptr)
230 {
231 defaultExceptionHandler = new G4ExceptionHandler();
232 }
233
234 if(fRunManagerKernel != nullptr)
235 {
236 G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0001",
238 "More than one G4RunManagerKernel is constructed.");
239 }
240 fRunManagerKernel = this;
241 // construction of Geant4 kernel classes
242 eventManager = new G4EventManager();
243
244 switch(rmkType)
245 {
246 case masterRMK:
247 // Master thread behvior
249 new G4Region("DefaultRegionForTheWorld"); // deleted by store
251 new G4Region("DefaultRegionForParallelWorld"); // deleted by store
254 ->GetDefaultProductionCuts());
257 ->GetDefaultProductionCuts());
258 break;
259 case workerRMK:
260 // Worker thread behavior
262 "DefaultRegionForTheWorld", true);
264 "DefaultRegionForParallelWorld", true);
265 break;
266 default:
267 defaultRegion = nullptr;
270 msgx
271 << " This type of RunManagerKernel can only be used in mult-threaded "
272 "applications.";
273 G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)", "Run0106",
274 FatalException, msgx);
275 }
276 runManagerKernelType = rmkType;
277
278 // set the initial application state
280
281 // version banner
282 G4String vs = G4Version;
283 vs = vs.substr(1, vs.size() - 2);
284 switch(rmkType)
285 {
286 case masterRMK:
287 versionString = " Geant4 version ";
288 versionString += vs;
289 versionString += " ";
290 versionString += G4Date;
291 G4cout << G4endl
292 << "**************************************************************"
293 << G4endl << versionString << G4endl
294 << " << in Multi-threaded mode >> " << G4endl
295 << " Copyright : Geant4 Collaboration"
296 << G4endl
297 << " References : NIM A 506 (2003), 250-303"
298 << G4endl
299 << " : IEEE-TNS 53 (2006), 270-278"
300 << G4endl
301 << " : NIM A 835 (2016), 186-225"
302 << G4endl
303 << " WWW : http://geant4.org/"
304 << G4endl
305 << "**************************************************************"
306 << G4endl << G4endl;
307 break;
308 default:
309 if(verboseLevel)
310 {
311 versionString = " Local thread RunManagerKernel version ";
312 versionString += vs;
313 G4cout
314 << G4endl
315 << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
316 "^^^^^^^^^"
317 << G4endl << versionString << G4endl
318 << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
319 "^^^^^^^^^"
320 << G4endl << G4endl;
321 }
322 }
323
324 #ifdef G4MULTITHREADED
325 G4UnitDefinition::GetUnitsTable().Synchronize();
326 #endif
327}
328
329// --------------------------------------------------------------------
331{
333 return;
334
335 // Remove old world logical volume from the default region, if exist
337 {
338 if(defaultRegion->GetNumberOfRootVolumes() > size_t(1))
339 {
340 G4Exception("G4RunManager::SetupDefaultRegion", "Run0005", FatalException,
341 "Default world region should have a unique logical volume.");
342 }
345 if(verboseLevel > 1)
346 G4cout
347 << "Obsolete world logical volume is removed from the default region."
348 << G4endl;
349 }
350}
351
352// --------------------------------------------------------------------
354{
356 // set the application state to the quite state
357 if(pStateManager->GetCurrentState() != G4State_Quit)
358 {
359 if(verboseLevel > 1)
360 G4cout << "G4 kernel has come to Quit state." << G4endl;
361 pStateManager->SetNewState(G4State_Quit);
362 }
363
364 // open geometry for deletion
366
367 // deletion of Geant4 kernel classes
370 if(verboseLevel > 1)
371 G4cout << "G4SDManager deleted." << G4endl;
372 delete eventManager;
373 if(verboseLevel > 1)
374 G4cout << "EventManager deleted." << G4endl;
375
377 if(verboseLevel > 1)
378 G4cout << "Units table cleared." << G4endl;
379
380 // deletion of path-finder field-manager store, geometry and transportation
381 // manager
386 if(verboseLevel > 1)
387 G4cout << "TransportationManager deleted." << G4endl;
388
389 // deletion of navigation levels
390 if(verboseLevel > 1)
393
394 // deletion of G4RNGHelper singleton
396 {
398 if(verboseLevel > 1)
399 G4cout << "G4RNGHelper object is deleted." << G4endl;
400 }
401
402 // deletion of allocators
404 if(allocList)
405 {
406 allocList->Destroy(numberOfStaticAllocators, verboseLevel);
407 delete allocList;
408 if(verboseLevel > 1)
409 G4cout << "G4Allocator objects are deleted." << G4endl;
410 }
411
413 if((runManagerKernelType == workerRMK) && (verboseLevel > 1))
414 {
415 G4cout << "Thread-local UImanager is to be deleted." << G4endl
416 << "There should not be any thread-local G4cout/G4cerr hereafter."
417 << G4endl;
418 }
419 delete pUImanager;
420 if(verboseLevel > 1)
421 G4cout << "UImanager deleted." << G4endl;
422
423 delete pStateManager;
424 if(verboseLevel > 1)
425 G4cout << "StateManager deleted." << G4endl;
426 delete defaultExceptionHandler;
427 if(verboseLevel > 1)
428 G4cout << "RunManagerKernel is deleted. Good bye :)" << G4endl;
429 fRunManagerKernel = nullptr;
430}
431
432// --------------------------------------------------------------------
434{
438 G4MTRunManager::masterWorlds_t masterWorlds = masterRM->GetMasterWorlds();
439 for(auto itrMW = masterWorlds.cbegin();
440 itrMW != masterWorlds.cend(); ++itrMW)
441 {
442 G4VPhysicalVolume* wv = (*itrMW).second;
443 G4VPhysicalVolume* pWorld =
445 ->IsWorldExisting(wv->GetName());
446 if(pWorld == nullptr)
447 {
448 transM->RegisterWorld(wv);
449 }
450 }
451}
452
453// --------------------------------------------------------------------
455 G4bool topologyIsChanged)
456{
458 G4ApplicationState currentState = stateManager->GetCurrentState();
459 if(currentState != G4State_Init)
460 {
461 if(!(currentState == G4State_Idle || currentState == G4State_PreInit))
462 {
463 G4cout << "Current application state is "
464 << stateManager->GetStateString(currentState) << G4endl;
465 G4Exception("G4RunManagerKernel::DefineWorldVolume",
466 "DefineWorldVolumeAtIncorrectState", FatalException,
467 "Geant4 kernel is not Init state : Method ignored.");
468 return;
469 }
470 else
471 {
472 stateManager->SetNewState(G4State_Init);
473 }
474 }
475
476 currentWorld = worldVol;
480 G4MTRunManager::masterWorlds_t masterWorlds = masterRM->GetMasterWorlds();
481 for(auto itrMW = masterWorlds.cbegin();
482 itrMW != masterWorlds.cend(); ++itrMW)
483 {
484 if((*itrMW).first == 0)
485 {
486 if((*itrMW).second != currentWorld)
487 {
488 G4Exception("G4RunManagerKernel::WorkerDefineWorldVolume", "RUN3091",
489 FatalException, "Mass world is inconsistent");
490 }
491 transM->SetWorldForTracking((*itrMW).second);
492 }
493 else
494 {
495 transM->RegisterWorld((*itrMW).second);
496 }
497 }
498
499 if(topologyIsChanged)
501
502 // Notify the VisManager as well
504 {
506 if(pVVisManager != nullptr)
507 pVVisManager->GeometryHasChanged();
508 }
509
510 geometryInitialized = true;
511 stateManager->SetNewState(currentState);
512 if(physicsInitialized && currentState != G4State_Idle)
513 {
514 stateManager->SetNewState(G4State_Idle);
515 }
516}
517
518// --------------------------------------------------------------------
520 G4bool topologyIsChanged)
521{
523 G4ApplicationState currentState = stateManager->GetCurrentState();
524
525 if(currentState != G4State_Init)
526 {
527 if(!(currentState == G4State_Idle || currentState == G4State_PreInit))
528 {
529 G4cout << "Current application state is "
530 << stateManager->GetStateString(currentState) << G4endl;
531 G4Exception("G4RunManagerKernel::DefineWorldVolume",
532 "DefineWorldVolumeAtIncorrectState", FatalException,
533 "Geant4 kernel is not Init state : Method ignored.");
534 return;
535 }
536 else
537 {
538 stateManager->SetNewState(G4State_Init);
539 }
540 }
541
542 // The world volume MUST NOT have a region defined by the user
543 if(worldVol->GetLogicalVolume()->GetRegion() != nullptr)
544 {
545 if(worldVol->GetLogicalVolume()->GetRegion() != defaultRegion)
546 {
548 ED << "The world volume has a user-defined region <"
549 << worldVol->GetLogicalVolume()->GetRegion()->GetName() << ">."
550 << G4endl;
551 ED << "World would have a default region assigned by RunManagerKernel."
552 << G4endl;
553 G4Exception("G4RunManager::DefineWorldVolume", "Run0004", FatalException,
554 ED);
555 }
556 }
557
559
560 // Accept the world volume
561 currentWorld = worldVol;
562
563 // Set the default region to the world
564
565 G4LogicalVolume* worldLog = currentWorld->GetLogicalVolume();
566 worldLog->SetRegion(defaultRegion);
568 if(verboseLevel > 1)
569 G4cout << worldLog->GetName() << " is registered to the default region."
570 << G4endl;
571
572 // Set the world volume, notify the Navigator and reset its state
574 ->SetWorldForTracking(currentWorld);
575 if(topologyIsChanged)
577
578 // Notify the VisManager as well
580 {
582 if(pVVisManager != nullptr)
583 pVVisManager->GeometryHasChanged();
584 }
585
586 geometryInitialized = true;
587 stateManager->SetNewState(currentState);
588 if(physicsInitialized && currentState != G4State_Idle)
589 {
590 stateManager->SetNewState(G4State_Idle);
591 }
592}
593
594// --------------------------------------------------------------------
596{
597 physicsList = uPhys;
598
600 return;
601
602 SetupPhysics();
603 if(verboseLevel > 2)
605 if(verboseLevel > 1)
606 {
607 G4cout << "List of instantiated particles "
608 "============================================"
609 << G4endl;
611 for(G4int i = 0; i < nPtcl; ++i)
612 {
615 G4cout << pd->GetParticleName() << " ";
616 if(i % 10 == 9)
617 G4cout << G4endl;
618 }
619 G4cout << G4endl;
620 }
621}
622
623// --------------------------------------------------------------------
625{
627
628 physicsList->ConstructParticle();
629
630 // For sanity reason
634 if(gion != nullptr)
635 {
637 }
639
641 pItr->reset();
642 while((*pItr)())
643 {
644 G4ParticleDefinition* particle = pItr->value();
645 if(!(particle->IsGeneralIon()))
646 particle->SetParticleDefinitionID();
647 }
648
649 if(gion != nullptr)
650 {
651 G4int gionId = gion->GetParticleDefinitionID();
652 pItr->reset(false);
653 while((*pItr)())
654 {
655 G4ParticleDefinition* particle = pItr->value();
656 if(particle->IsGeneralIon())
657 particle->SetParticleDefinitionID(gionId);
658 }
659 }
660#ifdef G4MULTITHREADED
661 G4UnitDefinition::GetUnitsTable().Synchronize();
662#endif
663}
664
665// --------------------------------------------------------------------
666namespace
667{
668 G4Mutex initphysicsmutex = G4MUTEX_INITIALIZER;
669}
670
671// --------------------------------------------------------------------
673{
675 G4ApplicationState currentState = stateManager->GetCurrentState();
676 if(currentState != G4State_Init)
677 {
678 G4cout << "Current application state is "
679 << stateManager->GetStateString(currentState) << G4endl;
680 if(!(currentState == G4State_Idle || currentState == G4State_PreInit))
681 {
682 G4Exception("G4RunManagerKernel::InitializePhysics",
683 "InitializePhysicsIncorrectState", FatalException,
684 "Geant4 kernel is not Init state : Method ignored.");
685 return;
686 }
687 else
688 {
689 // G4Exception("G4RunManagerKernel::DefineWorldVolume",
690 // "DefineWorldVolumeAtIncorrectState", JustWarning,
691 // "Geant4 kernel is not Init state : Assuming Init state.");
692 G4cout
693 << "Warning : Geant4 kernel is not Init state : Assuming Init state."
694 << G4endl;
695 stateManager->SetNewState(G4State_Init);
696 }
697 }
698
699 if(physicsList == nullptr)
700 {
701 G4Exception("G4RunManagerKernel::InitializePhysics", "Run0012",
702 FatalException, "G4VUserPhysicsList is not defined");
703 return;
704 }
705
706 if(verboseLevel > 1)
707 G4cout << "physicsList->Construct() start." << G4endl;
708 if(numberOfParallelWorld > 0)
709 physicsList->UseCoupledTransportation();
710 physicsList->Construct();
711
712 if(verboseLevel > 1)
713 G4cout << "physicsList->CheckParticleList() start." << G4endl;
714 physicsList->CheckParticleList();
715
716 // Cannot assume that SetCuts() and CheckRegions() are thread safe.
717 // We need to mutex (report from valgrind --tool=drd)
718 G4AutoLock l(&initphysicsmutex);
720 {
721 if(verboseLevel > 1)
722 G4cout << "physicsList->setCut() start." << G4endl;
723 physicsList->SetCuts();
724 }
725 CheckRegions();
726 l.unlock();
727
728 /*******************
729 // static G4bool createIsomerOnlyOnce = false;
730 // if(G4Threading::IsMultithreadedApplication() &&
731 G4Threading::IsMasterThread())
732 // {
733 // if(!createIsomerOnlyOnce)
734 // {
735 // createIsomerOnlyOnce = true;
736 // G4ParticleDefinition* gion =
737 G4ParticleTable::GetParticleTable()->GetGenericIon();
738 // if(gion != nullptr)
739 // {
740 // G4ParticleTable::GetParticleTable()
741 ->GetIonTable()->CreateAllIsomer();
742 // PropagateGenericIonID();
743 // }
744 // }
745 // }
746 *********************/
747
748 physicsInitialized = true;
749#ifdef G4MULTITHREADED
750 G4UnitDefinition::GetUnitsTable().Synchronize();
751#endif
752 stateManager->SetNewState(currentState);
753 if(geometryInitialized && currentState != G4State_Idle)
754 {
755 stateManager->SetNewState(G4State_Idle);
756 }
757}
758
759// --------------------------------------------------------------------
761{
763 G4ApplicationState currentState = stateManager->GetCurrentState();
764
765 if(!geometryInitialized)
766 {
767 G4Exception("G4RunManagerKernel::RunInitialization", "Run0021", JustWarning,
768 "Geometry has not yet initialized : method ignored.");
769 return false;
770 }
771
772 if(!physicsInitialized)
773 {
774 G4Exception("G4RunManagerKernel::RunInitialization", "Run0022", JustWarning,
775 "Physics has not yet initialized : method ignored.");
776 return false;
777 }
778
779 if(currentState != G4State_Idle)
780 {
781 G4Exception("G4RunManagerKernel::RunInitialization", "Run0023", JustWarning,
782 "Geant4 kernel not in Idle state : method ignored.");
783 return false;
784 }
785
787 CheckRegularGeometry();
788
789 stateManager->SetNewState(G4State_Init);
792 UpdateRegion();
793 BuildPhysicsTables(fakeRun);
794
796 {
798 // CheckRegularGeometry();
799 // Notify the VisManager as well
801 {
803 if(pVVisManager != nullptr)
804 pVVisManager->GeometryHasChanged();
805 }
806 }
807
809
810#ifdef G4MULTITHREADED
811 G4UnitDefinition::GetUnitsTable().Synchronize();
812#endif
813 stateManager->SetNewState(G4State_Idle);
814 stateManager->SetNewState(G4State_GeomClosed);
815 return true;
816}
817
818// --------------------------------------------------------------------
820{
823 if(gion != nullptr)
824 {
825 // G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer();
826 G4int gionId = gion->GetParticleDefinitionID();
828 pItr->reset(false);
829 while((*pItr)())
830 {
831 G4ParticleDefinition* particle = pItr->value();
832 if(particle->IsGeneralIon())
833 particle->SetParticleDefinitionID(gionId);
834 }
835 }
836}
837
838// --------------------------------------------------------------------
840{
844}
845
846// --------------------------------------------------------------------
848{
850 {
852 return;
853 }
854
855 // We have to tweak the navigator's state in case a geometry has been
856 // modified between runs. By the following calls we ensure that navigator's
857 // state is reset properly. It is required the geometry to be closed
858 // and previous optimisations to be cleared.
859
861 if(verboseLevel > 1)
862 G4cout << "Start closing geometry." << G4endl;
863
864 geomManager->OpenGeometry();
865 geomManager->CloseGeometry(geometryToBeOptimized, verboseLevel > 1);
866
868}
869
870// --------------------------------------------------------------------
872{
874 G4ApplicationState currentState = stateManager->GetCurrentState();
875 if(currentState != G4State_Init)
876 {
877 G4Exception("G4RunManagerKernel::UpdateRegion", "Run0024", JustWarning,
878 "Geant4 kernel not in Init state : method ignored.");
879 return;
880 }
881
883 return;
884
885 CheckRegions();
886
888
890 currentWorld);
891}
892
893// --------------------------------------------------------------------
895{
897 physicsNeedsToBeReBuilt)
898 {
899 #ifdef G4MULTITHREADED
901 {
902 // make sure workers also rebuild physics tables
904 pUImanager->ApplyCommand("/run/physicsModified");
905 }
906 #endif
907 physicsList->BuildPhysicsTable();
908 ////G4ProductionCutsTable::GetProductionCutsTable()->PhysicsTableUpdated();
909 physicsNeedsToBeReBuilt = false;
910 }
911
912 if(!fakeRun && verboseLevel > 1)
913 DumpRegion();
914 if(!fakeRun && verboseLevel > 0)
915 physicsList->DumpCutValuesTable();
916 if(!fakeRun)
917 physicsList->DumpCutValuesTableIfRequested();
918}
919
920// --------------------------------------------------------------------
922{
925 std::size_t nWorlds = transM->GetNoWorlds();
926 std::vector<G4VPhysicalVolume*>::iterator wItr;
927 for(std::size_t i = 0; i < G4RegionStore::GetInstance()->size(); ++i)
928 {
929 G4Region* region = (*(G4RegionStore::GetInstance()))[i];
930
931 // Let each region have a pointer to the world volume where it belongs to.
932 // G4Region::SetWorld() checks if the region belongs to the given world and
933 // set it only if it does. Thus, here we go through all the registered world
934 // volumes.
935 region->SetWorld(nullptr); // reset
936 region->UsedInMassGeometry(false);
937 region->UsedInParallelGeometry(false);
938 wItr = transM->GetWorldsIterator();
939 for(std::size_t iw = 0; iw < nWorlds; ++iw)
940 {
941 if(region->BelongsTo(*wItr))
942 {
943 if(*wItr == currentWorld)
944 {
945 region->UsedInMassGeometry(true);
946 }
947 else
948 {
949 region->UsedInParallelGeometry(true);
950 }
951 }
952 region->SetWorld(*wItr);
953 ++wItr;
954 }
955
956 G4ProductionCuts* cuts = region->GetProductionCuts();
957 if(cuts == nullptr)
958 {
959 if(region->IsInMassGeometry() && verboseLevel > 0)
960 {
961 G4cout << "Warning : Region <" << region->GetName()
962 << "> does not have specific production cuts," << G4endl
963 << "even though it appears in the current tracking world."
964 << G4endl;
965 G4cout << "Default cuts are used for this region." << G4endl;
966 }
967
968 if(region->IsInMassGeometry() || region->IsInParallelGeometry())
969 {
970 region->SetProductionCuts(
973 }
974 }
975 }
976
977 //
978 // If a parallel world has no region, set default region for parallel world
979 //
980
981 wItr = transM->GetWorldsIterator();
982 for(std::size_t iw = 0; iw < nWorlds; ++iw)
983 {
984 if(*wItr != currentWorld)
985 {
986 G4LogicalVolume* pwLogical = (*wItr)->GetLogicalVolume();
987 if(pwLogical->GetRegion() == nullptr)
988 {
991 }
992 }
993 ++wItr;
994 }
995}
996
997// --------------------------------------------------------------------
999{
1000 G4Region* region = G4RegionStore::GetInstance()->GetRegion(rname);
1001 if(region != nullptr)
1002 DumpRegion(region);
1003}
1004
1005// --------------------------------------------------------------------
1007{
1008 if(region == nullptr)
1009 {
1010 for(std::size_t i = 0; i < G4RegionStore::GetInstance()->size(); ++i)
1011 {
1013 }
1014 }
1015 else
1016 {
1018 return;
1019 G4cout << G4endl;
1020 G4cout << "Region <" << region->GetName() << "> -- ";
1021 if(region->GetWorldPhysical())
1022 {
1023 G4cout << " -- appears in <" << region->GetWorldPhysical()->GetName()
1024 << "> world volume";
1025 }
1026 else
1027 {
1028 G4cout << " -- is not associated to any world.";
1029 }
1030 G4cout << G4endl;
1031 if(region->IsInMassGeometry())
1032 {
1033 G4cout << " This region is in the mass world." << G4endl;
1034 }
1035 if(region->IsInParallelGeometry())
1036 {
1037 G4cout << " This region is in the parallel world." << G4endl;
1038 }
1039
1040 G4cout << " Root logical volume(s) : ";
1041 std::size_t nRootLV = region->GetNumberOfRootVolumes();
1042 auto lvItr = region->GetRootLogicalVolumeIterator();
1043 for(std::size_t j = 0; j < nRootLV; ++j)
1044 {
1045 G4cout << (*lvItr)->GetName() << " ";
1046 ++lvItr;
1047 }
1048 G4cout << G4endl;
1049
1050 G4cout << " Pointers : G4VUserRegionInformation["
1051 << region->GetUserInformation() << "], G4UserLimits["
1052 << region->GetUserLimits() << "], G4FastSimulationManager["
1053 << region->GetFastSimulationManager() << "], G4UserSteppingAction["
1054 << region->GetRegionalSteppingAction() << "]" << G4endl;
1055
1056 G4cout << " Materials : ";
1057 auto mItr = region->GetMaterialIterator();
1058 std::size_t nMaterial = region->GetNumberOfMaterials();
1059 for(std::size_t iMate = 0; iMate < nMaterial; ++iMate)
1060 {
1061 G4cout << (*mItr)->GetName() << " ";
1062 ++mItr;
1063 }
1064 G4cout << G4endl;
1065 G4ProductionCuts* cuts = region->GetProductionCuts();
1066 if(!cuts && region->IsInMassGeometry())
1067 {
1068 G4cerr << "Warning : Region <" << region->GetName()
1069 << "> does not have specific production cuts." << G4endl;
1070 G4cerr << "Default cuts are used for this region." << G4endl;
1072 ->GetDefaultProductionCuts());
1073 }
1074 else if(cuts != nullptr)
1075 {
1076 G4cout << " Production cuts : "
1077 << " gamma "
1078 << G4BestUnit(cuts->GetProductionCut("gamma"), "Length")
1079 << " e- " << G4BestUnit(cuts->GetProductionCut("e-"), "Length")
1080 << " e+ " << G4BestUnit(cuts->GetProductionCut("e+"), "Length")
1081 << " proton "
1082 << G4BestUnit(cuts->GetProductionCut("proton"), "Length")
1083 << G4endl;
1084 }
1085 }
1086}
1087
1088// --------------------------------------------------------------------
1089void G4RunManagerKernel::CheckRegularGeometry()
1090{
1092 for(auto pos = store->cbegin(); pos != store->cend(); ++pos)
1093 {
1094 if((*pos) && ((*pos)->GetNoDaughters() == 1))
1095 {
1096 if((*pos)->GetDaughter(0)->IsRegularStructure())
1097 {
1098 SetScoreSplitter();
1099 return;
1100 }
1101 }
1102 }
1103}
1104
1105// --------------------------------------------------------------------
1106G4bool G4RunManagerKernel::ConfirmCoupledTransportation()
1107{
1109 auto theParticleIterator = theParticleTable->GetIterator();
1110 theParticleIterator->reset();
1111 while((*theParticleIterator)())
1112 {
1115 if(pm)
1116 {
1118 G4VProcess* p = (*pv)[0];
1119 return ((p->GetProcessName()) == "CoupledTransportation");
1120 }
1121 }
1122 return false;
1123}
1124
1125// --------------------------------------------------------------------
1126void G4RunManagerKernel::SetScoreSplitter()
1127{
1130 auto theParticleIterator = theParticleTable->GetIterator();
1131
1132 // Ensure that Process is added only once to the particles' process managers
1133 static G4ThreadLocal G4bool InitSplitter = false;
1134 if(!InitSplitter)
1135 {
1136 InitSplitter = true;
1137
1138 theParticleIterator->reset();
1139 while((*theParticleIterator)())
1140 {
1141 G4ParticleDefinition* particle = theParticleIterator->value();
1142 G4ProcessManager* pmanager = particle->GetProcessManager();
1143 if(pmanager)
1144 {
1145 pmanager->AddDiscreteProcess(pSplitter);
1146 }
1147 }
1148
1149 if(verboseLevel > 0)
1150 {
1151 G4cout
1152 << "G4RunManagerKernel -- G4ScoreSplittingProcess is appended to all "
1153 "particles."
1154 << G4endl;
1155 }
1156 }
1157}
1158
1159// --------------------------------------------------------------------
1161{
1163 auto theParticleIterator = theParticleTable->GetIterator();
1164 theParticleIterator->reset();
1165 // loop on particles and get process manager from there list of processes
1166 while((*theParticleIterator)())
1167 {
1170 if(pm != nullptr)
1171 {
1172 G4ProcessVector& procs = *(pm->GetProcessList());
1173 for(G4int idx = 0; idx < (G4int)procs.size(); ++idx)
1174 {
1175 const G4VProcess* masterP = procs[idx]->GetMasterProcess();
1176 if(masterP == nullptr)
1177 {
1178 // Process does not have an associated shadow master process
1179 // We are in master mode or sequential
1180 procs[idx]->SetMasterProcess(const_cast<G4VProcess*>(procs[idx]));
1181 }
1182 }
1183 }
1184 }
1185}
G4ApplicationState
@ G4State_Init
@ G4State_Idle
@ G4State_Quit
@ G4State_GeomClosed
@ G4State_PreInit
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
@ typeDoIt
#define G4BestUnit(a, b)
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:85
std::mutex G4Mutex
Definition: G4Threading.hh:81
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define theParticleIterator
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4AllocatorList * GetAllocatorListIfExist()
std::size_t Size() const
void Destroy(G4int nStat=0, G4int verboseLevel=0)
static G4int Enable(const std::string &)
Definition: G4Backtrace.hh:756
static G4FieldManagerStore * GetInstanceIfExist()
static G4Geantino * GeantinoDefinition()
Definition: G4Geantino.cc:81
static G4GeometryManager * GetInstance()
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=nullptr)
void OpenGeometry(G4VPhysicalVolume *vol=nullptr)
static G4GeometryManager * GetInstanceIfExist()
static void ConstructParticle()
void InitializeLightIons()
Definition: G4IonTable.cc:205
static G4LogicalVolumeStore * GetInstance()
void SetRegion(G4Region *reg)
G4Region * GetRegion() const
const G4String & GetName() const
static G4MTRunManager * GetMasterRunManager()
std::map< G4int, G4VPhysicalVolume * > masterWorlds_t
static masterWorlds_t & GetMasterWorlds()
static G4NavigationHistoryPool * GetInstance()
static G4ParallelWorldProcessStore * GetInstanceIfExist()
G4ProcessManager * GetProcessManager() const
G4bool IsGeneralIon() const
void SetParticleDefinitionID(G4int id=-1)
G4int GetParticleDefinitionID() const
const G4String & GetParticleName() const
void reset(G4bool ifSkipIon=true)
G4IonTable * GetIonTable() const
G4ParticleDefinition * GetParticle(G4int index) const
G4int entries() const
G4PTblDicIterator * GetIterator() const
static G4ParticleTable * GetParticleTable()
void SetReadiness(G4bool val=true)
G4ParticleDefinition * GetGenericIon() const
void DumpTable(const G4String &particle_name="ALL")
static G4PathFinder * GetInstanceIfExist()
Definition: G4PathFinder.cc:66
G4int AddDiscreteProcess(G4VProcess *aProcess, G4int ord=ordDefault)
G4ProcessVector * GetAlongStepProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const
G4ProcessVector * GetProcessList() const
std::size_t size() const
void UpdateCoupleTable(G4VPhysicalVolume *currentWorld)
static G4ProductionCutsTable * GetProductionCutsTable()
G4ProductionCuts * GetDefaultProductionCuts() const
G4double GetProductionCut(G4int index) const
static G4RegionStore * GetInstance()
void UpdateMaterialList(G4VPhysicalVolume *currentWorld=nullptr)
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
std::size_t GetNumberOfRootVolumes() const
G4bool BelongsTo(G4VPhysicalVolume *thePhys) const
Definition: G4Region.cc:414
std::size_t GetNumberOfMaterials() const
G4FastSimulationManager * GetFastSimulationManager() const
Definition: G4Region.cc:140
G4VUserRegionInformation * GetUserInformation() const
void SetWorld(G4VPhysicalVolume *wp)
Definition: G4Region.cc:398
G4bool IsInParallelGeometry() const
G4ProductionCuts * GetProductionCuts() const
void RemoveRootLogicalVolume(G4LogicalVolume *lv, G4bool scan=true)
Definition: G4Region.cc:328
G4VPhysicalVolume * GetWorldPhysical() const
void SetProductionCuts(G4ProductionCuts *cut)
G4UserLimits * GetUserLimits() const
const G4String & GetName() const
G4bool IsInMassGeometry() const
G4UserSteppingAction * GetRegionalSteppingAction() const
Definition: G4Region.cc:158
void UsedInParallelGeometry(G4bool val=true)
std::vector< G4Material * >::const_iterator GetMaterialIterator() const
void AddRootLogicalVolume(G4LogicalVolume *lv, G4bool search=true)
Definition: G4Region.cc:293
std::vector< G4LogicalVolume * >::iterator GetRootLogicalVolumeIterator()
void UsedInMassGeometry(G4bool val=true)
G4PrimaryTransformer * GetPrimaryTransformer() const
G4Region * defaultRegionForParallelWorld
static G4RunManagerKernel * GetRunManagerKernel()
void SetPhysics(G4VUserPhysicsList *uPhys)
void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
G4bool RunInitialization(G4bool fakeRun=false)
void WorkerDefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
virtual void SetupShadowProcess() const
void DumpRegion(const G4String &rname) const
void BuildPhysicsTables(G4bool fakeRun)
static G4SDManager * GetSDMpointerIfExist()
Definition: G4SDManager.cc:47
const G4ApplicationState & GetCurrentState() const
G4VExceptionHandler * GetExceptionHandler() const
G4String GetStateString(const G4ApplicationState &aState) const
static G4StateManager * GetStateManager()
G4bool SetNewState(const G4ApplicationState &requestedState)
static G4TemplateRNGHelper< T > * GetInstanceIfExist()
Definition: G4RNGHelper.cc:53
G4bool RegisterWorld(G4VPhysicalVolume *aWorld)
static G4TransportationManager * GetTransportationManager()
static G4TransportationManager * GetInstanceIfExist()
G4VPhysicalVolume * IsWorldExisting(const G4String &worldName)
void SetWorldForTracking(G4VPhysicalVolume *theWorld)
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
std::size_t GetNoWorlds() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:495
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
static void ClearUnitsTable()
static G4UnitsTable & GetUnitsTable()
G4LogicalVolume * GetLogicalVolume() const
const G4String & GetName() const
const G4String & GetProcessName() const
Definition: G4VProcess.hh:386
void UseCoupledTransportation(G4bool vl=true)
virtual void ConstructParticle()=0
void DumpCutValuesTable(G4int flag=1)
static G4VVisManager * GetConcreteInstance()
virtual void GeometryHasChanged()=0
G4bool IsWorkerThread()
Definition: G4Threading.cc:123
G4bool IsMasterThread()
Definition: G4Threading.cc:124
#define G4ThreadLocal
Definition: tls.hh:77