CMS 3D CMS Logo

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

#include <RunManagerMT.h>

Public Member Functions

void abortRun (bool softAbort=false)
 
const SensitiveDetectorCatalogcatalog () const
 
sim::ChordFinderSetterchordFinderSetterForWorker () const
 
void Connect (RunAction *)
 
const std::vector< std::string > & G4Commands () const
 
void initG4 (const DDCompactView *pDD, const MagneticField *pMF, const HepPDT::ParticleDataTable *fPDGTable)
 
void initializeUserActions ()
 
PhysicsListphysicsListForWorker () const
 
 RunManagerMT (edm::ParameterSet const &p)
 
void stopG4 ()
 
const DDDWorldworld () const
 
 ~RunManagerMT ()
 

Private Member Functions

void DumpMagneticField (const G4Field *) const
 
void terminateRun ()
 

Private Attributes

SensitiveDetectorCatalog m_catalog
 
bool m_check
 
std::unique_ptr
< sim::ChordFinderSetter
m_chordFinderSetter
 
G4Run * m_currentRun
 
sim::FieldBuilderm_fieldBuilder
 
std::string m_FieldFile
 
std::vector< std::string > m_G4Commands
 
G4MTRunManagerKernel * m_kernel
 
bool m_managerInitialized
 
edm::ParameterSet m_pField
 
std::unique_ptr< PhysicsListm_physicsList
 
const std::string m_PhysicsTablesDir
 
edm::ParameterSet m_pPhysics
 
edm::ParameterSet m_pRunAction
 
bool m_pUseMagneticField
 
std::string m_RegionFile
 
SimActivityRegistry m_registry
 
bool m_RestorePhysicsTables
 
std::unique_ptr< SimRunInterfacem_runInterface
 
bool m_runTerminated
 
bool m_StorePhysicsTables
 
RunActionm_userRunAction
 
std::unique_ptr< DDDWorldm_world
 
std::string m_WriteFile
 

Detailed Description

RunManagerMT should be constructed in a newly spanned thread (acting as the Geant4 master thread), and there should be exactly one instance of it.

Definition at line 58 of file RunManagerMT.h.

Constructor & Destructor Documentation

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

Definition at line 59 of file RunManagerMT.cc.

References assert(), edm::ParameterSet::getUntrackedParameter(), m_check, m_currentRun, m_FieldFile, m_kernel, m_RegionFile, m_WriteFile, and AlCaHLTBitMon_QueryRunRegistry::string.

59  :
60  m_managerInitialized(false),
61  m_runTerminated(false),
62  m_pUseMagneticField(p.getParameter<bool>("UseMagneticField")),
63  m_PhysicsTablesDir(p.getParameter<std::string>("PhysicsTablesDirectory")),
64  m_StorePhysicsTables(p.getParameter<bool>("StorePhysicsTables")),
65  m_RestorePhysicsTables(p.getParameter<bool>("RestorePhysicsTables")),
66  m_pField(p.getParameter<edm::ParameterSet>("MagneticField")),
67  m_pPhysics(p.getParameter<edm::ParameterSet>("Physics")),
68  m_pRunAction(p.getParameter<edm::ParameterSet>("RunAction")),
69  m_G4Commands(p.getParameter<std::vector<std::string> >("G4Commands")),
70  m_fieldBuilder(nullptr)
71 {
72  m_currentRun = 0;
73  G4RunManagerKernel *kernel = G4MTRunManagerKernel::GetRunManagerKernel();
74  if(!kernel) m_kernel = new G4MTRunManagerKernel();
75  else {
76  m_kernel = dynamic_cast<G4MTRunManagerKernel *>(kernel);
78  }
79 
80  m_check = p.getUntrackedParameter<bool>("CheckOverlap",false);
81  m_WriteFile = p.getUntrackedParameter<std::string>("FileNameGDML","");
82  m_FieldFile = p.getUntrackedParameter<std::string>("FileNameField","");
83  m_RegionFile = p.getUntrackedParameter<std::string>("FileNameRegions","");
84 }
const std::string m_PhysicsTablesDir
Definition: RunManagerMT.h:119
bool m_managerInitialized
Definition: RunManagerMT.h:112
G4MTRunManagerKernel * m_kernel
Definition: RunManagerMT.h:109
edm::ParameterSet m_pRunAction
Definition: RunManagerMT.h:125
assert(m_qm.get())
bool m_runTerminated
Definition: RunManagerMT.h:113
sim::FieldBuilder * m_fieldBuilder
Definition: RunManagerMT.h:132
std::vector< std::string > m_G4Commands
Definition: RunManagerMT.h:126
G4Run * m_currentRun
Definition: RunManagerMT.h:116
std::string m_RegionFile
Definition: RunManagerMT.h:137
std::string m_WriteFile
Definition: RunManagerMT.h:136
bool m_pUseMagneticField
Definition: RunManagerMT.h:114
bool m_StorePhysicsTables
Definition: RunManagerMT.h:120
std::string m_FieldFile
Definition: RunManagerMT.h:135
edm::ParameterSet m_pField
Definition: RunManagerMT.h:123
edm::ParameterSet m_pPhysics
Definition: RunManagerMT.h:124
bool m_RestorePhysicsTables
Definition: RunManagerMT.h:121
RunManagerMT::~RunManagerMT ( )

