CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes | Friends
RunManagerMT Class Reference

#include <RunManagerMT.h>

Public Member Functions

const SensitiveDetectorCatalogcatalog () const
 
void Connect (RunAction *)
 
const std::vector< std::string > & G4Commands () const
 
void initG4 (const DDCompactView *, const cms::DDCompactView *, const HepPDT::ParticleDataTable *)
 
void initializeUserActions ()
 
PhysicsListphysicsListForWorker () const
 
 RunManagerMT (edm::ParameterSet const &)
 
void stopG4 ()
 
const DDDWorldworld () const
 
 ~RunManagerMT ()
 

Private Member Functions

void terminateRun ()
 

Private Attributes

SensitiveDetectorCatalog m_catalog
 
bool m_check
 
G4Run * m_currentRun
 
std::vector< std::string > m_G4Commands
 
edm::ParameterSet m_g4overlap
 
G4MTRunManagerKernel * m_kernel
 
bool m_managerInitialized
 
edm::ParameterSet m_p
 
std::unique_ptr< PhysicsListm_physicsList
 
const std::string m_PhysicsTablesDir
 
edm::ParameterSet m_pPhysics
 
edm::ParameterSet m_pRunAction
 
SimActivityRegistry m_registry
 
bool m_RestorePhysicsTables
 
std::unique_ptr< SimRunInterfacem_runInterface
 
bool m_runTerminated
 
G4StateManager * m_stateManager
 
bool m_StorePhysicsTables
 
CustomUIsessionm_UIsession
 
RunActionm_userRunAction
 
std::unique_ptr< DDDWorldm_world
 

Friends

class RunManagerMTWorker
 

Detailed Description

Definition at line 51 of file RunManagerMT.h.

Constructor & Destructor Documentation

RunManagerMT::RunManagerMT ( edm::ParameterSet const &  p)
explicit

Definition at line 67 of file RunManagerMT.cc.

References edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), m_check, m_currentRun, m_kernel, m_physicsList, m_runInterface, m_stateManager, m_UIsession, m_userRunAction, and m_world.

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")),
77  m_p(p) {
78  m_currentRun = nullptr;
80  m_physicsList.reset(nullptr);
81  m_world.reset(nullptr);
82 
83  m_runInterface.reset(nullptr);
84  m_userRunAction = nullptr;
85  m_currentRun = nullptr;
86 
87  m_kernel = new G4MTRunManagerKernel();
88  m_stateManager = G4StateManager::GetStateManager();
89  double th = p.getParameter<double>("ThresholdForGeometryExceptions") * CLHEP::GeV;
90  bool tr = p.getParameter<bool>("TraceExceptions");
91  m_stateManager->SetExceptionHandler(new ExceptionHandler(th, tr));
92  m_check = p.getUntrackedParameter<bool>("CheckGeometry", false);
93 }
const std::string m_PhysicsTablesDir
Definition: RunManagerMT.h:95
bool m_managerInitialized
Definition: RunManagerMT.h:87
G4MTRunManagerKernel * m_kernel
Definition: RunManagerMT.h:83
edm::ParameterSet m_pRunAction
Definition: RunManagerMT.h:100
bool m_runTerminated
Definition: RunManagerMT.h:88
G4StateManager * m_stateManager
Definition: RunManagerMT.h:91
std::vector< std::string > m_G4Commands
Definition: RunManagerMT.h:102
G4Run * m_currentRun
Definition: RunManagerMT.h:90
edm::ParameterSet m_p
Definition: RunManagerMT.h:103
bool m_StorePhysicsTables
Definition: RunManagerMT.h:96
std::unique_ptr< PhysicsList > m_physicsList
Definition: RunManagerMT.h:86
std::unique_ptr< DDDWorld > m_world
Definition: RunManagerMT.h:105
edm::ParameterSet m_pPhysics
Definition: RunManagerMT.h:99
bool m_RestorePhysicsTables
Definition: RunManagerMT.h:97
std::unique_ptr< SimRunInterface > m_runInterface
Definition: RunManagerMT.h:93
edm::ParameterSet m_g4overlap
Definition: RunManagerMT.h:101
RunAction * m_userRunAction
Definition: RunManagerMT.h:89
CustomUIsession * m_UIsession
Definition: RunManagerMT.h:85
RunManagerMT::~RunManagerMT ( )

Definition at line 95 of file RunManagerMT.cc.

References m_UIsession.

95 { delete m_UIsession; }
CustomUIsession * m_UIsession
Definition: RunManagerMT.h:85

Member Function Documentation

const SensitiveDetectorCatalog& RunManagerMT::catalog ( ) const
inline

