ATLAS Offline Software
Loading...
Searching...
No Matches
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_physListSvc("PhysicsListSvc", "G4AtlasRunManager")
28{ }
29
30
31G4AtlasRunManager* G4AtlasRunManager::GetG4AtlasRunManager ATLAS_NOT_THREAD_SAFE ()
32{
33 static G4AtlasRunManager *thisManager = nullptr;
34 if (!thisManager) { thisManager = new G4AtlasRunManager; } // Leaked
35 return thisManager;
36}
37
38
40{
41 // ADA 11/28.2018: switch initialization order to meet ISF requirements
42 // Call the base class Initialize method. This will call
43 // InitializeGeometry and InitializePhysics.
44 if (m_quietMode) { SetVerboseLevel(0); } // HACK
45 G4RunManager::Initialize();
46}
47
49{
50 ATH_MSG_DEBUG( "InitializeGeometry()" );
51
52 // Create/assign detector construction
53 G4RunManager::SetUserInitialization(
54 m_detConstruction->GetDetectorConstruction().release());
55 if (userDetector) {
56 G4RunManager::InitializeGeometry();
57 }
58 else {
59 ATH_MSG_WARNING( " User Detector not set!!! Geometry NOT initialized!!!" );
60 }
61 return;
62}
63
64
66{
67 ATH_MSG_DEBUG( "G4AtlasRunManager::EndEvent" );
68}
69
70
72{
73 ATH_MSG_INFO( "InitializePhysics()" );
74 kernel->InitializePhysics();
75 physicsInitialized = true;
76
77 // Grab the physics list tool and set the extra options
78 if (m_physListSvc.retrieve().isFailure()) {
79 ATH_MSG_ERROR ( "Could not retrieve the physics list tool" );
80 G4ExceptionDescription description;
81 description << "InitializePhysics: Failed to retrieve IPhysicsListSvc.";
82 G4Exception("G4AtlasRunManager", "CouldNotRetrievePLTool", FatalException, description);
83 abort(); // to keep Coverity happy
84 }
85 m_physListSvc->SetPhysicsOptions();
86
87 if (m_recordFlux) {
88 m_fluxRecorder->InitializeFluxRecording();
89 }
90
91 return;
92}
93
95{
96
97 G4StateManager* stateManager = G4StateManager::GetStateManager();
98 stateManager->SetNewState(G4State_GeomClosed);
99
100 currentEvent = event;
101
102 eventManager->ProcessOneEvent(currentEvent);
103 if (currentEvent->IsAborted()) {
104 ATH_MSG_WARNING( "G4AtlasRunManager::ProcessEvent: Event Aborted at Detector Simulation level" );
105 currentEvent = nullptr;
106 return true;
107 }
108
109 if (m_recordFlux) { m_fluxRecorder->RecordFlux(currentEvent); }
110
111 this->StackPreviousEvent(currentEvent);
112 bool abort = currentEvent->IsAborted();
113 currentEvent = nullptr;
114
115 return abort;
116}
117
119{
120 ATH_MSG_DEBUG( " G4AtlasRunManager::RunTermination() " );
121 if (m_recordFlux) {
122 m_fluxRecorder->WriteFluxInformation();
123 }
124
125 this->CleanUpPreviousEvents();
126 previousEvents->clear();
127
128 if (userRunAction) {
129 userRunAction->EndOfRunAction(currentRun);
130 }
131
132 delete currentRun;
133 currentRun = nullptr;
134 runIDCounter++;
135
136 ATH_MSG_VERBOSE( "Changing the state..." );
137 G4StateManager* stateManager = G4StateManager::GetStateManager();
138 stateManager->SetNewState(G4State_Idle);
139
140 ATH_MSG_VERBOSE( "Opening the geometry back up" );
141 G4GeometryManager::GetInstance()->OpenGeometry();
142
143 ATH_MSG_VERBOSE( "Terminating the run... State is " << stateManager->GetStateString( stateManager->GetCurrentState() ) );
144 kernel->RunTermination();
145 ATH_MSG_VERBOSE( "All done..." );
146
147 userRunAction = nullptr;
148 userEventAction = nullptr;
149 userSteppingAction = nullptr;
150 userStackingAction = nullptr;
151 userTrackingAction = nullptr;
152 userDetector = nullptr;
153 userPrimaryGeneratorAction = nullptr;
154
155 return;
156}
157
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
G4AtlasRunManager *G4AtlasRunManager::GetG4AtlasRunManager ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
ATLAS custom singleton run manager.
void InitializeGeometry() override final
bool ProcessEvent(G4Event *event)
Does the work of simulating an ATLAS event.
ServiceHandle< IPhysicsListSvc > m_physListSvc
std::map< std::string, double > m_volumeSmartlessLevel
IDetectorConstructionTool * m_detConstruction
void RunTermination() override final
G4 function called at end of run.
G4AtlasRunManager()
Pure singleton private constructor.
bool m_quietMode
Quiet Mode for production.
std::unique_ptr< IFluxRecorder > m_fluxRecorder
Interface to flux recording.
void Initialize() override final
void InitializePhysics() override final
std::string description
glabal timer - how long have I taken so far?
Definition hcg.cxx:91