Definition at line 86 of file RunManagerMT.cc.

References m_runTerminated, and terminateRun().

87 {
88  if(!m_runTerminated) { terminateRun(); }
89  G4StateManager::GetStateManager()->SetNewState(G4State_Quit);
90  G4GeometryManager::GetInstance()->OpenGeometry();
91 }
void terminateRun()
bool m_runTerminated
Definition: RunManagerMT.h:113

Member Function Documentation

void RunManagerMT::abortRun ( bool  softAbort = false)
inline

Definition at line 74 of file RunManagerMT.h.

Referenced by ExceptionHandler::Notify().

74 {}
const SensitiveDetectorCatalog& RunManagerMT::catalog ( ) const
inline

Definition at line 80 of file RunManagerMT.h.

References m_catalog.

Referenced by RunManagerMTWorker::initializeThread().

80  {
81  return m_catalog;
82  }
SensitiveDetectorCatalog m_catalog
Definition: RunManagerMT.h:130
sim::ChordFinderSetter* RunManagerMT::chordFinderSetterForWorker ( ) const
inline

Definition at line 101 of file RunManagerMT.h.

References m_chordFinderSetter.

Referenced by RunManagerMTWorker::initializeThread().

101  {
102  return m_chordFinderSetter.get();
103  }
std::unique_ptr< sim::ChordFinderSetter > m_chordFinderSetter
Definition: RunManagerMT.h:133
void RunManagerMT::Connect ( RunAction runAction)

Definition at line 206 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().

207 {
210 }
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:59
SimActivityRegistry::BeginOfRunSignal m_beginOfRunSignal
Definition: RunAction.h:23
SimActivityRegistry m_registry
Definition: RunManagerMT.h:129
void RunManagerMT::DumpMagneticField ( const G4Field *  field) const
private

Definition at line 230 of file RunManagerMT.cc.

References funct::cos(), groupFilesInBlocks::fout, i, j, m_FieldFile, dbtoconf::out, phi, point, alignCSCRings::r, funct::sin(), z, and SiStripMonitorClusterAlca_cfi::zmax.

Referenced by initG4().

231 {
232  std::ofstream fout(m_FieldFile.c_str(), std::ios::out);
233  if(fout.fail()){
234  edm::LogWarning("SimG4CoreApplication")
235  << " RunManager WARNING : "
236  << "error opening file <" << m_FieldFile << "> for magnetic field";
237  } else {
238  double rmax = 9000*mm;
239  double zmax = 16000*mm;
240 
241  double dr = 5*cm;
242  double dz = 20*cm;
243 
244  int nr = (int)(rmax/dr);
245  int nz = 2*(int)(zmax/dz);
246 
247  double r = 0.0;
248  double z0 = -zmax;
249  double z;
250 
251  double phi = 0.0;
252  double cosf = cos(phi);
253  double sinf = sin(phi);
254 
255  double point[4] = {0.0,0.0,0.0,0.0};
256  double bfield[3] = {0.0,0.0,0.0};
257 
258  fout << std::setprecision(6);
259  for(int i=0; i<=nr; ++i) {
260  z = z0;
261  for(int j=0; j<=nz; ++j) {
262  point[0] = r*cosf;
263  point[1] = r*sinf;
264  point[2] = z;
265  field->GetFieldValue(point, bfield);
266  fout << "R(mm)= " << r/mm << " phi(deg)= " << phi/degree
267  << " Z(mm)= " << z/mm << " Bz(tesla)= " << bfield[2]/tesla
268  << " Br(tesla)= " << (bfield[0]*cosf + bfield[1]*sinf)/tesla
269  << " Bphi(tesla)= " << (bfield[0]*sinf - bfield[1]*cosf)/tesla
270  << G4endl;
271  z += dz;
272  }
273  r += dr;
274  }
275 
276  fout.close();
277  }
278 }
int i
Definition: DBlmapReader.cc:9
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
int j
Definition: DBlmapReader.cc:9
tuple out
Definition: dbtoconf.py:99
std::string m_FieldFile
Definition: RunManagerMT.h:135
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
const std::vector<std::string>& RunManagerMT::G4Commands ( ) const
inline

