CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
RunManagerMTWorker Class Reference

#include <RunManagerMTWorker.h>

Classes

struct  TLSData
 

Public Member Functions

void abortEvent ()
 
void abortRun (bool softAbort=false)
 
void Connect (RunAction *)
 
void Connect (EventAction *)
 
void Connect (TrackingAction *)
 
void Connect (SteppingAction *)
 
void endRun ()
 
SimTrackManagerGetSimTrackManager ()
 
void produce (const edm::Event &inpevt, const edm::EventSetup &es, RunManagerMT &runManagerMaster)
 
std::vector< std::shared_ptr< SimProducer > > producers ()
 
 RunManagerMTWorker (const edm::ParameterSet &iConfig, edm::ConsumesCollector &&i)
 
std::vector< SensitiveCaloDetector * > & sensCaloDetectors ()
 
std::vector< SensitiveTkDetector * > & sensTkDetectors ()
 
G4SimEventsimEvent ()
 
 ~RunManagerMTWorker ()
 

Private Member Functions

G4Event * generateEvent (const edm::Event &inpevt)
 
void initializeRun ()
 
void initializeThread (RunManagerMT &runManagerMaster, const edm::EventSetup &es)
 
void initializeTLS ()
 
void initializeUserActions ()
 
void resetGenParticleId (const edm::Event &inpevt)
 
void terminateRun ()
 

Private Attributes

int m_EvtMgrVerbosity
 
Generator m_generator
 
bool m_hasWatchers
 
edm::EDGetTokenT< edm::HepMCProductm_InToken
 
bool m_nonBeam
 
edm::ParameterSet m_p
 
edm::ParameterSet m_pCustomUIsession
 
edm::ParameterSet m_pEventAction
 
edm::ParameterSet m_pField
 
edm::ParameterSet m_pRunAction
 
edm::ParameterSet m_pStackingAction
 
edm::ParameterSet m_pSteppingAction
 
edm::ParameterSet m_pTrackingAction
 
bool m_pUseMagneticField
 
std::unique_ptr< G4SimEventm_simEvent
 
std::unique_ptr< CMSSteppingVerbosem_sVerbose
 
edm::EDGetTokenT< edm::LHCTransportLinkContainerm_theLHCTlinkToken
 

Static Private Attributes

static thread_local TLSDatam_tls = 0
 

Detailed Description

Definition at line 39 of file RunManagerMTWorker.h.

Constructor & Destructor Documentation

RunManagerMTWorker::RunManagerMTWorker ( const edm::ParameterSet iConfig,
edm::ConsumesCollector &&  i 
)
explicit

Definition at line 127 of file RunManagerMTWorker.cc.

References edm::ParameterSet::getParameter(), initializeTLS(), m_hasWatchers, m_simEvent, and m_sVerbose.

127  :
128  m_generator(iConfig.getParameter<edm::ParameterSet>("Generator")),
129  m_InToken(iC.consumes<edm::HepMCProduct>(iConfig.getParameter<edm::ParameterSet>("Generator").getParameter<edm::InputTag>("HepMCProductLabel"))),
130  m_theLHCTlinkToken(iC.consumes<edm::LHCTransportLinkContainer>(iConfig.getParameter<edm::InputTag>("theLHCTlinkTag"))),
131  m_nonBeam(iConfig.getParameter<bool>("NonBeamEvent")),
132  m_pUseMagneticField(iConfig.getParameter<bool>("UseMagneticField")),
133  m_EvtMgrVerbosity(iConfig.getUntrackedParameter<int>("G4EventManagerVerbosity",0)),
134  m_pField(iConfig.getParameter<edm::ParameterSet>("MagneticField")),
135  m_pRunAction(iConfig.getParameter<edm::ParameterSet>("RunAction")),
136  m_pEventAction(iConfig.getParameter<edm::ParameterSet>("EventAction")),
137  m_pStackingAction(iConfig.getParameter<edm::ParameterSet>("StackingAction")),
138  m_pTrackingAction(iConfig.getParameter<edm::ParameterSet>("TrackingAction")),
139  m_pSteppingAction(iConfig.getParameter<edm::ParameterSet>("SteppingAction")),
140  m_pCustomUIsession(iConfig.getUntrackedParameter<edm::ParameterSet>("CustomUIsession")),
141  m_p(iConfig)
142 {
143  initializeTLS();
144  m_simEvent.reset(nullptr);
145  m_sVerbose.reset(nullptr);
146  std::vector<edm::ParameterSet> watchers =
147  iConfig.getParameter<std::vector<edm::ParameterSet> >("Watchers");
148  m_hasWatchers = (watchers.empty()) ? false : true;
149 }
edm::ParameterSet m_pSteppingAction
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::unique_ptr< CMSSteppingVerbose > m_sVerbose
edm::EDGetTokenT< edm::HepMCProduct > m_InToken
edm::ParameterSet m_pEventAction
std::unique_ptr< G4SimEvent > m_simEvent
edm::ParameterSet m_pRunAction
edm::ParameterSet m_pTrackingAction
edm::ParameterSet m_pField
edm::EDGetTokenT< edm::LHCTransportLinkContainer > m_theLHCTlinkToken
edm::ParameterSet m_pCustomUIsession
std::vector< LHCTransportLink > LHCTransportLinkContainer
edm::ParameterSet m_p
edm::ParameterSet m_pStackingAction
RunManagerMTWorker::~RunManagerMTWorker ( )

