29 #include "HepPDT/ParticleDataTable.hh"
32 #include "G4GeometryManager.hh"
33 #include "G4StateManager.hh"
34 #include "G4ApplicationState.hh"
35 #include "G4MTRunManagerKernel.hh"
36 #include "G4UImanager.hh"
38 #include "G4EventManager.hh"
41 #include "G4TransportationManager.hh"
42 #include "G4ParticleTable.hh"
43 #include "G4CascadeInterface.hh"
44 #include "G4EmParameters.hh"
45 #include "G4HadronicParameters.hh"
46 #include "G4NuclearLevelData.hh"
48 #include "G4GDMLParser.hh"
49 #include "G4SystemOfUnits.hh"
51 #include "G4LogicalVolume.hh"
52 #include "G4LogicalVolumeStore.hh"
53 #include "G4PhysicalVolumeStore.hh"
54 #include "G4Region.hh"
55 #include "G4RegionStore.hh"
68 : m_managerInitialized(
false),
69 m_runTerminated(
false),
70 m_PhysicsTablesDir(p.getUntrackedParameter<std::
string>(
"PhysicsTablesDirectory",
"")),
71 m_StorePhysicsTables(p.getUntrackedParameter<bool>(
"StorePhysicsTables",
false)),
72 m_RestorePhysicsTables(p.getUntrackedParameter<bool>(
"RestorePhysicsTables",
false)),
73 m_pPhysics(p.getParameter<edm::
ParameterSet>(
"Physics")),
74 m_pRunAction(p.getParameter<edm::
ParameterSet>(
"RunAction")),
75 m_g4overlap(p.getUntrackedParameter<edm::
ParameterSet>(
"G4CheckOverlap")),
76 m_G4Commands(p.getParameter<std::
vector<std::
string> >(
"G4Commands")),
87 m_kernel =
new G4MTRunManagerKernel();
100 edm::LogWarning(
"SimG4CoreApplication") <<
"RunManagerMT::initG4 was already done - exit";
109 <<
"RunManagerMT: start initialising of geometry DD4hep: " << geoFromDD4hep <<
"\n"
110 <<
" cutsPerRegion: " << cuts <<
" cutForProton: " << protonCut <<
"\n"
111 <<
" G4 verbosity: " << verb;
116 G4UImanager::GetUIpointer()->SetCoutDestination(
m_UIsession);
117 G4UImanager::GetUIpointer()->SetMasterUIManager(
true);
120 G4VPhysicalVolume*
world =
m_world.get()->GetWorldVolume();
124 <<
"RunManagerMT: Define cuts: " << cuts <<
" Geant4 run manager verbosity: " << verb;
126 const G4RegionStore* regStore = G4RegionStore::GetInstance();
127 const G4PhysicalVolumeStore* pvs = G4PhysicalVolumeStore::GetInstance();
128 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
129 unsigned int numPV = pvs->size();
130 unsigned int numLV = lvs->size();
131 unsigned int nn = regStore->size();
133 <<
"RunManagerMT: " << numPV <<
" physical volumes; " << numLV <<
" logical volumes; " << nn <<
" regions.";
138 m_kernel->DefineWorldVolume(world,
true);
143 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT: create PhysicsList";
145 std::unique_ptr<PhysicsListMakerBase> physicsMaker(
147 if (physicsMaker.get() ==
nullptr) {
148 throw cms::Exception(
"Configuration") <<
"Unable to find the Physics list requested";
153 if (phys ==
nullptr) {
154 throw cms::Exception(
"Configuration") <<
"Physics list construction failed!";
159 G4HadronicParameters::Instance()->SetVerboseLevel(verb);
160 G4EmParameters::Instance()->SetVerbose(verb);
161 G4EmParameters::Instance()->SetWorkerVerbose(
std::max(verb - 1, 0));
165 if (monopoleMass > 0.0) {
180 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT: start initialisation of PhysicsList for master";
186 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT: PhysicsList and cuts are defined";
190 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT: Requested UI commands: ";
193 G4UImanager::GetUIpointer()->ApplyCommand(
command);
198 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT: G4State is Init";
202 if (
m_kernel->RunInitialization()) {
205 throw cms::Exception(
"LogicError") <<
"G4RunManagerKernel initialization failed!";
209 std::ostringstream
dir;
213 G4UImanager::GetUIpointer()->ApplyCommand(cmd);
217 G4NuclearLevelData::GetInstance()->UploadNuclearLevelData(84);
223 <<
"RunManagerMT: Physics is initilized, now initialise user actions, verb=" << verb;
229 if (!writeFile.empty()) {
231 gdml.SetRegionExport(
true);
232 gdml.SetEnergyCutsExport(
true);
233 gdml.Write(writeFile,
m_world->GetWorldVolume(),
true);
240 if (
m_check || !regionFile.empty()) {
245 G4HadronicParameters::Instance()->SetVerboseLevel(
std::max(verb - 1, 0));
256 G4cout <<
"RunManagerMT: initG4 done " << timer << G4endl;
271 G4GeometryManager::GetInstance()->OpenGeometry();
288 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT:: terminateRun done";
void Connect(RunAction *)
const std::string m_PhysicsTablesDir
Log< level::Info, true > LogVerbatim
bool m_managerInitialized
T getUntrackedParameter(std::string const &, T const &) const
void BeginOfRunAction(const G4Run *aRun) override
G4MTRunManagerKernel * m_kernel
SensitiveDetectorCatalog m_catalog
edm::ParameterSet m_pRunAction
HepPDT::ParticleDataTable ParticleDataTable
RunManagerMT(edm::ParameterSet const &)
SimActivityRegistry::EndOfRunSignal m_endOfRunSignal
G4StateManager * m_stateManager
BeginOfRunSignal beginOfRunSignal_
std::vector< std::string > m_G4Commands
void initializeUserActions()
Compact representation of the geometrical detector hierarchy.
const DDDWorld & world() const
TkSoA const *__restrict__ CAHitNtupletGeneratorKernelsGPU::QualityCuts cuts
EndOfRunSignal endOfRunSignal_
void connect(Observer< const T * > *iObs)
does not take ownership of memory
bool m_StorePhysicsTables
std::unique_ptr< PhysicsList > m_physicsList
std::unique_ptr< DDDWorld > m_world
edm::ParameterSet m_pPhysics
DDDWorldSignal dddWorldSignal_
T getParameter(std::string const &) const
bool m_RestorePhysicsTables
void initG4(const DDCompactView *, const cms::DDCompactView *, const HepPDT::ParticleDataTable *)
SimActivityRegistry::BeginOfRunSignal m_beginOfRunSignal
std::unique_ptr< SimRunInterface > m_runInterface
edm::ParameterSet m_g4overlap
Log< level::Warning, false > LogWarning
RunAction * m_userRunAction
CustomUIsession * m_UIsession
void EndOfRunAction(const G4Run *aRun) override
SimActivityRegistry m_registry