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 134 of file RunManagerMTWorker.cc.

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

134  :
135  m_generator(iConfig.getParameter<edm::ParameterSet>("Generator")),
136  m_InToken(iC.consumes<edm::HepMCProduct>(iConfig.getParameter<edm::ParameterSet>("Generator").getParameter<edm::InputTag>("HepMCProductLabel"))),
137  m_theLHCTlinkToken(iC.consumes<edm::LHCTransportLinkContainer>(iConfig.getParameter<edm::InputTag>("theLHCTlinkTag"))),
138  m_nonBeam(iConfig.getParameter<bool>("NonBeamEvent")),
139  m_pUseMagneticField(iConfig.getParameter<bool>("UseMagneticField")),
140  m_EvtMgrVerbosity(iConfig.getUntrackedParameter<int>("G4EventManagerVerbosity",0)),
141  m_pField(iConfig.getParameter<edm::ParameterSet>("MagneticField")),
142  m_pRunAction(iConfig.getParameter<edm::ParameterSet>("RunAction")),
143  m_pEventAction(iConfig.getParameter<edm::ParameterSet>("EventAction")),
144  m_pStackingAction(iConfig.getParameter<edm::ParameterSet>("StackingAction")),
145  m_pTrackingAction(iConfig.getParameter<edm::ParameterSet>("TrackingAction")),
146  m_pSteppingAction(iConfig.getParameter<edm::ParameterSet>("SteppingAction")),
147  m_pCustomUIsession(iConfig.getUntrackedParameter<edm::ParameterSet>("CustomUIsession")),
148  m_p(iConfig)
149 {
150  initializeTLS();
151  m_sVerbose.reset(nullptr);
152  std::vector<edm::ParameterSet> watchers =
153  iConfig.getParameter<std::vector<edm::ParameterSet> >("Watchers");
154  m_hasWatchers = (watchers.empty()) ? false : true;
155 }
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
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 157 of file RunManagerMTWorker.cc.

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

157  {
158  if(m_tls && !m_tls->runTerminated) { terminateRun(); }
159 }
static thread_local TLSData * m_tls

Member Function Documentation

void RunManagerMTWorker::abortEvent ( )

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

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

Definition at line 493 of file RunManagerMTWorker.cc.

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

Referenced by SimRunInterface::abortRun().

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

Definition at line 341 of file RunManagerMTWorker.cc.

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

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

342 {
345 }
SimActivityRegistry::EndOfRunSignal m_endOfRunSignal
Definition: RunAction.h:26
BeginOfRunSignal beginOfRunSignal_
static thread_local TLSData * m_tls
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:25
void RunManagerMTWorker::Connect ( EventAction eventAction)

Definition at line 347 of file RunManagerMTWorker.cc.

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

348 {
351 }
EndOfEventSignal endOfEventSignal_
SimActivityRegistry::EndOfEventSignal m_endOfEventSignal
Definition: EventAction.h:54
static thread_local TLSData * m_tls
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:53
void RunManagerMTWorker::Connect ( TrackingAction trackingAction)

Definition at line 353 of file RunManagerMTWorker.cc.

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

354 {
357 }
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
EndOfTrackSignal endOfTrackSignal_
BeginOfTrackSignal beginOfTrackSignal_
SimActivityRegistry::BeginOfTrackSignal m_beginOfTrackSignal
void RunManagerMTWorker::Connect ( SteppingAction steppingAction)

Definition at line 359 of file RunManagerMTWorker.cc.

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

360 {
362 }
SimActivityRegistry::G4StepSignal m_g4StepSignal
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 161 of file RunManagerMTWorker.cc.

References terminateRun().

161  {
162  terminateRun();
163 }
G4Event * RunManagerMTWorker::generateEvent ( const edm::Event inpevt)
private

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

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

Definition at line 364 of file RunManagerMTWorker.cc.

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

Referenced by SimRunInterface::SimRunInterface().

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

Definition at line 381 of file RunManagerMTWorker.cc.

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

Referenced by produce().

381  {
382  m_tls->currentRun.reset(new G4Run());
383  G4StateManager::GetStateManager()->SetNewState(G4State_GeomClosed);
384  if (m_tls->userRunAction) { m_tls->userRunAction->BeginOfRunAction(m_tls->currentRun.get()); }
385 }
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 184 of file RunManagerMTWorker.cc.