Definition at line 151 of file RunManagerMTWorker.cc.

References m_tls, RunManagerMTWorker::TLSData::runTerminated, and terminateRun().

151  {
152  if(m_tls && !m_tls->runTerminated) { terminateRun(); }
153 }
static thread_local TLSData * m_tls

Member Function Documentation

void RunManagerMTWorker::abortEvent ( )

Definition at line 476 of file RunManagerMTWorker.cc.

References RunManagerMTWorker::TLSData::currentEvent, RunManagerMTWorker::TLSData::kernel, m_tls, TrackingAction::PostUserTrackingAction(), RunManagerMTWorker::TLSData::runTerminated, and lumiQTWidget::t.

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

476  {
477  if(m_tls->runTerminated) { return; }
478  G4Track* t = m_tls->kernel->GetEventManager()->GetTrackingManager()->GetTrack();
479  t->SetTrackStatus(fStopAndKill) ;
480 
481  // CMS-specific act
482  //
483  TrackingAction* uta =
484  static_cast<TrackingAction *>(m_tls->kernel->GetEventManager()->GetUserTrackingAction());
485  uta->PostUserTrackingAction(t) ;
486 
487  m_tls->currentEvent->SetEventAborted();
488  m_tls->kernel->GetEventManager()->GetStackManager()->clear();
489  m_tls->kernel->GetEventManager()->GetTrackingManager()->EventAborted();
490 }
std::unique_ptr< G4Event > currentEvent
std::unique_ptr< G4RunManagerKernel > kernel
static thread_local TLSData * m_tls
void PostUserTrackingAction(const G4Track *aTrack) override
void RunManagerMTWorker::abortRun ( bool  softAbort = false)

Definition at line 492 of file RunManagerMTWorker.cc.

References abortEvent(), RunManagerMTWorker::TLSData::currentRun, m_tls, and terminateRun().

Referenced by SimRunInterface::abortRun().

492  {
493  if (!softAbort) { abortEvent(); }
494  m_tls->currentRun.reset();
495  terminateRun();
496 }
static thread_local TLSData * m_tls
std::unique_ptr< G4Run > currentRun
void RunManagerMTWorker::Connect ( RunAction runAction)

Definition at line 340 of file RunManagerMTWorker.cc.

References sim_act::Signaler< T >::connect(), RunAction::m_beginOfRunSignal, RunAction::m_endOfRunSignal, m_tls, and RunManagerMTWorker::TLSData::registry.

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

341 {
342  runAction->m_beginOfRunSignal.connect(m_tls->registry->beginOfRunSignal_);
343  runAction->m_endOfRunSignal.connect(m_tls->registry->endOfRunSignal_);
344 }
SimActivityRegistry::EndOfRunSignal m_endOfRunSignal
Definition: RunAction.h:25
std::unique_ptr< SimActivityRegistry > registry
static thread_local TLSData * m_tls
void connect(Observer< const T * > *iObs)
does not take ownership of memory
Definition: Signaler.h:59
SimActivityRegistry::BeginOfRunSignal m_beginOfRunSignal
Definition: RunAction.h:24
void RunManagerMTWorker::Connect ( EventAction eventAction)

Definition at line 346 of file RunManagerMTWorker.cc.

References sim_act::Signaler< T >::connect(), EventAction::m_beginOfEventSignal, EventAction::m_endOfEventSignal, m_tls, and RunManagerMTWorker::TLSData::registry.

347 {
348  eventAction->m_beginOfEventSignal.connect(m_tls->registry->beginOfEventSignal_);
349  eventAction->m_endOfEventSignal.connect(m_tls->registry->endOfEventSignal_);
350 }
SimActivityRegistry::EndOfEventSignal m_endOfEventSignal
Definition: EventAction.h:51
std::unique_ptr< SimActivityRegistry > registry
static thread_local TLSData * m_tls
void connect(Observer< const T * > *iObs)
does not take ownership of memory
Definition: Signaler.h:59
SimActivityRegistry::BeginOfEventSignal m_beginOfEventSignal
Definition: EventAction.h:50
void RunManagerMTWorker::Connect ( TrackingAction trackingAction)

Definition at line 352 of file RunManagerMTWorker.cc.

References sim_act::Signaler< T >::connect(), TrackingAction::m_beginOfTrackSignal, TrackingAction::m_endOfTrackSignal, m_tls, and RunManagerMTWorker::TLSData::registry.