Definition at line 84 of file RunManagerMT.h.

References m_G4Commands.

84  {
85  return m_G4Commands;
86  }
std::vector< std::string > m_G4Commands
Definition: RunManagerMT.h:126
void RunManagerMT::initG4 ( const DDCompactView pDD,
const MagneticField pMF,
const HepPDT::ParticleDataTable fPDGTable 
)

Definition at line 93 of file RunManagerMT.cc.

References RunAction::BeginOfRunAction(), sim::FieldBuilder::build(), asciidump::cmd, SurfaceDeformationFactory::create(), SimActivityRegistry::dddWorldSignal_, dir, DumpMagneticField(), g, reco::get(), edm::ParameterSet::getParameter(), recoMuon::in, initializeUserActions(), m_catalog, m_check, m_chordFinderSetter, m_currentRun, m_fieldBuilder, m_FieldFile, m_G4Commands, m_kernel, m_managerInitialized, m_pField, m_physicsList, m_PhysicsTablesDir, m_pPhysics, m_pUseMagneticField, m_RegionFile, m_registry, m_RestorePhysicsTables, m_StorePhysicsTables, m_userRunAction, m_world, m_WriteFile, G4RegionReporter::ReportRegions(), and AlCaHLTBitMon_QueryRunRegistry::string.