References SimActivityRegistry::beginOfJobSignal_, RunManagerMT::catalog(), mps_alisetup::command, edm::errors::Configuration, AttachSD::create(), g4SimHits_cfi::CustomUIsession, Exception, g, RunManagerMT::G4Commands(), 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, RunManagerMTWorker::TLSData::trackManager, RunManagerMTWorker::TLSData::UIsession, DDDWorld::WorkerSetAsWorld(), and RunManagerMT::world().

Referenced by produce().

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

Definition at line 165 of file RunManagerMTWorker.cc.

References edm::errors::Configuration, SimActivityRegistry::connect(), 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().

165  {
166  if(m_tls) { return; }
167  m_tls = new TLSData;
168 
169  edm::Service<SimActivityRegistry> otherRegistry;
170  //Look for an outside SimActivityRegistry
171  // this is used by the visualization code
172  int thisID = getThreadIndex();
173  if(otherRegistry){
174  m_tls->registry.connect(*otherRegistry);
175  if(thisID > 0) {
176  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.";
177  }
178  }
179  if(m_hasWatchers) {
181  }
182 }
std::vector< std::shared_ptr< SimWatcher > > watchers
void connect(Observer< const BeginOfJob * > *iObject)
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:85
static thread_local TLSData * m_tls
std::vector< std::shared_ptr< SimProducer > > producers
edm::ParameterSet m_p
void RunManagerMTWorker::initializeUserActions ( )
private

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

310  {
311  m_tls->runInterface.reset(new SimRunInterface(this, false));
313  m_tls->runInterface.get(),false));
314  m_tls->userRunAction->SetMaster(false);
315  Connect(m_tls->userRunAction.get());
316 
317  G4EventManager * eventManager = m_tls->kernel->GetEventManager();
318  eventManager->SetVerboseLevel(m_EvtMgrVerbosity);
319 
320  EventAction * userEventAction =
322  m_tls->trackManager.get(), m_sVerbose.get());
323  Connect(userEventAction);
324  eventManager->SetUserAction(userEventAction);
325 
326  TrackingAction* userTrackingAction =
327  new TrackingAction(userEventAction, m_pTrackingAction, m_sVerbose.get());
328  Connect(userTrackingAction);
329  eventManager->SetUserAction(userTrackingAction);
330 
331  SteppingAction* userSteppingAction =
332  new SteppingAction(userEventAction,m_pSteppingAction,m_sVerbose.get(),m_hasWatchers);
333  Connect(userSteppingAction);
334  eventManager->SetUserAction(userSteppingAction);
335 
336  eventManager->SetUserAction(new StackingAction(userTrackingAction,
338 
339 }
edm::ParameterSet m_pSteppingAction
std::unique_ptr< SimRunInterface > runInterface
std::unique_ptr< CMSSteppingVerbose > m_sVerbose
edm::ParameterSet m_pEventAction
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 403 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.

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

Definition at line 376 of file RunManagerMTWorker.cc.

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

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

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

531 {
533  inpevt.getByToken( m_theLHCTlinkToken, theLHCTlink );
534  if ( theLHCTlink.isValid() ) {
535  m_tls->trackManager->setLHCTransportLink( theLHCTlink.product() );
536  }
537 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
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 372 of file RunManagerMTWorker.cc.

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

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

Definition at line 368 of file RunManagerMTWorker.cc.

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

368  {
369  initializeTLS();
370  return m_tls->sensTkDets;
371 }
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 387 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().

387  {
388  if(!m_tls || m_tls->runTerminated) { return; }
389  if(m_tls->userRunAction) {
390  m_tls->userRunAction->EndOfRunAction(m_tls->currentRun.get());
391  m_tls->userRunAction.reset();
392  }
393  m_tls->currentEvent.reset();
394  m_simEvent.reset();
395 
396  if(m_tls->kernel) {
397  m_tls->kernel->RunTermination();
398  }
399 
400  m_tls->runTerminated = true;
401 }
std::unique_ptr< G4Event > currentEvent
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(), 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