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
 
const bool m_pUseMagneticField
 
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 59 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_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  if("" != m_FieldFile) { m_FieldFile += ".txt"; }
84 }
const std::string m_PhysicsTablesDir
Definition: RunManagerMT.h:120
bool m_managerInitialized
Definition: RunManagerMT.h:113
G4MTRunManagerKernel * m_kernel
Definition: RunManagerMT.h:110
edm::ParameterSet m_pRunAction
Definition: RunManagerMT.h:126
assert(m_qm.get())
bool m_runTerminated
Definition: RunManagerMT.h:114
sim::FieldBuilder * m_fieldBuilder
Definition: RunManagerMT.h:133
std::vector< std::string > m_G4Commands
Definition: RunManagerMT.h:127
G4Run * m_currentRun
Definition: RunManagerMT.h:117
std::string m_WriteFile
Definition: RunManagerMT.h:137
const bool m_pUseMagneticField
Definition: RunManagerMT.h:115
bool m_StorePhysicsTables
Definition: RunManagerMT.h:121
std::string m_FieldFile
Definition: RunManagerMT.h:136
edm::ParameterSet m_pField
Definition: RunManagerMT.h:124
edm::ParameterSet m_pPhysics
Definition: RunManagerMT.h:125
bool m_RestorePhysicsTables
Definition: RunManagerMT.h:122
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:114

Member Function Documentation

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

Definition at line 75 of file RunManagerMT.h.

Referenced by ExceptionHandler::Notify().

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

Definition at line 81 of file RunManagerMT.h.

References m_catalog.

Referenced by RunManagerMTWorker::initializeThread().

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

Definition at line 102 of file RunManagerMT.h.

References m_chordFinderSetter.

Referenced by RunManagerMTWorker::initializeThread().

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

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

200 {
203 }
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:130
void RunManagerMT::DumpMagneticField ( const G4Field *  field) const
private

Definition at line 223 of file RunManagerMT.cc.

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

Referenced by initG4().

224 {
225  std::ofstream fout(m_FieldFile.c_str(), std::ios::out);
226  if(fout.fail()){
227  edm::LogWarning("SimG4CoreApplication")
228  << " RunManager WARNING : "
229  << "error opening file <" << m_FieldFile << "> for magnetic field";
230  } else {
231  double rmax = 9000*mm;
232  double zmax = 16000*mm;
233 
234  double dr = 5*cm;
235  double dz = 20*cm;
236 
237  int nr = (int)(rmax/dr);
238  int nz = 2*(int)(zmax/dz);
239 
240  double r = 0.0;
241  double z0 = -zmax;
242  double z;
243 
244  double phi = 0.0;
245  double cosf = cos(phi);
246  double sinf = sin(phi);
247 
248  double point[4] = {0.0,0.0,0.0,0.0};
249  double bfield[3] = {0.0,0.0,0.0};
250 
251  fout << std::setprecision(6);
252  for(int i=0; i<=nr; ++i) {
253  z = z0;
254  for(int j=0; j<=nz; ++j) {
255  point[0] = r*cosf;
256  point[1] = r*sinf;
257  point[2] = z;
258  field->GetFieldValue(point, bfield);
259  fout << "R(mm)= " << r/mm << " phi(deg)= " << phi/degree
260  << " Z(mm)= " << z/mm << " Bz(tesla)= " << bfield[2]/tesla
261  << " Br(tesla)= " << (bfield[0]*cosf + bfield[1]*sinf)/tesla
262  << " Bphi(tesla)= " << (bfield[0]*sinf - bfield[1]*cosf)/tesla
263  << G4endl;
264  z += dz;
265  }
266  r += dr;
267  }
268 
269  fout.close();
270  }
271 }
int i
Definition: DBlmapReader.cc:9
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
float float float z
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:136
*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
Definition: DDAxes.h:10
const std::vector<std::string>& RunManagerMT::G4Commands ( ) const
inline

Definition at line 85 of file RunManagerMT.h.

References m_G4Commands.

Referenced by RunManagerMTWorker::initializeThread().

