Geant4-11
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
96
97// --------------------------------------------------------------------
99{
100 return fRunManagerKernel;
101}
102
103// --------------------------------------------------------------------
105{
106 #ifdef G4FPE_DEBUG
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 = allocList->Size();
125
126 if(G4StateManager::GetStateManager()->GetExceptionHandler() == nullptr)
127 {
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
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 += " ";
181 G4cout << G4endl
182 << "**************************************************************"
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 {
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 {
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
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 += " ";
291 G4cout << G4endl
292 << "**************************************************************"
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 "^^^^^^^^^"
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 > 0)
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 {
407 delete allocList;
408 if(verboseLevel > 1)
409 G4cout << "G4Allocator objects are deleted." << G4endl;
410 }
411
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 verboseLevel = 0;
419 }
420 delete pUImanager;
421 if(verboseLevel > 1)
422 G4cout << "UImanager deleted." << G4endl;
423
424 delete pStateManager;
425 if(verboseLevel > 1)
426 G4cout << "StateManager deleted." << G4endl;
428 if(verboseLevel > 0)
429 G4cout << "RunManagerKernel is deleted. Good bye :)" << G4endl;
430 fRunManagerKernel = nullptr;
431}
432
433// --------------------------------------------------------------------
435{
439 G4MTRunManager::masterWorlds_t masterWorlds = masterRM->GetMasterWorlds();
440 for(auto itrMW = masterWorlds.cbegin();
441 itrMW != masterWorlds.cend(); ++itrMW)
442 {
443 G4VPhysicalVolume* wv = (*itrMW).second;
444 G4VPhysicalVolume* pWorld =
446 ->IsWorldExisting(wv->GetName());
447 if(pWorld == nullptr)
448 {
449 transM->RegisterWorld(wv);
450 }
451 }
452}
453
454// --------------------------------------------------------------------
456 G4bool topologyIsChanged)
457{
459 G4ApplicationState currentState = stateManager->GetCurrentState();
460 if(currentState != G4State_Init)
461 {
462 if(!(currentState == G4State_Idle || currentState == G4State_PreInit))
463 {
464 G4cout << "Current application state is "
465 << stateManager->GetStateString(currentState) << G4endl;
466 G4Exception("G4RunManagerKernel::DefineWorldVolume",
467 "DefineWorldVolumeAtIncorrectState", FatalException,
468 "Geant4 kernel is not Init state : Method ignored.");
469 return;
470 }
471 else
472 {
473 stateManager->SetNewState(G4State_Init);
474 }
475 }
476
477 currentWorld = worldVol;
481 G4MTRunManager::masterWorlds_t masterWorlds = masterRM->GetMasterWorlds();
482 for(auto itrMW = masterWorlds.cbegin();
483 itrMW != masterWorlds.cend(); ++itrMW)
484 {
485 if((*itrMW).first == 0)
486 {
487 if((*itrMW).second != currentWorld)
488 {
489 G4Exception("G4RunManagerKernel::WorkerDefineWorldVolume", "RUN3091",
490 FatalException, "Mass world is inconsistent");
491 }
492 transM->SetWorldForTracking((*itrMW).second);
493 }
494 else
495 {
496 transM->RegisterWorld((*itrMW).second);
497 }
498 }
499
500 if(topologyIsChanged)
502
503 // Notify the VisManager as well
505 {
507 if(pVVisManager != nullptr)
508 pVVisManager->GeometryHasChanged();
509 }
510
511 geometryInitialized = true;
512 stateManager->SetNewState(currentState);
513 if(physicsInitialized && currentState != G4State_Idle)
514 {
515 stateManager->SetNewState(G4State_Idle);
516 }
517}
518
519// --------------------------------------------------------------------
521 G4bool topologyIsChanged)
522{
524 G4ApplicationState currentState = stateManager->GetCurrentState();
525
526 if(currentState != G4State_Init)
527 {
528 if(!(currentState == G4State_Idle || currentState == G4State_PreInit))
529 {
530 G4cout << "Current application state is "
531 << stateManager->GetStateString(currentState) << G4endl;
532 G4Exception("G4RunManagerKernel::DefineWorldVolume",
533 "DefineWorldVolumeAtIncorrectState", FatalException,
534 "Geant4 kernel is not Init state : Method ignored.");
535 return;
536 }
537 else
538 {
539 stateManager->SetNewState(G4State_Init);
540 }
541 }
542
543 // The world volume MUST NOT have a region defined by the user
544 if(worldVol->GetLogicalVolume()->GetRegion() != nullptr)
545 {
546 if(worldVol->GetLogicalVolume()->GetRegion() != defaultRegion)
547 {
549 ED << "The world volume has a user-defined region <"
550 << worldVol->GetLogicalVolume()->GetRegion()->GetName() << ">."
551 << G4endl;
552 ED << "World would have a default region assigned by RunManagerKernel."
553 << G4endl;
554 G4Exception("G4RunManager::DefineWorldVolume", "Run0004", FatalException,
555 ED);
556 }
557 }
558
560
561 // Accept the world volume
562 currentWorld = worldVol;
563
564 // Set the default region to the world
565
567 worldLog->SetRegion(defaultRegion);
569 if(verboseLevel > 1)
570 G4cout << worldLog->GetName() << " is registered to the default region."
571 << G4endl;
572
573 // Set the world volume, notify the Navigator and reset its state
576 if(topologyIsChanged)
578
579 // Notify the VisManager as well
581 {
583 if(pVVisManager != nullptr)
584 pVVisManager->GeometryHasChanged();
585 }
586
587 geometryInitialized = true;
588 stateManager->SetNewState(currentState);
589 if(physicsInitialized && currentState != G4State_Idle)
590 {
591 stateManager->SetNewState(G4State_Idle);
592 }
593}
594
595// --------------------------------------------------------------------
597{
598 physicsList = uPhys;
599
601 return;
602
603 SetupPhysics();
604 if(verboseLevel > 2)
606 if(verboseLevel > 1)
607 {
608 G4cout << "List of instantiated particles "
609 "============================================"
610 << G4endl;
612 for(G4int i = 0; i < nPtcl; ++i)
613 {
616 G4cout << pd->GetParticleName() << " ";
617 if(i % 10 == 9)
618 G4cout << G4endl;
619 }
620 G4cout << G4endl;
621 }
622}
623
624// --------------------------------------------------------------------
626{
628
630
631 // For sanity reason
635 if(gion != nullptr)
636 {
638 }
640
642 pItr->reset();
643 while((*pItr)())
644 {
645 G4ParticleDefinition* particle = pItr->value();
646 if(!(particle->IsGeneralIon()))
647 particle->SetParticleDefinitionID();
648 }
649
650 if(gion != nullptr)
651 {
652 G4int gionId = gion->GetParticleDefinitionID();
653 pItr->reset(false);
654 while((*pItr)())
655 {
656 G4ParticleDefinition* particle = pItr->value();
657 if(particle->IsGeneralIon())
658 particle->SetParticleDefinitionID(gionId);
659 }
660 }
661#ifdef G4MULTITHREADED
662 G4UnitDefinition::GetUnitsTable().Synchronize();
663#endif
664}
665
666// --------------------------------------------------------------------
667namespace
668{
670}
671
672// --------------------------------------------------------------------
674{
676 G4ApplicationState currentState = stateManager->GetCurrentState();
677 if(currentState != G4State_Init)
678 {
679 G4cout << "Current application state is "
680 << stateManager->GetStateString(currentState) << G4endl;
681 if(!(currentState == G4State_Idle || currentState == G4State_PreInit))
682 {
683 G4Exception("G4RunManagerKernel::InitializePhysics",
684 "InitializePhysicsIncorrectState", FatalException,
685 "Geant4 kernel is not Init state : Method ignored.");
686 return;
687 }
688 else
689 {
690 // G4Exception("G4RunManagerKernel::DefineWorldVolume",
691 // "DefineWorldVolumeAtIncorrectState", JustWarning,
692 // "Geant4 kernel is not Init state : Assuming Init state.");
693 G4cout
694 << "Warning : Geant4 kernel is not Init state : Assuming Init state."
695 << G4endl;
696 stateManager->SetNewState(G4State_Init);
697 }
698 }
699
700 if(physicsList == nullptr)
701 {
702 G4Exception("G4RunManagerKernel::InitializePhysics", "Run0012",
703 FatalException, "G4VUserPhysicsList is not defined");
704 return;
705 }
706
707 if(verboseLevel > 1)
708 G4cout << "physicsList->Construct() start." << G4endl;
712
713 if(verboseLevel > 1)
714 G4cout << "physicsList->CheckParticleList() start." << G4endl;
716
717 // Cannot assume that SetCuts() and CheckRegions() are thread safe.
718 // We need to mutex (report from valgrind --tool=drd)
721 {
722 if(verboseLevel > 1)
723 G4cout << "physicsList->setCut() start." << G4endl;
725 }
726 CheckRegions();
727 l.unlock();
728
729 /*******************
730 // static G4bool createIsomerOnlyOnce = false;
731 // if(G4Threading::IsMultithreadedApplication() &&
732 G4Threading::IsMasterThread())
733 // {
734 // if(!createIsomerOnlyOnce)
735 // {
736 // createIsomerOnlyOnce = true;
737 // G4ParticleDefinition* gion =
738 G4ParticleTable::GetParticleTable()->GetGenericIon();
739 // if(gion != nullptr)
740 // {
741 // G4ParticleTable::GetParticleTable()
742 ->GetIonTable()->CreateAllIsomer();
743 // PropagateGenericIonID();
744 // }
745 // }
746 // }
747 *********************/
748
749 physicsInitialized = true;
750#ifdef G4MULTITHREADED
751 G4UnitDefinition::GetUnitsTable().Synchronize();
752#endif
753 stateManager->SetNewState(currentState);
754 if(geometryInitialized && currentState != G4State_Idle)
755 {
756 stateManager->SetNewState(G4State_Idle);
757 }
758}
759
760// --------------------------------------------------------------------
762{
764 G4ApplicationState currentState = stateManager->GetCurrentState();
765
767 {
768 G4Exception("G4RunManagerKernel::RunInitialization", "Run0021", JustWarning,
769 "Geometry has not yet initialized : method ignored.");
770 return false;
771 }
772
774 {
775 G4Exception("G4RunManagerKernel::RunInitialization", "Run0022", JustWarning,
776 "Physics has not yet initialized : method ignored.");
777 return false;
778 }
779
780 if(currentState != G4State_Idle)
781 {
782 G4Exception("G4RunManagerKernel::RunInitialization", "Run0023", JustWarning,
783 "Geant4 kernel not in Idle state : method ignored.");
784 return false;
785 }
786
789
790 stateManager->SetNewState(G4State_Init);
793 UpdateRegion();
794 BuildPhysicsTables(fakeRun);
795
797 {
799 // CheckRegularGeometry();
800 // Notify the VisManager as well
802 {
804 if(pVVisManager != nullptr)
805 pVVisManager->GeometryHasChanged();
806 }
807 }
808
810
811#ifdef G4MULTITHREADED
812 G4UnitDefinition::GetUnitsTable().Synchronize();
813#endif
814 stateManager->SetNewState(G4State_Idle);
815 stateManager->SetNewState(G4State_GeomClosed);
816 return true;
817}
818
819// --------------------------------------------------------------------
821{
824 if(gion != nullptr)
825 {
826 // G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer();
827 G4int gionId = gion->GetParticleDefinitionID();
829 pItr->reset(false);
830 while((*pItr)())
831 {
832 G4ParticleDefinition* particle = pItr->value();
833 if(particle->IsGeneralIon())
834 particle->SetParticleDefinitionID(gionId);
835 }
836 }
837}
838
839// --------------------------------------------------------------------
841{
845}
846
847// --------------------------------------------------------------------
849{
851 {
853 return;
854 }
855
856 // We have to tweak the navigator's state in case a geometry has been
857 // modified between runs. By the following calls we ensure that navigator's
858 // state is reset properly. It is required the geometry to be closed
859 // and previous optimisations to be cleared.
860
862 if(verboseLevel > 1)
863 G4cout << "Start closing geometry." << G4endl;
864
865 geomManager->OpenGeometry();
867
869}
870
871// --------------------------------------------------------------------
873{
875 G4ApplicationState currentState = stateManager->GetCurrentState();
876 if(currentState != G4State_Init)
877 {
878 G4Exception("G4RunManagerKernel::UpdateRegion", "Run0024", JustWarning,
879 "Geant4 kernel not in Init state : method ignored.");
880 return;
881 }
882
884 return;
885
886 CheckRegions();
887
889
892}
893
894// --------------------------------------------------------------------
896{
899 {
900 #ifdef G4MULTITHREADED
902 {
903 // make sure workers also rebuild physics tables
905 pUImanager->ApplyCommand("/run/physicsModified");
906 }
907 #endif
911 }
912
913 if(!fakeRun && verboseLevel > 1)
914 DumpRegion();
915 if(!fakeRun && verboseLevel > 0)
917 if(!fakeRun)
919}
920
921// --------------------------------------------------------------------
923{
926 std::size_t nWorlds = transM->GetNoWorlds();
927 std::vector<G4VPhysicalVolume*>::iterator wItr;
928 for(std::size_t i = 0; i < G4RegionStore::GetInstance()->size(); ++i)
929 {
930 G4Region* region = (*(G4RegionStore::GetInstance()))[i];
931
932 // Let each region have a pointer to the world volume where it belongs to.
933 // G4Region::SetWorld() checks if the region belongs to the given world and
934 // set it only if it does. Thus, here we go through all the registered world
935 // volumes.
936 region->SetWorld(nullptr); // reset
937 region->UsedInMassGeometry(false);
938 region->UsedInParallelGeometry(false);
939 wItr = transM->GetWorldsIterator();
940 for(std::size_t iw = 0; iw < nWorlds; ++iw)
941 {
942 if(region->BelongsTo(*wItr))
943 {
944 if(*wItr == currentWorld)
945 {
946 region->UsedInMassGeometry(true);
947 }
948 else
949 {
950 region->UsedInParallelGeometry(true);
951 }
952 }
953 region->SetWorld(*wItr);
954 ++wItr;
955 }
956
957 G4ProductionCuts* cuts = region->GetProductionCuts();
958 if(cuts == nullptr)
959 {
960 if(region->IsInMassGeometry() && verboseLevel > 0)
961 {
962 G4cout << "Warning : Region <" << region->GetName()
963 << "> does not have specific production cuts," << G4endl
964 << "even though it appears in the current tracking world."
965 << G4endl;
966 G4cout << "Default cuts are used for this region." << G4endl;
967 }
968
969 if(region->IsInMassGeometry() || region->IsInParallelGeometry())
970 {
971 region->SetProductionCuts(
974 }
975 }
976 }
977
978 //
979 // If a parallel world has no region, set default region for parallel world
980 //
981
982 wItr = transM->GetWorldsIterator();
983 for(std::size_t iw = 0; iw < nWorlds; ++iw)
984 {
985 if(*wItr != currentWorld)
986 {
987 G4LogicalVolume* pwLogical = (*wItr)->GetLogicalVolume();
988 if(pwLogical->GetRegion() == nullptr)
989 {
992 }
993 }
994 ++wItr;
995 }
996}
997
998// --------------------------------------------------------------------
1000{
1001 G4Region* region = G4RegionStore::GetInstance()->GetRegion(rname);
1002 if(region != nullptr)
1003 DumpRegion(region);
1004}
1005
1006// --------------------------------------------------------------------
1008{
1009 if(region == nullptr)
1010 {
1011 for(std::size_t i = 0; i < G4RegionStore::GetInstance()->size(); ++i)
1012 {
1014 }
1015 }
1016 else
1017 {
1019 return;
1020 G4cout << G4endl;
1021 G4cout << "Region <" << region->GetName() << "> -- ";
1022 if(region->GetWorldPhysical())
1023 {
1024 G4cout << " -- appears in <" << region->GetWorldPhysical()->GetName()
1025 << "> world volume";
1026 }
1027 else
1028 {
1029 G4cout << " -- is not associated to any world.";
1030 }
1031 G4cout << G4endl;
1032 if(region->IsInMassGeometry())
1033 {
1034 G4cout << " This region is in the mass world." << G4endl;
1035 }
1036 if(region->IsInParallelGeometry())
1037 {
1038 G4cout << " This region is in the parallel world." << G4endl;
1039 }
1040
1041 G4cout << " Root logical volume(s) : ";
1042 std::size_t nRootLV = region->GetNumberOfRootVolumes();
1043 auto lvItr = region->GetRootLogicalVolumeIterator();
1044 for(std::size_t j = 0; j < nRootLV; ++j)
1045 {
1046 G4cout << (*lvItr)->GetName() << " ";
1047 ++lvItr;
1048 }
1049 G4cout << G4endl;
1050
1051 G4cout << " Pointers : G4VUserRegionInformation["
1052 << region->GetUserInformation() << "], G4UserLimits["
1053 << region->GetUserLimits() << "], G4FastSimulationManager["
1054 << region->GetFastSimulationManager() << "], G4UserSteppingAction["
1055 << region->GetRegionalSteppingAction() << "]" << G4endl;
1056
1057 G4cout << " Materials : ";
1058 auto mItr = region->GetMaterialIterator();
1059 std::size_t nMaterial = region->GetNumberOfMaterials();
1060 for(std::size_t iMate = 0; iMate < nMaterial; ++iMate)
1061 {
1062 G4cout << (*mItr)->GetName() << " ";
1063 ++mItr;
1064 }
1065 G4cout << G4endl;
1066 G4ProductionCuts* cuts = region->GetProductionCuts();
1067 if(!cuts && region->IsInMassGeometry())
1068 {
1069 G4cerr << "Warning : Region <" << region->GetName()
1070 << "> does not have specific production cuts." << G4endl;
1071 G4cerr << "Default cuts are used for this region." << G4endl;
1073 ->GetDefaultProductionCuts());
1074 }
1075 else if(cuts != nullptr)
1076 {
1077 G4cout << " Production cuts : "
1078 << " gamma "
1079 << G4BestUnit(cuts->GetProductionCut("gamma"), "Length")
1080 << " e- " << G4BestUnit(cuts->GetProductionCut("e-"), "Length")
1081 << " e+ " << G4BestUnit(cuts->GetProductionCut("e+"), "Length")
1082 << " proton "
1083 << G4BestUnit(cuts->GetProductionCut("proton"), "Length")
1084 << G4endl;
1085 }
1086 }
1087}
1088
1089// --------------------------------------------------------------------
1091{
1093 for(auto pos = store->cbegin(); pos != store->cend(); ++pos)
1094 {
1095 if((*pos) && ((*pos)->GetNoDaughters() == 1))
1096 {
1097 if((*pos)->GetDaughter(0)->IsRegularStructure())
1098 {
1100 return;
1101 }
1102 }
1103 }
1104}
1105
1106// --------------------------------------------------------------------
1108{
1110 auto theParticleIterator = theParticleTable->GetIterator();
1111 theParticleIterator->reset();
1112 while((*theParticleIterator)())
1113 {
1116 if(pm)
1117 {
1119 G4VProcess* p = (*pv)[0];
1120 return ((p->GetProcessName()) == "CoupledTransportation");
1121 }
1122 }
1123 return false;
1124}
1125
1126// --------------------------------------------------------------------
1128{
1131 auto theParticleIterator = theParticleTable->GetIterator();
1132
1133 // Ensure that Process is added only once to the particles' process managers
1134 static G4ThreadLocal G4bool InitSplitter = false;
1135 if(!InitSplitter)
1136 {
1137 InitSplitter = true;
1138
1139 theParticleIterator->reset();
1140 while((*theParticleIterator)())
1141 {
1142 G4ParticleDefinition* particle = theParticleIterator->value();
1143 G4ProcessManager* pmanager = particle->GetProcessManager();
1144 if(pmanager)
1145 {
1146 pmanager->AddDiscreteProcess(pSplitter);
1147 }
1148 }
1149
1150 if(verboseLevel > 0)
1151 {
1152 G4cout
1153 << "G4RunManagerKernel -- G4ScoreSplittingProcess is appended to all "
1154 "particles."
1155 << G4endl;
1156 }
1157 }
1158}
1159
1160// --------------------------------------------------------------------
1162{
1164 auto theParticleIterator = theParticleTable->GetIterator();
1165 theParticleIterator->reset();
1166 // loop on particles and get process manager from there list of processes
1167 while((*theParticleIterator)())
1168 {
1171 if(pm != nullptr)
1172 {
1173 G4ProcessVector& procs = *(pm->GetProcessList());
1174 for(std::size_t idx = 0; idx < procs.size(); ++idx)
1175 {
1176 const G4VProcess* masterP = procs[idx]->GetMasterProcess();
1177 if(masterP == nullptr)
1178 {
1179 // Process does not have an associated shadow master process
1180 // We are in master mode or sequential
1181 procs[idx]->SetMasterProcess(const_cast<G4VProcess*>(procs[idx]));
1182 }
1183 }
1184 }
1185 }
1186}
G4ApplicationState
@ G4State_Init
@ G4State_Idle
@ G4State_Quit
@ G4State_GeomClosed
@ G4State_PreInit
static const G4double pos
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
static void InvalidOperationDetection()
@ 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
static const G4String G4Date
Definition: G4Version.hh:60
static const G4String G4Version
Definition: G4Version.hh:58
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4AllocatorList * GetAllocatorListIfExist()
G4int Size() const
void Destroy(G4int nStat=0, G4int verboseLevel=0)
static int 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
G4bool BelongsTo(G4VPhysicalVolume *thePhys) const
Definition: G4Region.cc:414
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
size_t GetNumberOfRootVolumes() const
G4UserSteppingAction * GetRegionalSteppingAction() const
Definition: G4Region.cc:158
size_t GetNumberOfMaterials() const
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)
G4ExceptionHandler * defaultExceptionHandler
static G4ThreadLocal G4RunManagerKernel * fRunManagerKernel
void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
G4bool RunInitialization(G4bool fakeRun=false)
void WorkerDefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
G4VPhysicalVolume * currentWorld
virtual void SetupShadowProcess() const
G4VUserPhysicsList * physicsList
void DumpRegion(const G4String &rname) const
G4EventManager * eventManager
void BuildPhysicsTables(G4bool fakeRun)
static G4SDManager * GetSDMpointerIfExist()
Definition: G4SDManager.cc:47
const G4ApplicationState & GetCurrentState() 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()
size_t GetNoWorlds() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:485
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:382
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