Definition at line 72 of file RunManagerMT.h.

References m_catalog.

Referenced by RunManagerMTWorker::initializeG4().

72 { return m_catalog; }
SensitiveDetectorCatalog m_catalog
Definition: RunManagerMT.h:107
void RunManagerMT::Connect ( RunAction runAction)

Definition at line 266 of file RunManagerMT.cc.

References SimActivityRegistry::beginOfRunSignal_, sim_act::Signaler< T >::connect(), SimActivityRegistry::endOfRunSignal_, RunAction::m_beginOfRunSignal, RunAction::m_endOfRunSignal, and m_registry.

Referenced by SimRunInterface::Connect(), and initializeUserActions().

266  {
269 }
SimActivityRegistry::EndOfRunSignal m_endOfRunSignal
Definition: RunAction.h:24
BeginOfRunSignal beginOfRunSignal_
EndOfRunSignal endOfRunSignal_
void connect(Observer< const T * > *iObs)
does not take ownership of memory
Definition: Signaler.h:55
SimActivityRegistry::BeginOfRunSignal m_beginOfRunSignal
Definition: RunAction.h:23
SimActivityRegistry m_registry
Definition: RunManagerMT.h:106
const std::vector<std::string>& RunManagerMT::G4Commands ( ) const
inline

Definition at line 74 of file RunManagerMT.h.

References m_G4Commands.

Referenced by RunManagerMTWorker::initializeG4().

74 { return m_G4Commands; }
std::vector< std::string > m_G4Commands
Definition: RunManagerMT.h:102
void RunManagerMT::initG4 ( const DDCompactView pDD,
const cms::DDCompactView pDD4hep,
const HepPDT::ParticleDataTable fPDGTable 
)

Definition at line 97 of file RunManagerMT.cc.

References RunAction::BeginOfRunAction(), trackerTree::check(), mps_setup::cmd, mps_check::command, beamerCreator::create(), cuts, SimActivityRegistry::dddWorldSignal_, DeadROC_duringRun::dir, Exception, get, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), recoMuon::in, initializeUserActions(), m_catalog, m_check, m_currentRun, m_G4Commands, m_g4overlap, m_kernel, m_managerInitialized, m_p, m_physicsList, m_PhysicsTablesDir, m_pPhysics, m_registry, m_RestorePhysicsTables, m_stateManager, m_StorePhysicsTables, m_UIsession, m_userRunAction, m_world, SiStripPI::max, gpuVertexFinder::nn, AlCaHLTBitMon_QueryRunRegistry::string, and world().

