30 #include "HepPDT/ParticleDataTable.hh" 33 #include "G4GeometryManager.hh" 34 #include "G4ScoringManager.hh" 35 #include "G4StateManager.hh" 36 #include "G4ApplicationState.hh" 37 #include "G4MTRunManagerKernel.hh" 38 #include "G4UImanager.hh" 42 #include "G4TransportationManager.hh" 43 #include "G4ParticleTable.hh" 44 #include "G4CascadeInterface.hh" 45 #include "G4EmParameters.hh" 46 #include "G4LossTableManager.hh" 47 #include "G4HadronicParameters.hh" 48 #include "G4NuclearLevelData.hh" 49 #include <CLHEP/Units/SystemOfUnits.h> 50 #include "G4LogicalVolume.hh" 51 #include "G4LogicalVolumeStore.hh" 52 #include "G4PhysicalVolumeStore.hh" 53 #include "G4Region.hh" 54 #include "G4RegionStore.hh" 55 #include "G4PhysListUtil.hh" 56 #include "G4PhysicsListHelper.hh" 64 : m_PhysicsTablesDir(
p.getUntrackedParameter<
std::
string>(
"PhysicsTablesDirectory",
"")),
65 m_StorePhysicsTables(
p.getUntrackedParameter<
bool>(
"StorePhysicsTables",
false)),
66 m_RestorePhysicsTables(
p.getUntrackedParameter<
bool>(
"RestorePhysicsTables",
false)),
67 m_check(
p.getUntrackedParameter<
bool>(
"CheckGeometry")),
68 m_geoFromDD4hep(
p.getParameter<
bool>(
"g4GeometryDD4hepSource")),
69 m_score(
p.getParameter<
bool>(
"UseCommandBaseScorer")),
70 m_stepverb(
p.getUntrackedParameter<
int>(
"SteppingVerbosity", 0)),
71 m_regionFile(
p.getUntrackedParameter<
std::
string>(
"FileNameRegions",
"")),
80 m_kernel =
new G4MTRunManagerKernel();
82 double th =
p.getParameter<
double>(
"ThresholdForGeometryExceptions") * CLHEP::GeV;
83 bool tr =
p.getParameter<
bool>(
"TraceExceptions");
89 G4UImanager::GetUIpointer()->SetCoutDestination(
m_UIsession);
90 G4UImanager::GetUIpointer()->SetMasterUIManager(
true);
91 G4PhysListUtil::InitialiseParameters();
92 G4LossTableManager::Instance();
101 edm::LogWarning(
"SimG4CoreApplication") <<
"RunManagerMT::initG4 was already done - exit";
108 <<
"RunManagerMT: start initialising of geometry DD4hep: " <<
m_geoFromDD4hep <<
"\n" 109 <<
" cutsPerRegion: " <<
cuts <<
" cutForProton: " << protonCut <<
"\n" 110 <<
" G4 verbosity: " << verb;
116 G4VPhysicalVolume*
world =
m_world.get()->GetWorldVolume();
120 <<
"RunManagerMT: Define cuts: " <<
cuts <<
" Geant4 run manager verbosity: " << verb;
122 const G4RegionStore* regStore = G4RegionStore::GetInstance();
123 const G4PhysicalVolumeStore*
pvs = G4PhysicalVolumeStore::GetInstance();
124 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
125 unsigned int numPV =
pvs->size();
126 unsigned int numLV = lvs->size();
127 unsigned int nn = regStore->size();
129 <<
"RunManagerMT: " << numPV <<
" physical volumes; " << numLV <<
" logical volumes; " <<
nn <<
" regions.";
139 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT: create PhysicsList";
141 std::unique_ptr<PhysicsListMakerBase> physicsMaker(
143 if (physicsMaker.get() ==
nullptr) {
144 throw cms::Exception(
"Configuration") <<
"Unable to find the Physics list requested";
149 if (phys ==
nullptr) {
150 throw cms::Exception(
"Configuration") <<
"Physics list construction failed!";
155 G4HadronicParameters::Instance()->SetVerboseLevel(verb);
156 G4EmParameters::Instance()->SetVerbose(verb);
157 G4EmParameters::Instance()->SetWorkerVerbose(
std::max(verb - 1, 0));
158 G4PhysicsListHelper::GetPhysicsListHelper();
162 if (monopoleMass > 0.0) {
177 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT: start initialisation of PhysicsList for master";
183 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT: PhysicsList and cuts are defined";
187 G4ScoringManager* scManager = G4ScoringManager::GetScoringManager();
188 scManager->SetVerboseLevel(1);
192 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT: Requested UI commands: ";
195 G4UImanager::GetUIpointer()->ApplyCommand(
command);
202 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT: G4State is Init";
205 G4EmParameters::Instance()->Dump();
209 if (
m_kernel->RunInitialization()) {
212 throw cms::Exception(
"LogicError") <<
"G4RunManagerKernel initialization failed!";
220 std::ostringstream
dir;
224 G4UImanager::GetUIpointer()->ApplyCommand(
cmd);
228 G4NuclearLevelData::GetInstance()->UploadNuclearLevelData(84);
234 <<
"RunManagerMT: Physics is initilized, now initialise user actions, verb=" << verb;
247 G4HadronicParameters::Instance()->SetVerboseLevel(
std::max(verb - 1, 0));
258 G4cout <<
"RunManagerMT: initG4 done " << timer << G4endl;
274 G4GeometryManager::GetInstance()->OpenGeometry();
293 edm::LogVerbatim(
"SimG4CoreApplication") <<
"RunManagerMT::terminateRun done";
297 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
298 int numLV = lvs->size();
302 for (
int i = 0;
i < numLV; ++
i) {
304 auto nd = lv->GetNoDaughters();
305 auto vox = lv->GetVoxelHeader();
306 auto sma = lv->GetSmartless();
307 auto reg = lv->GetRegion();
308 size_t nsl = (
nullptr == vox) ? 0 : vox->GetNoSlices();
312 edm::LogVerbatim(
"Voxels") <<
" " <<
i <<
". Nd=" << nd <<
" Nsl=" << nsl <<
" Smartless=" << sma <<
" " 313 << lv->GetName() <<
" Region: " <<
rname;
318 <<
"RunManagerMT: nLV=" << numLV <<
" NlvVox=" << nvox <<
" Nslices=" << nslice;
323 std::vector<std::string> rnames =
m_Init.
getParameter<std::vector<std::string> >(
"VoxelRegions");
324 std::vector<double> rdensities =
m_Init.
getParameter<std::vector<double> >(
"VoxelDensityPerRegion");
326 std::size_t
n = rnames.size();
327 if (
n == rdensities.size()) {
330 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
331 for (
auto const& lv : *lvs) {
335 for (
int i = 0;
i <
nr; ++
i) {
336 if (nam == rnames[
i]) {
342 lv->SetSmartless(den);
345 <<
"RunManagerMT: default voxel density=" <<
density <<
"; number of regions with special density " <<
nr;
349 const G4RegionStore* regStore = G4RegionStore::GetInstance();
350 for (
auto const&
r : *regStore) {
351 const G4String&
name =
r->GetName();
352 if (
name ==
"HGCalRegion" ||
name ==
"FastTimerRegionETL" ||
name ==
"FastTimerRegionBTL") {
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]
edm::ParameterSet m_CheckOverlap
std::unique_ptr< SimRunInterface > m_runInterface
Log< level::Warning, false > LogWarning
RunAction * m_userRunAction
CustomUIsession * m_UIsession
void EndOfRunAction(const G4Run *aRun) override
SimActivityRegistry m_registry