ATLAS Offline Software
G4AtlasRunManager.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 #include "G4GeometryManager.hh"
9 #include "G4LogicalVolumeStore.hh"
10 #include "G4ParallelWorldScoringProcess.hh"
11 #include "G4RegionStore.hh"
12 #include "G4Run.hh"
13 #include "G4ScoringManager.hh"
14 #include "G4StateManager.hh"
15 #include "G4TransportationManager.hh"
16 #include "G4UImanager.hh"
17 #include "G4UserRunAction.hh"
18 #include "G4RunManager.hh"
19 #include "G4UserWorkerInitialization.hh"
20 #include "G4Version.hh"
21 
22 #include <string>
23 
25  : G4RunManager()
26  , AthMessaging("G4AtlasRunManager")
27  , m_recordFlux(false)
28  , m_physListSvc("PhysicsListSvc", "G4AtlasRunManager")
29  , m_volumeSmartlessLevel({})
30 { }
31 
32 
33 G4AtlasRunManager* G4AtlasRunManager::GetG4AtlasRunManager ATLAS_NOT_THREAD_SAFE ()
34 {
35  static G4AtlasRunManager *thisManager = nullptr;
36  if (!thisManager) { thisManager = new G4AtlasRunManager; } // Leaked
37  return thisManager;
38 }
39 
40 
42 {
43  // ADA 11/28.2018: switch initialization order to meet ISF requirements
44  // Call the base class Initialize method. This will call
45  // InitializeGeometry and InitializePhysics.
46  if (m_quietMode) { SetVerboseLevel(0); } // HACK
48 }
49 
51 {
52  G4RunManager::RunInitialization();
53  if(auto* uwi = GetUserWorkerInitialization()) {
54  uwi->WorkerRunStart();
55  }
56 }
57 
59 {
60  ATH_MSG_DEBUG( "InitializeGeometry()" );
61 
62  // Create/assign detector construction
63  G4RunManager::SetUserInitialization(
65  if (userDetector) {
66  G4RunManager::InitializeGeometry();
67  }
68  else {
69  ATH_MSG_WARNING( " User Detector not set!!! Geometry NOT initialized!!!" );
70  }
71  return;
72 }
73 
74 
76 {
77  ATH_MSG_DEBUG( "G4AtlasRunManager::EndEvent" );
78 }
79 
80 
82 {
83  ATH_MSG_INFO( "InitializePhysics()" );
84  kernel->InitializePhysics();
85  physicsInitialized = true;
86 
87  // Grab the physics list tool and set the extra options
88  if (m_physListSvc.retrieve().isFailure()) {
89  ATH_MSG_ERROR ( "Could not retrieve the physics list tool" );
90  G4ExceptionDescription description;
91  description << "InitializePhysics: Failed to retrieve IPhysicsListSvc.";
92  G4Exception("G4AtlasRunManager", "CouldNotRetrievePLTool", FatalException, description);
93  abort(); // to keep Coverity happy
94  }
95  m_physListSvc->SetPhysicsOptions();
96 
97  if (m_recordFlux) {
98  m_fluxRecorder->InitializeFluxRecording();
99  }
100 
101  return;
102 }
103 
105 {
106 
107  G4StateManager* stateManager = G4StateManager::GetStateManager();
108  stateManager->SetNewState(G4State_GeomClosed);
109 
110  currentEvent = event;
111 
112  eventManager->ProcessOneEvent(currentEvent);
113  if (currentEvent->IsAborted()) {
114  ATH_MSG_WARNING( "G4AtlasRunManager::ProcessEvent: Event Aborted at Detector Simulation level" );
115  currentEvent = nullptr;
116  return true;
117  }
118 
119  if (m_recordFlux) { m_fluxRecorder->RecordFlux(currentEvent); }
120 
121  this->StackPreviousEvent(currentEvent);
122  bool abort = currentEvent->IsAborted();
123  currentEvent = nullptr;
124 
125  return abort;
126 }
127 
129 {
130  ATH_MSG_DEBUG( " G4AtlasRunManager::RunTermination() " );
131  if (m_recordFlux) {
132  m_fluxRecorder->WriteFluxInformation();
133  }
134 
135  this->CleanUpPreviousEvents();
136  previousEvents->clear();
137 
138  if (userRunAction) {
139  userRunAction->EndOfRunAction(currentRun);
140  }
141 
142  delete currentRun;
143  currentRun = nullptr;
144  runIDCounter++;
145 
146  ATH_MSG_VERBOSE( "Changing the state..." );
147  G4StateManager* stateManager = G4StateManager::GetStateManager();
148  stateManager->SetNewState(G4State_Idle);
149 
150  ATH_MSG_VERBOSE( "Opening the geometry back up" );
151  G4GeometryManager::GetInstance()->OpenGeometry();
152 
153  ATH_MSG_VERBOSE( "Terminating the run... State is " << stateManager->GetStateString( stateManager->GetCurrentState() ) );
154  kernel->RunTermination();
155  ATH_MSG_VERBOSE( "All done..." );
156 
157  userRunAction = nullptr;
158  userEventAction = nullptr;
159  userSteppingAction = nullptr;
160  userStackingAction = nullptr;
161  userTrackingAction = nullptr;
162  userDetector = nullptr;
163  userPrimaryGeneratorAction = nullptr;
164 
165  return;
166 }
167 
G4AtlasRunManager::Initialize
void Initialize() override final
Definition: G4AtlasRunManager.cxx:41
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
G4AtlasRunManager::RunTermination
void RunTermination() override final
G4 function called at end of run.
Definition: G4AtlasRunManager.cxx:128
G4AtlasRunManager::m_quietMode
bool m_quietMode
Quiet Mode for production.
Definition: G4AtlasRunManager.h:107
IDetectorConstructionTool::GetDetectorConstruction
virtual UPDetectorConstruction GetDetectorConstruction()=0
G4AtlasRunManager::m_physListSvc
ServiceHandle< IPhysicsListSvc > m_physListSvc
Definition: G4AtlasRunManager.h:94
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
G4AtlasRunManager
ATLAS custom singleton run manager.
Definition: G4AtlasRunManager.h:28
G4AtlasRunManager::m_detConstruction
IDetectorConstructionTool * m_detConstruction
Definition: G4AtlasRunManager.h:96
G4AtlasRunManager::G4AtlasRunManager
G4AtlasRunManager()
Pure singleton private constructor.
Definition: G4AtlasRunManager.cxx:24
G4AtlasRunManager.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
G4AtlasRunManager::m_fluxRecorder
std::unique_ptr< IFluxRecorder > m_fluxRecorder
Interface to flux recording.
Definition: G4AtlasRunManager.h:100
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
G4AtlasRunManager::ProcessEvent
bool ProcessEvent(G4Event *event)
Does the work of simulating an ATLAS event.
Definition: G4AtlasRunManager.cxx:104
G4AtlasRunManager::RunInitialization
void RunInitialization() override final
G4 function called at start of run.
Definition: G4AtlasRunManager.cxx:50
G4AtlasRunManager::m_recordFlux
bool m_recordFlux
Definition: G4AtlasRunManager.h:92
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
ATLAS_NOT_THREAD_SAFE
G4AtlasRunManager *G4AtlasRunManager::GetG4AtlasRunManager ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
Definition: G4AtlasRunManager.cxx:33
jobOptions.Initialize
Initialize
Definition: jobOptions.pA.py:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
G4AtlasRunManager::InitializePhysics
void InitializePhysics() override final
Definition: G4AtlasRunManager.cxx:81
G4AtlasRunManager::InitializeGeometry
void InitializeGeometry() override final
Definition: G4AtlasRunManager.cxx:58
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88
G4AtlasRunManager::EndEvent
void EndEvent()
Definition: G4AtlasRunManager.cxx:75