99  {
100  if (m_managerInitialized) {
101  edm::LogWarning("SimG4CoreApplication") << "RunManagerMT::initG4 was already done - exit";
102  return;
103  }
104  bool geoFromDD4hep = m_p.getParameter<bool>("g4GeometryDD4hepSource");
105  bool cuts = m_pPhysics.getParameter<bool>("CutsPerRegion");
106  bool protonCut = m_pPhysics.getParameter<bool>("CutsOnProton");
107  int verb = m_pPhysics.getUntrackedParameter<int>("Verbosity", 0);
108  int stepverb = m_p.getUntrackedParameter<int>("SteppingVerbosity", 0);
109  edm::LogVerbatim("SimG4CoreApplication")
110  << "RunManagerMT: start initialising of geometry DD4hep: " << geoFromDD4hep << "\n"
111  << " cutsPerRegion: " << cuts << " cutForProton: " << protonCut << "\n"
112  << " G4 verbosity: " << verb;
113 
114  G4Timer timer;
115  timer.Start();
116 
117  G4UImanager::GetUIpointer()->SetCoutDestination(m_UIsession);
118  G4UImanager::GetUIpointer()->SetMasterUIManager(true);
119 
120  m_world = std::make_unique<DDDWorld>(pDD, pDD4hep, m_catalog, verb, cuts, protonCut);
121  G4VPhysicalVolume* world = m_world.get()->GetWorldVolume();
122 
123  m_kernel->SetVerboseLevel(verb);
124  edm::LogVerbatim("SimG4CoreApplication")
125  << "RunManagerMT: Define cuts: " << cuts << " Geant4 run manager verbosity: " << verb;
126 
127  const G4RegionStore* regStore = G4RegionStore::GetInstance();
128  const G4PhysicalVolumeStore* pvs = G4PhysicalVolumeStore::GetInstance();
129  const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
130  unsigned int numPV = pvs->size();
131  unsigned int numLV = lvs->size();
132  unsigned int nn = regStore->size();
133  edm::LogVerbatim("SimG4CoreApplication")
134  << "RunManagerMT: " << numPV << " physical volumes; " << numLV << " logical volumes; " << nn << " regions.";
135 
136  if (m_check) {
137  m_kernel->SetVerboseLevel(2);
138  }
139  m_kernel->DefineWorldVolume(world, true);
141  m_stateManager->SetNewState(G4State_PreInit);
142 
143  // Create physics list
144  edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMT: create PhysicsList";
145 
146  std::unique_ptr<PhysicsListMakerBase> physicsMaker(
148  if (physicsMaker.get() == nullptr) {
149  throw cms::Exception("Configuration") << "Unable to find the Physics list requested";
150  }
151  m_physicsList = physicsMaker->make(m_pPhysics, m_registry);
152 
153  PhysicsList* phys = m_physicsList.get();
154  if (phys == nullptr) {
155  throw cms::Exception("Configuration") << "Physics list construction failed!";
156  }
157  if (stepverb > 0) {
158  verb = std::max(verb, 1);
159  }
160  G4HadronicParameters::Instance()->SetVerboseLevel(verb);
161  G4EmParameters::Instance()->SetVerbose(verb);
162  G4EmParameters::Instance()->SetWorkerVerbose(std::max(verb - 1, 0));
163 
164  // exotic particle physics
165  double monopoleMass = m_pPhysics.getUntrackedParameter<double>("MonopoleMass", 0);
166  if (monopoleMass > 0.0) {
167  phys->RegisterPhysics(new CMSMonopolePhysics(fPDGTable, m_pPhysics));
168  }
169  bool exotica = m_pPhysics.getUntrackedParameter<bool>("ExoticaTransport", false);
170  if (exotica) {
171  CMSExoticaPhysics exo(phys, m_pPhysics);
172  }
173 
174  // adding GFlash, Russian Roulette for eletrons and gamma,
175  // step limiters on top of any Physics Lists
176  phys->RegisterPhysics(new ParametrisedEMPhysics("EMoptions", m_pPhysics));
177 
179  m_physicsList->SetPhysicsTableRetrieved(m_PhysicsTablesDir);
180  }
181  edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMT: start initialisation of PhysicsList for master";
182 
183  m_physicsList->SetDefaultCutValue(m_pPhysics.getParameter<double>("DefaultCutValue") * CLHEP::cm);
184  m_physicsList->SetCutsWithDefault();
185  m_kernel->SetPhysics(phys);
186 
187  edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMT: PhysicsList and cuts are defined";
188 
189  // Geant4 UI commands before initialisation of physics
190  if (!m_G4Commands.empty()) {
191  edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMT: Requested UI commands: ";
192  for (const std::string& command : m_G4Commands) {
193  edm::LogVerbatim("SimG4CoreApplication") << " " << command;
194  G4UImanager::GetUIpointer()->ApplyCommand(command);
195  }
196  }
197 
198  m_stateManager->SetNewState(G4State_Init);
199  edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMT: G4State is Init";
200  m_kernel->InitializePhysics();
201  m_kernel->SetUpDecayChannels();
202 
203  if (m_kernel->RunInitialization()) {
204  m_managerInitialized = true;
205  } else {
206  throw cms::Exception("LogicError") << "G4RunManagerKernel initialization failed!";
207  }
208 
209  if (m_StorePhysicsTables) {
210  std::ostringstream dir;
211  dir << m_PhysicsTablesDir << '\0';
212  std::string cmd = std::string("/control/shell mkdir -p ") + m_PhysicsTablesDir;
213  if (!std::ifstream(dir.str().c_str(), std::ios::in))
214  G4UImanager::GetUIpointer()->ApplyCommand(cmd);
215  m_physicsList->StorePhysicsTable(m_PhysicsTablesDir);
216  }
217  // Appload nuclear level data up to Z=84
218  G4NuclearLevelData::GetInstance()->UploadNuclearLevelData(84);
219 
220  if (verb > 1) {
221  m_physicsList->DumpCutValuesTable();
222  }
223  edm::LogVerbatim("SimG4CoreApplication")
224  << "RunManagerMT: Physics is initilized, now initialise user actions, verb=" << verb;
225 
227 
228  // geometry dump
229  auto writeFile = m_p.getUntrackedParameter<std::string>("FileNameGDML", "");
230  if (!writeFile.empty()) {
231  G4GDMLParser gdml;
232  gdml.SetRegionExport(true);
233  gdml.SetEnergyCutsExport(true);
234  gdml.Write(writeFile, m_world->GetWorldVolume(), true);
235  }
236 
237  // G4Region dump file name
238  auto regionFile = m_p.getUntrackedParameter<std::string>("FileNameRegions", "");
239 
240  // Geometry checks
241  if (m_check || !regionFile.empty()) {
242  CMSG4CheckOverlap check(m_g4overlap, regionFile, m_UIsession, world);
243  }
244 
245  m_stateManager->SetNewState(G4State_PreInit);
246  G4HadronicParameters::Instance()->SetVerboseLevel(std::max(verb - 1, 0));
247 
248  // If the Geant4 particle table is needed, decomment the lines below
249  //
250  //G4ParticleTable::GetParticleTable()->DumpTable("ALL");
251  //
252  m_stateManager->SetNewState(G4State_GeomClosed);
253  m_currentRun = new G4Run();
255  timer.Stop();
256  G4cout.precision(4);
257  G4cout << "RunManagerMT: initG4 done " << timer << G4endl;
258 }
const std::string m_PhysicsTablesDir
Definition: RunManagerMT.h:95
Log< level::Info, true > LogVerbatim
bool m_managerInitialized
Definition: RunManagerMT.h:87
T getUntrackedParameter(std::string const &, T const &) const
void BeginOfRunAction(const G4Run *aRun) override
Definition: RunAction.cc:17
G4MTRunManagerKernel * m_kernel
Definition: RunManagerMT.h:83
SensitiveDetectorCatalog m_catalog
Definition: RunManagerMT.h:107
G4StateManager * m_stateManager
Definition: RunManagerMT.h:91
std::vector< std::string > m_G4Commands
Definition: RunManagerMT.h:102
G4Run * m_currentRun
Definition: RunManagerMT.h:90
void initializeUserActions()
const DDDWorld & world() const
Definition: RunManagerMT.h:70
TkSoA const *__restrict__ CAHitNtupletGeneratorKernelsGPU::QualityCuts cuts
edm::ParameterSet m_p
Definition: RunManagerMT.h:103
bool m_StorePhysicsTables
Definition: RunManagerMT.h:96
std::unique_ptr< PhysicsList > m_physicsList
Definition: RunManagerMT.h:86
std::unique_ptr< DDDWorld > m_world
Definition: RunManagerMT.h:105
edm::ParameterSet m_pPhysics
Definition: RunManagerMT.h:99
DDDWorldSignal dddWorldSignal_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
bool m_RestorePhysicsTables
Definition: RunManagerMT.h:97
list command
Definition: mps_check.py:25
list cmd
Definition: mps_setup.py:244
int32_t *__restrict__ nn
edm::ParameterSet m_g4overlap
Definition: RunManagerMT.h:101
#define get
Log< level::Warning, false > LogWarning
RunAction * m_userRunAction
Definition: RunManagerMT.h:89
CustomUIsession * m_UIsession
Definition: RunManagerMT.h:85
SimActivityRegistry m_registry
Definition: RunManagerMT.h:106
void RunManagerMT::initializeUserActions ( )

