Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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 "G4RunManagerKernel.hh"
32
33#include "G4AllocatorList.hh"
34#include "G4ApplicationState.hh"
35#include "G4AutoLock.hh"
36#include "G4ExceptionHandler.hh"
38#include "G4Geantino.hh"
39#include "G4GeometryManager.hh"
40#include "G4IonConstructor.hh"
41#include "G4IonTable.hh"
42#include "G4LogicalVolume.hh"
44#include "G4MTRunManager.hh"
48#include "G4ParticleTable.hh"
50#include "G4PathFinder.hh"
52#include "G4ProcessManager.hh"
53#include "G4ProcessVector.hh"
54#include "G4ProductionCuts.hh"
56#include "G4RNGHelper.hh"
57#include "G4Region.hh"
58#include "G4RegionStore.hh"
59#include "G4SDManager.hh"
61#include "G4StateManager.hh"
62#include "G4TiMemory.hh"
64#include "G4UImanager.hh"
65#include "G4UnitsTable.hh"
66#include "G4VPhysicalVolume.hh"
67#include "G4VProcess.hh"
68#include "G4VUserPhysicsList.hh"
69#include "G4VVisManager.hh"
70#include "G4Version.hh"
71#include "G4ios.hh"
72
73#include <vector>
74
75#ifdef G4BT_DEBUG
76# include "G4Backtrace.hh"
77#endif
78
79#ifdef G4FPE_DEBUG
80# include "G4FPEDetection.hh"
81#endif
82
83// The following lines are needed since G4VUserPhysicsList
84// uses a #define theParticleIterator
85#ifdef theParticleIterator
86# undef theParticleIterator
87#endif
88
89G4ThreadLocal G4RunManagerKernel* G4RunManagerKernel::fRunManagerKernel = nullptr;
90
91// --------------------------------------------------------------------
93{
94 return fRunManagerKernel;
95}
96
97// --------------------------------------------------------------------
99{
100#ifdef G4FPE_DEBUG
101 InvalidOperationDetection();
102#endif
103
104#ifdef G4BT_DEBUG
105 auto _signals = G4GetEnv<std::string>("G4BACKTRACE", "");
106 if (_signals.empty()) {
108 }
109 else {
110 G4Backtrace::Enable(_signals);
111 }
112#endif
113
115 if (allocList != nullptr) numberOfStaticAllocators = (G4int)allocList->Size();
116
117 if (G4StateManager::GetStateManager()->GetExceptionHandler() == nullptr) {
118 defaultExceptionHandler = new G4ExceptionHandler();
119 }
120 if (fRunManagerKernel != nullptr) {
121 G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0001", FatalException,
122 "More than one G4RunManagerKernel is constructed.");
123 }
124 fRunManagerKernel = this;
125
127 if (particleTable->entries() > 0) {
128 // No particle should be registered beforehand
130 ED << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << G4endl;
131 ED << " G4RunManagerKernel fatal exception" << G4endl;
132 ED << " -- Following particles have already been registered" << G4endl;
133 ED << " before G4RunManagerKernel is instantiated." << G4endl;
134 for (G4int i = 0; i < particleTable->entries(); ++i) {
135 ED << " " << particleTable->GetParticle(i)->GetParticleName() << G4endl;
136 }
137 ED << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << G4endl;
138 G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0002", FatalException, ED);
139 }
140
141 // construction of Geant4 kernel classes
142 eventManager = new G4EventManager();
143
144 defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
146 new G4Region("DefaultRegionForParallelWorld"); // deleted by store
148 G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
150 G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
151
153 // set the initial application state
155
156 // version banner
157 G4String vs = G4Version;
158 vs = vs.substr(1, vs.size() - 2);
159 versionString = " Geant4 version ";
160 versionString += vs;
161 versionString += " ";
162 versionString += G4Date;
163 G4cout << G4endl << "**************************************************************" << G4endl
164 << versionString << G4endl << " Copyright : Geant4 Collaboration"
165 << G4endl << " References : NIM A 506 (2003), 250-303" << G4endl
166 << " : IEEE-TNS 53 (2006), 270-278" << G4endl
167 << " : NIM A 835 (2016), 186-225" << G4endl
168 << " WWW : http://geant4.org/" << G4endl
169 << "**************************************************************" << G4endl << G4endl;
170}
171
172// --------------------------------------------------------------------
174{
175// This version of the constructor should never be called in sequential mode!
176#ifndef G4MULTITHREADED
178 msg << "Geant4 code is compiled without multi-threading support "
179 "(-DG4MULTITHREADED is set to off).";
180 msg << " This type of RunManagerKernel can only be used in mult-threaded "
181 "applications.";
182 G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)", "Run0105", FatalException, msg);
183#endif
184
185#ifdef G4FPE_DEBUG
187 InvalidOperationDetection();
188 }
189#endif
190
191#ifdef G4BT_DEBUG
192 auto _signals = G4GetEnv<std::string>("G4BACKTRACE", "");
193 if (_signals.empty()) {
195 }
196 else {
197 G4Backtrace::Enable(_signals);
198 }
199#endif
200
201 if (G4StateManager::GetStateManager()->GetExceptionHandler() == nullptr) {
202 defaultExceptionHandler = new G4ExceptionHandler();
203 }
204
205 if (fRunManagerKernel != nullptr) {
206 G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0001", FatalException,
207 "More than one G4RunManagerKernel is constructed.");
208 }
209 fRunManagerKernel = this;
210 // construction of Geant4 kernel classes
211 eventManager = new G4EventManager();
212
213 switch (rmkType) {
214 case masterRMK:
215 // Master thread behvior
216 defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
218 new G4Region("DefaultRegionForParallelWorld"); // deleted by store
220 G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
222 G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
223 break;
224 case workerRMK:
225 // Worker thread behavior
226 defaultRegion = G4RegionStore::GetInstance()->GetRegion("DefaultRegionForTheWorld", true);
228 G4RegionStore::GetInstance()->GetRegion("DefaultRegionForParallelWorld", true);
229 break;
230 default:
231 defaultRegion = nullptr;
234 msgx << " This type of RunManagerKernel can only be used in mult-threaded "
235 "applications.";
236 G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)", "Run0106", FatalException,
237 msgx);
238 }
239 runManagerKernelType = rmkType;
240
241 // set the initial application state
243
244 // version banner
245 G4String vs = G4Version;
246 vs = vs.substr(1, vs.size() - 2);
247 switch (rmkType) {
248 case masterRMK:
249 versionString = " Geant4 version ";
250 versionString += vs;
251 versionString += " ";
252 versionString += G4Date;
253 G4cout << G4endl << "**************************************************************" << G4endl
254 << versionString << G4endl << " << in Multi-threaded mode >> " << G4endl
255 << " Copyright : Geant4 Collaboration" << G4endl
256 << " References : NIM A 506 (2003), 250-303" << G4endl
257 << " : IEEE-TNS 53 (2006), 270-278" << G4endl
258 << " : NIM A 835 (2016), 186-225" << G4endl
259 << " WWW : http://geant4.org/" << G4endl
260 << "**************************************************************" << G4endl
261 << G4endl;
262 break;
263 default:
264 if (verboseLevel != 0) {
265 versionString = " Local thread RunManagerKernel version ";
266 versionString += vs;
267 G4cout << G4endl
268 << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
269 "^^^^^^^^^"
270 << G4endl << versionString << G4endl
271 << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
272 "^^^^^^^^^"
273 << G4endl << G4endl;
274 }
275 }
276
277#ifdef G4MULTITHREADED
278 G4UnitDefinition::GetUnitsTable().Synchronize();
279#endif
280}
281
282// --------------------------------------------------------------------
284{
285 if (runManagerKernelType == workerRMK) return;
286
287 // Remove old world logical volume from the default region, if exist
289 if (defaultRegion->GetNumberOfRootVolumes() > size_t(1)) {
290 G4Exception("G4RunManager::SetupDefaultRegion", "Run0005", FatalException,
291 "Default world region should have a unique logical volume.");
292 }
295 if (verboseLevel > 1)
296 G4cout << "Obsolete world logical volume is removed from the default region." << G4endl;
297 }
298}
299
300// --------------------------------------------------------------------
302{
304 // set the application state to the quite state
305 if (pStateManager->GetCurrentState() != G4State_Quit) {
306 if (verboseLevel > 1) G4cout << "G4 kernel has come to Quit state." << G4endl;
307 pStateManager->SetNewState(G4State_Quit);
308 }
309
310 // open geometry for deletion
312
313 // deletion of Geant4 kernel classes
316 if (verboseLevel > 1) G4cout << "G4SDManager deleted." << G4endl;
317 delete eventManager;
318 if (verboseLevel > 1) G4cout << "EventManager deleted." << G4endl;
319
321 if (verboseLevel > 1) G4cout << "Units table cleared." << G4endl;
322
323 // deletion of path-finder field-manager store, geometry and transportation
324 // manager
329 if (verboseLevel > 1) G4cout << "TransportationManager deleted." << G4endl;
330
331 // deletion of navigation levels
332 if (verboseLevel > 1) G4NavigationHistoryPool::GetInstance()->Print();
334
335 // deletion of G4RNGHelper singleton
338 if (verboseLevel > 1) G4cout << "G4RNGHelper object is deleted." << G4endl;
339 }
340
341 // deletion of allocators
343 if (allocList != nullptr) {
344 allocList->Destroy(numberOfStaticAllocators, verboseLevel);
345 delete allocList;
346 if (verboseLevel > 1) G4cout << "G4Allocator objects are deleted." << G4endl;
347 }
348
350 if ((runManagerKernelType == workerRMK) && (verboseLevel > 1)) {
351 G4cout << "Thread-local UImanager is to be deleted." << G4endl
352 << "There should not be any thread-local G4cout/G4cerr hereafter." << G4endl;
353 }
354 delete pUImanager;
355 if (verboseLevel > 1) G4cout << "UImanager deleted." << G4endl;
356
357 delete pStateManager;
358 if (verboseLevel > 1) G4cout << "StateManager deleted." << G4endl;
359 delete defaultExceptionHandler;
360 if (verboseLevel > 1) G4cout << "RunManagerKernel is deleted. Good bye :)" << G4endl;
361 fRunManagerKernel = nullptr;
362}
363
364// --------------------------------------------------------------------
366{
369 G4MTRunManager::masterWorlds_t masterWorlds = masterRM->GetMasterWorlds();
370 for (const auto& masterWorld : masterWorlds) {
371 G4VPhysicalVolume* wv = masterWorld.second;
372 G4VPhysicalVolume* pWorld =
374 if (pWorld == nullptr) {
375 transM->RegisterWorld(wv);
376 }
377 }
378}
379
380// --------------------------------------------------------------------
382 G4bool topologyIsChanged)
383{
385 G4ApplicationState currentState = stateManager->GetCurrentState();
386 if (currentState != G4State_Init) {
387 if (currentState != G4State_Idle && currentState != G4State_PreInit) {
388 G4cout << "Current application state is " << stateManager->GetStateString(currentState)
389 << G4endl;
390 G4Exception("G4RunManagerKernel::DefineWorldVolume", "DefineWorldVolumeAtIncorrectState",
391 FatalException, "Geant4 kernel is not Init state : Method ignored.");
392 return;
393 }
394
395 stateManager->SetNewState(G4State_Init);
396 }
397
398 currentWorld = worldVol;
401 G4MTRunManager::masterWorlds_t masterWorlds = masterRM->GetMasterWorlds();
402 for (const auto& masterWorld : masterWorlds) {
403 if (masterWorld.first == 0) {
404 if (masterWorld.second != currentWorld) {
405 G4Exception("G4RunManagerKernel::WorkerDefineWorldVolume", "RUN3091", FatalException,
406 "Mass world is inconsistent");
407 }
408 transM->SetWorldForTracking(masterWorld.second);
409 }
410 else {
411 transM->RegisterWorld(masterWorld.second);
412 }
413 }
414
415 if (topologyIsChanged) geometryNeedsToBeClosed = true;
416
417 // Notify the VisManager as well
420 if (pVVisManager != nullptr) pVVisManager->GeometryHasChanged();
421 }
422
423 geometryInitialized = true;
424 stateManager->SetNewState(currentState);
425 if (physicsInitialized && currentState != G4State_Idle) {
426 stateManager->SetNewState(G4State_Idle);
427 }
428}
429
430// --------------------------------------------------------------------
432{
434 G4ApplicationState currentState = stateManager->GetCurrentState();
435
436 if (currentState != G4State_Init) {
437 if (currentState != G4State_Idle && currentState != G4State_PreInit) {
438 G4cout << "Current application state is " << stateManager->GetStateString(currentState)
439 << G4endl;
440 G4Exception("G4RunManagerKernel::DefineWorldVolume", "DefineWorldVolumeAtIncorrectState",
441 FatalException, "Geant4 kernel is not Init state : Method ignored.");
442 return;
443 }
444
445 stateManager->SetNewState(G4State_Init);
446 }
447
448 // The world volume MUST NOT have a region defined by the user
449 if (worldVol->GetLogicalVolume()->GetRegion() != nullptr) {
450 if (worldVol->GetLogicalVolume()->GetRegion() != defaultRegion) {
452 ED << "The world volume has a user-defined region <"
453 << worldVol->GetLogicalVolume()->GetRegion()->GetName() << ">." << G4endl;
454 ED << "World would have a default region assigned by RunManagerKernel." << G4endl;
455 G4Exception("G4RunManager::DefineWorldVolume", "Run0004", FatalException, ED);
456 }
457 }
458
460
461 // Accept the world volume
462 currentWorld = worldVol;
463
464 // Set the default region to the world
465
466 G4LogicalVolume* worldLog = currentWorld->GetLogicalVolume();
467 worldLog->SetRegion(defaultRegion);
469 if (verboseLevel > 1)
470 G4cout << worldLog->GetName() << " is registered to the default region." << G4endl;
471
472 // Set the world volume, notify the Navigator and reset its state
474 if (topologyIsChanged) geometryNeedsToBeClosed = true;
475
476 // Notify the VisManager as well
479 if (pVVisManager != nullptr) pVVisManager->GeometryHasChanged();
480 }
481
482 geometryInitialized = true;
483 stateManager->SetNewState(currentState);
484 if (physicsInitialized && currentState != G4State_Idle) {
485 stateManager->SetNewState(G4State_Idle);
486 }
487}
488
489// --------------------------------------------------------------------
491{
492 physicsList = uPhys;
493
494 if (runManagerKernelType == workerRMK) return;
495
496 SetupPhysics();
497 if (verboseLevel > 2) G4ParticleTable::GetParticleTable()->DumpTable();
498 if (verboseLevel > 1) {
499 G4cout << "List of instantiated particles "
500 "============================================"
501 << G4endl;
503 for (G4int i = 0; i < nPtcl; ++i) {
505 G4cout << pd->GetParticleName() << " ";
506 if (i % 10 == 9) G4cout << G4endl;
507 }
508 G4cout << G4endl;
509 }
510}
511
512// --------------------------------------------------------------------
514{
516
517 physicsList->ConstructParticle();
518
519 // For sanity reason
522 if (gion != nullptr) {
524 }
526
528 pItr->reset();
529 while ((*pItr)()) {
530 G4ParticleDefinition* particle = pItr->value();
531 if (!(particle->IsGeneralIon())) particle->SetParticleDefinitionID();
532 }
533
534 if (gion != nullptr) {
535 G4int gionId = gion->GetParticleDefinitionID();
536 pItr->reset(false);
537 while ((*pItr)()) {
538 G4ParticleDefinition* particle = pItr->value();
539 if (particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
540 }
541 }
542#ifdef G4MULTITHREADED
543 G4UnitDefinition::GetUnitsTable().Synchronize();
544#endif
545}
546
547// --------------------------------------------------------------------
548namespace
549{
550G4Mutex initphysicsmutex = G4MUTEX_INITIALIZER;
551}
552
553// --------------------------------------------------------------------
555{
557 G4ApplicationState currentState = stateManager->GetCurrentState();
558 if (currentState != G4State_Init) {
559 G4cout << "Current application state is " << stateManager->GetStateString(currentState)
560 << G4endl;
561 if (currentState != G4State_Idle && currentState != G4State_PreInit) {
562 G4Exception("G4RunManagerKernel::InitializePhysics", "InitializePhysicsIncorrectState",
563 FatalException, "Geant4 kernel is not Init state : Method ignored.");
564 return;
565 }
566
567 G4cout << "Warning : Geant4 kernel is not Init state : Assuming Init state." << G4endl;
568 stateManager->SetNewState(G4State_Init);
569 }
570
571 if (physicsList == nullptr) {
572 G4Exception("G4RunManagerKernel::InitializePhysics", "Run0012", FatalException,
573 "G4VUserPhysicsList is not defined");
574 return;
575 }
576
577 if (verboseLevel > 1) G4cout << "physicsList->Construct() start." << G4endl;
578 if (numberOfParallelWorld > 0) physicsList->UseCoupledTransportation();
579 physicsList->Construct();
580
581 if (verboseLevel > 1) G4cout << "physicsList->CheckParticleList() start." << G4endl;
582 physicsList->CheckParticleList();
583
584 // Cannot assume that SetCuts() and CheckRegions() are thread safe.
585 // We need to mutex (report from valgrind --tool=drd)
586 G4AutoLock l(&initphysicsmutex);
588 if (verboseLevel > 1) G4cout << "physicsList->setCut() start." << G4endl;
589 physicsList->SetCuts();
590 }
591 CheckRegions();
592 l.unlock();
593
594 physicsInitialized = true;
595
596#ifdef G4MULTITHREADED
597 G4UnitDefinition::GetUnitsTable().Synchronize();
598#endif
599
600 stateManager->SetNewState(currentState);
601 if (geometryInitialized && currentState != G4State_Idle) {
602 stateManager->SetNewState(G4State_Idle);
603 }
604}
605
606// --------------------------------------------------------------------
608{
610 G4ApplicationState currentState = stateManager->GetCurrentState();
611
612 if (!geometryInitialized) {
613 G4Exception("G4RunManagerKernel::RunInitialization", "Run0021", JustWarning,
614 "Geometry has not yet initialized : method ignored.");
615 return false;
616 }
617
618 if (!physicsInitialized) {
619 G4Exception("G4RunManagerKernel::RunInitialization", "Run0022", JustWarning,
620 "Physics has not yet initialized : method ignored.");
621 return false;
622 }
623
624 if (currentState != G4State_Idle) {
625 G4Exception("G4RunManagerKernel::RunInitialization", "Run0023", JustWarning,
626 "Geant4 kernel not in Idle state : method ignored.");
627 return false;
628 }
629
630 if (geometryNeedsToBeClosed) CheckRegularGeometry();
631
632 stateManager->SetNewState(G4State_Init);
635 UpdateRegion();
636 BuildPhysicsTables(fakeRun);
637
640 // CheckRegularGeometry();
641 // Notify the VisManager as well
644 if (pVVisManager != nullptr) pVVisManager->GeometryHasChanged();
645 }
646 }
647
649
650#ifdef G4MULTITHREADED
651 G4UnitDefinition::GetUnitsTable().Synchronize();
652#endif
653
654 stateManager->SetNewState(G4State_Idle);
655 stateManager->SetNewState(G4State_GeomClosed);
656 return true;
657}
658
659// --------------------------------------------------------------------
661{
663 if (gion != nullptr) {
664 G4int gionId = gion->GetParticleDefinitionID();
666 pItr->reset(false);
667 while ((*pItr)()) {
668 G4ParticleDefinition* particle = pItr->value();
669 if (particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
670 }
671 }
672}
673
674// --------------------------------------------------------------------
681
682// --------------------------------------------------------------------
684{
687 return;
688 }
689
690 // We have to tweak the navigator's state in case a geometry has been
691 // modified between runs. By the following calls we ensure that navigator's
692 // state is reset properly. It is required the geometry to be closed
693 // and previous optimisations to be cleared.
694
696 if (verboseLevel > 1) G4cout << "Start closing geometry." << G4endl;
697
698 geomManager->OpenGeometry();
699 geomManager->CloseGeometry(geometryToBeOptimized, verboseLevel > 1);
700
702}
703
704// --------------------------------------------------------------------
706{
708 G4ApplicationState currentState = stateManager->GetCurrentState();
709 if (currentState != G4State_Init) {
710 G4Exception("G4RunManagerKernel::UpdateRegion", "Run0024", JustWarning,
711 "Geant4 kernel not in Init state : method ignored.");
712 return;
713 }
714
715 if (runManagerKernelType == workerRMK) return;
716
717 CheckRegions();
718
720
722}
723
724// --------------------------------------------------------------------
726{
727 if (G4ProductionCutsTable::GetProductionCutsTable()->IsModified() || physicsNeedsToBeReBuilt) {
728#ifdef G4MULTITHREADED
730 // make sure workers also rebuild physics tables
732 pUImanager->ApplyCommand("/run/physicsModified");
733 }
734#endif
735 physicsList->BuildPhysicsTable();
736 physicsNeedsToBeReBuilt = false;
737 }
738
739 if (!fakeRun && verboseLevel > 1) DumpRegion();
740 if (!fakeRun && verboseLevel > 0) physicsList->DumpCutValuesTable();
741 if (!fakeRun) physicsList->DumpCutValuesTableIfRequested();
742}
743
744// --------------------------------------------------------------------
746{
748 std::size_t nWorlds = transM->GetNoWorlds();
749 std::vector<G4VPhysicalVolume*>::iterator wItr;
750 for (auto region : *G4RegionStore::GetInstance()) {
751 // Let each region have a pointer to the world volume where it belongs to.
752 // G4Region::SetWorld() checks if the region belongs to the given world and
753 // set it only if it does. Thus, here we go through all the registered world
754 // volumes.
755 region->SetWorld(nullptr); // reset
756 region->UsedInMassGeometry(false);
757 region->UsedInParallelGeometry(false);
758 wItr = transM->GetWorldsIterator();
759 for (std::size_t iw = 0; iw < nWorlds; ++iw) {
760 if (region->BelongsTo(*wItr)) {
761 if (*wItr == currentWorld) {
762 region->UsedInMassGeometry(true);
763 }
764 else {
765 region->UsedInParallelGeometry(true);
766 }
767 }
768 region->SetWorld(*wItr);
769 ++wItr;
770 }
771
772 G4ProductionCuts* cuts = region->GetProductionCuts();
773 if (cuts == nullptr) {
774 if (region->IsInMassGeometry() && verboseLevel > 0) {
775 G4cout << "Warning : Region <" << region->GetName()
776 << "> does not have specific production cuts," << G4endl
777 << "even though it appears in the current tracking world." << G4endl;
778 G4cout << "Default cuts are used for this region." << G4endl;
779 }
780
781 if (region->IsInMassGeometry() || region->IsInParallelGeometry()) {
782 region->SetProductionCuts(
783 G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
784 }
785 }
786 }
787
788 //
789 // If a parallel world has no region, set default region for parallel world
790 //
791
792 wItr = transM->GetWorldsIterator();
793 for (std::size_t iw = 0; iw < nWorlds; ++iw) {
794 if (*wItr != currentWorld) {
795 G4LogicalVolume* pwLogical = (*wItr)->GetLogicalVolume();
796 if (pwLogical->GetRegion() == nullptr) {
799 }
800 }
801 ++wItr;
802 }
803}
804
805// --------------------------------------------------------------------
807{
809 if (region != nullptr) DumpRegion(region);
810}
811
812// --------------------------------------------------------------------
814{
815 if (region == nullptr) {
816 for (const auto& i : *G4RegionStore::GetInstance()) {
817 DumpRegion(i);
818 }
819 }
820 else {
821 if (G4Threading::IsWorkerThread()) return;
822 G4cout << G4endl;
823 G4cout << "Region <" << region->GetName() << "> -- ";
824 if (region->GetWorldPhysical() != nullptr) {
825 G4cout << " -- appears in <" << region->GetWorldPhysical()->GetName() << "> world volume";
826 }
827 else {
828 G4cout << " -- is not associated to any world.";
829 }
830 G4cout << G4endl;
831 if (region->IsInMassGeometry()) {
832 G4cout << " This region is in the mass world." << G4endl;
833 }
834 if (region->IsInParallelGeometry()) {
835 G4cout << " This region is in the parallel world." << G4endl;
836 }
837
838 G4cout << " Root logical volume(s) : ";
839 std::size_t nRootLV = region->GetNumberOfRootVolumes();
840 auto lvItr = region->GetRootLogicalVolumeIterator();
841 for (std::size_t j = 0; j < nRootLV; ++j) {
842 G4cout << (*lvItr)->GetName() << " ";
843 ++lvItr;
844 }
845 G4cout << G4endl;
846
847 G4cout << " Pointers : G4VUserRegionInformation[" << region->GetUserInformation()
848 << "], G4UserLimits[" << region->GetUserLimits() << "], G4FastSimulationManager["
849 << region->GetFastSimulationManager() << "], G4UserSteppingAction["
850 << region->GetRegionalSteppingAction() << "]" << G4endl;
851
852 G4cout << " Materials : ";
853 auto mItr = region->GetMaterialIterator();
854 std::size_t nMaterial = region->GetNumberOfMaterials();
855 for (std::size_t iMate = 0; iMate < nMaterial; ++iMate) {
856 G4cout << (*mItr)->GetName() << " ";
857 ++mItr;
858 }
859 G4cout << G4endl;
860 G4ProductionCuts* cuts = region->GetProductionCuts();
861 if ((cuts == nullptr) && region->IsInMassGeometry()) {
862 G4cerr << "Warning : Region <" << region->GetName()
863 << "> does not have specific production cuts." << G4endl;
864 G4cerr << "Default cuts are used for this region." << G4endl;
865 region->SetProductionCuts(
866 G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
867 }
868 else if (cuts != nullptr) {
869 G4cout << " Production cuts : "
870 << " gamma " << G4BestUnit(cuts->GetProductionCut("gamma"), "Length") << " e- "
871 << G4BestUnit(cuts->GetProductionCut("e-"), "Length") << " e+ "
872 << G4BestUnit(cuts->GetProductionCut("e+"), "Length") << " proton "
873 << G4BestUnit(cuts->GetProductionCut("proton"), "Length") << G4endl;
874 }
875 }
876}
877
878// --------------------------------------------------------------------
879void G4RunManagerKernel::CheckRegularGeometry()
880{
882 for (const auto& pos : *store) {
883 if ((pos != nullptr) && (pos->GetNoDaughters() == 1)) {
884 if (pos->GetDaughter(0)->IsRegularStructure()) {
885 SetScoreSplitter();
886 return;
887 }
888 }
889 }
890}
891
892// --------------------------------------------------------------------
893G4bool G4RunManagerKernel::ConfirmCoupledTransportation()
894{
896 auto theParticleIterator = theParticleTable->GetIterator();
898 while ((*theParticleIterator)()) {
901 if (pm != nullptr) {
903 G4VProcess* p = (*pv)[0];
904 return ((p->GetProcessName()) == "CoupledTransportation");
905 }
906 }
907 return false;
908}
909
910// --------------------------------------------------------------------
911void G4RunManagerKernel::SetScoreSplitter()
912{
913 auto pSplitter = new G4ScoreSplittingProcess();
915 auto theParticleIterator = theParticleTable->GetIterator();
916
917 // Ensure that Process is added only once to the particles' process managers
918 static G4ThreadLocal G4bool InitSplitter = false;
919 if (!InitSplitter) {
920 InitSplitter = true;
921
922 theParticleIterator->reset();
923 while ((*theParticleIterator)()) {
924 G4ParticleDefinition* particle = theParticleIterator->value();
925 G4ProcessManager* pmanager = particle->GetProcessManager();
926 if (pmanager != nullptr) {
927 pmanager->AddDiscreteProcess(pSplitter);
928 }
929 }
930
931 if (verboseLevel > 0) {
932 G4cout << "G4RunManagerKernel -- G4ScoreSplittingProcess is appended to all "
933 "particles."
934 << G4endl;
935 }
936 }
937}
938
939// --------------------------------------------------------------------
941{
943 auto theParticleIterator = theParticleTable->GetIterator();
945 // loop on particles and get process manager from there list of processes
946 while ((*theParticleIterator)()) {
949 if (pm != nullptr) {
950 G4ProcessVector& procs = *(pm->GetProcessList());
951 for (G4int idx = 0; idx < (G4int)procs.size(); ++idx) {
952 const G4VProcess* masterP = procs[idx]->GetMasterProcess();
953 if (masterP == nullptr) {
954 // Process does not have an associated shadow master process
955 // We are in master mode or sequential
956 procs[idx]->SetMasterProcess(const_cast<G4VProcess*>(procs[idx]));
957 }
958 }
959 }
960 }
961}
G4ApplicationState
@ G4State_Init
@ G4State_Idle
@ G4State_Quit
@ G4State_GeomClosed
@ G4State_PreInit
_Tp G4GetEnv(const std::string &env_id, _Tp _default=_Tp())
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
@ typeDoIt
#define G4BestUnit(a, b)
#define G4MUTEX_INITIALIZER
std::mutex G4Mutex
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define theParticleIterator
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
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 &)
static G4FieldManagerStore * GetInstanceIfExist()
static G4Geantino * GeantinoDefinition()
Definition G4Geantino.cc:76
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()
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()
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()
G4double GetProductionCut(G4int index) const
const std::vector< G4double > & GetProductionCuts() const
static G4RegionStore * GetInstance()
void UpdateMaterialList(G4VPhysicalVolume *currentWorld=nullptr)
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
std::size_t GetNumberOfRootVolumes() const
std::size_t GetNumberOfMaterials() const
G4FastSimulationManager * GetFastSimulationManager() const
Definition G4Region.cc:140
G4VUserRegionInformation * GetUserInformation() const
G4bool IsInParallelGeometry() const
G4ProductionCuts * GetProductionCuts() const
void RemoveRootLogicalVolume(G4LogicalVolume *lv, G4bool scan=true)
Definition G4Region.cc:342
G4VPhysicalVolume * GetWorldPhysical() const
void SetProductionCuts(G4ProductionCuts *cut)
G4UserLimits * GetUserLimits() const
const G4String & GetName() const
G4bool IsInMassGeometry() const
G4UserSteppingAction * GetRegionalSteppingAction() const
Definition G4Region.cc:158
std::vector< G4Material * >::const_iterator GetMaterialIterator() const
void AddRootLogicalVolume(G4LogicalVolume *lv, G4bool search=true)
Definition G4Region.cc:293
std::vector< G4LogicalVolume * >::iterator GetRootLogicalVolumeIterator()
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()
const G4ApplicationState & GetCurrentState() const
G4String GetStateString(const G4ApplicationState &aState) const
static G4StateManager * GetStateManager()
G4bool SetNewState(const G4ApplicationState &requestedState)
static G4TemplateRNGHelper< T > * GetInstanceIfExist()
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)
static G4UImanager * GetUIpointer()
static void ClearUnitsTable()
static G4UnitsTable & GetUnitsTable()
G4LogicalVolume * GetLogicalVolume() const
const G4String & GetName() const
const G4String & GetProcessName() const
void UseCoupledTransportation(G4bool vl=true)
virtual void ConstructParticle()=0
void DumpCutValuesTable(G4int flag=1)
static G4VVisManager * GetConcreteInstance()
virtual void GeometryHasChanged()=0
G4bool IsWorkerThread()
G4bool IsMasterThread()
#define G4ThreadLocal
Definition tls.hh:77