353 {
354  trackingAction->m_beginOfTrackSignal.connect(m_tls->registry->beginOfTrackSignal_);
355  trackingAction->m_endOfTrackSignal.connect(m_tls->registry->endOfTrackSignal_);
356 }
std::unique_ptr< SimActivityRegistry > registry
static thread_local TLSData * m_tls
SimActivityRegistry::EndOfTrackSignal m_endOfTrackSignal
void connect(Observer< const T * > *iObs)
does not take ownership of memory
Definition: Signaler.h:59
SimActivityRegistry::BeginOfTrackSignal m_beginOfTrackSignal
void RunManagerMTWorker::Connect ( SteppingAction steppingAction)

Definition at line 358 of file RunManagerMTWorker.cc.

References sim_act::Signaler< T >::connect(), SteppingAction::m_g4StepSignal, m_tls, and RunManagerMTWorker::TLSData::registry.

359 {
360  steppingAction->m_g4StepSignal.connect(m_tls->registry->g4StepSignal_);
361 }
SimActivityRegistry::G4StepSignal m_g4StepSignal
std::unique_ptr< SimActivityRegistry > registry
static thread_local TLSData * m_tls
void connect(Observer< const T * > *iObs)
does not take ownership of memory
Definition: Signaler.h:59
void RunManagerMTWorker::endRun ( )

Definition at line 155 of file RunManagerMTWorker.cc.

References terminateRun().

155  {
156  terminateRun();
157 }
G4Event * RunManagerMTWorker::generateEvent ( const edm::Event inpevt)
private

Definition at line 498 of file RunManagerMTWorker.cc.

References RunManagerMTWorker::TLSData::currentEvent, edm::EventID::event(), runTauDisplay::evtid, edm::Event::getByToken(), edm::HepMCProduct::GetEvent(), Generator::HepMC2G4(), edm::EventBase::id(), m_generator, m_InToken, m_nonBeam, m_simEvent, m_tls, Generator::nonBeamEvent2G4(), resetGenParticleId(), and Generator::setGenEvent().

Referenced by produce().

498  {
499  m_tls->currentEvent.reset();
500  m_simEvent.reset();
501 
502  // 64 bits event ID in CMSSW converted into Geant4 event ID
503  G4int evtid = (G4int)inpevt.id().event();
504  G4Event * evt = new G4Event(evtid);
505 
507 
508  inpevt.getByToken(m_InToken, HepMCEvt);
509 
510  m_generator.setGenEvent(HepMCEvt->GetEvent());
511 
512  // required to reset the GenParticle Id for particles transported
513  // along the beam pipe
514  // to their original value for SimTrack creation
515  resetGenParticleId( inpevt );
516 
517  if (!m_nonBeam)
518  {
519  m_generator.HepMC2G4(HepMCEvt->GetEvent(),evt);
520  }
521  else
522  {
523  m_generator.nonBeamEvent2G4(HepMCEvt->GetEvent(),evt);
524  }
525 
526  return evt;
527 }
EventNumber_t event() const
Definition: EventID.h:41
std::unique_ptr< G4Event > currentEvent
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
void HepMC2G4(const HepMC::GenEvent *g, G4Event *e)
Definition: Generator.cc:107
edm::EDGetTokenT< edm::HepMCProduct > m_InToken
std::unique_ptr< G4SimEvent > m_simEvent
static thread_local TLSData * m_tls
void resetGenParticleId(const edm::Event &inpevt)
void setGenEvent(const HepMC::GenEvent *inpevt)
Definition: Generator.h:25
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
void nonBeamEvent2G4(const HepMC::GenEvent *g, G4Event *e)
Definition: Generator.cc:572
edm::EventID id() const
Definition: EventBase.h:60
SimTrackManager * RunManagerMTWorker::GetSimTrackManager ( )

Definition at line 363 of file RunManagerMTWorker.cc.

References initializeTLS(), m_tls, and RunManagerMTWorker::TLSData::trackManager.

Referenced by SimRunInterface::SimRunInterface().

363  {
364  initializeTLS();
365  return m_tls->trackManager.get();
366 }
std::unique_ptr< SimTrackManager > trackManager
static thread_local TLSData * m_tls
void RunManagerMTWorker::initializeRun ( )
private

Definition at line 380 of file RunManagerMTWorker.cc.

References RunManagerMTWorker::TLSData::currentRun, m_tls, and RunManagerMTWorker::TLSData::userRunAction.

Referenced by produce().

380  {
381  m_tls->currentRun.reset(new G4Run());
382  G4StateManager::GetStateManager()->SetNewState(G4State_GeomClosed);
383  if (m_tls->userRunAction) { m_tls->userRunAction->BeginOfRunAction(m_tls->currentRun.get()); }
384 }
static thread_local TLSData * m_tls
std::unique_ptr< RunAction > userRunAction
std::unique_ptr< G4Run > currentRun
void RunManagerMTWorker::initializeThread ( RunManagerMT runManagerMaster,
const edm::EventSetup es 
)
private