Definition at line 260 of file RunManagerMT.cc.

References Connect(), m_pRunAction, m_runInterface, and m_userRunAction.

Referenced by initG4().

260  {
261  m_runInterface = std::make_unique<SimRunInterface>(this, true);
263  Connect(m_userRunAction);
264 }
void Connect(RunAction *)
edm::ParameterSet m_pRunAction
Definition: RunManagerMT.h:100
std::unique_ptr< SimRunInterface > m_runInterface
Definition: RunManagerMT.h:93
RunAction * m_userRunAction
Definition: RunManagerMT.h:89
PhysicsList* RunManagerMT::physicsListForWorker ( ) const
inline

Definition at line 78 of file RunManagerMT.h.

References m_physicsList.

Referenced by RunManagerMTWorker::initializeG4().

78 { return m_physicsList.get(); }
std::unique_ptr< PhysicsList > m_physicsList
Definition: RunManagerMT.h:86
void RunManagerMT::stopG4 ( )

Definition at line 271 of file RunManagerMT.cc.

References m_runTerminated, m_stateManager, and terminateRun().

271  {
272  G4GeometryManager::GetInstance()->OpenGeometry();
273  m_stateManager->SetNewState(G4State_Quit);
274  if (!m_runTerminated) {
275  terminateRun();
276  }
277 }
void terminateRun()
bool m_runTerminated
Definition: RunManagerMT.h:88
G4StateManager * m_stateManager
Definition: RunManagerMT.h:91
void RunManagerMT::terminateRun ( )
private

Definition at line 279 of file RunManagerMT.cc.

References RunAction::EndOfRunAction(), m_currentRun, m_kernel, m_runTerminated, and m_userRunAction.

Referenced by stopG4().