95 {
96  if (m_managerInitialized) return;
97 
98  // DDDWorld: get the DDCV from the ES and use it to build the World
100  m_world.reset(new DDDWorld(pDD, map_, m_catalog, m_check));
102 
103  // setup the magnetic field
105  {
106  const GlobalPoint g(0.,0.,0.);
107 
110  G4TransportationManager * tM =
111  G4TransportationManager::GetTransportationManager();
112  m_fieldBuilder->build( tM->GetFieldManager(),
113  tM->GetPropagatorInField());
114  if("" != m_FieldFile) {
115  DumpMagneticField(tM->GetFieldManager()->GetDetectorField());
116  }
117  }
118 
119  // Create physics list
120  std::unique_ptr<PhysicsListMakerBase>
121  physicsMaker(PhysicsListFactory::get()->create(
122  m_pPhysics.getParameter<std::string> ("type")));
123  if (physicsMaker.get()==0) {
124  throw SimG4Exception("Unable to find the Physics list requested");
125  }
126  m_physicsList =
127  physicsMaker->make(map_,fPDGTable,m_chordFinderSetter.get(),m_pPhysics,m_registry);
128 
129  PhysicsList* phys = m_physicsList.get();
130  if (phys==0) {
131  throw SimG4Exception("Physics list construction failed!");
132  }
133 
134  // adding GFlash, Russian Roulette for eletrons and gamma,
135  // step limiters on top of any Physics Lists
136  phys->RegisterPhysics(new ParametrisedEMPhysics("EMoptions",m_pPhysics));
137 
138  m_physicsList->ResetStoredInAscii();
140  m_physicsList->SetPhysicsTableRetrieved(m_PhysicsTablesDir);
141  }
142  edm::LogInfo("SimG4CoreApplication")
143  << "RunManagerMT: start initialisation of PhysicsList for master";
144 
145  m_kernel->SetPhysics(phys);
146  m_kernel->InitializePhysics();
147  m_kernel->SetUpDecayChannels();
148 
149  // The following line was with the following comment in
150  // G4MTRunManager::InitializePhysics() in 10.00.p01; in practice
151  // needed to initialize certain singletons during the master thread
152  // initialization in order to avoid races later...
153  //
154  //BERTINI, this is needed to create pseudo-particles, to be removed
155  G4CascadeInterface::Initialize();
156 
157  if (m_kernel->RunInitialization()) { m_managerInitialized = true; }
158  else {
159  throw SimG4Exception("G4RunManagerKernel initialization failed!");
160  }
161 
163  {
164  std::ostringstream dir;
165  dir << m_PhysicsTablesDir << '\0';
166  std::string cmd = std::string("/control/shell mkdir -p ")+m_PhysicsTablesDir;
167  if (!std::ifstream(dir.str().c_str(), std::ios::in))
168  G4UImanager::GetUIpointer()->ApplyCommand(cmd);
169  m_physicsList->StorePhysicsTable(m_PhysicsTablesDir);
170  }
171 
173 
174  if(0 < m_G4Commands.size()) {
175  G4cout << "RunManagerMT: Requested UI commands: " << G4endl;
176  for (unsigned it=0; it<m_G4Commands.size(); ++it) {
177  G4cout << " " << m_G4Commands[it] << G4endl;
178  G4UImanager::GetUIpointer()->ApplyCommand(m_G4Commands[it]);
179  }
180  }
181  if("" != m_WriteFile) {
182  G4GDMLParser gdml(new G4GDMLReadStructure(), new CMSGDMLWriteStructure());
183  gdml.Write(m_WriteFile, m_world->GetWorldVolume(), true);
184  }
185 
186  if("" != m_RegionFile) {
187  G4RegionReporter rrep;
189  }
190 
191  // If the Geant4 particle table is needed, decomment the lines below
192  //
193  //G4ParticleTable::GetParticleTable()->DumpTable("ALL");
194  //
195  G4StateManager::GetStateManager()->SetNewState(G4State_GeomClosed);
196  m_currentRun = new G4Run();
198 }
const std::string m_PhysicsTablesDir
Definition: RunManagerMT.h:119
bool m_managerInitialized
Definition: RunManagerMT.h:112
T getParameter(std::string const &) const
G4MTRunManagerKernel * m_kernel
Definition: RunManagerMT.h:109
SensitiveDetectorCatalog m_catalog
Definition: RunManagerMT.h:130
sim::FieldBuilder * m_fieldBuilder
Definition: RunManagerMT.h:132
std::vector< std::string > m_G4Commands
Definition: RunManagerMT.h:126
G4Run * m_currentRun
Definition: RunManagerMT.h:116
std::string m_RegionFile
Definition: RunManagerMT.h:137
void initializeUserActions()
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
std::string m_WriteFile
Definition: RunManagerMT.h:136
void build(G4FieldManager *fM=nullptr, G4PropagatorInField *fP=nullptr, ChordFinderSetter *setter=nullptr)
Definition: FieldBuilder.cc:48
string cmd
Definition: asciidump.py:19
bool m_pUseMagneticField
Definition: RunManagerMT.h:114
void DumpMagneticField(const G4Field *) const
bool m_StorePhysicsTables
Definition: RunManagerMT.h:120
std::unique_ptr< PhysicsList > m_physicsList
Definition: RunManagerMT.h:111
std::string m_FieldFile
Definition: RunManagerMT.h:135
edm::ParameterSet m_pField
Definition: RunManagerMT.h:123
std::unique_ptr< DDDWorld > m_world
Definition: RunManagerMT.h:128
edm::ParameterSet m_pPhysics
Definition: RunManagerMT.h:124
void BeginOfRunAction(const G4Run *aRun)
Definition: RunAction.cc:21
DDDWorldSignal dddWorldSignal_
bool m_RestorePhysicsTables
Definition: RunManagerMT.h:121
std::unique_ptr< sim::ChordFinderSetter > m_chordFinderSetter
Definition: RunManagerMT.h:133
void ReportRegions(const std::string &ss)
dbl *** dir
Definition: mlp_gen.cc:35
RunAction * m_userRunAction
Definition: RunManagerMT.h:115
SurfaceDeformation * create(int type, const std::vector< double > &params)
T get(const Candidate &c)
Definition: component.h:55
SimActivityRegistry m_registry
Definition: RunManagerMT.h:129
void RunManagerMT::initializeUserActions ( )

Definition at line 200 of file RunManagerMT.cc.

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

Referenced by initG4().

200  {
201  m_runInterface.reset(new SimRunInterface(this, true));
204 }
void Connect(RunAction *)
edm::ParameterSet m_pRunAction
Definition: RunManagerMT.h:125
std::unique_ptr< SimRunInterface > m_runInterface
Definition: RunManagerMT.h:117
RunAction * m_userRunAction
Definition: RunManagerMT.h:115
PhysicsList* RunManagerMT::physicsListForWorker ( ) const
inline

Definition at line 92 of file RunManagerMT.h.

References m_physicsList.

Referenced by RunManagerMTWorker::initializeThread().

92  {
93  return m_physicsList.get();
94  }
std::unique_ptr< PhysicsList > m_physicsList
Definition: RunManagerMT.h:111
void RunManagerMT::stopG4 ( )

Definition at line 212 of file RunManagerMT.cc.

References m_runTerminated, and terminateRun().