85  {
86  return m_G4Commands;
87  }
std::vector< std::string > m_G4Commands
Definition: RunManagerMT.h:127
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_registry, m_RestorePhysicsTables, m_StorePhysicsTables, m_userRunAction, m_world, m_WriteFile, 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  if("" != m_WriteFile) {
104  G4GDMLParser gdml;
105  gdml.Write(m_WriteFile, m_world->GetWorldVolume());
106  }
107 
108  // setup the magnetic field
110  {
111  const GlobalPoint g(0.,0.,0.);
112 
115  G4TransportationManager * tM =
116  G4TransportationManager::GetTransportationManager();
117  m_fieldBuilder->build( tM->GetFieldManager(),
118  tM->GetPropagatorInField());
119  if("" != m_FieldFile) {
120  DumpMagneticField(tM->GetFieldManager()->GetDetectorField());
121  }
122  }
123 
124  // Create physics list
125  std::unique_ptr<PhysicsListMakerBase>
126  physicsMaker(PhysicsListFactory::get()->create(
127  m_pPhysics.getParameter<std::string> ("type")));
128  if (physicsMaker.get()==0) {
129  throw SimG4Exception("Unable to find the Physics list requested");
130  }
131  m_physicsList =
132  physicsMaker->make(map_,fPDGTable,m_chordFinderSetter.get(),m_pPhysics,m_registry);
133 
134  PhysicsList* phys = m_physicsList.get();
135  if (phys==0) {
136  throw SimG4Exception("Physics list construction failed!");
137  }
138 
139  // adding GFlash, Russian Roulette for eletrons and gamma,
140  // step limiters on top of any Physics Lists
141  phys->RegisterPhysics(new ParametrisedEMPhysics("EMoptions",m_pPhysics));
142 
143  m_kernel->SetPhysics(phys);
144  m_kernel->InitializePhysics();
145  m_kernel->SetUpDecayChannels();
146  // The following line was with the following comment in
147  // G4MTRunManager::InitializePhysics() in 10.00.p01; in practice
148  // needed to initialize certain singletons during the master thread
149  // initialization in order to avoid races later...
150  //
151  //BERTINI, this is needed to create pseudo-particles, to be removed
152  G4CascadeInterface::Initialize();
153  //
154 
155  m_physicsList->ResetStoredInAscii();
157  m_physicsList->SetPhysicsTableRetrieved(m_PhysicsTablesDir);
158  }
159 
160  if (m_kernel->RunInitialization()) { m_managerInitialized = true; }
161  else {
162  throw SimG4Exception("G4RunManagerKernel initialization failed!");
163  }
164 
166  {
167  std::ostringstream dir;
168  dir << m_PhysicsTablesDir << '\0';
169  std::string cmd = std::string("/control/shell mkdir -p ")+m_PhysicsTablesDir;
170  if (!std::ifstream(dir.str().c_str(), std::ios::in))
171  G4UImanager::GetUIpointer()->ApplyCommand(cmd);
172  m_physicsList->StorePhysicsTable(m_PhysicsTablesDir);
173  }
174 
176 
177  for (unsigned it=0; it<m_G4Commands.size(); it++) {
178  edm::LogInfo("SimG4CoreApplication") << "RunManagerMT:: Requests UI: "
179  << m_G4Commands[it];
180  G4UImanager::GetUIpointer()->ApplyCommand(m_G4Commands[it]);
181  }
182 
183  // If the Geant4 particle table is needed, decomment the lines below
184  //
185  // G4cout << "Output of G4ParticleTable DumpTable:" << G4endl;
186  // G4ParticleTable::GetParticleTable()->DumpTable("ALL");
187  G4StateManager::GetStateManager()->SetNewState(G4State_GeomClosed);
188  m_currentRun = new G4Run();
190 }
const std::string m_PhysicsTablesDir
Definition: RunManagerMT.h:120
bool m_managerInitialized
Definition: RunManagerMT.h:113
T getParameter(std::string const &) const
G4MTRunManagerKernel * m_kernel
Definition: RunManagerMT.h:110
SensitiveDetectorCatalog m_catalog
Definition: RunManagerMT.h:131
sim::FieldBuilder * m_fieldBuilder
Definition: RunManagerMT.h:133
std::vector< std::string > m_G4Commands
Definition: RunManagerMT.h:127
G4Run * m_currentRun
Definition: RunManagerMT.h:117
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:137
void build(G4FieldManager *fM=nullptr, G4PropagatorInField *fP=nullptr, ChordFinderSetter *setter=nullptr)
Definition: FieldBuilder.cc:48
const bool m_pUseMagneticField
Definition: RunManagerMT.h:115
string cmd
Definition: asciidump.py:19
void DumpMagneticField(const G4Field *) const
bool m_StorePhysicsTables
Definition: RunManagerMT.h:121
std::unique_ptr< PhysicsList > m_physicsList
Definition: RunManagerMT.h:112
std::string m_FieldFile
Definition: RunManagerMT.h:136
edm::ParameterSet m_pField
Definition: RunManagerMT.h:124
std::unique_ptr< DDDWorld > m_world
Definition: RunManagerMT.h:129
edm::ParameterSet m_pPhysics
Definition: RunManagerMT.h:125
void BeginOfRunAction(const G4Run *aRun)
Definition: RunAction.cc:21
DDDWorldSignal dddWorldSignal_
bool m_RestorePhysicsTables
Definition: RunManagerMT.h:122
std::unique_ptr< sim::ChordFinderSetter > m_chordFinderSetter
Definition: RunManagerMT.h:134
dbl *** dir
Definition: mlp_gen.cc:35
RunAction * m_userRunAction
Definition: RunManagerMT.h:116
SurfaceDeformation * create(int type, const std::vector< double > &params)
T get(const Candidate &c)
Definition: component.h:55
SimActivityRegistry m_registry
Definition: RunManagerMT.h:130
void RunManagerMT::initializeUserActions ( )

