CMS 3D CMS Logo

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

#include <RunManager.h>

Public Member Functions

void abortEvent ()
 
void abortRun (bool softAbort=false)
 
void Connect (RunAction *)
 
void Connect (EventAction *)
 
void Connect (TrackingAction *)
 
void Connect (SteppingAction *)
 
const G4Event * currentEvent () const
 
const G4Run * currentRun () const
 
const Generatorgenerator () const
 
SimTrackManagerGetSimTrackManager ()
 
void initG4 (const edm::EventSetup &es)
 
void initializeRun ()
 
void initializeUserActions ()
 
void produce (edm::Event &inpevt, const edm::EventSetup &es)
 
std::vector< std::shared_ptr
< SimProducer > > 
producers () const
 
 RunManager (edm::ParameterSet const &p)
 
std::vector
< SensitiveCaloDetector * > & 
sensCaloDetectors ()
 
std::vector
< SensitiveTkDetector * > & 
sensTkDetectors ()
 
G4SimEventsimEvent ()
 
void stopG4 ()
 
void terminateRun ()
 
 ~RunManager ()
 

Protected Member Functions

void DumpMagneticField (const G4Field *) const
 
G4Event * generateEvent (edm::Event &inpevt)
 
void resetGenParticleId (edm::Event &inpevt)
 

Private Attributes

bool firstRun
 
edm::ESWatcher
< IdealGeometryRecord
idealGeomRcdWatcher_
 
edm::ESWatcher
< IdealMagneticFieldRecord
idealMagRcdWatcher_
 
AttachSDm_attach
 
bool m_check
 
sim::ChordFinderSetterm_chordFinderSetter
 
G4Event * m_currentEvent
 
G4Run * m_currentRun
 
int m_EvtMgrVerbosity
 
sim::FieldBuilderm_fieldBuilder
 
std::string m_FieldFile
 
std::vector< std::string > m_G4Commands
 
Generatorm_generator
 
std::string m_InTag
 
G4RunManagerKernel * m_kernel
 
bool m_managerInitialized
 
bool m_nonBeam
 
edm::ParameterSet m_p
 
edm::ParameterSet m_pEventAction
 
edm::ParameterSet m_pField
 
edm::ParameterSet m_pGenerator
 
edm::ParameterSet m_pGeometry
 
std::auto_ptr< PhysicsListm_physicsList
 
std::string m_PhysicsTablesDir
 
edm::ParameterSet m_pPhysics
 
PrimaryTransformerm_primaryTransformer
 
std::vector< std::shared_ptr
< SimProducer > > 
m_producers
 
edm::ParameterSet m_pRunAction
 
edm::ParameterSet m_pStackingAction
 
edm::ParameterSet m_pSteppingAction
 
edm::ParameterSet m_pTrackingAction
 
bool m_pUseMagneticField
 
edm::ParameterSet m_pVertexGenerator
 
std::string m_RegionFile
 
SimActivityRegistry m_registry
 
bool m_RestorePhysicsTables
 
bool m_runAborted
 
bool m_runInitialized
 
SimRunInterfacem_runInterface
 
bool m_runTerminated
 
std::vector
< SensitiveCaloDetector * > 
m_sensCaloDets
 
std::vector
< SensitiveTkDetector * > 
m_sensTkDets
 
G4SimEventm_simEvent
 
bool m_StorePhysicsTables
 
edm::InputTag m_theLHCTlinkTag
 
std::auto_ptr< SimTrackManagerm_trackManager
 
RunActionm_userRunAction
 
std::vector< std::shared_ptr
< SimWatcher > > 
m_watchers
 
std::string m_WriteFile
 

Detailed Description

Definition at line 57 of file RunManager.h.

Constructor & Destructor Documentation

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

Definition at line 106 of file RunManager.cc.

References SimActivityRegistry::connect(), createWatchers(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), m_check, m_FieldFile, m_generator, m_InTag, m_kernel, m_p, m_pGenerator, m_producers, m_RegionFile, m_registry, m_runInterface, m_userRunAction, m_watchers, m_WriteFile, and AlCaHLTBitMon_QueryRunRegistry::string.

