Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 "G4Version.hh"
19 
20 #include <string>
21 
23  : G4RunManager()
24  , AthMessaging("G4AtlasRunManager")
25  , m_recordFlux(false)
26  , m_fastSimTool("FastSimulationMasterTool")
27  , m_physListSvc("PhysicsListSvc", "G4AtlasRunManager")
28  , m_detGeoSvc("DetectorGeometrySvc", "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 
50 
52 {
53  ATH_MSG_DEBUG( "InitializeGeometry()" );
54  if (m_detGeoSvc.retrieve().isFailure()) {
55  ATH_MSG_ERROR ( "Could not retrieve the DetectorGeometrySvc" );
56  G4ExceptionDescription description;
57  description << "InitializeGeometry: Failed to retrieve IDetectorGeometrySvc.";
58  G4Exception("G4AtlasRunManager", "CouldNotRetrieveDetGeoSvc", FatalException, description);
59  abort(); // to keep Coverity happy
60  }
61 
62  // Create/assign detector construction
63  G4RunManager::SetUserInitialization(
64  m_detGeoSvc->GetDetectorConstruction().release());
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  // Fast simulations last
98  if (m_fastSimTool.retrieve().isFailure()) {
99  ATH_MSG_ERROR ( "Could not retrieve the FastSim master tool" );
100  G4ExceptionDescription description;
101  description << "InitializePhysics: Failed to retrieve IFastSimulationMasterTool.";
102  G4Exception("G4AtlasRunManager", "CouldNotRetrieveFastSimMaster", FatalException, description);
103  abort(); // to keep Coverity happy
104  }
105  if(m_fastSimTool->initializeFastSims().isFailure()) {
106  G4ExceptionDescription description;
107  description << "InitializePhysics: Call to IFastSimulationMasterTool::initializeFastSims failed.";
108  G4Exception("G4AtlasRunManager", "FailedToInitializeFastSims", FatalException, description);
109  abort(); // to keep Coverity happy
110  }
111 
112  if (m_recordFlux) {
113  m_fluxRecorder->InitializeFluxRecording();
114  }
115 
116  return;
117 }
118 
120 {
121 
122  G4StateManager* stateManager = G4StateManager::GetStateManager();
123  stateManager->SetNewState(G4State_GeomClosed);
124 
125  currentEvent = event;
126 
127  eventManager->ProcessOneEvent(currentEvent);
128  if (currentEvent->IsAborted()) {
129  ATH_MSG_WARNING( "G4AtlasRunManager::ProcessEvent: Event Aborted at Detector Simulation level" );
130  currentEvent = nullptr;
131  return true;
132  }
133 
134  if (m_recordFlux) { m_fluxRecorder->RecordFlux(currentEvent); }
135 
136  this->StackPreviousEvent(currentEvent);
137  bool abort = currentEvent->IsAborted();
138  currentEvent = nullptr;
139 
140  return abort;
141 }
142 
144 {
145  ATH_MSG_DEBUG( " G4AtlasRunManager::RunTermination() " );
146  if (m_recordFlux) {
147  m_fluxRecorder->WriteFluxInformation();
148  }
149 
150  this->CleanUpPreviousEvents();
151  previousEvents->clear();
152 
153  if (userRunAction) {
154  userRunAction->EndOfRunAction(currentRun);
155  }
156 
157  delete currentRun;
158  currentRun = nullptr;
159  runIDCounter++;
160 
161  ATH_MSG_VERBOSE( "Changing the state..." );
162  G4StateManager* stateManager = G4StateManager::GetStateManager();
163  stateManager->SetNewState(G4State_Idle);
164 
165  ATH_MSG_VERBOSE( "Opening the geometry back up" );
166  G4GeometryManager::GetInstance()->OpenGeometry();
167 
168  ATH_MSG_VERBOSE( "Terminating the run... State is " << stateManager->GetStateString( stateManager->GetCurrentState() ) );
169  kernel->RunTermination();
170  ATH_MSG_VERBOSE( "All done..." );
171 
172  userRunAction = nullptr;
173  userEventAction = nullptr;
174  userSteppingAction = nullptr;
175  userStackingAction = nullptr;
176  userTrackingAction = nullptr;
177  userDetector = nullptr;
178  userPrimaryGeneratorAction = nullptr;
179 
180  return;
181 }
182 
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:143
G4AtlasRunManager::m_quietMode
bool m_quietMode
Quiet Mode for production.
Definition: G4AtlasRunManager.h:104
G4AtlasRunManager::m_physListSvc
ServiceHandle< IPhysicsListSvc > m_physListSvc
Definition: G4AtlasRunManager.h:91
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
G4AtlasRunManager
ATLAS custom singleton run manager.
Definition: G4AtlasRunManager.h:30
G4AtlasRunManager::G4AtlasRunManager
G4AtlasRunManager()
Pure singleton private constructor.
Definition: G4AtlasRunManager.cxx:22
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:97
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:119
G4AtlasRunManager::m_recordFlux
bool m_recordFlux
Definition: G4AtlasRunManager.h:88
G4AtlasRunManager::m_detGeoSvc
ServiceHandle< IDetectorGeometrySvc > m_detGeoSvc
Definition: G4AtlasRunManager.h:93
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::m_fastSimTool
ToolHandle< IFastSimulationMasterTool > m_fastSimTool
Definition: G4AtlasRunManager.h:90
G4AtlasRunManager::InitializeGeometry
void InitializeGeometry() override final
Definition: G4AtlasRunManager.cxx:51
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