CMS 3D CMS Logo

RunManagerMTWorker.cc
Go to the documentation of this file.
12 
14 
24 
31 
36 
40 
43 
45 
47 
51 
52 #include "G4Event.hh"
53 #include "G4Run.hh"
54 #include "G4SystemOfUnits.hh"
55 #include "G4Threading.hh"
56 #include "G4UImanager.hh"
57 #include "G4WorkerThread.hh"
58 #include "G4WorkerRunManagerKernel.hh"
59 #include "G4StateManager.hh"
60 #include "G4TransportationManager.hh"
61 #include "G4Field.hh"
62 #include "G4FieldManager.hh"
63 
64 #include <atomic>
65 #include <memory>
66 
67 #include <thread>
68 #include <sstream>
69 #include <vector>
70 
71 static std::once_flag applyOnce;
72 thread_local bool RunManagerMTWorker::dumpMF = false;
73 
74 // from https://hypernews.cern.ch/HyperNews/CMS/get/edmFramework/3302/2.html
75 namespace {
76  std::atomic<int> thread_counter{0};
77 
78  int get_new_thread_index() { return thread_counter++; }
79 
80  thread_local int s_thread_index = get_new_thread_index();
81 
82  int getThreadIndex() { return s_thread_index; }
83 
84  void createWatchers(const edm::ParameterSet& iP,
85  SimActivityRegistry* iReg,
86  std::vector<std::shared_ptr<SimWatcher> >& oWatchers,
87  std::vector<std::shared_ptr<SimProducer> >& oProds) {
88  if (!iP.exists("Watchers")) {
89  return;
90  }
91 
92  std::vector<edm::ParameterSet> watchers = iP.getParameter<std::vector<edm::ParameterSet> >("Watchers");
93 
94  for (auto& watcher : watchers) {
95  std::unique_ptr<SimWatcherMakerBase> maker(
96  SimWatcherFactory::get()->create(watcher.getParameter<std::string>("type")));
97  if (maker == nullptr) {
99  << "Unable to find the requested Watcher <" << watcher.getParameter<std::string>("type");
100  }
101  std::shared_ptr<SimWatcher> watcherTemp;
102  std::shared_ptr<SimProducer> producerTemp;
103  maker->make(watcher, *(iReg), watcherTemp, producerTemp);
104  oWatchers.push_back(watcherTemp);
105  if (producerTemp) {
106  oProds.push_back(producerTemp);
107  }
108  }
109  }
110 
111  std::atomic<int> active_tlsdata{0};
112  std::atomic<bool> tls_shutdown_timeout{false};
113  std::atomic<int> n_tls_shutdown_task{0};
114 } // namespace
115 
117  std::unique_ptr<G4RunManagerKernel> kernel; //must be deleted last
118  std::unique_ptr<RunAction> userRunAction;
119  std::unique_ptr<SimRunInterface> runInterface;
120  std::unique_ptr<SimActivityRegistry> registry;
121  std::unique_ptr<SimTrackManager> trackManager;
122  std::vector<SensitiveTkDetector*> sensTkDets;
123  std::vector<SensitiveCaloDetector*> sensCaloDets;
124  std::vector<std::shared_ptr<SimWatcher> > watchers;
125  std::vector<std::shared_ptr<SimProducer> > producers;
126  //G4Run can only be deleted if there is a G4RunManager
127  // on the thread where the G4Run is being deleted,
128  // else it causes a segmentation fault
129  G4Run* currentRun = nullptr;
130  std::unique_ptr<G4Event> currentEvent;
132  bool threadInitialized = false;
133  bool runTerminated = false;
134 
135  TLSData() { ++active_tlsdata; }
136 
137  ~TLSData() { --active_tlsdata; }
138 };
139 
140 //This can not be a smart pointer since we must delete some of the members
141 // before leaving main() else we get a segmentation fault caused by accessing
142 // other 'singletons' after those singletons have been deleted. Instead we
143 // atempt to delete all TLS at RunManagerMTWorker destructor. If that fails for
144 // some reason, it is better to leak than cause a crash.
146 
148  : m_generator(iConfig.getParameter<edm::ParameterSet>("Generator")),
149  m_InToken(iC.consumes<edm::HepMCProduct>(
150  iConfig.getParameter<edm::ParameterSet>("Generator").getParameter<edm::InputTag>("HepMCProductLabel"))),
151  m_theLHCTlinkToken(
152  iC.consumes<edm::LHCTransportLinkContainer>(iConfig.getParameter<edm::InputTag>("theLHCTlinkTag"))),
153  m_nonBeam(iConfig.getParameter<bool>("NonBeamEvent")),
154  m_pUseMagneticField(iConfig.getParameter<bool>("UseMagneticField")),
155  m_LHCTransport(iConfig.getParameter<bool>("LHCTransport")),
156  m_EvtMgrVerbosity(iConfig.getUntrackedParameter<int>("G4EventManagerVerbosity", 0)),
157  m_pField(iConfig.getParameter<edm::ParameterSet>("MagneticField")),
158  m_pRunAction(iConfig.getParameter<edm::ParameterSet>("RunAction")),
159  m_pEventAction(iConfig.getParameter<edm::ParameterSet>("EventAction")),
160  m_pStackingAction(iConfig.getParameter<edm::ParameterSet>("StackingAction")),
161  m_pTrackingAction(iConfig.getParameter<edm::ParameterSet>("TrackingAction")),
162  m_pSteppingAction(iConfig.getParameter<edm::ParameterSet>("SteppingAction")),
163  m_pCustomUIsession(iConfig.getUntrackedParameter<edm::ParameterSet>("CustomUIsession")),
164  m_p(iConfig),
165  m_simEvent(nullptr),
166  m_sVerbose(nullptr) {
167  std::vector<edm::ParameterSet> watchers = iConfig.getParameter<std::vector<edm::ParameterSet> >("Watchers");
168  m_hasWatchers = !watchers.empty();
169  initializeTLS();
170  int thisID = getThreadIndex();
171  if (m_LHCTransport) {
172  m_LHCToken = iC.consumes<edm::HepMCProduct>(edm::InputTag("LHCTransport"));
173  }
174  edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMTWorker is constructed for the thread " << thisID;
175 }
176 
178  ++n_tls_shutdown_task;
179  resetTLS();
180 
181  {
182  //make sure all tasks are done before continuing
183  timespec s;
184  s.tv_sec = 0;
185  s.tv_nsec = 10000;
186  while (n_tls_shutdown_task != 0) {
187  nanosleep(&s, nullptr);
188  }
189  }
190 }
191 
193  m_tls = nullptr;
194 
195  if (active_tlsdata != 0 and not tls_shutdown_timeout) {
196  ++n_tls_shutdown_task;
197  //need to run tasks on each thread which has set the tls
198  auto task = edm::make_functor_task(tbb::task::allocate_root(), []() { resetTLS(); });
199  tbb::task::enqueue(*task);
200  timespec s;
201  s.tv_sec = 0;
202  s.tv_nsec = 10000;
203  //we do not want this thread to be used for a new task since it
204  // has already cleared its structures. In order to fill all TBB
205  // threads we wait for all TLSes to clear
206  int count = 0;
207  while (active_tlsdata.load() != 0 and ++count < 1000) {
208  nanosleep(&s, nullptr);
209  }
210  if (count >= 1000) {
211  tls_shutdown_timeout = true;
212  }
213  }
214  --n_tls_shutdown_task;
215 }
216 
218  int thisID = getThreadIndex();
219  edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMTWorker::endRun for the thread " << thisID;
220  terminateRun();
221 }
222 
224  if (m_tls) {
225  return;
226  }
227 
228  m_tls = new TLSData();
229  m_tls->registry = std::make_unique<SimActivityRegistry>();
230 
231  edm::Service<SimActivityRegistry> otherRegistry;
232  //Look for an outside SimActivityRegistry
233  // this is used by the visualization code
234  int thisID = getThreadIndex();
235  if (otherRegistry) {
236  m_tls->registry->connect(*otherRegistry);
237  if (thisID > 0) {
239  << "SimActivityRegistry service (i.e. visualization) is not supported for more than 1 thread. "
240  << " \n If this use case is needed, RunManagerMTWorker has to be updated.";
241  }
242  }
243  if (m_hasWatchers) {
245  }
246 }
247 
249  // I guess everything initialized here should be in thread_local storage
250  initializeTLS();
252  return;
253 
254  int thisID = getThreadIndex();
255  edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMTWorker::initializeThread " << thisID << " is started";
256 
257  // Initialize per-thread output
258  G4Threading::G4SetThreadId(thisID);
259  G4UImanager::GetUIpointer()->SetUpForAThread(thisID);
260  const std::string& uitype = m_pCustomUIsession.getUntrackedParameter<std::string>("Type", "MessageLogger");
261  if (uitype == "MessageLogger") {
262  new CustomUIsession();
263  } else if (uitype == "MessageLoggerThreadPrefix") {
265  } else if (uitype == "FilePerThread") {
267  } else {
269  << "Invalid value of CustomUIsession.Type '" << uitype
270  << "', valid are MessageLogger, MessageLoggerThreadPrefix, FilePerThread";
271  }
272 
273  // Initialize worker part of shared resources (geometry, physics)
274  G4WorkerThread::BuildGeometryAndPhysicsVector();
275 
276  // Create worker run manager
277  m_tls->kernel.reset(G4WorkerRunManagerKernel::GetRunManagerKernel());
278  if (!m_tls->kernel) {
279  m_tls->kernel = std::make_unique<G4WorkerRunManagerKernel>();
280  }
281 
282  // Define G4 exception handler
283  G4StateManager::GetStateManager()->SetExceptionHandler(new ExceptionHandler());
284 
285  // Set the geometry for the worker, share from master
286  auto worldPV = runManagerMaster->world().GetWorldVolume();
287  m_tls->kernel->WorkerDefineWorldVolume(worldPV);
288  G4TransportationManager* tM = G4TransportationManager::GetTransportationManager();
289  tM->SetWorldForTracking(worldPV);
290 
291  // we need the track manager now
292  m_tls->trackManager = std::make_unique<SimTrackManager>();
293 
294  // setup the magnetic field
295  if (m_pUseMagneticField) {
296  const GlobalPoint g(0., 0., 0.);
297 
299  es.get<IdealMagneticFieldRecord>().get(pMF);
300 
301  sim::FieldBuilder fieldBuilder(pMF.product(), m_pField);
302  CMSFieldManager* fieldManager = new CMSFieldManager();
303  tM->SetFieldManager(fieldManager);
304  fieldBuilder.build(fieldManager, tM->GetPropagatorInField());
305 
306  std::string fieldFile = m_p.getUntrackedParameter<std::string>("FileNameField", "");
307  if (!fieldFile.empty()) {
308  std::call_once(applyOnce, []() { dumpMF = true; });
309  if (dumpMF) {
310  edm::LogVerbatim("SimG4CoreApplication") << " RunManagerMTWorker: Dump magnetic field to file " << fieldFile;
311  DumpMagneticField(tM->GetFieldManager()->GetDetectorField(), fieldFile);
312  }
313  }
314  }
315 
316  // attach sensitive detector
317  AttachSD attach;
318  auto sensDets =
319  attach.create(es, runManagerMaster->catalog(), m_p, m_tls->trackManager.get(), *(m_tls->registry.get()));
320 
321  m_tls->sensTkDets.swap(sensDets.first);
322  m_tls->sensCaloDets.swap(sensDets.second);
323 
324  edm::LogVerbatim("SimG4CoreApplication")
325  << " RunManagerMTWorker: Sensitive Detector building finished; found " << m_tls->sensTkDets.size()
326  << " Tk type Producers, and " << m_tls->sensCaloDets.size() << " Calo type producers ";
327 
328  // Set the physics list for the worker, share from master
329  PhysicsList* physicsList = runManagerMaster->physicsListForWorker();
330 
331  edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMTWorker: start initialisation of PhysicsList for the thread";
332 
333  // Geant4 UI commands in PreInit state
334  if (!runManagerMaster->G4Commands().empty()) {
335  G4cout << "RunManagerMTWorker: Requested UI commands: " << G4endl;
336  for (const std::string& command : runManagerMaster->G4Commands()) {
337  G4cout << " " << command << G4endl;
338  G4UImanager::GetUIpointer()->ApplyCommand(command);
339  }
340  }
341  G4StateManager::GetStateManager()->SetNewState(G4State_Init);
342 
343  physicsList->InitializeWorker();
344  m_tls->kernel->SetPhysics(physicsList);
345  m_tls->kernel->InitializePhysics();
346 
347  const bool kernelInit = m_tls->kernel->RunInitialization();
348  if (!kernelInit) {
349  throw edm::Exception(edm::errors::Configuration) << "RunManagerMTWorker: Geant4 kernel initialization failed";
350  }
351  //tell all interesting parties that we are beginning the job
352  BeginOfJob aBeginOfJob(&es);
353  m_tls->registry->beginOfJobSignal_(&aBeginOfJob);
354 
355  G4int sv = m_p.getUntrackedParameter<int>("SteppingVerbosity", 0);
356  G4double elim = m_p.getUntrackedParameter<double>("StepVerboseThreshold", 0.1) * CLHEP::GeV;
357  std::vector<int> ve = m_p.getUntrackedParameter<std::vector<int> >("VerboseEvents");
358  std::vector<int> vn = m_p.getUntrackedParameter<std::vector<int> >("VertexNumber");
359  std::vector<int> vt = m_p.getUntrackedParameter<std::vector<int> >("VerboseTracks");
360 
361  if (sv > 0) {
362  m_sVerbose = std::make_unique<CMSSteppingVerbose>(sv, elim, ve, vn, vt);
363  }
365 
366  edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMTWorker::initializeThread done for the thread " << thisID;
367 
368  G4StateManager::GetStateManager()->SetNewState(G4State_Idle);
369  m_tls->threadInitialized = true;
370 }
371 
373  m_tls->runInterface = std::make_unique<SimRunInterface>(this, false);
374  m_tls->userRunAction = std::make_unique<RunAction>(m_pRunAction, m_tls->runInterface.get(), false);
375  m_tls->userRunAction->SetMaster(false);
376  Connect(m_tls->userRunAction.get());
377 
378  G4EventManager* eventManager = m_tls->kernel->GetEventManager();
379  eventManager->SetVerboseLevel(m_EvtMgrVerbosity);
380 
381  EventAction* userEventAction =
383  Connect(userEventAction);
384  eventManager->SetUserAction(userEventAction);
385 
386  TrackingAction* userTrackingAction = new TrackingAction(userEventAction, m_pTrackingAction, m_sVerbose.get());
387  Connect(userTrackingAction);
388  eventManager->SetUserAction(userTrackingAction);
389 
390  SteppingAction* userSteppingAction =
391  new SteppingAction(userEventAction, m_pSteppingAction, m_sVerbose.get(), m_hasWatchers);
392  Connect(userSteppingAction);
393  eventManager->SetUserAction(userSteppingAction);
394 
395  eventManager->SetUserAction(new StackingAction(userTrackingAction, m_pStackingAction, m_sVerbose.get()));
396 }
397 
399  runAction->m_beginOfRunSignal.connect(m_tls->registry->beginOfRunSignal_);
400  runAction->m_endOfRunSignal.connect(m_tls->registry->endOfRunSignal_);
401 }
402 
404  eventAction->m_beginOfEventSignal.connect(m_tls->registry->beginOfEventSignal_);
405  eventAction->m_endOfEventSignal.connect(m_tls->registry->endOfEventSignal_);
406 }
407 
409  trackingAction->m_beginOfTrackSignal.connect(m_tls->registry->beginOfTrackSignal_);
410  trackingAction->m_endOfTrackSignal.connect(m_tls->registry->endOfTrackSignal_);
411 }
412 
414  steppingAction->m_g4StepSignal.connect(m_tls->registry->g4StepSignal_);
415 }
416 
418  initializeTLS();
419  return m_tls->trackManager.get();
420 }
421 std::vector<SensitiveTkDetector*>& RunManagerMTWorker::sensTkDetectors() {
422  initializeTLS();
423  return m_tls->sensTkDets;
424 }
425 std::vector<SensitiveCaloDetector*>& RunManagerMTWorker::sensCaloDetectors() {
426  initializeTLS();
427  return m_tls->sensCaloDets;
428 }
429 std::vector<std::shared_ptr<SimProducer> >& RunManagerMTWorker::producers() {
430  initializeTLS();
431  return m_tls->producers;
432 }
433 
435  int thisID = getThreadIndex();
436  edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMTWorker::initializeRun " << thisID << " is started";
437  m_tls->currentRun = new G4Run();
438  G4StateManager::GetStateManager()->SetNewState(G4State_GeomClosed);
439  if (m_tls->userRunAction) {
440  m_tls->userRunAction->BeginOfRunAction(m_tls->currentRun);
441  }
442 }
443 
445  edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMTWorker::terminateRun ";
446  if (!m_tls || m_tls->runTerminated) {
447  return;
448  }
449  int thisID = getThreadIndex();
450  edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMTWorker::terminateRun " << thisID << " is started";
451  if (m_tls->userRunAction) {
452  m_tls->userRunAction->EndOfRunAction(m_tls->currentRun);
453  m_tls->userRunAction.reset();
454  }
455  m_tls->currentEvent.reset();
456  m_simEvent = nullptr;
457 
458  if (m_tls->kernel) {
459  m_tls->kernel->RunTermination();
460  }
461 
462  m_tls->runTerminated = true;
463 }
464 
465 std::unique_ptr<G4SimEvent> RunManagerMTWorker::produce(const edm::Event& inpevt,
466  const edm::EventSetup& es,
467  RunManagerMT& runManagerMaster) {
468  // The initialization and begin/end run is a bit convoluted due to
469  // - Geant4 deals per-thread
470  // - OscarMTProducer deals per-stream
471  // and framework/TBB is free to schedule work in streams to the
472  // threads as it likes.
473  //
474  // We have to do the per-thread initialization, and per-thread
475  // per-run initialization here by ourselves.
476 
477  if (!(m_tls && m_tls->threadInitialized)) {
478  edm::LogVerbatim("SimG4CoreApplication")
479  << "RunManagerMTWorker::produce(): stream " << inpevt.streamID() << " thread " << getThreadIndex()
480  << " Geant4 initialisation for this thread";
481  initializeG4(&runManagerMaster, es);
482  m_tls->threadInitialized = true;
483  }
484  // Initialize run
485  if (inpevt.id().run() != m_tls->currentRunNumber) {
486  if (m_tls->currentRunNumber != 0 && !m_tls->runTerminated) {
487  // If previous run in this thread was not terminated via endRun() call, terminate it now
488  terminateRun();
489  }
490  initializeRun();
491  m_tls->currentRunNumber = inpevt.id().run();
492  }
493  m_tls->runInterface->setRunManagerMTWorker(this); // For UserActions
494 
495  m_tls->currentEvent.reset(generateEvent(inpevt));
496 
497  auto simEvent = std::make_unique<G4SimEvent>();
498  m_simEvent = simEvent.get();
501  if (m_generator.genVertex() != nullptr) {
502  auto genVertex = m_generator.genVertex();
503  m_simEvent->collisionPoint(math::XYZTLorentzVectorD(genVertex->x() / CLHEP::cm,
504  genVertex->y() / CLHEP::cm,
505  genVertex->z() / CLHEP::cm,
506  genVertex->t() / CLHEP::second));
507  }
508  if (m_tls->currentEvent->GetNumberOfPrimaryVertex() == 0) {
509  std::stringstream ss;
510  ss << "RunManagerMTWorker::produce: event " << inpevt.id().event() << " with no G4PrimaryVertices \n";
511  throw SimG4Exception(ss.str());
512 
513  } else {
514  if (!m_tls->kernel) {
515  std::stringstream ss;
516  ss << "RunManagerMTWorker::produce: "
517  << " no G4WorkerRunManagerKernel yet for thread index" << getThreadIndex() << ", id " << std::hex
518  << std::this_thread::get_id() << " \n";
519  throw SimG4Exception(ss.str());
520  }
521 
522  edm::LogVerbatim("SimG4CoreApplication")
523  << "RunManagerMTWorker::produce: start EventID=" << inpevt.id().event() << " StreamID=" << inpevt.streamID()
524  << " threadIndex=" << getThreadIndex() << " weight=" << m_simEvent->weight() << "; "
525  << m_tls->currentEvent->GetNumberOfPrimaryVertex() << " vertices for Geant4; generator produced "
526  << m_simEvent->nGenParts() << " particles.";
527 
528  m_tls->kernel->GetEventManager()->ProcessOneEvent(m_tls->currentEvent.get());
529  }
530 
531  //remove memory only needed during event processing
532  m_tls->currentEvent.reset();
533 
534  for (auto& sd : m_tls->sensCaloDets) {
535  sd->reset();
536  }
537  edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMTWorker::produce: ended Event " << inpevt.id().event();
538 
539  m_simEvent = nullptr;
540  return simEvent;
541 }
542 
544  if (m_tls->runTerminated) {
545  return;
546  }
547  G4Track* t = m_tls->kernel->GetEventManager()->GetTrackingManager()->GetTrack();
548  t->SetTrackStatus(fStopAndKill);
549 
550  // CMS-specific act
551  //
552  TrackingAction* uta = static_cast<TrackingAction*>(m_tls->kernel->GetEventManager()->GetUserTrackingAction());
554 
555  m_tls->currentEvent->SetEventAborted();
556  m_tls->kernel->GetEventManager()->GetStackManager()->clear();
557  m_tls->kernel->GetEventManager()->GetTrackingManager()->EventAborted();
558 }
559 
560 void RunManagerMTWorker::abortRun(bool softAbort) {
561  if (!softAbort) {
562  abortEvent();
563  }
564  m_tls->currentRun = nullptr;
565  terminateRun();
566 }
567 
569  m_tls->currentEvent.reset();
570  m_simEvent = nullptr;
571 
572  // 64 bits event ID in CMSSW converted into Geant4 event ID
573  G4int evtid = (G4int)inpevt.id().event();
574  G4Event* evt = new G4Event(evtid);
575 
577  inpevt.getByToken(m_InToken, HepMCEvt);
578 
579  m_generator.setGenEvent(HepMCEvt->GetEvent());
580 
581  // required to reset the GenParticle Id for particles transported
582  // along the beam pipe
583  // to their original value for SimTrack creation
584  resetGenParticleId(inpevt);
585 
586  if (!m_nonBeam) {
587  m_generator.HepMC2G4(HepMCEvt->GetEvent(), evt);
588  if (m_LHCTransport) {
590  inpevt.getByToken(m_LHCToken, LHCMCEvt);
591  m_generator.nonCentralEvent2G4(LHCMCEvt->GetEvent(), evt);
592  }
593  } else {
594  m_generator.nonCentralEvent2G4(HepMCEvt->GetEvent(), evt);
595  }
596 
597  return evt;
598 }
599 
602  inpevt.getByToken(m_theLHCTlinkToken, theLHCTlink);
603  if (theLHCTlink.isValid()) {
604  m_tls->trackManager->setLHCTransportLink(theLHCTlink.product());
605  }
606 }
607 
608 void RunManagerMTWorker::DumpMagneticField(const G4Field* field, const std::string& file) const {
609  std::ofstream fout(file.c_str(), std::ios::out);
610  if (fout.fail()) {
611  edm::LogWarning("SimG4CoreApplication")
612  << " RunManager WARNING : error opening file <" << file << "> for magnetic field";
613  } else {
614  // CMS magnetic field volume
615  double rmax = 9000 * mm;
616  double zmax = 24000 * mm;
617 
618  double dr = 1 * cm;
619  double dz = 5 * cm;
620 
621  int nr = (int)(rmax / dr);
622  int nz = 2 * (int)(zmax / dz);
623 
624  double r = 0.0;
625  double z0 = -zmax;
626  double z;
627 
628  double phi = 0.0;
629  double cosf = cos(phi);
630  double sinf = sin(phi);
631 
632  double point[4] = {0.0, 0.0, 0.0, 0.0};
633  double bfield[3] = {0.0, 0.0, 0.0};
634 
635  fout << std::setprecision(6);
636  for (int i = 0; i <= nr; ++i) {
637  z = z0;
638  for (int j = 0; j <= nz; ++j) {
639  point[0] = r * cosf;
640  point[1] = r * sinf;
641  point[2] = z;
642  field->GetFieldValue(point, bfield);
643  fout << "R(mm)= " << r / mm << " phi(deg)= " << phi / degree << " Z(mm)= " << z / mm
644  << " Bz(tesla)= " << bfield[2] / tesla << " Br(tesla)= " << (bfield[0] * cosf + bfield[1] * sinf) / tesla
645  << " Bphi(tesla)= " << (bfield[0] * sinf - bfield[1] * cosf) / tesla << G4endl;
646  z += dz;
647  }
648  r += dr;
649  }
650 
651  fout.close();
652  }
653 }
Generator::eventWeight
virtual const double eventWeight() const
Definition: Generator.h:32
FieldBuilder.h
G4SimEvent::hepEvent
void hepEvent(const HepMC::GenEvent *r)
Definition: G4SimEvent.h:23
RunManagerMTWorker::m_theLHCTlinkToken
edm::EDGetTokenT< edm::LHCTransportLinkContainer > m_theLHCTlinkToken
Definition: RunManagerMTWorker.h:86
RunManagerMTWorker::m_tls
static thread_local TLSData * m_tls
Definition: RunManagerMTWorker.h:103
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
RunManagerMTWorker::initializeG4
void initializeG4(RunManagerMT *runManagerMaster, const edm::EventSetup &es)
Definition: RunManagerMTWorker.cc:248
RunManagerMTWorker::sensTkDetectors
std::vector< SensitiveTkDetector * > & sensTkDetectors()
Definition: RunManagerMTWorker.cc:421
SimTrackManager
Definition: SimTrackManager.h:35
Handle.h
RunManagerMTWorker::TLSData::trackManager
std::unique_ptr< SimTrackManager > trackManager
Definition: RunManagerMTWorker.cc:121
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
RunAction.h
TrackingAction.h
RunManagerMTWorker::abortRun
void abortRun(bool softAbort=false)
Definition: RunManagerMTWorker.cc:560
edm::LHCTransportLinkContainer
std::vector< LHCTransportLink > LHCTransportLinkContainer
Definition: LHCTransportLinkContainer.h:8
ESTransientHandle.h
MessageLogger.h
SteppingAction.h
EventAction
Definition: EventAction.h:23
RunManagerMTWorker::m_simEvent
G4SimEvent * m_simEvent
Definition: RunManagerMTWorker.h:107
SensitiveCaloDetector.h
CustomUIsessionThreadPrefix
Definition: CustomUIsessionThreadPrefix.h:13
edm::Handle::product
T const * product() const
Definition: Handle.h:70
RunManagerMTWorker::TLSData::producers
std::vector< std::shared_ptr< SimProducer > > producers
Definition: RunManagerMTWorker.cc:125
ExceptionHandler
Definition: ExceptionHandler.h:19
ESHandle.h
BeginOfJob.h
EventAction::m_beginOfEventSignal
SimActivityRegistry::BeginOfEventSignal m_beginOfEventSignal
Definition: EventAction.h:43
EventAction::m_endOfEventSignal
SimActivityRegistry::EndOfEventSignal m_endOfEventSignal
Definition: EventAction.h:44
runTauDisplay.evtid
evtid
Definition: runTauDisplay.py:293
RunManagerMTWorker::TLSData::watchers
std::vector< std::shared_ptr< SimWatcher > > watchers
Definition: RunManagerMTWorker.cc:124
RunManagerMTWorker::resetTLS
static void resetTLS()
Definition: RunManagerMTWorker.cc:192
CMSFieldManager.h
edm
HLT enums.
Definition: AlignableModifier.h:19
TrackingAction::PostUserTrackingAction
void PostUserTrackingAction(const G4Track *aTrack) override
Definition: TrackingAction.cc:43
math::XYZTLorentzVectorD
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
SimG4Exception
Definition: SimG4Exception.h:13
Generator::genVertex
virtual const math::XYZTLorentzVector * genVertex() const
Definition: Generator.h:31
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
CMSFieldManager
Definition: CMSFieldManager.h:24
RunManagerMTWorker.h
Generator::nonCentralEvent2G4
void nonCentralEvent2G4(const HepMC::GenEvent *g, G4Event *e)
Definition: Generator.cc:542
FunctorTask.h
RunManagerMTWorker::m_generator
Generator m_generator
Definition: RunManagerMTWorker.h:83
edm::make_functor_task
FunctorTask< F > * make_functor_task(ALLOC &&iAlloc, F f)
Definition: FunctorTask.h:47
RunManagerMTWorker::abortEvent
void abortEvent()
Definition: RunManagerMTWorker.cc:543
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
EventAction.h
RunManagerMTWorker::m_LHCTransport
bool m_LHCTransport
Definition: RunManagerMTWorker.h:91
SteppingAction
Definition: SteppingAction.h:31
RunManagerMTWorker::simEvent
G4SimEvent * simEvent()
Definition: RunManagerMTWorker.h:55
RunManagerMTWorker::m_pEventAction
edm::ParameterSet m_pEventAction
Definition: RunManagerMTWorker.h:96
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
RunManagerMTWorker::Connect
void Connect(RunAction *)
Definition: RunManagerMTWorker.cc:398
AttachSD::create
std::pair< std::vector< SensitiveTkDetector * >, std::vector< SensitiveCaloDetector * > > create(const edm::EventSetup &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *, SimActivityRegistry &reg) const
Definition: AttachSD.cc:15
RunManagerMTWorker::m_EvtMgrVerbosity
int m_EvtMgrVerbosity
Definition: RunManagerMTWorker.h:92
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
CastorDigiValidation.StackingAction
StackingAction
Definition: CastorDigiValidation.py:136
mps_check.command
list command
Definition: mps_check.py:25
RunManagerMTWorker::m_pCustomUIsession
edm::ParameterSet m_pCustomUIsession
Definition: RunManagerMTWorker.h:100
edm::Handle< edm::HepMCProduct >
createWatchers
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:91
RunAction::m_beginOfRunSignal
SimActivityRegistry::BeginOfRunSignal m_beginOfRunSignal
Definition: RunAction.h:23
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
RunManagerMTWorker::GetSimTrackManager
SimTrackManager * GetSimTrackManager()
Definition: RunManagerMTWorker.cc:417
RunManagerMTWorker::~RunManagerMTWorker
~RunManagerMTWorker()
Definition: RunManagerMTWorker.cc:177
RunManagerMTWorker::sensCaloDetectors
std::vector< SensitiveCaloDetector * > & sensCaloDetectors()
Definition: RunManagerMTWorker.cc:425
SensitiveTkDetector.h
DDDWorld.h
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
SimActivityRegistry.h
RunManagerMTWorker::TLSData::sensCaloDets
std::vector< SensitiveCaloDetector * > sensCaloDets
Definition: RunManagerMTWorker.cc:123
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
RunManagerMT::catalog
const SensitiveDetectorCatalog & catalog() const
Definition: RunManagerMT.h:77
TrackingAction
Definition: TrackingAction.h:16
RunManagerMTWorker::m_p
edm::ParameterSet m_p
Definition: RunManagerMTWorker.h:101
alignCSCRings.s
s
Definition: alignCSCRings.py:92
RunManagerMTWorker::initializeUserActions
void initializeUserActions()
Definition: RunManagerMTWorker.cc:372
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
RunManagerMTWorker::m_hasWatchers
bool m_hasWatchers
Definition: RunManagerMTWorker.h:90
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
RunManagerMTWorker::TLSData::currentRun
G4Run * currentRun
Definition: RunManagerMTWorker.cc:129
SiStripMonitorCluster_cfi.zmax
zmax
Definition: SiStripMonitorCluster_cfi.py:201
g4SimHits_cfi.CustomUIsession
CustomUIsession
Definition: g4SimHits_cfi.py:87
RunManagerMTWorker::TLSData::currentEvent
std::unique_ptr< G4Event > currentEvent
Definition: RunManagerMTWorker.cc:130
Service.h
TrackValidation_cff.task
task
Definition: TrackValidation_cff.py:252
pfDeepBoostedJetPreprocessParams_cfi.sv
sv
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:352
DDAxes::z
RunManagerMT::world
const DDDWorld & world() const
Definition: RunManagerMT.h:75
IdealMagneticFieldRecord.h
edm::ESHandle< MagneticField >
TrackingAction::m_endOfTrackSignal
SimActivityRegistry::EndOfTrackSignal m_endOfTrackSignal
Definition: TrackingAction.h:29
Generator::setGenEvent
void setGenEvent(const HepMC::GenEvent *inpevt)
Definition: Generator.h:24
CustomUIsessionToFile
Definition: CustomUIsessionToFile.h:19
CustomUIsession.h
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
RunManagerMTWorker::DumpMagneticField
void DumpMagneticField(const G4Field *, const std::string &) const
Definition: RunManagerMTWorker.cc:608
G4SimEvent::nGenParts
unsigned int nGenParts() const
Definition: G4SimEvent.h:22
BeginOfJob
Definition: BeginOfJob.h:8
RunManagerMTWorker::m_pStackingAction
edm::ParameterSet m_pStackingAction
Definition: RunManagerMTWorker.h:97
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
PhysicsList
Definition: PhysicsList.h:7
HLTMuonOfflineAnalyzer_cfi.z0
z0
Definition: HLTMuonOfflineAnalyzer_cfi.py:98
Point3DBase< float, GlobalTag >
edm::EventID::run
RunNumber_t run() const
Definition: EventID.h:38
g4SimHits_cfi.EventAction
EventAction
Definition: g4SimHits_cfi.py:225
sim_act::Signaler::connect
void connect(Observer< const T * > *iObs)
does not take ownership of memory
Definition: Signaler.h:55
g4SimHits_cfi.TrackingAction
TrackingAction
Definition: g4SimHits_cfi.py:266
RunManagerMTWorker::initializeRun
void initializeRun()
Definition: RunManagerMTWorker.cc:434
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
RunManagerMTWorker::m_LHCToken
edm::EDGetTokenT< edm::HepMCProduct > m_LHCToken
Definition: RunManagerMTWorker.h:85
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:681
RunManagerMTWorker::generateEvent
G4Event * generateEvent(const edm::Event &inpevt)
Definition: RunManagerMTWorker.cc:568
SimG4Exception.h
RunManagerMT
Definition: RunManagerMT.h:55
RunManagerMTWorker::m_pSteppingAction
edm::ParameterSet m_pSteppingAction
Definition: RunManagerMTWorker.h:99
RunManagerMTWorker::terminateRun
void terminateRun()
Definition: RunManagerMTWorker.cc:444
RunAction
Definition: RunAction.h:15
RunManagerMTWorker::TLSData::kernel
std::unique_ptr< G4RunManagerKernel > kernel
Definition: RunManagerMTWorker.cc:117
edm::ParameterSet
Definition: ParameterSet.h:47
EgHLTOffHistBins_cfi.nr
nr
Definition: EgHLTOffHistBins_cfi.py:4
RunManagerMTWorker::m_pField
edm::ParameterSet m_pField
Definition: RunManagerMTWorker.h:94
DDDWorld::GetWorldVolume
G4VPhysicalVolume * GetWorldVolume() const
Definition: DDDWorld.h:24
Event.h
ParameterSet
Definition: Functions.h:16
RunManagerMT.h
RunManagerMTWorker::TLSData::runTerminated
bool runTerminated
Definition: RunManagerMTWorker.cc:133
SimWatcherFactory.h
G4SimEvent.h
GeV
const double GeV
Definition: MathUtil.h:16
thread_safety_macros.h
StackingAction.h
groupFilesInBlocks.fout
fout
Definition: groupFilesInBlocks.py:162
RunManagerMTWorker::TLSData::runInterface
std::unique_ptr< SimRunInterface > runInterface
Definition: RunManagerMTWorker.cc:119
edm::EventID::event
EventNumber_t event() const
Definition: EventID.h:40
edm::Service
Definition: Service.h:30
createfilelist.int
int
Definition: createfilelist.py:10
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
RunManagerMT::G4Commands
const std::vector< std::string > & G4Commands() const
Definition: RunManagerMT.h:79
RunManagerMTWorker::m_nonBeam
bool m_nonBeam
Definition: RunManagerMTWorker.h:88
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
RunManagerMTWorker::TLSData::threadInitialized
bool threadInitialized
Definition: RunManagerMTWorker.cc:132
RunManagerMTWorker::produce
std::unique_ptr< G4SimEvent > produce(const edm::Event &inpevt, const edm::EventSetup &es, RunManagerMT &runManagerMaster)
Definition: RunManagerMTWorker.cc:465
IdealGeometryRecord.h
MagneticField.h
RunManagerMTWorker::m_sVerbose
std::unique_ptr< CMSSteppingVerbose > m_sVerbose
Definition: RunManagerMTWorker.h:108
edm::EventSetup
Definition: EventSetup.h:57
CastorDigiValidation.SteppingAction
SteppingAction
Definition: CastorDigiValidation.py:147
RunManagerMTWorker::TLSData::~TLSData
~TLSData()
Definition: RunManagerMTWorker.cc:137
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
RunManagerMTWorker::endRun
void endRun()
Definition: RunManagerMTWorker.cc:217
get
#define get
RunManagerMTWorker::resetGenParticleId
void resetGenParticleId(const edm::Event &inpevt)
Definition: RunManagerMTWorker.cc:600
CustomUIsessionToFile.h
G4SimEvent::collisionPoint
void collisionPoint(const math::XYZTLorentzVectorD &v)
Definition: G4SimEvent.h:27
AttachSD.h
TrackingAction::m_beginOfTrackSignal
SimActivityRegistry::BeginOfTrackSignal m_beginOfTrackSignal
Definition: TrackingAction.h:28
alignCSCRings.r
r
Definition: alignCSCRings.py:93
RunAction::m_endOfRunSignal
SimActivityRegistry::EndOfRunSignal m_endOfRunSignal
Definition: RunAction.h:24
DDAxes::phi
edm::Event::streamID
StreamID streamID() const
Definition: Event.h:98
SteppingAction::m_g4StepSignal
SimActivityRegistry::G4StepSignal m_g4StepSignal
Definition: SteppingAction.h:38
ExceptionHandler.h
SimActivityRegistry
Definition: SimActivityRegistry.h:43
CMSSteppingVerbose.h
RunManagerMT::physicsListForWorker
PhysicsList * physicsListForWorker() const
Definition: RunManagerMT.h:84
SimRunInterface.h
PVValHelper::dz
Definition: PVValidationHelpers.h:50
RunManagerMTWorker::m_InToken
edm::EDGetTokenT< edm::HepMCProduct > m_InToken
Definition: RunManagerMTWorker.h:84
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
RunManagerMTWorker::TLSData::TLSData
TLSData()
Definition: RunManagerMTWorker.cc:135
RunManagerMTWorker::TLSData::registry
std::unique_ptr< SimActivityRegistry > registry
Definition: RunManagerMTWorker.cc:120
flavorHistoryFilter_cfi.dr
dr
Definition: flavorHistoryFilter_cfi.py:37
Exception
Definition: hltDiff.cc:246
applyOnce
static std::once_flag applyOnce
Definition: RunManagerMTWorker.cc:71
edm::EventBase::id
edm::EventID id() const
Definition: EventBase.h:59
CustomUIsessionThreadPrefix.h
G4SimEvent::weight
void weight(float w)
Definition: G4SimEvent.h:25
RunManagerMTWorker::TLSData
Definition: RunManagerMTWorker.cc:116
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
RunManagerMTWorker::producers
std::vector< std::shared_ptr< SimProducer > > & producers()
Definition: RunManagerMTWorker.cc:429
RunManagerMTWorker::RunManagerMTWorker
RunManagerMTWorker(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&i)
Definition: RunManagerMTWorker.cc:147
sd
double sd
Definition: CascadeWrapper.h:113
Generator::HepMC2G4
void HepMC2G4(const HepMC::GenEvent *g, G4Event *e)
Definition: Generator.cc:112
RunManagerMTWorker::TLSData::userRunAction
std::unique_ptr< RunAction > userRunAction
Definition: RunManagerMTWorker.cc:118
AttachSD
Definition: AttachSD.h:17
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
HepMCProduct
RunManagerMTWorker::TLSData::sensTkDets
std::vector< SensitiveTkDetector * > sensTkDets
Definition: RunManagerMTWorker.cc:122
RunManagerMTWorker::initializeTLS
void initializeTLS()
Definition: RunManagerMTWorker.cc:223
ConsumesCollector.h
edm::HepMCProduct
Definition: HepMCProduct.h:18
ParameterSet.h
RunManagerMTWorker::m_pTrackingAction
edm::ParameterSet m_pTrackingAction
Definition: RunManagerMTWorker.h:98
Generator::genEvent
virtual const HepMC::GenEvent * genEvent() const
Definition: Generator.h:30
RunManagerMTWorker::dumpMF
static thread_local bool dumpMF
Definition: RunManagerMTWorker.h:105
HepMCProduct.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
ecalTB2006H4_GenSimDigiReco_cfg.G4cout
G4cout
Definition: ecalTB2006H4_GenSimDigiReco_cfg.py:303
point
*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
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
edm::errors::Configuration
Definition: EDMException.h:36
RunManagerMTWorker::m_pUseMagneticField
bool m_pUseMagneticField
Definition: RunManagerMTWorker.h:89
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
RunManagerMTWorker::TLSData::currentRunNumber
edm::RunNumber_t currentRunNumber
Definition: RunManagerMTWorker.cc:131
PhysicsList.h
g
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
RunManagerMTWorker::m_pRunAction
edm::ParameterSet m_pRunAction
Definition: RunManagerMTWorker.h:95
sim::FieldBuilder
Definition: FieldBuilder.h:15