107  : m_generator(0), m_nonBeam(p.getParameter<bool>("NonBeamEvent")),
109  m_managerInitialized(false),
110  m_runInitialized(false), m_runTerminated(false), m_runAborted(false),
111  firstRun(true),
112  m_pUseMagneticField(p.getParameter<bool>("UseMagneticField")),
114  m_PhysicsTablesDir(p.getParameter<std::string>("PhysicsTablesDirectory")),
115  m_StorePhysicsTables(p.getParameter<bool>("StorePhysicsTables")),
116  m_RestorePhysicsTables(p.getParameter<bool>("RestorePhysicsTables")),
117  m_EvtMgrVerbosity(p.getUntrackedParameter<int>("G4EventManagerVerbosity",0)),
118  m_pField(p.getParameter<edm::ParameterSet>("MagneticField")),
119  m_pGenerator(p.getParameter<edm::ParameterSet>("Generator")),
120  m_pPhysics(p.getParameter<edm::ParameterSet>("Physics")),
121  m_pRunAction(p.getParameter<edm::ParameterSet>("RunAction")),
122  m_pEventAction(p.getParameter<edm::ParameterSet>("EventAction")),
123  m_pStackingAction(p.getParameter<edm::ParameterSet>("StackingAction")),
124  m_pTrackingAction(p.getParameter<edm::ParameterSet>("TrackingAction")),
125  m_pSteppingAction(p.getParameter<edm::ParameterSet>("SteppingAction")),
126  m_G4Commands(p.getParameter<std::vector<std::string> >("G4Commands")),
127  m_p(p), m_fieldBuilder(0), m_chordFinderSetter(nullptr),
128  m_theLHCTlinkTag(p.getParameter<edm::InputTag>("theLHCTlinkTag"))
129 {
130  m_kernel = G4RunManagerKernel::GetRunManagerKernel();
131  if (m_kernel==0) m_kernel = new G4RunManagerKernel();
132 
133  m_check = p.getUntrackedParameter<bool>("CheckOverlap",false);
134  m_WriteFile = p.getUntrackedParameter<std::string>("FileNameGDML","");
135  m_FieldFile = p.getUntrackedParameter<std::string>("FileNameField","");
136  m_RegionFile = p.getUntrackedParameter<std::string>("FileNameRegions","");
137 
138  m_userRunAction = 0;
139  m_runInterface = 0;
140 
141  //Look for an outside SimActivityRegistry
142  // this is used by the visualization code
143  edm::Service<SimActivityRegistry> otherRegistry;
144  if(otherRegistry){
145  m_registry.connect(*otherRegistry);
146  }
147 
149 
151  m_InTag = m_pGenerator.getParameter<std::string>("HepMCProductLabel") ;
152 
153 }
T getParameter(std::string const &) const
bool m_check
Definition: RunManager.h:127
edm::ParameterSet m_pGenerator
Definition: RunManager.h:130
G4Event * m_currentEvent
Definition: RunManager.h:116
SimActivityRegistry m_registry
Definition: RunManager.h:145
edm::ParameterSet m_p
Definition: RunManager.h:139
std::vector< std::shared_ptr< SimProducer > > m_producers
Definition: RunManager.h:147
void connect(Observer< const BeginOfJob * > *iObject)
Generator * m_generator
Definition: RunManager.h:103
static void createWatchers(const edm::ParameterSet &iP, SimActivityRegistry &iReg, std::vector< std::shared_ptr< SimWatcher > > &oWatchers, std::vector< std::shared_ptr< SimProducer > > &oProds)
Definition: RunManager.cc:72
bool m_pUseMagneticField
Definition: RunManager.h:114
bool m_nonBeam
Definition: RunManager.h:106
int m_EvtMgrVerbosity
Definition: RunManager.h:126
std::string m_WriteFile
Definition: RunManager.h:159
bool firstRun
Definition: RunManager.h:113
SimRunInterface * m_runInterface
Definition: RunManager.h:119
bool m_RestorePhysicsTables
Definition: RunManager.h:125
std::vector< std::shared_ptr< SimWatcher > > m_watchers
Definition: RunManager.h:146
G4Run * m_currentRun
Definition: RunManager.h:115
edm::ParameterSet m_pStackingAction
Definition: RunManager.h:135
edm::ParameterSet m_pEventAction
Definition: RunManager.h:134
bool m_runTerminated
Definition: RunManager.h:111
edm::ParameterSet m_pField
Definition: RunManager.h:129
edm::ParameterSet m_pPhysics
Definition: RunManager.h:132
edm::ParameterSet m_pSteppingAction
Definition: RunManager.h:137
RunAction * m_userRunAction
Definition: RunManager.h:118
std::string m_InTag
Definition: RunManager.h:104
bool m_runInitialized
Definition: RunManager.h:110
sim::ChordFinderSetter * m_chordFinderSetter
Definition: RunManager.h:151
std::string m_RegionFile
Definition: RunManager.h:160
PrimaryTransformer * m_primaryTransformer
Definition: RunManager.h:108
sim::FieldBuilder * m_fieldBuilder
Definition: RunManager.h:150
std::string m_PhysicsTablesDir
Definition: RunManager.h:123
bool m_StorePhysicsTables
Definition: RunManager.h:124
edm::ParameterSet m_pRunAction
Definition: RunManager.h:133
edm::ParameterSet m_pTrackingAction
Definition: RunManager.h:136
std::vector< std::string > m_G4Commands
Definition: RunManager.h:138
std::string m_FieldFile
Definition: RunManager.h:158
G4SimEvent * m_simEvent
Definition: RunManager.h:117
bool m_managerInitialized
Definition: RunManager.h:109
edm::InputTag m_theLHCTlinkTag
Definition: RunManager.h:156
G4RunManagerKernel * m_kernel
Definition: RunManager.h:101
bool m_runAborted
Definition: RunManager.h:112
RunManager::~RunManager ( )

Definition at line 155 of file RunManager.cc.

References m_runInterface, m_runTerminated, and terminateRun().

156 {
157  if (!m_runTerminated) { terminateRun(); }
158  G4StateManager::GetStateManager()->SetNewState(G4State_Quit);
159  G4GeometryManager::GetInstance()->OpenGeometry();
160  // if (m_kernel!=0) delete m_kernel;
161  delete m_runInterface;
162 }
SimRunInterface * m_runInterface
Definition: RunManager.h:119
void terminateRun()
Definition: RunManager.cc:468
bool m_runTerminated
Definition: RunManager.h:111

Member Function Documentation

void RunManager::abortEvent ( )

Definition at line 389 of file RunManager.cc.

References m_currentEvent, m_kernel, m_runTerminated, TrackingAction::PostUserTrackingAction(), and tree::t.

Referenced by SimRunInterface::abortEvent(), and abortRun().

390 {
391  if (m_runTerminated) { return; }
392  G4Track* t =
393  m_kernel->GetEventManager()->GetTrackingManager()->GetTrack();
394  t->SetTrackStatus(fStopAndKill) ;
395 
396  // CMS-specific act
397  //
398  TrackingAction* uta =
399  (TrackingAction*)m_kernel->GetEventManager()->GetUserTrackingAction() ;
400  uta->PostUserTrackingAction(t) ;
401 
402  m_currentEvent->SetEventAborted();
403 
404  // do NOT call this method for now
405  // because it'll set abortRequested=true (withing G4EventManager)
406  // this will make Geant4, in the event *next* after the aborted one
407  // NOT to get the primary, thus there's NOTHING to trace, and it goes
408  // to the end of G4Event::DoProcessing(G4Event*), where abortRequested
409  // will be reset to true again
410  //
411  //m_kernel->GetEventManager()->AbortCurrentEvent();
412  //
413  // instead, mimic what it does, except (re)setting abortRequested
414  //
415  m_kernel->GetEventManager()->GetStackManager()->clear() ;
416  m_kernel->GetEventManager()->GetTrackingManager()->EventAborted() ;
417 
418  G4StateManager* stateManager = G4StateManager::GetStateManager();
419  stateManager->SetNewState(G4State_GeomClosed);
420 }
tuple t
Definition: tree.py:139
G4Event * m_currentEvent
Definition: RunManager.h:116
bool m_runTerminated
Definition: RunManager.h:111
virtual void PostUserTrackingAction(const G4Track *aTrack)
G4RunManagerKernel * m_kernel
Definition: RunManager.h:101
void RunManager::abortRun ( bool  softAbort = false)