Definition at line 179 of file RunManagerMTWorker.cc.

References RunManagerMT::catalog(), mps_check::command, edm::errors::Configuration, AttachSD::create(), g4SimHits_cfi::CustomUIsession, Exception, g, RunManagerMT::G4Commands(), ecalTB2006H4_GenSimDigiReco_cfg::G4cout, edm::EventSetup::get(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), DDDWorld::GetWorldVolumeForWorker(), GeV, initializeTLS(), initializeUserActions(), RunManagerMTWorker::TLSData::kernel, m_p, m_pCustomUIsession, m_pField, m_pUseMagneticField, m_sVerbose, m_tls, RunManagerMT::physicsListForWorker(), edm::ESHandle< T >::product(), RunManagerMTWorker::TLSData::registry, RunManagerMTWorker::TLSData::sensCaloDets, RunManagerMTWorker::TLSData::sensTkDets, AlCaHLTBitMon_QueryRunRegistry::string, pfDeepBoostedJetPreprocessParams_cfi::sv, RunManagerMTWorker::TLSData::trackManager, RunManagerMTWorker::TLSData::UIsession, DDDWorld::WorkerSetAsWorld(), and RunManagerMT::world().

Referenced by produce().

179  {
180  // I guess everything initialized here should be in thread_local storage
181  initializeTLS();
182 
183  int thisID = getThreadIndex();
184 
185  edm::LogVerbatim("SimG4CoreApplication")
186  << "RunManagerMTWorker::initializeThread " << thisID;
187 
188  // Initialize per-thread output
189  G4Threading::G4SetThreadId( thisID );
190  G4UImanager::GetUIpointer()->SetUpForAThread( thisID );
192  if(uitype == "MessageLogger") {
193  m_tls->UIsession.reset(new CustomUIsession());
194  }
195  else if(uitype == "MessageLoggerThreadPrefix") {
197  }
198  else if(uitype == "FilePerThread") {
200  }
201  else {
203  << "Invalid value of CustomUIsession.Type '" << uitype
204  << "', valid are MessageLogger, MessageLoggerThreadPrefix, FilePerThread";
205  }
206 
207  // Initialize worker part of shared resources (geometry, physics)
208  G4WorkerThread::BuildGeometryAndPhysicsVector();
209 
210  // Create worker run manager
211  m_tls->kernel.reset(G4WorkerRunManagerKernel::GetRunManagerKernel());
212  if(!m_tls->kernel) { m_tls->kernel.reset(new G4WorkerRunManagerKernel()); }
213 
214  // Define G4 exception handler
215  G4StateManager::GetStateManager()->SetExceptionHandler(new ExceptionHandler());
216 
217  // Set the geometry for the worker, share from master
219 
220  // we need the track manager now
221  m_tls->trackManager.reset(new SimTrackManager());
222 
223  // Get DDCompactView, or would it be better to get the object from
224  // runManagerMaster instead of EventSetup in here?
226  es.get<IdealGeometryRecord>().get(pDD);
227 
228  // setup the magnetic field
230  {
231  const GlobalPoint g(0.,0.,0.);
232 
234  es.get<IdealMagneticFieldRecord>().get(pMF);
235 
236  sim::FieldBuilder fieldBuilder(pMF.product(), m_pField);
237  CMSFieldManager* fieldManager = new CMSFieldManager();
238  G4TransportationManager * tM =
239  G4TransportationManager::GetTransportationManager();
240  tM->SetFieldManager(fieldManager);
241  fieldBuilder.build( fieldManager, tM->GetPropagatorInField());
242  }
243 
244  // attach sensitive detector
245  AttachSD attach;
246  std::pair< std::vector<SensitiveTkDetector*>,
247  std::vector<SensitiveCaloDetector*> > sensDets =
248  attach.create(runManagerMaster.world(),
249  (*pDD),
250  runManagerMaster.catalog(),
251  m_p,
252  m_tls->trackManager.get(),
253  *(m_tls->registry.get()));
254 
255  m_tls->sensTkDets.swap(sensDets.first);
256  m_tls->sensCaloDets.swap(sensDets.second);
257 
258  edm::LogVerbatim("SimG4CoreApplication")
259  << " RunManagerMTWorker: Sensitive Detector building finished; found "
260  << m_tls->sensTkDets.size() << " Tk type Producers, and "
261  << m_tls->sensCaloDets.size() << " Calo type producers ";
262 
263  // Set the physics list for the worker, share from master
264  PhysicsList *physicsList = runManagerMaster.physicsListForWorker();
265 
266  edm::LogVerbatim("SimG4CoreApplication")
267  << "RunManagerMTWorker: start initialisation of PhysicsList for the thread";
268 
269  // Geant4 UI commands in PreInit state
270  if(!runManagerMaster.G4Commands().empty()) {
271  G4cout << "RunManagerMTWorker: Requested UI commands: " << G4endl;
272  for(const std::string& command: runManagerMaster.G4Commands()) {
273  G4cout << " " << command << G4endl;
274  G4UImanager::GetUIpointer()->ApplyCommand(command);
275  }
276  }
277  G4StateManager::GetStateManager()->SetNewState(G4State_Init);
278 
279  physicsList->InitializeWorker();
280  m_tls->kernel->SetPhysics(physicsList);
281  m_tls->kernel->InitializePhysics();
282 
283  const bool kernelInit = m_tls->kernel->RunInitialization();
284  if(!kernelInit) {
286  << "RunManagerMTWorker: Geant4 kernel initialization failed";
287  }
288  //tell all interesting parties that we are beginning the job
289  BeginOfJob aBeginOfJob(&es);
290  m_tls->registry->beginOfJobSignal_(&aBeginOfJob);
291 
292  G4int sv = m_p.getParameter<int>("SteppingVerbosity");
293  G4double elim = m_p.getParameter<double>("StepVerboseThreshold")*CLHEP::GeV;
294  std::vector<int> ve = m_p.getParameter<std::vector<int> >("VerboseEvents");
295  std::vector<int> vn = m_p.getParameter<std::vector<int> >("VertexNumber");
296  std::vector<int> vt = m_p.getParameter<std::vector<int> >("VerboseTracks");
297 
298  if(sv > 0) {
299  m_sVerbose.reset(new CMSSteppingVerbose(sv, elim, ve, vn, vt));
300  }
302 
303  edm::LogVerbatim("SimG4CoreApplication")
304  << "RunManagerMTWorker::initializeThread done for the thread " << thisID;
305 
306  G4StateManager::GetStateManager()->SetNewState(G4State_Idle);
307 }
T getParameter(std::string const &) const
const SensitiveDetectorCatalog & catalog() const
Definition: RunManagerMT.h:77
T getUntrackedParameter(std::string const &, T const &) const
const double GeV
Definition: MathUtil.h:16
std::pair< std::vector< SensitiveTkDetector * >, std::vector< SensitiveCaloDetector * > > create(const DDDWorld &, const DDCompactView &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *, SimActivityRegistry &reg) const
Definition: AttachSD.cc:15
std::unique_ptr< CMSSteppingVerbose > m_sVerbose
std::vector< SensitiveTkDetector * > sensTkDets
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::unique_ptr< G4RunManagerKernel > kernel
std::unique_ptr< SimActivityRegistry > registry
const DDDWorld & world() const
Definition: RunManagerMT.h:73
std::unique_ptr< SimTrackManager > trackManager
std::unique_ptr< CustomUIsession > UIsession
static thread_local TLSData * m_tls
std::vector< SensitiveCaloDetector * > sensCaloDets
PhysicsList * physicsListForWorker() const
Definition: RunManagerMT.h:88
edm::ParameterSet m_pField
G4VPhysicalVolume * GetWorldVolumeForWorker() const
Definition: DDDWorld.h:24
list command
Definition: mps_check.py:24
static void WorkerSetAsWorld(G4VPhysicalVolume *pv)
Definition: DDDWorld.cc:38
const std::vector< std::string > & G4Commands() const
Definition: RunManagerMT.h:81
edm::ParameterSet m_pCustomUIsession
T get() const
Definition: EventSetup.h:68
edm::ParameterSet m_p
T const * product() const
Definition: ESHandle.h:84
void RunManagerMTWorker::initializeTLS ( )
private