279  {
280  if (nullptr != m_userRunAction) {
282  delete m_userRunAction;
283  m_userRunAction = nullptr;
284  }
285  if (!m_runTerminated) {
286  m_kernel->RunTermination();
287  }
288  m_runTerminated = true;
289  edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMT:: terminateRun done";
290 }
Log< level::Info, true > LogVerbatim
G4MTRunManagerKernel * m_kernel
Definition: RunManagerMT.h:83
bool m_runTerminated
Definition: RunManagerMT.h:88
G4Run * m_currentRun
Definition: RunManagerMT.h:90
RunAction * m_userRunAction
Definition: RunManagerMT.h:89
void EndOfRunAction(const G4Run *aRun) override
Definition: RunAction.cc:26
const DDDWorld& RunManagerMT::world ( ) const
inline

Definition at line 70 of file RunManagerMT.h.

References m_world.

Referenced by initG4(), and RunManagerMTWorker::initializeG4().

70 { return *m_world; }
std::unique_ptr< DDDWorld > m_world
Definition: RunManagerMT.h:105

Friends And Related Function Documentation

friend class RunManagerMTWorker
friend

Definition at line 52 of file RunManagerMT.h.

Member Data Documentation

SensitiveDetectorCatalog RunManagerMT::m_catalog
private

Definition at line 107 of file RunManagerMT.h.

Referenced by catalog(), and initG4().

bool RunManagerMT::m_check
private

Definition at line 98 of file RunManagerMT.h.

Referenced by initG4(), and RunManagerMT().

G4Run* RunManagerMT::m_currentRun
private

Definition at line 90 of file RunManagerMT.h.

Referenced by initG4(), RunManagerMT(), and terminateRun().

std::vector<std::string> RunManagerMT::m_G4Commands
private

Definition at line 102 of file RunManagerMT.h.

Referenced by G4Commands(), and initG4().

edm::ParameterSet RunManagerMT::m_g4overlap
private

Definition at line 101 of file RunManagerMT.h.

Referenced by initG4().

G4MTRunManagerKernel* RunManagerMT::m_kernel
private

Definition at line 83 of file RunManagerMT.h.

Referenced by initG4(), RunManagerMT(), and terminateRun().

bool RunManagerMT::m_managerInitialized
private

Definition at line 87 of file RunManagerMT.h.

Referenced by initG4().

edm::ParameterSet RunManagerMT::m_p
private

Definition at line 103 of file RunManagerMT.h.

Referenced by initG4().

std::unique_ptr<PhysicsList> RunManagerMT::m_physicsList
private

Definition at line 86 of file RunManagerMT.h.

Referenced by initG4(), physicsListForWorker(), and RunManagerMT().

const std::string RunManagerMT::m_PhysicsTablesDir
private

Definition at line 95 of file RunManagerMT.h.

Referenced by initG4().

edm::ParameterSet RunManagerMT::m_pPhysics
private

Definition at line 99 of file RunManagerMT.h.

Referenced by initG4().

edm::ParameterSet RunManagerMT::m_pRunAction
private

Definition at line 100 of file RunManagerMT.h.

Referenced by initializeUserActions().

SimActivityRegistry RunManagerMT::m_registry
private

Definition at line 106 of file RunManagerMT.h.

Referenced by Connect(), and initG4().

bool RunManagerMT::m_RestorePhysicsTables
private

Definition at line 97 of file RunManagerMT.h.

Referenced by initG4().

std::unique_ptr<SimRunInterface> RunManagerMT::m_runInterface
private

Definition at line 93 of file RunManagerMT.h.

Referenced by initializeUserActions(), and RunManagerMT().

bool RunManagerMT::m_runTerminated
private

Definition at line 88 of file RunManagerMT.h.

Referenced by stopG4(), and terminateRun().

G4StateManager* RunManagerMT::m_stateManager
private

Definition at line 91 of file RunManagerMT.h.

Referenced by initG4(), RunManagerMT(), and stopG4().

bool RunManagerMT::m_StorePhysicsTables
private

Definition at line 96 of file RunManagerMT.h.

Referenced by initG4().

CustomUIsession* RunManagerMT::m_UIsession
private

Definition at line 85 of file RunManagerMT.h.

Referenced by initG4(), RunManagerMT(), and ~RunManagerMT().

RunAction* RunManagerMT::m_userRunAction
private

Definition at line 89 of file RunManagerMT.h.

Referenced by initG4(), initializeUserActions(), RunManagerMT(), and terminateRun().

std::unique_ptr<DDDWorld> RunManagerMT::m_world
private

Definition at line 105 of file RunManagerMT.h.

Referenced by initG4(), RunManagerMT(), and world().