Definition at line 486 of file RunManager.cc.

References abortEvent(), m_currentRun, m_runAborted, m_runInitialized, and terminateRun().

Referenced by SimRunInterface::abortRun(), ExceptionHandler::Notify(), and produce().

487 {
488  m_runAborted = false;
489  if (!softAbort) { abortEvent(); }
490  if (m_currentRun!=0) { delete m_currentRun; m_currentRun = 0; }
491  m_runInitialized = false;
492  m_runAborted = true;
493  terminateRun();
494 }
void abortEvent()
Definition: RunManager.cc:389
void terminateRun()
Definition: RunManager.cc:468
G4Run * m_currentRun
Definition: RunManager.h:115
bool m_runInitialized
Definition: RunManager.h:110
bool m_runAborted
Definition: RunManager.h:112
void RunManager::Connect ( RunAction runAction)

Definition at line 510 of file RunManager.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().

511 {
514 }
SimActivityRegistry m_registry
Definition: RunManager.h:145
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
void RunManager::Connect ( EventAction eventAction)

Definition at line 516 of file RunManager.cc.

References SimActivityRegistry::beginOfEventSignal_, sim_act::Signaler< T >::connect(), SimActivityRegistry::endOfEventSignal_, EventAction::m_beginOfEventSignal, EventAction::m_endOfEventSignal, and m_registry.

517 {
520 }
SimActivityRegistry m_registry
Definition: RunManager.h:145
EndOfEventSignal endOfEventSignal_
SimActivityRegistry::EndOfEventSignal m_endOfEventSignal
Definition: EventAction.h:46
BeginOfEventSignal beginOfEventSignal_
void connect(Observer< const T * > *iObs)
does not take ownership of memory
Definition: Signaler.h:59
SimActivityRegistry::BeginOfEventSignal m_beginOfEventSignal
Definition: EventAction.h:45
void RunManager::Connect ( TrackingAction trackingAction)

Definition at line 522 of file RunManager.cc.

References SimActivityRegistry::beginOfTrackSignal_, sim_act::Signaler< T >::connect(), SimActivityRegistry::endOfTrackSignal_, TrackingAction::m_beginOfTrackSignal, TrackingAction::m_endOfTrackSignal, and m_registry.

523 {
526 }
SimActivityRegistry m_registry
Definition: RunManager.h:145
SimActivityRegistry::EndOfTrackSignal m_endOfTrackSignal
void connect(Observer< const T * > *iObs)
does not take ownership of memory
Definition: Signaler.h:59
EndOfTrackSignal endOfTrackSignal_
BeginOfTrackSignal beginOfTrackSignal_
SimActivityRegistry::BeginOfTrackSignal m_beginOfTrackSignal
void RunManager::Connect ( SteppingAction steppingAction)

Definition at line 528 of file RunManager.cc.

References sim_act::Signaler< T >::connect(), SimActivityRegistry::g4StepSignal_, SteppingAction::m_g4StepSignal, and m_registry.

529 {
531 }
SimActivityRegistry m_registry
Definition: RunManager.h:145
SimActivityRegistry::G4StepSignal m_g4StepSignal
void connect(Observer< const T * > *iObs)
does not take ownership of memory
Definition: Signaler.h:59
const G4Event* RunManager::currentEvent ( ) const
inline

Definition at line 75 of file RunManager.h.

References m_currentEvent.

75 { return m_currentEvent; }
G4Event * m_currentEvent
Definition: RunManager.h:116
const G4Run* RunManager::currentRun ( ) const
inline

Definition at line 71 of file RunManager.h.

References m_currentRun.

71 { return m_currentRun; }
G4Run * m_currentRun
Definition: RunManager.h:115
void RunManager::DumpMagneticField ( const G4Field *  field) const
protected

Definition at line 533 of file RunManager.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().

534 {
535  std::ofstream fout(m_FieldFile.c_str(), std::ios::out);
536  if(fout.fail()){
537  edm::LogWarning("SimG4CoreApplication")
538  << " RunManager WARNING : "
539  << "error opening file <" << m_FieldFile << "> for magnetic field";
540  } else {
541  double rmax = 9000*mm;
542  double zmax = 16000*mm;
543 
544  double dr = 5*cm;
545  double dz = 20*cm;
546 
547  int nr = (int)(rmax/dr);
548  int nz = 2*(int)(zmax/dz);
549 
550  double r = 0.0;
551  double z0 = -zmax;
552  double z;
553 
554  double phi = 0.0;
555  double cosf = cos(phi);
556  double sinf = sin(phi);
557 
558  double point[4] = {0.0,0.0,0.0,0.0};
559  double bfield[3] = {0.0,0.0,0.0};
560 
561  fout << std::setprecision(6);
562  for(int i=0; i<=nr; ++i) {
563  z = z0;
564  for(int j=0; j<=nz; ++j) {
565  point[0] = r*cosf;
566  point[1] = r*sinf;
567  point[2] = z;
568  field->GetFieldValue(point, bfield);
569  fout << "R(mm)= " << r/mm << " phi(deg)= " << phi/degree
570  << " Z(mm)= " << z/mm << " Bz(tesla)= " << bfield[2]/tesla
571  << " Br(tesla)= " << (bfield[0]*cosf + bfield[1]*sinf)/tesla
572  << " Bphi(tesla)= " << (bfield[0]*sinf - bfield[1]*cosf)/tesla
573  << G4endl;
574  z += dz;
575  }
576  r += dr;
577  }
578 
579  fout.close();
580  }
581 }
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: RunManager.h:158
*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
G4Event * RunManager::generateEvent ( edm::Event inpevt)
protected