Definition at line 159 of file RunManagerMTWorker.cc.

References edm::errors::Configuration, createWatchers(), Exception, m_hasWatchers, m_p, m_tls, RunManagerMTWorker::TLSData::producers, RunManagerMTWorker::TLSData::registry, and RunManagerMTWorker::TLSData::watchers.

Referenced by GetSimTrackManager(), initializeThread(), producers(), RunManagerMTWorker(), sensCaloDetectors(), and sensTkDetectors().

159  {
160  if(m_tls) { return; }
161  m_tls = new TLSData;
162  m_tls->registry.reset(new SimActivityRegistry());
163 
164  edm::Service<SimActivityRegistry> otherRegistry;
165  //Look for an outside SimActivityRegistry
166  // this is used by the visualization code
167  int thisID = getThreadIndex();
168  if(otherRegistry){
169  m_tls->registry->connect(*otherRegistry);
170  if(thisID > 0) {
171  throw edm::Exception(edm::errors::Configuration) << "SimActivityRegistry service (i.e. visualization) is not supported for more than 1 thread. If this use case is needed, RunManagerMTWorker has to be updated.";
172  }
173  }
174  if(m_hasWatchers) {
176  }
177 }
std::vector< std::shared_ptr< SimWatcher > > watchers
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:86
std::unique_ptr< SimActivityRegistry > registry
static thread_local TLSData * m_tls
std::vector< std::shared_ptr< SimProducer > > producers
edm::ParameterSet m_p
void RunManagerMTWorker::initializeUserActions ( )
private

