Geant4 10.7.0
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//
27//
28//
29
30#include "G4RunManagerKernel.hh"
31
32#include <vector>
33
34#include "G4ApplicationState.hh"
35#include "G4ExceptionHandler.hh"
37#include "G4GeometryManager.hh"
38#include "G4LogicalVolume.hh"
40#include "G4PathFinder.hh"
42#include "G4StateManager.hh"
44#include "G4VPhysicalVolume.hh"
45#include "G4VUserPhysicsList.hh"
46
48#include "G4ParticleTable.hh"
49#include "G4ProductionCuts.hh"
51#include "G4Region.hh"
52#include "G4RegionStore.hh"
53#include "G4SDManager.hh"
54#include "G4TiMemory.hh"
55#include "G4UImanager.hh"
56#include "G4UnitsTable.hh"
57#include "G4VVisManager.hh"
58#include "G4Version.hh"
59#include "G4ios.hh"
60
61#include "G4AllocatorList.hh"
62#include "G4MTRunManager.hh"
63
64#include "G4AutoLock.hh"
65#include "G4RNGHelper.hh"
66
67#ifdef G4BT_DEBUG
68#include "G4Backtrace.hh"
69#endif
70
71#ifdef G4FPE_DEBUG
72# include "G4FPEDetection.hh"
73#endif
74
75// The following lines are needed since G4VUserPhysicsList uses a #define
76// theParticleIterator
77#ifdef theParticleIterator
78# undef theParticleIterator
79#endif
80
81G4ThreadLocal G4RunManagerKernel* G4RunManagerKernel::fRunManagerKernel = 0;
82
84{
85 return fRunManagerKernel;
86}
87
89 : physicsList(0)
90 , currentWorld(0)
91 , geometryInitialized(false)
92 , physicsInitialized(false)
93 , geometryToBeOptimized(true)
94 , physicsNeedsToBeReBuilt(true)
95 , verboseLevel(0)
96 , numberOfParallelWorld(0)
97 , geometryNeedsToBeClosed(true)
98 , numberOfStaticAllocators(0)
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())
107 {
109 }
110 else
111 {
112 G4Backtrace::Enable(_signals);
113 }
114#endif
115
117 if(allocList)
118 numberOfStaticAllocators = allocList->Size();
119 defaultExceptionHandler = new G4ExceptionHandler();
120 if(fRunManagerKernel)
121 {
122 G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0001",
124 "More than one G4RunManagerKernel is constructed.");
125 }
126 fRunManagerKernel = this;
127
129 if(particleTable->entries() > 0)
130 {
131 // No particle should be registered beforehand
133 ED << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << G4endl;
134 ED << " G4RunManagerKernel fatal exception" << G4endl;
135 ED << " -- Following particles have already been registered" << G4endl;
136 ED << " before G4RunManagerKernel is instantiated." << G4endl;
137 for(int i = 0; i < particleTable->entries(); i++)
138 {
139 ED << " " << particleTable->GetParticle(i)->GetParticleName()
140 << G4endl;
141 }
142 ED << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << G4endl;
143 G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0002",
144 FatalException, ED);
145 }
146
147 // construction of Geant4 kernel classes
148 eventManager = new G4EventManager();
149
150 defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
152 new G4Region("DefaultRegionForParallelWorld"); // deleted by store
155 ->GetDefaultProductionCuts());
158 ->GetDefaultProductionCuts());
159
161 // set the initial application state
163
164 // version banner
165 G4String vs = G4Version;
166 vs = vs.substr(1, vs.size() - 2);
167 versionString = " Geant4 version ";
168 versionString += vs;
169 versionString += " ";
170 versionString += G4Date;
171 G4cout << G4endl
172 << "**************************************************************"
173 << G4endl << versionString << G4endl
174 << " Copyright : Geant4 Collaboration" << G4endl
175 << " References : NIM A 506 (2003), 250-303"
176 << G4endl
177 << " : IEEE-TNS 53 (2006), 270-278"
178 << G4endl
179 << " : NIM A 835 (2016), 186-225"
180 << G4endl << " WWW : http://geant4.org/"
181 << G4endl
182 << "**************************************************************"
183 << G4endl << G4endl;
184}
185
187 : physicsList(0)
188 , currentWorld(0)
189 , geometryInitialized(false)
190 , physicsInitialized(false)
191 , geometryToBeOptimized(true)
192 , physicsNeedsToBeReBuilt(true)
193 , verboseLevel(0)
194 , numberOfParallelWorld(0)
195 , geometryNeedsToBeClosed(true)
196 , numberOfStaticAllocators(0)
197{
198// This version of the constructor should never be called in sequential mode!
199#ifndef G4MULTITHREADED
201 msg << "Geant4 code is compiled without multi-threading support "
202 "(-DG4MULTITHREADED "
203 "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 defaultExceptionHandler = new G4ExceptionHandler();
230 if(fRunManagerKernel)
231 {
232 G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0001",
234 "More than one G4RunManagerKernel is constructed.");
235 }
236 fRunManagerKernel = this;
237 // construction of Geant4 kernel classes
238 eventManager = new G4EventManager();
239
240 switch(rmkType)
241 {
242 case masterRMK:
243 // Master thread behvior
245 new G4Region("DefaultRegionForTheWorld"); // deleted by store
247 new G4Region("DefaultRegionForParallelWorld"); // deleted by store
250 ->GetDefaultProductionCuts());
253 ->GetDefaultProductionCuts());
254 break;
255 case workerRMK:
256 // Worker thread behavior
258 "DefaultRegionForTheWorld", true);
260 "DefaultRegionForParallelWorld", true);
261 break;
262 default:
263 defaultRegion = 0;
266 msgx
267 << " This type of RunManagerKernel can only be used in mult-threaded "
268 "applications.";
269 G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)", "Run0106",
270 FatalException, msgx);
271 }
272 runManagerKernelType = rmkType;
273
274 // set the initial application state
276
277 // version banner
278 G4String vs = G4Version;
279 vs = vs.substr(1, vs.size() - 2);
280 switch(rmkType)
281 {
282 case masterRMK:
283 versionString = " Geant4 version ";
284 versionString += vs;
285 versionString += " ";
286 versionString += G4Date;
287 G4cout << G4endl
288 << "**************************************************************"
289 << G4endl << versionString << G4endl
290 << " << in Multi-threaded mode >> " << G4endl
291 << " Copyright : Geant4 Collaboration"
292 << G4endl
293 << " References : NIM A 506 (2003), 250-303"
294 << G4endl
295 << " : IEEE-TNS 53 (2006), 270-278"
296 << G4endl
297 << " : NIM A 835 (2016), 186-225"
298 << G4endl
299 << " WWW : http://geant4.org/"
300 << G4endl
301 << "**************************************************************"
302 << G4endl << G4endl;
303 break;
304 default:
305 if(verboseLevel)
306 {
307 versionString = " Local thread RunManagerKernel version ";
308 versionString += vs;
309 G4cout
310 << G4endl
311 << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
312 "^^^^^^^^^"
313 << G4endl << versionString << G4endl
314 << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
315 "^^^^^^^^^"
316 << G4endl << G4endl;
317 }
318 }
319
320#ifdef G4MULTITHREADED
321 G4UnitDefinition::GetUnitsTable().Synchronize();
322#endif
323}
324
326{
328 return;
329
330 // Remove old world logical volume from the default region, if exist
332 {
333 if(defaultRegion->GetNumberOfRootVolumes() > size_t(1))
334 {
335 G4Exception("G4RunManager::SetupDefaultRegion", "Run0005", FatalException,
336 "Default world region should have a unique logical volume.");
337 }
338 std::vector<G4LogicalVolume*>::iterator lvItr =
341 if(verboseLevel > 1)
342 G4cout
343 << "Obsolete world logical volume is removed from the default region."
344 << G4endl;
345 }
346}
347
349{
351 // set the application state to the quite state
352 if(pStateManager->GetCurrentState() != G4State_Quit)
353 {
354 if(verboseLevel > 0)
355 G4cout << "G4 kernel has come to Quit state." << G4endl;
356 pStateManager->SetNewState(G4State_Quit);
357 }
358
359 // open geometry for deletion
361
362 // deletion of Geant4 kernel classes
365 if(pwps)
366 delete pwps;
368 if(fSDM)
369 {
370 delete fSDM;
371 if(verboseLevel > 1)
372 G4cout << "G4SDManager deleted." << G4endl;
373 }
374 delete eventManager;
375 if(verboseLevel > 1)
376 G4cout << "EventManager deleted." << G4endl;
377
379 if(verboseLevel > 1)
380 G4cout << "Units table cleared." << G4endl;
381
382 // deletion of path-finder field-manager store, geometry and transportation
383 // manager
385 if(pFinder)
386 delete pFinder;
388 if(fmStore)
389 delete fmStore;
391 if(gManager)
392 delete gManager;
393 G4TransportationManager* tManager =
395 if(tManager)
396 {
397 delete tManager;
398 if(verboseLevel > 1)
399 G4cout << "TransportationManager deleted." << G4endl;
400 }
401
402 // deletion of navigation levels
403 if(verboseLevel > 1)
406
407 // deletion of G4RNGHelper singleton
409 {
411 if(rngHelper)
412 {
413 delete rngHelper;
414 if(verboseLevel > 1)
415 G4cout << "G4RNGHelper object is deleted." << G4endl;
416 }
417 }
418
419 // deletion of allocators
421 if(allocList)
422 {
423 allocList->Destroy(numberOfStaticAllocators, verboseLevel);
424 delete allocList;
425 if(verboseLevel > 1)
426 G4cout << "G4Allocator objects are deleted." << G4endl;
427 }
428
430 if((runManagerKernelType == workerRMK) && (verboseLevel > 0))
431 {
432 G4cout << "Thread-local UImanager is to be deleted." << G4endl
433 << "There should not be any thread-local G4cout/G4cerr hereafter."
434 << G4endl;
435 verboseLevel = 0;
436 }
437 if(pUImanager)
438 delete pUImanager;
439 if(verboseLevel > 1)
440 G4cout << "UImanager deleted." << G4endl;
441
442 delete pStateManager;
443 if(verboseLevel > 1)
444 G4cout << "StateManager deleted." << G4endl;
445 delete defaultExceptionHandler;
446 if(verboseLevel > 0)
447 G4cout << "RunManagerKernel is deleted. Good bye :)" << G4endl;
448 fRunManagerKernel = 0;
449}
450
452{
456 G4MTRunManager::masterWorlds_t masterWorlds = masterRM->GetMasterWorlds();
457 G4MTRunManager::masterWorlds_t::iterator itrMW = masterWorlds.begin();
458 for(; itrMW != masterWorlds.end(); itrMW++)
459 {
460 G4VPhysicalVolume* wv = (*itrMW).second;
461 G4VPhysicalVolume* pWorld =
463 wv->GetName());
464 if(!pWorld)
465 {
466 transM->RegisterWorld(wv);
467 }
468 }
469}
470
472 G4bool topologyIsChanged)
473{
475 G4ApplicationState currentState = stateManager->GetCurrentState();
476 if(currentState != G4State_Init)
477 {
478 if(!(currentState == G4State_Idle || currentState == G4State_PreInit))
479 {
480 G4cout << "Current application state is "
481 << stateManager->GetStateString(currentState) << G4endl;
482 G4Exception("G4RunManagerKernel::DefineWorldVolume",
483 "DefineWorldVolumeAtIncorrectState", FatalException,
484 "Geant4 kernel is not Init state : Method ignored.");
485 return;
486 }
487 else
488 {
489 // G4Exception("G4RunManagerKernel::DefineWorldVolume",
490 // "DefineWorldVolumeAtIncorrectState",
491 // JustWarning,
492 // "Geant4 kernel is not Init state : Assuming Init state.");
493 // G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init
494 // state."
495 // <<G4endl;
496 stateManager->SetNewState(G4State_Init);
497 }
498 }
499
500 currentWorld = worldVol;
504 G4MTRunManager::masterWorlds_t masterWorlds = masterRM->GetMasterWorlds();
505 G4MTRunManager::masterWorlds_t::iterator itrMW = masterWorlds.begin();
506 for(; itrMW != masterWorlds.end(); itrMW++)
507 {
508 if((*itrMW).first == 0)
509 {
510 if((*itrMW).second != currentWorld)
511 {
512 G4Exception("G4RunManagerKernel::WorkerDefineWorldVolume", "RUN3091",
513 FatalException, "Mass world is inconsistent");
514 }
515 transM->SetWorldForTracking((*itrMW).second);
516 }
517 else
518 {
519 transM->RegisterWorld((*itrMW).second);
520 }
521 }
522
523 if(topologyIsChanged)
525
526 // Notify the VisManager as well
528 {
530 if(pVVisManager)
531 pVVisManager->GeometryHasChanged();
532 }
533
534 geometryInitialized = true;
535 stateManager->SetNewState(currentState);
536 if(physicsInitialized && currentState != G4State_Idle)
537 {
538 stateManager->SetNewState(G4State_Idle);
539 }
540}
541
543 G4bool topologyIsChanged)
544{
546 G4ApplicationState currentState = stateManager->GetCurrentState();
547
548 if(currentState != G4State_Init)
549 {
550 if(!(currentState == G4State_Idle || currentState == G4State_PreInit))
551 {
552 G4cout << "Current application state is "
553 << stateManager->GetStateString(currentState) << G4endl;
554 G4Exception("G4RunManagerKernel::DefineWorldVolume",
555 "DefineWorldVolumeAtIncorrectState", FatalException,
556 "Geant4 kernel is not Init state : Method ignored.");
557 return;
558 }
559 else
560 {
561 // G4Exception("G4RunManagerKernel::DefineWorldVolume",
562 // "DefineWorldVolumeAtIncorrectState",
563 // JustWarning,
564 // "Geant4 kernel is not Init state : Assuming Init state.");
565 // G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init
566 // state."
567 // <<G4endl;
568 stateManager->SetNewState(G4State_Init);
569 }
570 }
571
572 // The world volume MUST NOT have a region defined by the user
573 if(worldVol->GetLogicalVolume()->GetRegion())
574 {
575 if(worldVol->GetLogicalVolume()->GetRegion() != defaultRegion)
576 {
578 ED << "The world volume has a user-defined region <"
579 << worldVol->GetLogicalVolume()->GetRegion()->GetName() << ">."
580 << G4endl;
581 ED << "World would have a default region assigned by RunManagerKernel."
582 << G4endl;
583 G4Exception("G4RunManager::DefineWorldVolume", "Run0004", FatalException,
584 ED);
585 }
586 }
587
589
590 // Accept the world volume
591 currentWorld = worldVol;
592
593 // Set the default region to the world
594
595 G4LogicalVolume* worldLog = currentWorld->GetLogicalVolume();
596 worldLog->SetRegion(defaultRegion);
598 if(verboseLevel > 1)
599 G4cout << worldLog->GetName() << " is registered to the default region."
600 << G4endl;
601
602 // Set the world volume, notify the Navigator and reset its state
604 currentWorld);
605 if(topologyIsChanged)
607
608 // Notify the VisManager as well
610 {
612 if(pVVisManager)
613 pVVisManager->GeometryHasChanged();
614 }
615
616 geometryInitialized = true;
617 stateManager->SetNewState(currentState);
618 if(physicsInitialized && currentState != G4State_Idle)
619 {
620 stateManager->SetNewState(G4State_Idle);
621 }
622}
623
625{
626 physicsList = uPhys;
627
629 return;
630
631 SetupPhysics();
632 if(verboseLevel > 2)
634 if(verboseLevel > 1)
635 {
636 G4cout << "List of instantiated particles "
637 "============================================"
638 << G4endl;
640 for(G4int i = 0; i < nPtcl; i++)
641 {
644 G4cout << pd->GetParticleName() << " ";
645 if(i % 10 == 9)
646 G4cout << G4endl;
647 }
648 G4cout << G4endl;
649 }
650}
651
652#include "G4Geantino.hh"
653#include "G4IonConstructor.hh"
654#include "G4IonTable.hh"
656
658{
660
661 physicsList->ConstructParticle();
662
663 // For sanity reason
667 if(gion)
668 {
670 }
672
675 pItr->reset();
676 while((*pItr)())
677 {
678 G4ParticleDefinition* particle = pItr->value();
679 if(!(particle->IsGeneralIon()))
680 particle->SetParticleDefinitionID();
681 }
682
683 if(gion)
684 {
685 G4int gionId = gion->GetParticleDefinitionID();
686 pItr->reset(false);
687 while((*pItr)())
688 {
689 G4ParticleDefinition* particle = pItr->value();
690 if(particle->IsGeneralIon())
691 particle->SetParticleDefinitionID(gionId);
692 }
693 }
694#ifdef G4MULTITHREADED
695 G4UnitDefinition::GetUnitsTable().Synchronize();
696#endif
697}
698
699namespace
700{
701 G4Mutex initphysicsmutex = G4MUTEX_INITIALIZER;
702}
703
705{
707 G4ApplicationState currentState = stateManager->GetCurrentState();
708 if(currentState != G4State_Init)
709 {
710 G4cout << "Current application state is "
711 << stateManager->GetStateString(currentState) << G4endl;
712 if(!(currentState == G4State_Idle || currentState == G4State_PreInit))
713 {
714 G4Exception("G4RunManagerKernel::InitializePhysics",
715 "InitializePhysicsIncorrectState", FatalException,
716 "Geant4 kernel is not Init state : Method ignored.");
717 return;
718 }
719 else
720 {
721 // G4Exception("G4RunManagerKernel::DefineWorldVolume",
722 //"DefineWorldVolumeAtIncorrectState",
723 // JustWarning,
724 //"Geant4 kernel is not Init state : Assuming Init state.");
725 G4cout
726 << "Warning : Geant4 kernel is not Init state : Assuming Init state."
727 << G4endl;
728 stateManager->SetNewState(G4State_Init);
729 }
730 }
731
732 if(!physicsList)
733 {
734 G4Exception("G4RunManagerKernel::InitializePhysics", "Run0012",
735 FatalException, "G4VUserPhysicsList is not defined");
736 return;
737 }
738
739 if(verboseLevel > 1)
740 G4cout << "physicsList->Construct() start." << G4endl;
741 if(numberOfParallelWorld > 0)
742 physicsList->UseCoupledTransportation();
743 physicsList->Construct();
744
745 if(verboseLevel > 1)
746 G4cout << "physicsList->CheckParticleList() start." << G4endl;
747 physicsList->CheckParticleList();
748 // Cannot assume that SetCuts and CheckRegions are thread safe. We need to
749 // mutex Report from valgrind --tool=drd
750 G4AutoLock l(&initphysicsmutex);
752 {
753 if(verboseLevel > 1)
754 G4cout << "physicsList->setCut() start." << G4endl;
755 physicsList->SetCuts();
756 }
757 CheckRegions();
758 l.unlock();
759
760 /*******************
761 // static G4bool createIsomerOnlyOnce = false;
762 // if(G4Threading::IsMultithreadedApplication() &&
763 G4Threading::IsMasterThread())
764 // {
765 // if(!createIsomerOnlyOnce)
766 // {
767 // createIsomerOnlyOnce = true;
768 // G4ParticleDefinition* gion =
769 G4ParticleTable::GetParticleTable()->GetGenericIon();
770 // if(gion)
771 // {
772 // G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer();
773 // PropagateGenericIonID();
774 // }
775 // }
776 // }
777 *********************/
778
779 physicsInitialized = true;
780#ifdef G4MULTITHREADED
781 G4UnitDefinition::GetUnitsTable().Synchronize();
782#endif
783 stateManager->SetNewState(currentState);
784 if(geometryInitialized && currentState != G4State_Idle)
785 {
786 stateManager->SetNewState(G4State_Idle);
787 }
788}
789
791{
793 G4ApplicationState currentState = stateManager->GetCurrentState();
794
795 if(!geometryInitialized)
796 {
797 G4Exception("G4RunManagerKernel::RunInitialization", "Run0021", JustWarning,
798 "Geometry has not yet initialized : method ignored.");
799 return false;
800 }
801
802 if(!physicsInitialized)
803 {
804 G4Exception("G4RunManagerKernel::RunInitialization", "Run0022", JustWarning,
805 "Physics has not yet initialized : method ignored.");
806 return false;
807 }
808
809 if(currentState != G4State_Idle)
810 {
811 G4Exception("G4RunManagerKernel::RunInitialization", "Run0023", JustWarning,
812 "Geant4 kernel not in Idle state : method ignored.");
813 return false;
814 }
815
817 CheckRegularGeometry();
818
819 stateManager->SetNewState(G4State_Init);
822 UpdateRegion();
823 BuildPhysicsTables(fakeRun);
824
826 {
828 // CheckRegularGeometry();
829 // Notify the VisManager as well
831 {
833 if(pVVisManager)
834 pVVisManager->GeometryHasChanged();
835 }
836 }
837
839
840#ifdef G4MULTITHREADED
841 G4UnitDefinition::GetUnitsTable().Synchronize();
842#endif
843 stateManager->SetNewState(G4State_Idle);
844 stateManager->SetNewState(G4State_GeomClosed);
845 return true;
846}
847
849{
852 if(gion)
853 {
854 // G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer();
855 G4int gionId = gion->GetParticleDefinitionID();
858 pItr->reset(false);
859 while((*pItr)())
860 {
861 G4ParticleDefinition* particle = pItr->value();
862 if(particle->IsGeneralIon())
863 particle->SetParticleDefinitionID(gionId);
864 }
865 }
866}
867
869{
873}
874
876{
878 {
880 return;
881 }
882
883 // We have to tweak the navigator's state in case a geometry has been
884 // modified between runs. By the following calls we ensure that navigator's
885 // state is reset properly. It is required the geometry to be closed
886 // and previous optimisations to be cleared.
887
889 if(verboseLevel > 1)
890 G4cout << "Start closing geometry." << G4endl;
891
892 geomManager->OpenGeometry();
893 geomManager->CloseGeometry(geometryToBeOptimized, verboseLevel > 1);
894
896}
897
899{
901 G4ApplicationState currentState = stateManager->GetCurrentState();
902 if(currentState != G4State_Init)
903 {
904 G4Exception("G4RunManagerKernel::UpdateRegion", "Run0024", JustWarning,
905 "Geant4 kernel not in Init state : method ignored.");
906 return;
907 }
908
910 return;
911
912 CheckRegions();
913
915
917 currentWorld);
918}
919
921{
923 physicsNeedsToBeReBuilt)
924 {
925#ifdef G4MULTITHREADED
927 {
928 // make sure workers also rebuild physics tables
930 pUImanager->ApplyCommand("/run/physicsModified");
931 }
932#endif
933 physicsList->BuildPhysicsTable();
934 ////G4ProductionCutsTable::GetProductionCutsTable()->PhysicsTableUpdated();
935 physicsNeedsToBeReBuilt = false;
936 }
937
938 if(!fakeRun && verboseLevel > 1)
939 DumpRegion();
940 if(!fakeRun && verboseLevel > 0)
941 physicsList->DumpCutValuesTable();
942 if(!fakeRun)
943 physicsList->DumpCutValuesTableIfRequested();
944}
945
947{
950 size_t nWorlds = transM->GetNoWorlds();
951 std::vector<G4VPhysicalVolume*>::iterator wItr;
952 for(size_t i = 0; i < G4RegionStore::GetInstance()->size(); i++)
953 {
954 G4Region* region = (*(G4RegionStore::GetInstance()))[i];
955
956 // Let each region have a pointer to the world volume where it belongs to.
957 // G4Region::SetWorld() checks if the region belongs to the given world and
958 // set it only if it does. Thus, here we go through all the registered world
959 // volumes.
960 region->SetWorld(0); // reset
961 region->UsedInMassGeometry(false);
962 region->UsedInParallelGeometry(false);
963 wItr = transM->GetWorldsIterator();
964 for(size_t iw = 0; iw < nWorlds; iw++)
965 {
966 if(region->BelongsTo(*wItr))
967 {
968 if(*wItr == currentWorld)
969 {
970 region->UsedInMassGeometry(true);
971 }
972 else
973 {
974 region->UsedInParallelGeometry(true);
975 }
976 }
977 region->SetWorld(*wItr);
978 wItr++;
979 }
980
981 G4ProductionCuts* cuts = region->GetProductionCuts();
982 if(!cuts)
983 {
984 if(region->IsInMassGeometry())
985 {
986 G4cout << "Warning : Region <" << region->GetName()
987 << "> does not have specific production cuts," << G4endl
988 << "even though it appears in the current tracking world."
989 << G4endl;
990 G4cout << "Default cuts are used for this region." << G4endl;
991 }
992
993 if(region->IsInMassGeometry() || region->IsInParallelGeometry())
994 {
995 region->SetProductionCuts(
998 }
999 }
1000 }
1001
1002 //
1003 // If a parallel world has no region, set default region for parallel world
1004 //
1005
1006 wItr = transM->GetWorldsIterator();
1007 for(size_t iw = 0; iw < nWorlds; iw++)
1008 {
1009 // G4cout << "+++ " << (*wItr)->GetName() << G4endl;
1010 if(*wItr != currentWorld)
1011 {
1012 G4LogicalVolume* pwLogical = (*wItr)->GetLogicalVolume();
1013 if(!(pwLogical->GetRegion()))
1014 {
1017 // G4cout << "+++++ defaultRegionForParallelWorld is set to "
1018 // << (*wItr)->GetName() << " +++++" << G4endl;
1019 }
1020 }
1021 wItr++;
1022 }
1023}
1024
1026{
1027 G4Region* region = G4RegionStore::GetInstance()->GetRegion(rname);
1028 if(region)
1029 DumpRegion(region);
1030}
1031
1033{
1034 if(!region)
1035 {
1036 for(size_t i = 0; i < G4RegionStore::GetInstance()->size(); i++)
1037 {
1039 }
1040 }
1041 else
1042 {
1044 return;
1045 G4cout << G4endl;
1046 G4cout << "Region <" << region->GetName() << "> -- ";
1047 if(region->GetWorldPhysical())
1048 {
1049 G4cout << " -- appears in <" << region->GetWorldPhysical()->GetName()
1050 << "> world volume";
1051 }
1052 else
1053 {
1054 G4cout << " -- is not associated to any world.";
1055 }
1056 G4cout << G4endl;
1057 if(region->IsInMassGeometry())
1058 {
1059 G4cout << " This region is in the mass world." << G4endl;
1060 }
1061 if(region->IsInParallelGeometry())
1062 {
1063 G4cout << " This region is in the parallel world." << G4endl;
1064 }
1065
1066 G4cout << " Root logical volume(s) : ";
1067 size_t nRootLV = region->GetNumberOfRootVolumes();
1068 std::vector<G4LogicalVolume*>::iterator lvItr =
1070 for(size_t j = 0; j < nRootLV; j++)
1071 {
1072 G4cout << (*lvItr)->GetName() << " ";
1073 lvItr++;
1074 }
1075 G4cout << G4endl;
1076
1077 G4cout << " Pointers : G4VUserRegionInformation["
1078 << region->GetUserInformation() << "], G4UserLimits["
1079 << region->GetUserLimits() << "], G4FastSimulationManager["
1080 << region->GetFastSimulationManager() << "], G4UserSteppingAction["
1081 << region->GetRegionalSteppingAction() << "]" << G4endl;
1082
1083 G4cout << " Materials : ";
1084 std::vector<G4Material*>::const_iterator mItr =
1085 region->GetMaterialIterator();
1086 size_t nMaterial = region->GetNumberOfMaterials();
1087 for(size_t iMate = 0; iMate < nMaterial; iMate++)
1088 {
1089 G4cout << (*mItr)->GetName() << " ";
1090 mItr++;
1091 }
1092 G4cout << G4endl;
1093 G4ProductionCuts* cuts = region->GetProductionCuts();
1094 if(!cuts && region->IsInMassGeometry())
1095 {
1096 G4cerr << "Warning : Region <" << region->GetName()
1097 << "> does not have specific production cuts." << G4endl;
1098 G4cerr << "Default cuts are used for this region." << G4endl;
1100 ->GetDefaultProductionCuts());
1101 }
1102 else if(cuts)
1103 {
1104 G4cout << " Production cuts : "
1105 << " gamma "
1106 << G4BestUnit(cuts->GetProductionCut("gamma"), "Length")
1107 << " e- " << G4BestUnit(cuts->GetProductionCut("e-"), "Length")
1108 << " e+ " << G4BestUnit(cuts->GetProductionCut("e+"), "Length")
1109 << " proton "
1110 << G4BestUnit(cuts->GetProductionCut("proton"), "Length")
1111 << G4endl;
1112 }
1113 }
1114}
1115
1116#include "G4LogicalVolumeStore.hh"
1117void G4RunManagerKernel::CheckRegularGeometry()
1118{
1120 for(G4LogicalVolumeStore::iterator pos = store->begin(); pos != store->end();
1121 pos++)
1122 {
1123 if((*pos) && ((*pos)->GetNoDaughters() == 1))
1124 {
1125 if((*pos)->GetDaughter(0)->IsRegularStructure())
1126 {
1127 SetScoreSplitter();
1128 return;
1129 }
1130 }
1131 }
1132}
1133
1134#include "G4ParticleDefinition.hh"
1135#include "G4ParticleTable.hh"
1136#include "G4ProcessManager.hh"
1137#include "G4ProcessVector.hh"
1138#include "G4VProcess.hh"
1139G4bool G4RunManagerKernel::ConfirmCoupledTransportation()
1140{
1143 theParticleTable->GetIterator();
1144 theParticleIterator->reset();
1145 while((*theParticleIterator)())
1146 {
1149 if(pm)
1150 {
1152 G4VProcess* p = (*pv)[0];
1153 return ((p->GetProcessName()) == "CoupledTransportation");
1154 }
1155 }
1156 return false;
1157}
1158
1160void G4RunManagerKernel::SetScoreSplitter()
1161{
1165 theParticleTable->GetIterator();
1166
1167 // Ensure that Process is added only once to the particles' process managers
1168 static G4ThreadLocal bool InitSplitter = false;
1169 if(!InitSplitter)
1170 {
1171 InitSplitter = true;
1172
1173 theParticleIterator->reset();
1174 while((*theParticleIterator)())
1175 {
1176 G4ParticleDefinition* particle = theParticleIterator->value();
1177 G4ProcessManager* pmanager = particle->GetProcessManager();
1178 if(pmanager)
1179 {
1180 pmanager->AddDiscreteProcess(pSplitter);
1181 }
1182 }
1183
1184 if(verboseLevel > 0)
1185 {
1186 G4cout
1187 << "G4RunManagerKernel -- G4ScoreSplittingProcess is appended to all "
1188 "particles."
1189 << G4endl;
1190 }
1191 }
1192}
1193
1195{
1198 theParticleTable->GetIterator();
1199 theParticleIterator->reset();
1200 // loop on particles and get process manager from there list of processes
1201 while((*theParticleIterator)())
1202 {
1205 if(pm)
1206 {
1207 G4ProcessVector& procs = *(pm->GetProcessList());
1208 for(std::size_t idx = 0; idx < procs.size(); ++idx)
1209 {
1210 const G4VProcess* masterP = procs[idx]->GetMasterProcess();
1211 if(!masterP)
1212 {
1213 // Process does not have an associated shadow master process
1214 // We are in master mode or sequential
1215 procs[idx]->SetMasterProcess(const_cast<G4VProcess*>(procs[idx]));
1216 }
1217 }
1218 }
1219 }
1220}
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:35
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()
G4int Size() const
void Destroy(G4int nStat=0, G4int verboseLevel=0)
static int Enable(const std::string &)
Definition: G4Backtrace.hh:757
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
std::map< G4int, G4VPhysicalVolume * > masterWorlds_t
static G4MTRunManager * GetMasterRunManager()
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=0)
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
G4bool BelongsTo(G4VPhysicalVolume *thePhys) const
Definition: G4Region.cc:404
G4FastSimulationManager * GetFastSimulationManager() const
Definition: G4Region.cc:130
G4VUserRegionInformation * GetUserInformation() const
void SetWorld(G4VPhysicalVolume *wp)
Definition: G4Region.cc:388
G4bool IsInParallelGeometry() const
G4ProductionCuts * GetProductionCuts() const
void RemoveRootLogicalVolume(G4LogicalVolume *lv, G4bool scan=true)
Definition: G4Region.cc:318
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:148
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:283
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:48
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:46
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