Definition at line 355 of file RunManager.cc.

References edm::EventID::event(), edm::Event::getByLabel(), Generator::HepMC2G4(), edm::EventBase::id(), m_currentEvent, m_generator, m_InTag, m_nonBeam, m_simEvent, Generator::nonBeamEvent2G4(), resetGenParticleId(), and Generator::setGenEvent().

Referenced by produce().

356 {
357  if (m_currentEvent!=0) { delete m_currentEvent; }
358  m_currentEvent = 0;
359  if (m_simEvent!=0) { delete m_simEvent; }
360  m_simEvent = 0;
361 
362  // 64 bits event ID in CMSSW converted into Geant4 event ID
363  G4int evtid = (G4int)inpevt.id().event();
364  G4Event * evt = new G4Event(evtid);
365 
367 
368  inpevt.getByLabel( m_InTag, HepMCEvt ) ;
369 
370  m_generator->setGenEvent(HepMCEvt->GetEvent());
371 
372  // required to reset the GenParticle Id for particles transported
373  // along the beam pipe
374  // to their original value for SimTrack creation
375  resetGenParticleId( inpevt );
376 
377  if (!m_nonBeam)
378  {
379  m_generator->HepMC2G4(HepMCEvt->GetEvent(),evt);
380  }
381  else
382  {
383  m_generator->nonBeamEvent2G4(HepMCEvt->GetEvent(),evt);
384  }
385 
386  return evt;
387 }
EventNumber_t event() const
Definition: EventID.h:41
G4Event * m_currentEvent
Definition: RunManager.h:116
void HepMC2G4(const HepMC::GenEvent *g, G4Event *e)
Definition: Generator.cc:100
Generator * m_generator
Definition: RunManager.h:103
bool m_nonBeam
Definition: RunManager.h:106
void setGenEvent(const HepMC::GenEvent *inpevt)
Definition: Generator.h:25
void resetGenParticleId(edm::Event &inpevt)
Definition: RunManager.cc:496
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:413
void nonBeamEvent2G4(const HepMC::GenEvent *g, G4Event *e)
Definition: Generator.cc:500
std::string m_InTag
Definition: RunManager.h:104
edm::EventID id() const
Definition: EventBase.h:60
G4SimEvent * m_simEvent
Definition: RunManager.h:117
const Generator* RunManager::generator ( ) const
inline

Definition at line 74 of file RunManager.h.

References m_generator.

74 { return m_generator; }
Generator * m_generator
Definition: RunManager.h:103
SimTrackManager * RunManager::GetSimTrackManager ( )

Definition at line 505 of file RunManager.cc.

References m_trackManager.

Referenced by SimRunInterface::SimRunInterface().

506 {
507  return m_trackManager.get();
508 }
std::auto_ptr< SimTrackManager > m_trackManager
Definition: RunManager.h:149
void RunManager::initG4 ( const edm::EventSetup es)

Definition at line 164 of file RunManager.cc.

References SimActivityRegistry::beginOfJobSignal_, sim::FieldBuilder::build(), edm::ESWatcher< T >::check(), asciidump::cmd, AttachSD::create(), SurfaceDeformationFactory::create(), SimActivityRegistry::dddWorldSignal_, dir, DumpMagneticField(), Exception, firstRun, g, edm::EventSetup::get(), reco::get(), edm::ParameterSet::getParameter(), DDDWorld::GetWorldVolume(), idealGeomRcdWatcher_, idealMagRcdWatcher_, recoMuon::in, initializeRun(), initializeUserActions(), m_attach, m_check, m_chordFinderSetter, m_fieldBuilder, m_FieldFile, m_G4Commands, m_kernel, m_managerInitialized, m_p, m_pField, m_physicsList, m_PhysicsTablesDir, m_pPhysics, m_primaryTransformer, m_pUseMagneticField, m_RegionFile, m_registry, m_RestorePhysicsTables, m_sensCaloDets, m_sensTkDets, m_StorePhysicsTables, m_trackManager, m_WriteFile, G4RegionReporter::ReportRegions(), and AlCaHLTBitMon_QueryRunRegistry::string.