Definition at line 309 of file RunManagerMTWorker.cc.

References Connect(), g4SimHits_cfi::EventAction, RunManagerMTWorker::TLSData::kernel, m_EvtMgrVerbosity, m_hasWatchers, m_pEventAction, m_pRunAction, m_pStackingAction, m_pSteppingAction, m_pTrackingAction, m_sVerbose, m_tls, g4SimHits_cfi::RunAction, RunManagerMTWorker::TLSData::runInterface, CastorDigiValidation::StackingAction, CastorDigiValidation::SteppingAction, g4SimHits_cfi::TrackingAction, RunManagerMTWorker::TLSData::trackManager, and RunManagerMTWorker::TLSData::userRunAction.

Referenced by initializeThread().

309  {
310  m_tls->runInterface.reset(new SimRunInterface(this, false));
312  m_tls->runInterface.get(),false));
313  m_tls->userRunAction->SetMaster(false);
314  Connect(m_tls->userRunAction.get());
315 
316  G4EventManager * eventManager = m_tls->kernel->GetEventManager();
317  eventManager->SetVerboseLevel(m_EvtMgrVerbosity);
318 
319  EventAction * userEventAction =
321  m_tls->trackManager.get(), m_sVerbose.get());
322  Connect(userEventAction);
323  eventManager->SetUserAction(userEventAction);
324 
325  TrackingAction* userTrackingAction =
326  new TrackingAction(userEventAction, m_pTrackingAction, m_sVerbose.get());
327  Connect(userTrackingAction);
328  eventManager->SetUserAction(userTrackingAction);
329 
330  SteppingAction* userSteppingAction =
331  new SteppingAction(userEventAction,m_pSteppingAction,m_sVerbose.get(),m_hasWatchers);
332  Connect(userSteppingAction);
333  eventManager->SetUserAction(userSteppingAction);
334 
335  eventManager->SetUserAction(new StackingAction(userTrackingAction,
337 
338 }
edm::ParameterSet m_pSteppingAction
std::unique_ptr< SimRunInterface > runInterface
std::unique_ptr< CMSSteppingVerbose > m_sVerbose
std::unique_ptr< G4RunManagerKernel > kernel
edm::ParameterSet m_pEventAction
RunAction
list of unwanted particles (gluons and quarks)
std::unique_ptr< SimTrackManager > trackManager
static thread_local TLSData * m_tls
edm::ParameterSet m_pRunAction
std::unique_ptr< RunAction > userRunAction
edm::ParameterSet m_pTrackingAction
edm::ParameterSet m_pStackingAction
void Connect(RunAction *)
void RunManagerMTWorker::produce ( const edm::Event inpevt,
const edm::EventSetup es,
RunManagerMT runManagerMaster 
)

Definition at line 402 of file RunManagerMTWorker.cc.

References RunManagerMTWorker::TLSData::currentEvent, RunManagerMTWorker::TLSData::currentRunNumber, edm::EventID::event(), Generator::eventWeight(), generateEvent(), Generator::genEvent(), Generator::genVertex(), edm::EventBase::id(), initializeRun(), initializeThread(), RunManagerMTWorker::TLSData::kernel, LogDebug, m_generator, m_simEvent, m_tls, nullptr, edm::EventID::run(), RunManagerMTWorker::TLSData::runInterface, RunManagerMTWorker::TLSData::runTerminated, edm::second(), edm::Event::streamID(), terminateRun(), and RunManagerMTWorker::TLSData::threadInitialized.

403  {
404  // The initialization and begin/end run is a bit convoluted due to
405  // - Geant4 deals per-thread
406  // - OscarMTProducer deals per-stream
407  // and framework/TBB is free to schedule work in streams to the
408  // threads as it likes.
409  //
410  // We have to do the per-thread initialization, and per-thread
411  // per-run initialization here by ourselves.
412 
413  if(!(m_tls && m_tls->threadInitialized)) {
414  LogDebug("SimG4CoreApplication")
415  << "RunManagerMTWorker::produce(): stream "
416  << inpevt.streamID() << " thread " << getThreadIndex() << " initializing";
417  initializeThread(runManagerMaster, es);
418  m_tls->threadInitialized = true;
419  }
420  // Initialize run
421  if(inpevt.id().run() != m_tls->currentRunNumber) {
422  if(m_tls->currentRunNumber != 0 && !m_tls->runTerminated) {
423  // If previous run in this thread was not terminated via endRun() call, terminate it now
424  terminateRun();
425  }
426  initializeRun();
427  m_tls->currentRunNumber = inpevt.id().run();
428  }
429  m_tls->runInterface->setRunManagerMTWorker(this); // For UserActions
430 
431  m_tls->currentEvent.reset(generateEvent(inpevt));
432 
433  m_simEvent.reset(new G4SimEvent());
434  m_simEvent->hepEvent(m_generator.genEvent());
436  if (m_generator.genVertex() != nullptr ) {
437  auto genVertex = m_generator.genVertex();
438  m_simEvent->collisionPoint(
439  math::XYZTLorentzVectorD(genVertex->x()/centimeter,
440  genVertex->y()/centimeter,
441  genVertex->z()/centimeter,
442  genVertex->t()/second));
443  }
444  if (m_tls->currentEvent->GetNumberOfPrimaryVertex()==0) {
445  std::stringstream ss;
446  ss << "RunManagerMTWorker::produce(): event " << inpevt.id().event()
447  << " with no G4PrimaryVertices \n" ;
448  throw SimG4Exception(ss.str());
449 
450  } else {
451  if(!m_tls->kernel) {
452  std::stringstream ss;
453  ss << " RunManagerMT::produce(): "
454  << " no G4WorkerRunManagerKernel yet for thread index"
455  << getThreadIndex() << ", id " << std::hex
456  << std::this_thread::get_id() << " \n";
457  throw SimG4Exception(ss.str());
458  }
459 
460  edm::LogVerbatim("SimG4CoreApplication")
461  << " RunManagerMTWorker::produce: start Event " << inpevt.id().event()
462  << " stream id " << inpevt.streamID()
463  << " thread index " << getThreadIndex()
464  << " of weight " << m_simEvent->weight()
465  << " with " << m_simEvent->nTracks() << " tracks and "
466  << m_simEvent->nVertices()
467  << " vertices, generated by " << m_simEvent->nGenParts() << " particles ";
468 
469  m_tls->kernel->GetEventManager()->ProcessOneEvent(m_tls->currentEvent.get());
470 
471  edm::LogVerbatim("SimG4CoreApplication")
472  << " RunManagerMTWorker::produce: ended Event " << inpevt.id().event();
473  }
474 }
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
virtual const math::XYZTLorentzVector * genVertex() const
Definition: Generator.h:30
std::unique_ptr< G4Event > currentEvent
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
virtual const HepMC::GenEvent * genEvent() const
Definition: Generator.h:29
std::unique_ptr< SimRunInterface > runInterface
#define nullptr
std::unique_ptr< G4RunManagerKernel > kernel
U second(std::pair< T, U > const &p)
std::unique_ptr< G4SimEvent > m_simEvent
static thread_local TLSData * m_tls
void initializeThread(RunManagerMT &runManagerMaster, const edm::EventSetup &es)
G4Event * generateEvent(const edm::Event &inpevt)
edm::EventID id() const
Definition: EventBase.h:60
StreamID streamID() const
Definition: Event.h:96
std::vector< std::shared_ptr< SimProducer > > RunManagerMTWorker::producers ( )

Definition at line 375 of file RunManagerMTWorker.cc.

References initializeTLS(), m_tls, and RunManagerMTWorker::TLSData::producers.

375  {
376  initializeTLS();
377  return m_tls->producers;
378 }
static thread_local TLSData * m_tls
std::vector< std::shared_ptr< SimProducer > > producers
void RunManagerMTWorker::resetGenParticleId ( const edm::Event inpevt)
private

Definition at line 529 of file RunManagerMTWorker.cc.

References edm::Event::getByToken(), edm::HandleBase::isValid(), m_theLHCTlinkToken, m_tls, edm::Handle< T >::product(), and RunManagerMTWorker::TLSData::trackManager.

Referenced by generateEvent().

530 {
532  inpevt.getByToken( m_theLHCTlinkToken, theLHCTlink );
533  if ( theLHCTlink.isValid() ) {
534  m_tls->trackManager->setLHCTransportLink( theLHCTlink.product() );
535  }
536 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
std::unique_ptr< SimTrackManager > trackManager
static thread_local TLSData * m_tls
bool isValid() const
Definition: HandleBase.h:74
T const * product() const
Definition: Handle.h:81
edm::EDGetTokenT< edm::LHCTransportLinkContainer > m_theLHCTlinkToken
std::vector< SensitiveCaloDetector * > & RunManagerMTWorker::sensCaloDetectors ( )

Definition at line 371 of file RunManagerMTWorker.cc.

References initializeTLS(), m_tls, and RunManagerMTWorker::TLSData::sensCaloDets.

371  {
372  initializeTLS();
373  return m_tls->sensCaloDets;
374 }
static thread_local TLSData * m_tls
std::vector< SensitiveCaloDetector * > sensCaloDets
std::vector< SensitiveTkDetector * > & RunManagerMTWorker::sensTkDetectors ( )

Definition at line 367 of file RunManagerMTWorker.cc.

References initializeTLS(), m_tls, and RunManagerMTWorker::TLSData::sensTkDets.

367  {
368  initializeTLS();
369  return m_tls->sensTkDets;
370 }
std::vector< SensitiveTkDetector * > sensTkDets
static thread_local TLSData * m_tls
G4SimEvent* RunManagerMTWorker::simEvent ( )
inline

Definition at line 51 of file RunManagerMTWorker.h.

References particleFlowRecHitECAL_cfi::producers.

Referenced by SimRunInterface::simEvent().

51 { return m_simEvent.get(); }
std::unique_ptr< G4SimEvent > m_simEvent
void RunManagerMTWorker::terminateRun ( )
private

Definition at line 386 of file RunManagerMTWorker.cc.

References RunManagerMTWorker::TLSData::currentEvent, RunManagerMTWorker::TLSData::currentRun, RunManagerMTWorker::TLSData::kernel, m_simEvent, m_tls, RunManagerMTWorker::TLSData::runTerminated, and RunManagerMTWorker::TLSData::userRunAction.

Referenced by abortRun(), endRun(), RunManagerMT::physicsListForWorker(), produce(), and ~RunManagerMTWorker().

386  {
387  if(!m_tls || m_tls->runTerminated) { return; }
388  if(m_tls->userRunAction) {
389  m_tls->userRunAction->EndOfRunAction(m_tls->currentRun.get());
390  m_tls->userRunAction.reset();
391  }
392  m_tls->currentEvent.reset();
393  m_simEvent.reset();
394 
395  if(m_tls->kernel) {
396  m_tls->kernel->RunTermination();
397  }
398 
399  m_tls->runTerminated = true;
400 }
std::unique_ptr< G4Event > currentEvent
std::unique_ptr< G4RunManagerKernel > kernel
std::unique_ptr< G4SimEvent > m_simEvent
static thread_local TLSData * m_tls
std::unique_ptr< RunAction > userRunAction
std::unique_ptr< G4Run > currentRun

Member Data Documentation

int RunManagerMTWorker::m_EvtMgrVerbosity
private

Definition at line 82 of file RunManagerMTWorker.h.

Referenced by initializeUserActions().

Generator RunManagerMTWorker::m_generator
private

Definition at line 75 of file RunManagerMTWorker.h.

Referenced by generateEvent(), and produce().

bool RunManagerMTWorker::m_hasWatchers
private

Definition at line 81 of file RunManagerMTWorker.h.

Referenced by initializeTLS(), initializeUserActions(), and RunManagerMTWorker().

edm::EDGetTokenT<edm::HepMCProduct> RunManagerMTWorker::m_InToken
private

Definition at line 76 of file RunManagerMTWorker.h.

Referenced by generateEvent().

bool RunManagerMTWorker::m_nonBeam
private

Definition at line 79 of file RunManagerMTWorker.h.

Referenced by generateEvent().

edm::ParameterSet RunManagerMTWorker::m_p
private

Definition at line 91 of file RunManagerMTWorker.h.

Referenced by initializeThread(), and initializeTLS().

edm::ParameterSet RunManagerMTWorker::m_pCustomUIsession
private

Definition at line 90 of file RunManagerMTWorker.h.

Referenced by initializeThread().

edm::ParameterSet RunManagerMTWorker::m_pEventAction
private

Definition at line 86 of file RunManagerMTWorker.h.

Referenced by initializeUserActions().

edm::ParameterSet RunManagerMTWorker::m_pField
private

Definition at line 84 of file RunManagerMTWorker.h.

Referenced by initializeThread().

edm::ParameterSet RunManagerMTWorker::m_pRunAction
private

Definition at line 85 of file RunManagerMTWorker.h.

Referenced by initializeUserActions().

edm::ParameterSet RunManagerMTWorker::m_pStackingAction
private

Definition at line 87 of file RunManagerMTWorker.h.

Referenced by initializeUserActions().

edm::ParameterSet RunManagerMTWorker::m_pSteppingAction
private

Definition at line 89 of file RunManagerMTWorker.h.

Referenced by initializeUserActions().

edm::ParameterSet RunManagerMTWorker::m_pTrackingAction
private

Definition at line 88 of file RunManagerMTWorker.h.

Referenced by initializeUserActions().

bool RunManagerMTWorker::m_pUseMagneticField
private

Definition at line 80 of file RunManagerMTWorker.h.

Referenced by initializeThread().

std::unique_ptr<G4SimEvent> RunManagerMTWorker::m_simEvent
private

Definition at line 96 of file RunManagerMTWorker.h.

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

std::unique_ptr<CMSSteppingVerbose> RunManagerMTWorker::m_sVerbose
private
edm::EDGetTokenT<edm::LHCTransportLinkContainer> RunManagerMTWorker::m_theLHCTlinkToken
private

Definition at line 77 of file RunManagerMTWorker.h.

Referenced by resetGenParticleId().

thread_local RunManagerMTWorker::TLSData * RunManagerMTWorker::m_tls = 0
staticprivate