213 {
214  G4StateManager::GetStateManager()->SetNewState(G4State_Quit);
215  if(!m_runTerminated) { terminateRun(); }
216 }
void terminateRun()
bool m_runTerminated
Definition: RunManagerMT.h:113
void RunManagerMT::terminateRun ( )
private

Definition at line 218 of file RunManagerMT.cc.

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

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

218  {
220  delete m_userRunAction;
221  m_userRunAction = 0;
222  // delete m_currentRun;
223  //m_currentRun = 0;
224  if(m_kernel && !m_runTerminated) {
225  m_kernel->RunTermination();
226  m_runTerminated = true;
227  }
228 }
G4MTRunManagerKernel * m_kernel
Definition: RunManagerMT.h:109
bool m_runTerminated
Definition: RunManagerMT.h:113
G4Run * m_currentRun
Definition: RunManagerMT.h:116
void EndOfRunAction(const G4Run *aRun)
Definition: RunAction.cc:39
RunAction * m_userRunAction
Definition: RunManagerMT.h:115
const DDDWorld& RunManagerMT::world ( ) const
inline

Definition at line 76 of file RunManagerMT.h.

References m_world.

Referenced by RunManagerMTWorker::initializeThread().

76  {
77  return *m_world;
78  }
std::unique_ptr< DDDWorld > m_world
Definition: RunManagerMT.h:128

Member Data Documentation

SensitiveDetectorCatalog RunManagerMT::m_catalog
private

Definition at line 130 of file RunManagerMT.h.

Referenced by catalog(), and initG4().

bool RunManagerMT::m_check
private

Definition at line 122 of file RunManagerMT.h.

Referenced by initG4(), and RunManagerMT().

std::unique_ptr<sim::ChordFinderSetter> RunManagerMT::m_chordFinderSetter
private

Definition at line 133 of file RunManagerMT.h.

Referenced by chordFinderSetterForWorker(), and initG4().

G4Run* RunManagerMT::m_currentRun
private

Definition at line 116 of file RunManagerMT.h.

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

sim::FieldBuilder* RunManagerMT::m_fieldBuilder
private

Definition at line 132 of file RunManagerMT.h.

Referenced by initG4().

std::string RunManagerMT::m_FieldFile
private

Definition at line 135 of file RunManagerMT.h.

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

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

Definition at line 126 of file RunManagerMT.h.

Referenced by G4Commands(), and initG4().

G4MTRunManagerKernel* RunManagerMT::m_kernel
private

Definition at line 109 of file RunManagerMT.h.

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

bool RunManagerMT::m_managerInitialized
private

Definition at line 112 of file RunManagerMT.h.

Referenced by initG4().

edm::ParameterSet RunManagerMT::m_pField
private

Definition at line 123 of file RunManagerMT.h.

Referenced by initG4().

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

Definition at line 111 of file RunManagerMT.h.

Referenced by initG4(), and physicsListForWorker().

const std::string RunManagerMT::m_PhysicsTablesDir
private

Definition at line 119 of file RunManagerMT.h.

Referenced by initG4().

edm::ParameterSet RunManagerMT::m_pPhysics
private

Definition at line 124 of file RunManagerMT.h.

Referenced by initG4().

edm::ParameterSet RunManagerMT::m_pRunAction
private

Definition at line 125 of file RunManagerMT.h.

Referenced by initializeUserActions().

bool RunManagerMT::m_pUseMagneticField
private

Definition at line 114 of file RunManagerMT.h.

Referenced by initG4().

std::string RunManagerMT::m_RegionFile
private

Definition at line 137 of file RunManagerMT.h.

Referenced by initG4(), and RunManagerMT().

SimActivityRegistry RunManagerMT::m_registry
private

Definition at line 129 of file RunManagerMT.h.

Referenced by Connect(), and initG4().

bool RunManagerMT::m_RestorePhysicsTables
private

Definition at line 121 of file RunManagerMT.h.

Referenced by initG4().

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

Definition at line 117 of file RunManagerMT.h.

Referenced by initializeUserActions().

bool RunManagerMT::m_runTerminated
private

Definition at line 113 of file RunManagerMT.h.

Referenced by stopG4(), terminateRun(), and ~RunManagerMT().

bool RunManagerMT::m_StorePhysicsTables
private

Definition at line 120 of file RunManagerMT.h.

Referenced by initG4().

RunAction* RunManagerMT::m_userRunAction
private

Definition at line 115 of file RunManagerMT.h.

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

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

Definition at line 128 of file RunManagerMT.h.

Referenced by initG4(), and world().

std::string RunManagerMT::m_WriteFile
private

Definition at line 136 of file RunManagerMT.h.

Referenced by initG4(), and RunManagerMT().