165 {
166  bool geomChanged = idealGeomRcdWatcher_.check(es);
167  if (geomChanged && (!firstRun)) {
168  throw cms::Exception("BadConfig")
169  << "[SimG4Core RunManager]\n"
170  << "The Geometry configuration is changed during the job execution\n"
171  << "this is not allowed, the geometry must stay unchanged\n";
172  }
173  if (m_pUseMagneticField) {
174  bool magChanged = idealMagRcdWatcher_.check(es);
175  if (magChanged && (!firstRun)) {
176  throw cms::Exception("BadConfig")
177  << "[SimG4Core RunManager]\n"
178  << "The MagneticField configuration is changed during the job execution\n"
179  << "this is not allowed, the MagneticField must stay unchanged\n";
180  }
181  }
182 
183  if (m_managerInitialized) return;
184 
185  // DDDWorld: get the DDCV from the ES and use it to build the World
187  es.get<IdealGeometryRecord>().get(pDD);
188 
190  SensitiveDetectorCatalog catalog_;
191  const DDDWorld * world = new DDDWorld(&(*pDD), map_, catalog_, m_check);
193 
195  {
196  // setup the magnetic field
198  es.get<IdealMagneticFieldRecord>().get(pMF);
199  const GlobalPoint g(0.,0.,0.);
200 
202  m_fieldBuilder = new sim::FieldBuilder(&(*pMF), m_pField);
203  G4TransportationManager * tM =
204  G4TransportationManager::GetTransportationManager();
205  m_fieldBuilder->build( tM->GetFieldManager(),
206  tM->GetPropagatorInField(),
208  if("" != m_FieldFile) {
209  DumpMagneticField(tM->GetFieldManager()->GetDetectorField());
210  }
211  }
212 
213  // we need the track manager now
214  m_trackManager = std::auto_ptr<SimTrackManager>(new SimTrackManager);
215 
216  // attach sensitive detector
217  m_attach = new AttachSD;
218 
219  std::pair< std::vector<SensitiveTkDetector*>,
220  std::vector<SensitiveCaloDetector*> > sensDets =
221  m_attach->create(*world,(*pDD),catalog_,m_p,m_trackManager.get(),
222  m_registry);
223 
224  m_sensTkDets.swap(sensDets.first);
225  m_sensCaloDets.swap(sensDets.second);
226 
227  edm::LogInfo("SimG4CoreApplication")
228  << " RunManager: Sensitive Detector "
229  << "building finished; found "
230  << m_sensTkDets.size()
231  << " Tk type Producers, and "
232  << m_sensCaloDets.size()
233  << " Calo type producers ";
234 
236  es.get<PDTRecord>().get(fTable);
237  const HepPDT::ParticleDataTable *fPDGTable = &(*fTable);
238 
240 
241  std::auto_ptr<PhysicsListMakerBase>
242  physicsMaker(PhysicsListFactory::get()->create(
243  m_pPhysics.getParameter<std::string> ("type")));
244  if (physicsMaker.get()==0) {
245  throw SimG4Exception("Unable to find the Physics list requested");
246  }
247  m_physicsList =
248  physicsMaker->make(map_,fPDGTable,m_chordFinderSetter,m_pPhysics,m_registry);
249 
250  PhysicsList* phys = m_physicsList.get();
251  if (phys==0) {
252  throw SimG4Exception("Physics list construction failed!");
253  }
254 
255  // adding GFlash, Russian Roulette for eletrons and gamma,
256  // step limiters on top of any Physics Lists
257  phys->RegisterPhysics(new ParametrisedEMPhysics("EMoptions",m_pPhysics));
258 
259  m_physicsList->ResetStoredInAscii();
260  std::string tableDir = m_PhysicsTablesDir;
262  m_physicsList->SetPhysicsTableRetrieved(tableDir);
263  }
264  edm::LogInfo("SimG4CoreApplication")
265  << "RunManager: start initialisation of PhysicsList";
266 
267  m_kernel->SetPhysics(phys);
268  m_kernel->InitializePhysics();
269 
270  if (m_kernel->RunInitialization()) { m_managerInitialized = true; }
271  else {
272  throw SimG4Exception("G4RunManagerKernel initialization failed!");
273  }
274 
276  {
277  std::ostringstream dir;
278  dir << tableDir << '\0';
279  std::string cmd = std::string("/control/shell mkdir -p ")+tableDir;
280  if (!std::ifstream(dir.str().c_str(), std::ios::in))
281  G4UImanager::GetUIpointer()->ApplyCommand(cmd);
282  m_physicsList->StorePhysicsTable(tableDir);
283  }
284 
285  //tell all interesting parties that we are beginning the job
286  BeginOfJob aBeginOfJob(&es);
287  m_registry.beginOfJobSignal_(&aBeginOfJob);
288 
290 
291  if(0 < m_G4Commands.size()) {
292  G4cout << "RunManager: Requested UI commands: " << G4endl;
293  for (unsigned it=0; it<m_G4Commands.size(); ++it) {
294  G4cout << " " << m_G4Commands[it] << G4endl;
295  G4UImanager::GetUIpointer()->ApplyCommand(m_G4Commands[it]);
296  }
297  }
298 
299  if("" != m_WriteFile) {
300  G4GDMLParser gdml(new G4GDMLReadStructure(), new CMSGDMLWriteStructure());
301  gdml.Write(m_WriteFile, world->GetWorldVolume(), true);
302  }
303 
304  if("" != m_RegionFile) {
305  G4RegionReporter rrep;
307  }
308 
309  // If the Geant4 particle table is needed, decomment the lines below
310  //
311  // G4cout << "Output of G4ParticleTable DumpTable:" << G4endl;
312  // G4ParticleTable::GetParticleTable()->DumpTable("ALL");
313 
314  initializeRun();
315  firstRun= false;
316 }
T getParameter(std::string const &) const
bool m_check
Definition: RunManager.h:127
std::auto_ptr< SimTrackManager > m_trackManager
Definition: RunManager.h:149
edm::ESWatcher< IdealMagneticFieldRecord > idealMagRcdWatcher_
Definition: RunManager.h:154
const G4VPhysicalVolume * GetWorldVolume() const
Definition: DDDWorld.h:18
SimActivityRegistry m_registry
Definition: RunManager.h:145
edm::ParameterSet m_p
Definition: RunManager.h:139
HepPDT::ParticleDataTable ParticleDataTable
void initializeRun()
Definition: RunManager.cc:458
void initializeUserActions()
Definition: RunManager.cc:422
bool m_pUseMagneticField
Definition: RunManager.h:114
edm::ESWatcher< IdealGeometryRecord > idealGeomRcdWatcher_
Definition: RunManager.h:153
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::vector< SensitiveCaloDetector * > m_sensCaloDets
Definition: RunManager.h:143
std::vector< SensitiveTkDetector * > m_sensTkDets
Definition: RunManager.h:142
BeginOfJobSignal beginOfJobSignal_
std::auto_ptr< PhysicsList > m_physicsList
Definition: RunManager.h:107
std::string m_WriteFile
Definition: RunManager.h:159
bool firstRun
Definition: RunManager.h:113
void build(G4FieldManager *fM=nullptr, G4PropagatorInField *fP=nullptr, ChordFinderSetter *setter=nullptr)
Definition: FieldBuilder.cc:48
string cmd
Definition: asciidump.py:19
bool m_RestorePhysicsTables
Definition: RunManager.h:125
edm::ParameterSet m_pField
Definition: RunManager.h:129
edm::ParameterSet m_pPhysics
Definition: RunManager.h:132
DDDWorldSignal dddWorldSignal_
const T & get() const
Definition: EventSetup.h:55
std::pair< std::vector< SensitiveTkDetector * >, std::vector< SensitiveCaloDetector * > > create(const DDDWorld &w, const DDCompactView &cpv, const SensitiveDetectorCatalog &clg, edm::ParameterSet const &p, const SimTrackManager *m, SimActivityRegistry &reg) const
Definition: AttachSD.cc:23
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
void ReportRegions(const std::string &ss)
void DumpMagneticField(const G4Field *) const
Definition: RunManager.cc:533
sim::ChordFinderSetter * m_chordFinderSetter
Definition: RunManager.h:151
std::string m_RegionFile
Definition: RunManager.h:160
AttachSD * m_attach
Definition: RunManager.h:141
PrimaryTransformer * m_primaryTransformer
Definition: RunManager.h:108
sim::FieldBuilder * m_fieldBuilder
Definition: RunManager.h:150
std::string m_PhysicsTablesDir
Definition: RunManager.h:123
bool m_StorePhysicsTables
Definition: RunManager.h:124
dbl *** dir
Definition: mlp_gen.cc:35
std::vector< std::string > m_G4Commands
Definition: RunManager.h:138
SurfaceDeformation * create(int type, const std::vector< double > &params)
std::string m_FieldFile
Definition: RunManager.h:158
bool m_managerInitialized
Definition: RunManager.h:109
T get(const Candidate &c)
Definition: component.h:55
G4RunManagerKernel * m_kernel
Definition: RunManager.h:101
void RunManager::initializeRun ( )

Definition at line 458 of file RunManager.cc.

References RunAction::BeginOfRunAction(), m_currentRun, m_runAborted, m_runInitialized, and m_userRunAction.

Referenced by initG4().

459 {
460  m_runInitialized = false;
461  if (m_currentRun==0) { m_currentRun = new G4Run(); }
462  G4StateManager::GetStateManager()->SetNewState(G4State_GeomClosed);
464  m_runAborted = false;
465  m_runInitialized = true;
466 }
G4Run * m_currentRun
Definition: RunManager.h:115
RunAction * m_userRunAction
Definition: RunManager.h:118
void BeginOfRunAction(const G4Run *aRun)
Definition: RunAction.cc:21
bool m_runInitialized
Definition: RunManager.h:110
bool m_runAborted
Definition: RunManager.h:112
void RunManager::initializeUserActions ( )

Definition at line 422 of file RunManager.cc.

References Connect(), m_EvtMgrVerbosity, m_generator, m_kernel, m_pEventAction, m_pRunAction, m_pStackingAction, m_pSteppingAction, m_pTrackingAction, m_runInterface, m_trackManager, and m_userRunAction.

Referenced by initG4().

423 {
424  m_runInterface = new SimRunInterface(this, false);
425 
428 
429  G4EventManager * eventManager = m_kernel->GetEventManager();
430  eventManager->SetVerboseLevel(m_EvtMgrVerbosity);
431 
432  if (m_generator!=0) {
433  EventAction * userEventAction =
435  Connect(userEventAction);
436  eventManager->SetUserAction(userEventAction);
437 
438  TrackingAction* userTrackingAction =
439  new TrackingAction(userEventAction,m_pTrackingAction);
440  Connect(userTrackingAction);
441  eventManager->SetUserAction(userTrackingAction);
442 
443  SteppingAction* userSteppingAction =
444  new SteppingAction(userEventAction,m_pSteppingAction);
445  Connect(userSteppingAction);
446  eventManager->SetUserAction(userSteppingAction);
447 
448  eventManager->SetUserAction(new StackingAction(userTrackingAction,
450 
451  } else {
452  edm::LogWarning("SimG4CoreApplication") << " RunManager: WARNING : "
453  << "No generator; initialized "
454  << "only RunAction!";
455  }
456 }
std::auto_ptr< SimTrackManager > m_trackManager
Definition: RunManager.h:149
Generator * m_generator
Definition: RunManager.h:103
int m_EvtMgrVerbosity
Definition: RunManager.h:126
SimRunInterface * m_runInterface
Definition: RunManager.h:119
edm::ParameterSet m_pStackingAction
Definition: RunManager.h:135
edm::ParameterSet m_pEventAction
Definition: RunManager.h:134
edm::ParameterSet m_pSteppingAction
Definition: RunManager.h:137
RunAction * m_userRunAction
Definition: RunManager.h:118
void Connect(RunAction *)
Definition: RunManager.cc:510
edm::ParameterSet m_pRunAction
Definition: RunManager.h:133
edm::ParameterSet m_pTrackingAction
Definition: RunManager.h:136
G4RunManagerKernel * m_kernel
Definition: RunManager.h:101
void RunManager::produce ( edm::Event inpevt,
const edm::EventSetup es 
)

Definition at line 324 of file RunManager.cc.

References abortRun(), G4SimEvent::collisionPoint(), edm::EventID::event(), Generator::eventWeight(), generateEvent(), Generator::genEvent(), Generator::genVertex(), G4SimEvent::hepEvent(), edm::EventBase::id(), m_currentEvent, m_generator, m_kernel, m_simEvent, G4SimEvent::nGenParts(), G4SimEvent::nTracks(), G4SimEvent::nVertices(), edm::second(), and G4SimEvent::weight().

325 {
326  m_currentEvent = generateEvent(inpevt);
327  m_simEvent = new G4SimEvent;
330  if (m_generator->genVertex() !=0 ) {
333  m_generator->genVertex()->y()/centimeter,
334  m_generator->genVertex()->z()/centimeter,
335  m_generator->genVertex()->t()/second));
336  }
337  if (m_currentEvent->GetNumberOfPrimaryVertex()==0) {
338  edm::LogError("SimG4CoreApplication")
339  << " RunManager::produce event " << inpevt.id().event()
340  << " with no G4PrimaryVertices \n Aborting Run" ;
341 
342  abortRun(false);
343  } else {
344  m_kernel->GetEventManager()->ProcessOneEvent(m_currentEvent);
345  }
346 
347  edm::LogInfo("SimG4CoreApplication")
348  << " RunManager: saved : Event " << inpevt.id().event()
349  << " of weight " << m_simEvent->weight()
350  << " with " << m_simEvent->nTracks() << " tracks and "
351  << m_simEvent->nVertices()
352  << " vertices, generated by " << m_simEvent->nGenParts() << " particles ";
353 }
EventNumber_t event() const
Definition: EventID.h:41
virtual const math::XYZTLorentzVector * genVertex() const
Definition: Generator.h:30
virtual const double eventWeight() const
Definition: Generator.h:31
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
G4Event * m_currentEvent
Definition: RunManager.h:116
void abortRun(bool softAbort=false)
Definition: RunManager.cc:486
virtual const HepMC::GenEvent * genEvent() const
Definition: Generator.h:29
Generator * m_generator
Definition: RunManager.h:103
U second(std::pair< T, U > const &p)
void weight(float w)
Definition: G4SimEvent.h:27
void hepEvent(const HepMC::GenEvent *r)
Definition: G4SimEvent.h:25
unsigned int nTracks() const
Definition: G4SimEvent.h:22
unsigned int nVertices() const
Definition: G4SimEvent.h:23
unsigned int nGenParts() const
Definition: G4SimEvent.h:24
G4Event * generateEvent(edm::Event &inpevt)
Definition: RunManager.cc:355
edm::EventID id() const
Definition: EventBase.h:60
void collisionPoint(const math::XYZTLorentzVectorD &v)
Definition: G4SimEvent.h:29
G4SimEvent * m_simEvent
Definition: RunManager.h:117
G4RunManagerKernel * m_kernel
Definition: RunManager.h:101
std::vector<std::shared_ptr<SimProducer> > RunManager::producers ( ) const
inline

Definition at line 83 of file RunManager.h.

References m_producers.

83  {
84  return m_producers;
85  }
std::vector< std::shared_ptr< SimProducer > > m_producers
Definition: RunManager.h:147
void RunManager::resetGenParticleId ( edm::Event inpevt)
protected

Definition at line 496 of file RunManager.cc.

References edm::Event::getByLabel(), edm::HandleBase::isValid(), m_theLHCTlinkTag, m_trackManager, and edm::Handle< T >::product().

Referenced by generateEvent().

497 {
499  inpevt.getByLabel( m_theLHCTlinkTag, theLHCTlink );
500  if ( theLHCTlink.isValid() ) {
501  m_trackManager->setLHCTransportLink( theLHCTlink.product() );
502  }
503 }
std::auto_ptr< SimTrackManager > m_trackManager
Definition: RunManager.h:149
bool isValid() const
Definition: HandleBase.h:75
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:413
T const * product() const
Definition: Handle.h:81
edm::InputTag m_theLHCTlinkTag
Definition: RunManager.h:156
std::vector<SensitiveCaloDetector*>& RunManager::sensCaloDetectors ( )
inline

Definition at line 80 of file RunManager.h.

References m_sensCaloDets.

80  {
81  return m_sensCaloDets;
82  }
std::vector< SensitiveCaloDetector * > m_sensCaloDets
Definition: RunManager.h:143
std::vector<SensitiveTkDetector*>& RunManager::sensTkDetectors ( )
inline

Definition at line 77 of file RunManager.h.

References m_sensTkDets.

77  {
78  return m_sensTkDets;
79  }
std::vector< SensitiveTkDetector * > m_sensTkDets
Definition: RunManager.h:142
G4SimEvent* RunManager::simEvent ( )
inline

Definition at line 76 of file RunManager.h.

References m_simEvent.

Referenced by SimRunInterface::simEvent().

76 { return m_simEvent; }
G4SimEvent * m_simEvent
Definition: RunManager.h:117
void RunManager::stopG4 ( )

Definition at line 318 of file RunManager.cc.

References m_runTerminated, and terminateRun().

319 {
320  G4StateManager::GetStateManager()->SetNewState(G4State_Quit);
321  if (!m_runTerminated) { terminateRun(); }
322 }
void terminateRun()
Definition: RunManager.cc:468
bool m_runTerminated
Definition: RunManager.h:111
void RunManager::terminateRun ( )

Definition at line 468 of file RunManager.cc.

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

Referenced by abortRun(), stopG4(), and ~RunManager().

469 {
470  if (m_userRunAction!=0) {
472  delete m_userRunAction;
473  m_userRunAction = 0;
474  }
475  if (m_kernel!=0 && !m_runTerminated) {
476  delete m_currentEvent;
477  m_currentEvent = 0;
478  delete m_simEvent;
479  m_simEvent = 0;
480  m_kernel->RunTermination();
481  m_runInitialized = false;
482  m_runTerminated = true;
483  }
484 }
G4Event * m_currentEvent
Definition: RunManager.h:116
void EndOfRunAction(const G4Run *aRun)
Definition: RunAction.cc:39
G4Run * m_currentRun
Definition: RunManager.h:115
bool m_runTerminated
Definition: RunManager.h:111
RunAction * m_userRunAction
Definition: RunManager.h:118
bool m_runInitialized
Definition: RunManager.h:110
G4SimEvent * m_simEvent
Definition: RunManager.h:117
G4RunManagerKernel * m_kernel
Definition: RunManager.h:101

Member Data Documentation

bool RunManager::firstRun
private

Definition at line 113 of file RunManager.h.

Referenced by initG4().

edm::ESWatcher<IdealGeometryRecord> RunManager::idealGeomRcdWatcher_
private

Definition at line 153 of file RunManager.h.

Referenced by initG4().

edm::ESWatcher<IdealMagneticFieldRecord> RunManager::idealMagRcdWatcher_
private

Definition at line 154 of file RunManager.h.

Referenced by initG4().

AttachSD* RunManager::m_attach
private

Definition at line 141 of file RunManager.h.

Referenced by initG4().

bool RunManager::m_check
private

Definition at line 127 of file RunManager.h.

Referenced by initG4(), and RunManager().

sim::ChordFinderSetter* RunManager::m_chordFinderSetter
private

Definition at line 151 of file RunManager.h.