Definition at line 192 of file RunManagerMT.cc.

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

Referenced by initG4().

192  {
193  m_runInterface.reset(new SimRunInterface(this, true));
194 
197 }
void Connect(RunAction *)
edm::ParameterSet m_pRunAction
Definition: RunManagerMT.h:126
std::unique_ptr< SimRunInterface > m_runInterface
Definition: RunManagerMT.h:118
RunAction * m_userRunAction
Definition: RunManagerMT.h:116
PhysicsList* RunManagerMT::physicsListForWorker ( ) const
inline

Definition at line 93 of file RunManagerMT.h.

References m_physicsList.

Referenced by RunManagerMTWorker::initializeThread().

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

Definition at line 205 of file RunManagerMT.cc.

References m_runTerminated, and terminateRun().

206 {
207  G4StateManager::GetStateManager()->SetNewState(G4State_Quit);
208  if(!m_runTerminated) { terminateRun(); }
209 }
void terminateRun()
bool m_runTerminated
Definition: RunManagerMT.h:114
void RunManagerMT::terminateRun ( )
private

Definition at line 211 of file RunManagerMT.cc.

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

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

211  {
213  delete m_userRunAction;
214  m_userRunAction = 0;
215  // delete m_currentRun;
216  //m_currentRun = 0;
217  if(m_kernel && !m_runTerminated) {
218  m_kernel->RunTermination();
219  m_runTerminated = true;
220  }
221 }
G4MTRunManagerKernel * m_kernel
Definition: RunManagerMT.h:110
bool m_runTerminated
Definition: RunManagerMT.h:114
G4Run * m_currentRun
Definition: RunManagerMT.h:117
void EndOfRunAction(const G4Run *aRun)
Definition: RunAction.cc:39
RunAction * m_userRunAction
Definition: RunManagerMT.h:116
const DDDWorld& RunManagerMT::world ( ) const
inline

Definition at line 77 of file RunManagerMT.h.

References m_world.

Referenced by RunManagerMTWorker::initializeThread().

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

Member Data Documentation

SensitiveDetectorCatalog RunManagerMT::m_catalog
private

Definition at line 131 of file RunManagerMT.h.

Referenced by catalog(), and initG4().

bool RunManagerMT::m_check
private

Definition at line 123 of file RunManagerMT.h.

Referenced by initG4(), and RunManagerMT().

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

Definition at line 134 of file RunManagerMT.h.

Referenced by chordFinderSetterForWorker(), and initG4().

G4Run* RunManagerMT::m_currentRun
private

Definition at line 117 of file RunManagerMT.h.

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

sim::FieldBuilder* RunManagerMT::m_fieldBuilder
private

Definition at line 133 of file RunManagerMT.h.

Referenced by initG4().

std::string RunManagerMT::m_FieldFile
private

Definition at line 136 of file RunManagerMT.h.

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

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

Definition at line 127 of file RunManagerMT.h.

Referenced by G4Commands(), and initG4().

G4MTRunManagerKernel* RunManagerMT::m_kernel
private

Definition at line 110 of file RunManagerMT.h.

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

bool RunManagerMT::m_managerInitialized
private

Definition at line 113 of file RunManagerMT.h.

Referenced by initG4().

edm::ParameterSet RunManagerMT::m_pField
private

Definition at line 124 of file RunManagerMT.h.

Referenced by initG4().

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

Definition at line 112 of file RunManagerMT.h.

Referenced by initG4(), and physicsListForWorker().

const std::string RunManagerMT::m_PhysicsTablesDir
private

Definition at line 120 of file RunManagerMT.h.

Referenced by initG4().

edm::ParameterSet RunManagerMT::m_pPhysics
private

Definition at line 125 of file RunManagerMT.h.

Referenced by initG4().

edm::ParameterSet RunManagerMT::m_pRunAction
private

Definition at line 126 of file RunManagerMT.h.

Referenced by initializeUserActions().

const bool RunManagerMT::m_pUseMagneticField
private

Definition at line 115 of file RunManagerMT.h.

Referenced by initG4().

SimActivityRegistry RunManagerMT::m_registry
private

Definition at line 130 of file RunManagerMT.h.

Referenced by Connect(), and initG4().

bool RunManagerMT::m_RestorePhysicsTables
private

Definition at line 122 of file RunManagerMT.h.

Referenced by initG4().

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

Definition at line 118 of file RunManagerMT.h.

Referenced by initializeUserActions().

bool RunManagerMT::m_runTerminated
private

Definition at line 114 of file RunManagerMT.h.

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

bool RunManagerMT::m_StorePhysicsTables
private

Definition at line 121 of file RunManagerMT.h.

Referenced by initG4().

RunAction* RunManagerMT::m_userRunAction
private

Definition at line 116 of file RunManagerMT.h.

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

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

Definition at line 129 of file RunManagerMT.h.

Referenced by initG4(), and world().

std::string RunManagerMT::m_WriteFile
private

Definition at line 137 of file RunManagerMT.h.

Referenced by initG4(), and RunManagerMT().