Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4RunManagerKernel Class Reference

#include <G4RunManagerKernel.hh>

Public Member Functions

 G4RunManagerKernel ()
 
virtual ~G4RunManagerKernel ()
 
void DefineWorldVolume (G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
 
void SetPhysics (G4VUserPhysicsList *uPhys)
 
void InitializePhysics ()
 
G4bool RunInitialization ()
 
void RunTermination ()
 
void UpdateRegion ()
 
void DumpRegion (const G4String &rname) const
 
void DumpRegion (G4Region *region=0) const
 
void GeometryHasBeenModified ()
 
void PhysicsHasBeenModified ()
 
G4EventManagerGetEventManager () const
 
G4StackManagerGetStackManager () const
 
G4TrackingManagerGetTrackingManager () const
 
void SetPrimaryTransformer (G4PrimaryTransformer *pt)
 
G4PrimaryTransformerGetPrimaryTransformer () const
 
const G4StringGetVersionString () const
 
void SetVerboseLevel (G4int vl)
 
void SetGeometryToBeOptimized (G4bool vl)
 
G4int GetNumberOfParallelWorld () const
 
void SetNumberOfParallelWorld (G4int i)
 

Static Public Member Functions

static G4RunManagerKernelGetRunManagerKernel ()
 

Detailed Description

Definition at line 68 of file G4RunManagerKernel.hh.

Constructor & Destructor Documentation

◆ G4RunManagerKernel()

G4RunManagerKernel::G4RunManagerKernel ( )

Definition at line 65 of file G4RunManagerKernel.cc.

66:physicsList(0),currentWorld(0),
67 geometryInitialized(false),physicsInitialized(false),
68 geometryNeedsToBeClosed(true),geometryToBeOptimized(true),
69 physicsNeedsToBeReBuilt(true),verboseLevel(0),
70 numberOfParallelWorld(0)
71{
72#ifdef G4FPE_DEBUG
73 InvalidOperationDetection();
74#endif
75
76 defaultExceptionHandler = new G4ExceptionHandler();
77 if(fRunManagerKernel)
78 {
79 G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0001",
80 FatalException,"More than one G4RunManagerKernel is constructed.");
81 }
82 fRunManagerKernel = this;
83
85 if(particleTable->entries()>0)
86 {
87 // No particle should be registered beforehand
89 ED<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<G4endl;
90 ED<<" G4RunManagerKernel fatal exception"<<G4endl;
91 ED<<" -- Following particles have already been registered"<<G4endl;
92 ED<<" before G4RunManagerKernel is instantiated."<<G4endl;
93 for(int i=0;i<particleTable->entries();i++)
94 { ED<<" "<<particleTable->GetParticle(i)->GetParticleName()<<G4endl; }
95 ED<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<G4endl;
96 G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0002",
98 }
99
100 // construction of Geant4 kernel classes
101 eventManager = new G4EventManager();
102 defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
103 defaultRegionForParallelWorld = new G4Region("DefaultRegionForParallelWorld"); // deleted by store
104 defaultRegion->SetProductionCuts(
105 G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
106 defaultRegionForParallelWorld->SetProductionCuts(
107 G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
108
109 // Following line is tentatively moved from SetPhysics method
110 // Commented out for introduction of non-static particle definition // G4ParticleTable::GetParticleTable()->SetReadiness();
111 // set the initial application state
113
114 // version banner
115 G4String vs = G4Version;
116 vs = vs.substr(1,vs.size()-2);
117 versionString = " Geant4 version ";
118 versionString += vs;
119 versionString += " ";
120 versionString += G4Date;
121 G4cout << G4endl
122 << "*************************************************************" << G4endl
123 << versionString << G4endl
124 << " Copyright : Geant4 Collaboration" << G4endl
125 << " Reference : NIM A 506 (2003), 250-303" << G4endl
126 << " WWW : http://cern.ch/geant4" << G4endl
127 << "*************************************************************" << G4endl
128 << G4endl;
129}
@ G4State_PreInit
@ FatalException
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
const G4String & GetParticleName() const
G4int entries() const
static G4ParticleTable * GetParticleTable()
G4ParticleDefinition * GetParticle(G4int index)
static G4ProductionCutsTable * GetProductionCutsTable()
void SetProductionCuts(G4ProductionCuts *cut)
static G4StateManager * GetStateManager()
G4bool SetNewState(G4ApplicationState requestedState)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76

◆ ~G4RunManagerKernel()

G4RunManagerKernel::~G4RunManagerKernel ( )
virtual

Definition at line 131 of file G4RunManagerKernel.cc.

132{
134 // set the application state to the quite state
135 if(pStateManager->GetCurrentState()!=G4State_Quit)
136 {
137 if(verboseLevel>0) G4cout << "G4 kernel has come to Quit state." << G4endl;
138 pStateManager->SetNewState(G4State_Quit);
139 }
140
141 // open geometry for deletion
143
144 // deletion of Geant4 kernel classes
146 if(fSDM)
147 {
148 delete fSDM;
149 if(verboseLevel>1) G4cout << "G4SDManager deleted." << G4endl;
150 }
151 delete eventManager;
152 if(verboseLevel>1) G4cout << "EventManager deleted." << G4endl;
154 {
155 if(pUImanager) delete pUImanager;
156 if(verboseLevel>1) G4cout << "UImanager deleted." << G4endl;
157 }
159 if(verboseLevel>1) G4cout << "Units table cleared." << G4endl;
160 delete pStateManager;
161 if(verboseLevel>1) G4cout << "StateManager deleted." << G4endl;
162 delete defaultExceptionHandler;
163 if(verboseLevel>1) G4cout << "RunManagerKernel is deleted." << G4endl;
164 fRunManagerKernel = 0;
165}
@ G4State_Quit
void OpenGeometry(G4VPhysicalVolume *vol=0)
static G4GeometryManager * GetInstance()
static G4SDManager * GetSDMpointerIfExist()
Definition: G4SDManager.cc:49
G4ApplicationState GetCurrentState() const
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:51
static void ClearUnitsTable()

Member Function Documentation

◆ DefineWorldVolume()

void G4RunManagerKernel::DefineWorldVolume ( G4VPhysicalVolume worldVol,
G4bool  topologyIsChanged = true 
)

Definition at line 167 of file G4RunManagerKernel.cc.

169{
171 G4ApplicationState currentState = stateManager->GetCurrentState();
172 if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
173 {
174 G4Exception("G4RunManagerKernel::DefineWorldVolume",
175 "Run00031",
177 "Geant4 kernel is not PreInit or Idle state : Method ignored.");
178 return;
179 }
180
181 // The world volume MUST NOT have a region defined by the user
182 if(worldVol->GetLogicalVolume()->GetRegion())
183 {
184 if(worldVol->GetLogicalVolume()->GetRegion()!=defaultRegion)
185 {
187 ED << "The world volume has a user-defined region <"
188 << worldVol->GetLogicalVolume()->GetRegion()->GetName()
189 << ">." << G4endl;
190 ED << "World would have a default region assigned by RunManagerKernel."
191 << G4endl;
192 G4Exception("G4RunManager::DefineWorldVolume",
193 "Run0004", FatalException, ED);
194 }
195 }
196
197 // Remove old world logical volume from the default region, if exist
198 if(defaultRegion->GetNumberOfRootVolumes())
199 {
200 if(defaultRegion->GetNumberOfRootVolumes()>size_t(1))
201 {
202 G4Exception("G4RunManager::DefineWorldVolume",
203 "Run0005",
205 "Default world region should have a unique logical volume.");
206 }
207 std::vector<G4LogicalVolume*>::iterator lvItr
208 = defaultRegion->GetRootLogicalVolumeIterator();
209 defaultRegion->RemoveRootLogicalVolume(*lvItr,false);
210 if(verboseLevel>1) G4cout
211 << "Obsolete world logical volume is removed from the default region." << G4endl;
212 }
213
214 // Accept the world volume
215 currentWorld = worldVol;
216
217 // Set the default region to the world
218 G4LogicalVolume* worldLog = currentWorld->GetLogicalVolume();
219 worldLog->SetRegion(defaultRegion);
220 defaultRegion->AddRootLogicalVolume(worldLog);
221 if(verboseLevel>1) G4cout << worldLog->GetName()
222 << " is registered to the default region." << G4endl;
223
224 // Set the world volume, notify the Navigator and reset its state
226 ->SetWorldForTracking(currentWorld);
227 if(topologyIsChanged) geometryNeedsToBeClosed = true;
228
229 // Notify the VisManager as well
231 if(pVVisManager) pVVisManager->GeometryHasChanged();
232
233 geometryInitialized = true;
234 if(physicsInitialized && currentState!=G4State_Idle)
235 { stateManager->SetNewState(G4State_Idle); }
236}
G4ApplicationState
@ G4State_Idle
@ JustWarning
G4String GetName() const
void SetRegion(G4Region *reg)
G4Region * GetRegion() const
void RemoveRootLogicalVolume(G4LogicalVolume *lv, G4bool scan=true)
Definition: G4Region.cc:256
const G4String & GetName() const
size_t GetNumberOfRootVolumes() const
void AddRootLogicalVolume(G4LogicalVolume *lv)
Definition: G4Region.cc:227
std::vector< G4LogicalVolume * >::iterator GetRootLogicalVolumeIterator()
static G4TransportationManager * GetTransportationManager()
void SetWorldForTracking(G4VPhysicalVolume *theWorld)
G4LogicalVolume * GetLogicalVolume() const
static G4VVisManager * GetConcreteInstance()
virtual void GeometryHasChanged()=0

Referenced by G4RunManager::DefineWorldVolume(), G4ErrorRunManagerHelper::InitializeGeometry(), and G4RunManager::InitializeGeometry().

◆ DumpRegion() [1/2]

void G4RunManagerKernel::DumpRegion ( const G4String rname) const

Definition at line 488 of file G4RunManagerKernel.cc.

489{
491 if(region) DumpRegion(region);
492}
static G4RegionStore * GetInstance()
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
void DumpRegion(const G4String &rname) const

Referenced by G4RunManager::DumpRegion(), and DumpRegion().

◆ DumpRegion() [2/2]

void G4RunManagerKernel::DumpRegion ( G4Region region = 0) const

Definition at line 494 of file G4RunManagerKernel.cc.

495{
496 if(!region)
497 {
498 for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
500 }
501 else
502 {
503 G4cout << G4endl;
504 G4cout << "Region <" << region->GetName() << "> -- ";
505 if(region->GetWorldPhysical())
506 {
507 G4cout << " -- appears in <"
508 << region->GetWorldPhysical()->GetName() << "> world volume";
509 }
510 else
511 { G4cout << " -- is not associated to any world."; }
512 G4cout << G4endl;
513 if(region->IsInMassGeometry())
514 { G4cout << " This region is in the mass world." << G4endl; }
515 if(region->IsInParallelGeometry())
516 { G4cout << " This region is in the parallel world." << G4endl; }
517
518 G4cout << " Root logical volume(s) : ";
519 size_t nRootLV = region->GetNumberOfRootVolumes();
520 std::vector<G4LogicalVolume*>::iterator lvItr = region->GetRootLogicalVolumeIterator();
521 for(size_t j=0;j<nRootLV;j++)
522 { G4cout << (*lvItr)->GetName() << " "; lvItr++; }
523 G4cout << G4endl;
524
525 G4cout << " Pointers : G4VUserRegionInformation[" << region->GetUserInformation()
526 << "], G4UserLimits[" << region->GetUserLimits()
527 << "], G4FastSimulationManager[" << region->GetFastSimulationManager()
528 << "], G4UserSteppingAction[" << region->GetRegionalSteppingAction() << "]" << G4endl;
529
530// if(region->GetWorldPhysical()!=currentWorld)
531// {
532// G4cout << G4endl;
533// return;
534// }
535 G4cout << " Materials : ";
536 std::vector<G4Material*>::const_iterator mItr = region->GetMaterialIterator();
537 size_t nMaterial = region->GetNumberOfMaterials();
538 for(size_t iMate=0;iMate<nMaterial;iMate++)
539 {
540 G4cout << (*mItr)->GetName() << " ";
541 mItr++;
542 }
543 G4cout << G4endl;
544 G4ProductionCuts* cuts = region->GetProductionCuts();
545 if(!cuts && region->IsInMassGeometry())
546 {
547 G4cerr << "Warning : Region <" << region->GetName()
548 << "> does not have specific production cuts." << G4endl;
549 G4cerr << "Default cuts are used for this region." << G4endl;
550 region->SetProductionCuts(
551 G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
552 }
553 else if(cuts)
554 {
555 G4cout << " Production cuts : "
556 << " gamma "
557 << G4BestUnit(cuts->GetProductionCut("gamma"),"Length")
558 << " e- "
559 << G4BestUnit(cuts->GetProductionCut("e-"),"Length")
560 << " e+ "
561 << G4BestUnit(cuts->GetProductionCut("e+"),"Length")
562 << " proton "
563 << G4BestUnit(cuts->GetProductionCut("proton"),"Length")
564 << G4endl;
565 }
566 }
567}
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
G4DLLIMPORT std::ostream G4cerr
G4double GetProductionCut(G4int index) const
G4FastSimulationManager * GetFastSimulationManager() const
G4VUserRegionInformation * GetUserInformation() const
G4bool IsInParallelGeometry() const
G4ProductionCuts * GetProductionCuts() const
G4VPhysicalVolume * GetWorldPhysical() const
G4UserLimits * GetUserLimits() const
G4bool IsInMassGeometry() const
G4UserSteppingAction * GetRegionalSteppingAction() const
size_t GetNumberOfMaterials() const
std::vector< G4Material * >::const_iterator GetMaterialIterator() const
const G4String & GetName() const

◆ GeometryHasBeenModified()

void G4RunManagerKernel::GeometryHasBeenModified ( )
inline

Definition at line 147 of file G4RunManagerKernel.hh.

148 { geometryNeedsToBeClosed = true; }

Referenced by G4RunManager::GeometryHasBeenModified(), and G4RunManager::SetGeometryToBeOptimized().

◆ GetEventManager()

G4EventManager * G4RunManagerKernel::GetEventManager ( ) const
inline

Definition at line 161 of file G4RunManagerKernel.hh.

162 { return eventManager; }

Referenced by G4RunManager::G4RunManager().

◆ GetNumberOfParallelWorld()

G4int G4RunManagerKernel::GetNumberOfParallelWorld ( ) const
inline

Definition at line 187 of file G4RunManagerKernel.hh.

188 { return numberOfParallelWorld; }

Referenced by G4PhysicsListHelper::AddTransportation().

◆ GetPrimaryTransformer()

G4PrimaryTransformer * G4RunManagerKernel::GetPrimaryTransformer ( ) const
inline

Definition at line 169 of file G4RunManagerKernel.hh.

170 { return eventManager->GetPrimaryTransformer(); }
G4PrimaryTransformer * GetPrimaryTransformer() const

Referenced by RunInitialization().

◆ GetRunManagerKernel()

G4RunManagerKernel * G4RunManagerKernel::GetRunManagerKernel ( )
static

Definition at line 62 of file G4RunManagerKernel.cc.

63{ return fRunManagerKernel; }

Referenced by G4PhysicsListHelper::AddTransportation(), and G4ErrorRunManagerHelper::G4ErrorRunManagerHelper().

◆ GetStackManager()

G4StackManager * G4RunManagerKernel::GetStackManager ( ) const
inline

Definition at line 163 of file G4RunManagerKernel.hh.

164 { return eventManager->GetStackManager(); }
G4StackManager * GetStackManager() const

◆ GetTrackingManager()

G4TrackingManager * G4RunManagerKernel::GetTrackingManager ( ) const
inline

Definition at line 165 of file G4RunManagerKernel.hh.

166 { return eventManager->GetTrackingManager(); }
G4TrackingManager * GetTrackingManager() const

◆ GetVersionString()

const G4String & G4RunManagerKernel::GetVersionString ( ) const
inline

Definition at line 172 of file G4RunManagerKernel.hh.

173 { return versionString; }

Referenced by G4RunManager::GetVersionString().

◆ InitializePhysics()

void G4RunManagerKernel::InitializePhysics ( )

Definition at line 258 of file G4RunManagerKernel.cc.

259{
261 G4ApplicationState currentState = stateManager->GetCurrentState();
262 if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
263 {
264 G4Exception("G4RunManagerKernel::InitializePhysics",
265 "Run0011", JustWarning,
266 "Geant4 kernel is not PreInit or Idle state : Method ignored.");
267 return;
268 }
269
270 if(!physicsList)
271 {
272 G4Exception("G4RunManagerKernel::InitializePhysics",
273 "Run0012", FatalException,
274 "G4VUserPhysicsList is not defined");
275 return;
276 }
277
278 if(verboseLevel>1) G4cout << "physicsList->Construct() start." << G4endl;
279 if(numberOfParallelWorld>0) physicsList->UseCoupledTransportation();
280 physicsList->Construct();
281
282 if(verboseLevel>1) G4cout << "physicsList->CheckParticleList() start." << G4endl;
283 physicsList->CheckParticleList();
284 if(verboseLevel>1) G4cout << "physicsList->setCut() start." << G4endl;
285 physicsList->SetCuts();
286 CheckRegions();
287 physicsInitialized = true;
288 if(geometryInitialized && currentState!=G4State_Idle)
289 { stateManager->SetNewState(G4State_Idle); }
290}
void UseCoupledTransportation(G4bool vl=true)

Referenced by G4ErrorRunManagerHelper::InitializePhysics(), and G4RunManager::InitializePhysics().

◆ PhysicsHasBeenModified()

void G4RunManagerKernel::PhysicsHasBeenModified ( )
inline

Definition at line 153 of file G4RunManagerKernel.hh.

154 { physicsNeedsToBeReBuilt = true; }

Referenced by G4RunManager::PhysicsHasBeenModified().

◆ RunInitialization()

G4bool G4RunManagerKernel::RunInitialization ( )

Definition at line 292 of file G4RunManagerKernel.cc.

293{
295 G4ApplicationState currentState = stateManager->GetCurrentState();
296
297 if(!geometryInitialized)
298 {
299 G4Exception("G4RunManagerKernel::RunInitialization",
300 "Run0021",
302 "Geometry has not yet initialized : method ignored.");
303 return false;
304 }
305
306 if(!physicsInitialized)
307 {
308 G4Exception("G4RunManagerKernel::RunInitialization",
309 "Run0022",
311 "Physics has not yet initialized : method ignored.");
312 return false;
313 }
314
315 if( currentState != G4State_Idle )
316 {
317 G4Exception("G4RunManagerKernel::RunInitialization",
318 "Run0023",
320 "Geant4 kernel not in Idle state : method ignored.");
321 return false;
322 }
323
324 //if(numberOfParallelWorld>0)
325 //{ // Confirm G4CoupledTransportation is used
326 // if(!ConfirmCoupledTransportation())
327 // { G4Exception("G4CoupledTransportation must be used for parallel world."); }
328 //}
329
330 UpdateRegion();
331 BuildPhysicsTables();
332
333 if(geometryNeedsToBeClosed)
334 {
335 ResetNavigator();
336 CheckRegularGeometry();
337 // Notify the VisManager as well
339 if(pVVisManager) pVVisManager->GeometryHasChanged();
340 }
341
343
344 stateManager->SetNewState(G4State_GeomClosed);
345 return true;
346}
@ G4State_GeomClosed
G4PrimaryTransformer * GetPrimaryTransformer() const

Referenced by G4ErrorRunManagerHelper::RunInitialization(), and G4RunManager::RunInitialization().

◆ RunTermination()

void G4RunManagerKernel::RunTermination ( )

◆ SetGeometryToBeOptimized()

void G4RunManagerKernel::SetGeometryToBeOptimized ( G4bool  vl)
inline

Definition at line 178 of file G4RunManagerKernel.hh.

179 {
180 if(geometryToBeOptimized != vl)
181 {
182 geometryToBeOptimized = vl;
183 geometryNeedsToBeClosed = true;
184 }
185 }

Referenced by G4RunManager::SetGeometryToBeOptimized().

◆ SetNumberOfParallelWorld()

void G4RunManagerKernel::SetNumberOfParallelWorld ( G4int  i)
inline

Definition at line 189 of file G4RunManagerKernel.hh.

190 { numberOfParallelWorld = i; }

Referenced by G4RunManager::InitializeGeometry().

◆ SetPhysics()

void G4RunManagerKernel::SetPhysics ( G4VUserPhysicsList uPhys)

Definition at line 238 of file G4RunManagerKernel.cc.

239{
240 physicsList = uPhys;
242 physicsList->ConstructParticle();
243 if(verboseLevel>2) G4ParticleTable::GetParticleTable()->DumpTable();
244 if(verboseLevel>1)
245 {
246 G4cout << "List of instantiated particles ============================================" << G4endl;
248 for(G4int i=0;i<nPtcl;i++)
249 {
251 G4cout << pd->GetParticleName() << " ";
252 if(i%10==9) G4cout << G4endl;
253 }
254 G4cout << G4endl;
255 }
256}
int G4int
Definition: G4Types.hh:66
void SetReadiness(G4bool val=true)
void DumpTable(const G4String &particle_name="ALL")
virtual void ConstructParticle()=0

Referenced by G4ErrorRunManagerHelper::InitializePhysics(), and G4RunManager::SetUserInitialization().

◆ SetPrimaryTransformer()

void G4RunManagerKernel::SetPrimaryTransformer ( G4PrimaryTransformer pt)
inline

Definition at line 167 of file G4RunManagerKernel.hh.

168 { eventManager->SetPrimaryTransformer(pt); }
void SetPrimaryTransformer(G4PrimaryTransformer *tf)

Referenced by G4RunManager::SetPrimaryTransformer().

◆ SetVerboseLevel()

void G4RunManagerKernel::SetVerboseLevel ( G4int  vl)
inline

Definition at line 175 of file G4RunManagerKernel.hh.

176 { verboseLevel = vl; }

Referenced by G4ErrorRunManagerHelper::G4ErrorRunManagerHelper(), and G4RunManager::SetVerboseLevel().

◆ UpdateRegion()

void G4RunManagerKernel::UpdateRegion ( )

Definition at line 373 of file G4RunManagerKernel.cc.

374{
376 G4ApplicationState currentState = stateManager->GetCurrentState();
377 if( currentState != G4State_Idle )
378 {
379 G4Exception("G4RunManagerKernel::UpdateRegion",
380 "Run0024",
382 "Geant4 kernel not in Idle state : method ignored.");
383 return;
384 }
385
386 CheckRegions();
389}
void UpdateCoupleTable(G4VPhysicalVolume *currentWorld)
void UpdateMaterialList(G4VPhysicalVolume *currentWorld=0)

Referenced by RunInitialization().


The documentation for this class was generated from the following files: