29 #include "HepPDT/ParticleDataTable.hh" 32 #include "G4GeometryManager.hh" 33 #include "G4ScoringManager.hh" 34 #include "G4StateManager.hh" 35 #include "G4ApplicationState.hh" 36 #include "G4MTRunManagerKernel.hh" 37 #include "G4UImanager.hh" 39 #include "G4EventManager.hh" 42 #include "G4TransportationManager.hh" 43 #include "G4ParticleTable.hh" 44 #include "G4CascadeInterface.hh" 45 #include "G4EmParameters.hh" 46 #include "G4HadronicParameters.hh" 47 #include "G4NuclearLevelData.hh" 49 #include "G4GDMLParser.hh" 50 #include "G4SystemOfUnits.hh" 52 #include "G4LogicalVolume.hh" 53 #include "G4LogicalVolumeStore.hh" 54 #include "G4PhysicalVolumeStore.hh" 55 #include "G4Region.hh" 56 #include "G4RegionStore.hh" 69 : m_managerInitialized(
false),
70 m_runTerminated(
false),
71 m_PhysicsTablesDir(
p.getUntrackedParameter<
std::
string>(
"PhysicsTablesDirectory",
"")),
72 m_StorePhysicsTables(
p.getUntrackedParameter<
bool>(
"StorePhysicsTables",
false)),
73 m_RestorePhysicsTables(
p.getUntrackedParameter<
bool>(
"RestorePhysicsTables",
false)),
88 m_kernel =
new G4MTRunManagerKernel();
90 double th =
p.getParameter<
double>(
"ThresholdForGeometryExceptions") * CLHEP::GeV;
91 bool tr =
p.getParameter<
bool>(
"TraceExceptions");
93 m_check =
p.getUntrackedParameter<
bool>(
"CheckGeometry",
false);
102 edm::LogWarning(
"SimG4CoreApplication") <<
"RunManagerMT::initG4 was already done - exit";
111 <<
"RunManagerMT: start initialising of geometry DD4hep: " << geoFromDD4hep <<
"\n" 112 <<
" cutsPerRegion: " <<
cuts <<
" cutForProton: " << protonCut <<
"\n" 113 <<
" G4 verbosity: " << verb;
118 G4UImanager::GetUIpointer()->SetCoutDestination(
m_UIsession);
119 G4UImanager::GetUIpointer()->SetMasterUIManager(
true);
122 G4VPhysicalVolume*
world =
m_world.get()->GetWorldVolume();
126 <<
"RunManagerMT: Define cuts: " <<
cuts <<
" Geant4 run manager verbosity: " << verb;
128 const G4RegionStore* regStore = G4RegionStore::GetInstance();
129 const G4PhysicalVolumeStore*
pvs = G4PhysicalVolumeStore::GetInstance();
130 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
131 unsigned int numPV =
pvs->size();
132 unsigned int numLV = lvs->size();
133 unsigned int nn = regStore->size();
135 <<
"RunManagerMT: " << numPV <<
" physical volumes; " << numLV <<
" logical volumes; " <<
nn <<
" regions.";
145 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT: create PhysicsList";
147 std::unique_ptr<PhysicsListMakerBase> physicsMaker(
149 if (physicsMaker.get() ==
nullptr) {
150 throw cms::Exception(
"Configuration") <<
"Unable to find the Physics list requested";
155 if (phys ==
nullptr) {
156 throw cms::Exception(
"Configuration") <<
"Physics list construction failed!";
161 G4HadronicParameters::Instance()->SetVerboseLevel(verb);
162 G4EmParameters::Instance()->SetVerbose(verb);
163 G4EmParameters::Instance()->SetWorkerVerbose(
std::max(verb - 1, 0));
167 if (monopoleMass > 0.0) {
182 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT: start initialisation of PhysicsList for master";
188 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT: PhysicsList and cuts are defined";
193 G4ScoringManager* scManager = G4ScoringManager::GetScoringManager();
194 scManager->SetVerboseLevel(1);
198 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT: Requested UI commands: ";
201 G4UImanager::GetUIpointer()->ApplyCommand(
command);
208 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT: G4State is Init";
211 G4EmParameters::Instance()->Dump();
215 if (
m_kernel->RunInitialization()) {
218 throw cms::Exception(
"LogicError") <<
"G4RunManagerKernel initialization failed!";
226 std::ostringstream
dir;
230 G4UImanager::GetUIpointer()->ApplyCommand(
cmd);
234 G4NuclearLevelData::GetInstance()->UploadNuclearLevelData(84);
240 <<
"RunManagerMT: Physics is initilized, now initialise user actions, verb=" << verb;
246 if (!writeFile.empty()) {
248 gdml.SetRegionExport(
true);
249 gdml.SetEnergyCutsExport(
true);
250 gdml.Write(writeFile,
m_world->GetWorldVolume(),
true);
257 if (
m_check || !regionFile.empty()) {
262 G4HadronicParameters::Instance()->SetVerboseLevel(
std::max(verb - 1, 0));
273 G4cout <<
"RunManagerMT: initG4 done " << timer << G4endl;
289 G4GeometryManager::GetInstance()->OpenGeometry();
308 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT::terminateRun done";
312 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
313 int numLV = lvs->size();
317 for (
int i = 0;
i < numLV; ++
i) {
319 auto nd = lv->GetNoDaughters();
320 auto vox = lv->GetVoxelHeader();
321 auto sma = lv->GetSmartless();
322 auto reg = lv->GetRegion();
323 size_t nsl = (
nullptr == vox) ? 0 : vox->GetNoSlices();
327 edm::LogVerbatim(
"Voxels") <<
" " <<
i <<
". Nd=" << nd <<
" Nsl=" << nsl <<
" Smartless=" << sma <<
" " 328 << lv->GetName() <<
" Region: " <<
rname;
333 <<
"RunManagerMT: nLV=" << numLV <<
" NlvVox=" << nvox <<
" Nslices=" << nslice;
338 std::vector<std::string> rnames =
m_p.
getParameter<std::vector<std::string> >(
"VoxelRegions");
339 std::vector<double> rdensities =
m_p.
getParameter<std::vector<double> >(
"VoxelDensityPerRegion");
341 std::size_t
n = rnames.size();
342 if (
n == rdensities.size()) {
345 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
346 for (
auto& lv : *lvs) {
350 for (
int i = 0;
i <
nr; ++
i) {
351 if (nam == rnames[
i]) {
357 lv->SetSmartless(den);
360 <<
"RunManagerMT: default voxel density=" <<
density <<
"; number of regions with special density " <<
nr;
void Connect(RunAction *)
void connect(Observer< const T *> *iObs)
does not take ownership of memory
const std::string m_PhysicsTablesDir
Log< level::Info, true > LogVerbatim
bool m_managerInitialized
T getParameter(std::string const &) const
void BeginOfRunAction(const G4Run *aRun) override
G4MTRunManagerKernel * m_kernel
SensitiveDetectorCatalog m_catalog
edm::ParameterSet m_pRunAction
def create(alignables, pedeDump, additionalData, outputFile, config)
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.
T getUntrackedParameter(std::string const &, T const &) const
RunAction
list of unwanted particles (gluons and quarks)
EndOfRunSignal endOfRunSignal_
bool m_StorePhysicsTables
const DDDWorld & world() const
std::unique_ptr< PhysicsList > m_physicsList
std::unique_ptr< DDDWorld > m_world
edm::ParameterSet m_pPhysics
DDDWorldSignal dddWorldSignal_
bool m_RestorePhysicsTables
void initG4(const DDCompactView *, const cms::DDCompactView *, const HepPDT::ParticleDataTable *)
SimActivityRegistry::BeginOfRunSignal m_beginOfRunSignal
const G4String rname[NREG]
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