9 #include <simulation/kernel/RunManager.h>
10 #include <simulation/kernel/RandomEngine.h>
11 #include <framework/logging/Logger.h>
13 #include <framework/pcore/ProcHandler.h>
15 #include <CLHEP/Random/Random.h>
17 #include <G4LogicalVolumeStore.hh>
18 #include <G4PhysicalVolumeStore.hh>
19 #include <G4SolidStore.hh>
20 #include <G4RegionStore.hh>
21 #include <G4GeometryManager.hh>
25 using namespace Belle2::Simulation;
31 if (!m_instance) m_instance =
new RunManager();
35 void RunManager::Initialize()
39 CLHEP::HepRandom::setTheEngine(m_randomEngine);
41 SetGeometryToBeOptimized(
true);
45 G4RunManager::Initialize();
49 void RunManager::beginRun(
int runNumber)
54 if (ConfirmBeamOnCondition()) {
56 SetRunIDCounter(runNumber);
59 ConstructScoringWorlds();
62 B2FATAL(
"The Geant4 kernel was not initialized properly ! The method 'ConfirmBeamOnCondition()' failed. ");
67 void RunManager::processEvent(
int evtNumber)
70 currentEvent = GenerateEvent(evtNumber);
71 eventManager->ProcessOneEvent(currentEvent);
72 AnalyzeEvent(currentEvent);
74 StackPreviousEvent(currentEvent);
79 void RunManager::endRun()
85 void RunManager::destroy()
87 delete m_randomEngine;
89 if (m_instance ==
nullptr)
return;
91 for (G4AssemblyVolume* assemblyVolume : m_AssemblyVolumes)
delete assemblyVolume;
92 m_AssemblyVolumes.clear();
94 if (ProcHandler::parallelProcessingUsed() and !ProcHandler::isOutputProcess()) {
104 G4LogicalVolumeStore::GetInstance()->clear();
105 G4PhysicalVolumeStore::GetInstance()->clear();
106 G4SolidStore::GetInstance()->clear();
107 G4RegionStore::GetInstance()->clear();
110 G4GeometryManager::GetInstance()->OpenGeometry();
117 m_instance =
nullptr;
125 RunManager::RunManager() : G4RunManager()
Interface class to make Geant4 use the Belle2 RandomGenerator.
The run manager controls the flow of the Geant4 program and manages the event loop(s) within a run.
virtual ~RunManager()
The RunManager destructor.
std::vector< G4AssemblyVolume * > m_AssemblyVolumes
Vector of pointers to G4AssemblyVolumes.
Abstract base class for different kinds of events.