Referenced by initG4().

G4Event* RunManager::m_currentEvent
private

Definition at line 116 of file RunManager.h.

Referenced by abortEvent(), currentEvent(), generateEvent(), produce(), and terminateRun().

G4Run* RunManager::m_currentRun
private

Definition at line 115 of file RunManager.h.

Referenced by abortRun(), currentRun(), initializeRun(), and terminateRun().

int RunManager::m_EvtMgrVerbosity
private

Definition at line 126 of file RunManager.h.

Referenced by initializeUserActions().

sim::FieldBuilder* RunManager::m_fieldBuilder
private

Definition at line 150 of file RunManager.h.

Referenced by initG4().

std::string RunManager::m_FieldFile
private

Definition at line 158 of file RunManager.h.

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

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

Definition at line 138 of file RunManager.h.

Referenced by initG4().

Generator* RunManager::m_generator
private

Definition at line 103 of file RunManager.h.

Referenced by generateEvent(), generator(), initializeUserActions(), produce(), and RunManager().

std::string RunManager::m_InTag
private

Definition at line 104 of file RunManager.h.

Referenced by generateEvent(), and RunManager().

G4RunManagerKernel* RunManager::m_kernel
private
bool RunManager::m_managerInitialized
private

Definition at line 109 of file RunManager.h.

Referenced by initG4().

bool RunManager::m_nonBeam
private

Definition at line 106 of file RunManager.h.

Referenced by generateEvent().

edm::ParameterSet RunManager::m_p
private

Definition at line 139 of file RunManager.h.

Referenced by initG4(), and RunManager().

edm::ParameterSet RunManager::m_pEventAction
private

Definition at line 134 of file RunManager.h.

Referenced by initializeUserActions().

edm::ParameterSet RunManager::m_pField
private

Definition at line 129 of file RunManager.h.

Referenced by initG4().

edm::ParameterSet RunManager::m_pGenerator
private

Definition at line 130 of file RunManager.h.

Referenced by RunManager().

edm::ParameterSet RunManager::m_pGeometry
private

Definition at line 128 of file RunManager.h.

std::auto_ptr<PhysicsList> RunManager::m_physicsList
private

Definition at line 107 of file RunManager.h.

Referenced by initG4().

std::string RunManager::m_PhysicsTablesDir
private

Definition at line 123 of file RunManager.h.

Referenced by initG4().

edm::ParameterSet RunManager::m_pPhysics
private

Definition at line 132 of file RunManager.h.

Referenced by initG4().

PrimaryTransformer* RunManager::m_primaryTransformer
private

Definition at line 108 of file RunManager.h.

Referenced by initG4().

std::vector<std::shared_ptr<SimProducer> > RunManager::m_producers
private

Definition at line 147 of file RunManager.h.

Referenced by producers(), and RunManager().

edm::ParameterSet RunManager::m_pRunAction
private

Definition at line 133 of file RunManager.h.

Referenced by initializeUserActions().

edm::ParameterSet RunManager::m_pStackingAction
private

Definition at line 135 of file RunManager.h.

Referenced by initializeUserActions().

edm::ParameterSet RunManager::m_pSteppingAction
private

Definition at line 137 of file RunManager.h.

Referenced by initializeUserActions().

edm::ParameterSet RunManager::m_pTrackingAction
private

Definition at line 136 of file RunManager.h.

Referenced by initializeUserActions().

bool RunManager::m_pUseMagneticField
private

Definition at line 114 of file RunManager.h.

Referenced by initG4().

edm::ParameterSet RunManager::m_pVertexGenerator
private

Definition at line 131 of file RunManager.h.

std::string RunManager::m_RegionFile
private

Definition at line 160 of file RunManager.h.

Referenced by initG4(), and RunManager().

SimActivityRegistry RunManager::m_registry
private

Definition at line 145 of file RunManager.h.

Referenced by Connect(), initG4(), and RunManager().

bool RunManager::m_RestorePhysicsTables
private

Definition at line 125 of file RunManager.h.

Referenced by initG4().

bool RunManager::m_runAborted
private

Definition at line 112 of file RunManager.h.

Referenced by abortRun(), and initializeRun().

bool RunManager::m_runInitialized
private

Definition at line 110 of file RunManager.h.

Referenced by abortRun(), initializeRun(), and terminateRun().

SimRunInterface* RunManager::m_runInterface
private

Definition at line 119 of file RunManager.h.

Referenced by initializeUserActions(), RunManager(), and ~RunManager().

bool RunManager::m_runTerminated
private

Definition at line 111 of file RunManager.h.

Referenced by abortEvent(), stopG4(), terminateRun(), and ~RunManager().

std::vector<SensitiveCaloDetector*> RunManager::m_sensCaloDets
private

Definition at line 143 of file RunManager.h.

Referenced by initG4(), and sensCaloDetectors().

std::vector<SensitiveTkDetector*> RunManager::m_sensTkDets
private

Definition at line 142 of file RunManager.h.

Referenced by initG4(), and sensTkDetectors().

G4SimEvent* RunManager::m_simEvent
private

Definition at line 117 of file RunManager.h.

Referenced by generateEvent(), produce(), simEvent(), and terminateRun().

bool RunManager::m_StorePhysicsTables
private

Definition at line 124 of file RunManager.h.

Referenced by initG4().

edm::InputTag RunManager::m_theLHCTlinkTag
private

Definition at line 156 of file RunManager.h.

Referenced by resetGenParticleId().

std::auto_ptr<SimTrackManager> RunManager::m_trackManager
private
RunAction* RunManager::m_userRunAction
private

Definition at line 118 of file RunManager.h.

Referenced by initializeRun(), initializeUserActions(), RunManager(), and terminateRun().

std::vector<std::shared_ptr<SimWatcher> > RunManager::m_watchers
private

Definition at line 146 of file RunManager.h.

Referenced by RunManager().

std::string RunManager::m_WriteFile
private

Definition at line 159 of file RunManager.h.

Referenced by initG4(), and RunManager().