DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4Exec.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DD4hep/Printout.h>
16 #include <DD4hep/Primitives.h>
17 #include <DD4hep/InstanceCount.h>
18 #include <DD4hep/Handle.h>
19 #include <DDG4/Geant4RunAction.h>
20 #include <DDG4/Geant4EventAction.h>
27 #include <DDG4/Geant4PhysicsList.h>
28 #include <DDG4/Geant4UIManager.h>
29 #include <DDG4/Geant4Kernel.h>
30 #include <DDG4/Geant4Random.h>
31 
32 // Geant4 include files
33 #include <G4Version.hh>
34 #include <G4UserRunAction.hh>
35 #include <G4UserEventAction.hh>
36 #include <G4UserTrackingAction.hh>
37 #include <G4UserStackingAction.hh>
38 #include <G4UserSteppingAction.hh>
39 #include <G4VUserPhysicsList.hh>
40 #include <G4VModularPhysicsList.hh>
41 #include <G4VUserPrimaryGeneratorAction.hh>
42 #include <G4VUserActionInitialization.hh>
43 #include <G4VUserDetectorConstruction.hh>
44 
45 // C/C++ include files
46 #include <memory>
47 #include <stdexcept>
48 
49 namespace {
50  G4Mutex action_mutex=G4MUTEX_INITIALIZER;
51 }
52 
54 namespace dd4hep {
55 
57  namespace sim {
58 
60 
62 
67  template <typename T> class SequenceHdl {
68  public:
74  : m_sequence(0), m_activeContext(0) {
75  }
77  SequenceHdl(Geant4Context* ctxt, T* seq) : m_sequence(0), m_activeContext(ctxt) {
78  _aquire(seq);
79  }
81  virtual ~SequenceHdl() {
82  _release();
83  }
85  void _aquire(T* s) {
87  m_sequence = s;
88  if ( m_sequence ) m_sequence->addRef();
89  }
91  void _release() {
92  detail::releasePtr(m_sequence);
94  }
97  m_activeContext = ctxt;
98  if ( m_sequence ) {
99  m_sequence->updateContext(ctxt);
100  }
101  }
103  Geant4Context* context() const {
104  return m_activeContext;
105  }
107  Geant4Kernel& kernel() const {
108  return context()->kernel();
109  }
112  if ( m_sequence ) {
113  m_sequence->configureFiber(ctxt);
114  }
115  }
117  void createClientContext(const G4Run* run) {
118  Geant4Run* r = new Geant4Run(run);
120  }
122  void destroyClientContext(const G4Run*) {
124  if ( r ) {
126  detail::deletePtr(r);
127  }
128  }
130  void createClientContext(const G4Event* evt) {
133  }
135  void destroyClientContext(const G4Event*) {
137  if ( e ) {
139  detail::deletePtr(e);
140  }
141  }
142  };
143 
145  class Geant4UserRunAction;
146  class Geant4UserEventAction;
147 
149 
155  public G4UserRunAction,
156  public SequenceHdl<Geant4RunActionSequence>
157  {
158  public:
162  : Base(ctxt, seq), eventAction(0) {
163  updateContext(ctxt);
164  configureFiber(ctxt);
165  }
168  }
170  virtual void BeginOfRunAction(const G4Run* run) final;
172  virtual void EndOfRunAction(const G4Run* run) final;
173  };
174 
176 
182  public G4UserEventAction,
183  public SequenceHdl<Geant4EventActionSequence>
184  {
185  public:
189  : Base(ctxt, seq), runAction(0) {
190  updateContext(ctxt);
191  configureFiber(ctxt);
192  }
195  }
197  virtual void BeginOfEventAction(const G4Event* evt) final;
199  virtual void EndOfEventAction(const G4Event* evt) final;
200  };
201 
203 
209  public G4UserTrackingAction,
210  public SequenceHdl<Geant4TrackingActionSequence>
211  {
212  public:
215  : Base(ctxt, seq) {
216  updateContext(ctxt);
217  configureFiber(ctxt);
218  }
221  }
223  virtual void PreUserTrackingAction(const G4Track* trk) final {
224  m_sequence->context()->kernel().setTrackMgr(fpTrackingManager);
225  m_sequence->begin(trk);
226  }
228  virtual void PostUserTrackingAction(const G4Track* trk) final {
229  m_sequence->end(trk);
231  }
232  };
233 
235 
241  public G4UserStackingAction,
242  public SequenceHdl<Geant4StackingActionSequence>
243  {
244  public:
247  : Base(ctxt, seq) {
248  updateContext(ctxt);
249  configureFiber(ctxt);
250  }
253  }
255  virtual void NewStage() override final {
256  m_sequence->newStage(stackManager);
257  }
259  virtual void PrepareNewEvent() override final {
260  m_sequence->prepare(stackManager);
261  }
262  virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track* track) override final {
263  auto ret = m_sequence->classifyNewTrack(stackManager, track);
264  if ( ret.type != NoTrackClassification )
265  return ret.value;
266  return this->G4UserStackingAction::ClassifyNewTrack(track);
267  }
268  };
269 
270 
272 
279  public SequenceHdl<Geant4GeneratorActionSequence>
280  {
281  public:
284  : G4VUserPrimaryGeneratorAction(), Base(ctxt, seq) {
285  updateContext(ctxt);
286  configureFiber(ctxt);
287  }
290  }
292  virtual void GeneratePrimaries(G4Event* event) final;
293  };
294 
296 
302  public G4UserSteppingAction,
303  public SequenceHdl<Geant4SteppingActionSequence>
304  {
305  public:
308  : Base(ctxt, seq) {
309  updateContext(ctxt);
310  configureFiber(ctxt);
311  }
314  }
316  virtual void UserSteppingAction(const G4Step* s) final {
317  (*m_sequence)(s, fpSteppingManager);
318  }
319  };
320 
322 
329  public SequenceHdl<Geant4DetectorConstructionSequence>
330  {
331  protected:
333  public:
336  : G4VUserDetectorConstruction(), Base(ctxt, seq),
337  m_ctxt(ctxt->kernel().detectorDescription(), this)
338  {
339  }
342  }
344  virtual void ConstructSDandField() final;
346  virtual G4VPhysicalVolume* Construct() final;
347  };
348 
350 
358  {
359  public:
362  : G4VUserActionInitialization(), Base(ctxt, seq) {
363  }
366  }
368  virtual void Build() const final;
370  virtual void BuildForMaster() const final;
371  };
372 
374  void Geant4UserRunAction::BeginOfRunAction(const G4Run* run) {
375  createClientContext(run);
376  kernel().executePhase("begin-run",(const void**)&run);
377  if ( m_sequence ) m_sequence->begin(run); // Action not mandatory
379  }
380 
382  void Geant4UserRunAction::EndOfRunAction(const G4Run* run) {
383  if ( m_sequence ) m_sequence->end(run); // Action not mandatory
384  kernel().executePhase("end-run",(const void**)&run);
386  }
387 
389  void Geant4UserEventAction::BeginOfEventAction(const G4Event* evt) {
390  kernel().executePhase("begin-event",(const void**)&evt);
391  if ( m_sequence ) m_sequence->begin(evt); // Action not mandatory
392  }
393 
395  void Geant4UserEventAction::EndOfEventAction(const G4Event* evt) {
396  if ( m_sequence ) m_sequence->end(evt); // Action not mandatory
397  kernel().executePhase("end-event",(const void**)&evt);
399  }
400 
403  createClientContext(event);
404  if ( m_sequence ) {
405  (*m_sequence)(event);
406  return;
407  }
408  throw std::runtime_error("GeneratePrimaries: Panic! No action sequencer defined. "
409  "No primary particles can be produced.");
410  }
411 
414  G4AutoLock protection_lock(&action_mutex);
415  Geant4Context* ctx = m_sequence->context();
420  updateContext(ctx);
421  }
422 
428  G4AutoLock protection_lock(&action_mutex);
431  if ( nullptr == m_ctxt.world ) {
432  m_sequence->except("+++ Executing G4 detector construction did not result in a valid world volume!");
433  }
435  return m_ctxt.world;
436  }
437 
440  G4AutoLock protection_lock(&action_mutex);
442  Geant4Context* ctx = krnl.workerContext();
443 
444  if ( m_sequence ) {
445  Geant4Context* old = m_sequence->context();
446  m_sequence->info("+++ Executing Geant4UserActionInitialization::Build. "
447  "Context:%p Kernel:%p [%ld]", (void*)ctx, (void*)&krnl, krnl.id());
448 
450  m_sequence->build();
452  }
454  Geant4UserGeneratorAction* gen_action = new Geant4UserGeneratorAction(ctx,krnl.generatorAction(false));
455  SetUserAction(gen_action);
456 
458  Geant4UserRunAction* run_action = new Geant4UserRunAction(ctx,krnl.runAction(false));
459  SetUserAction(run_action);
460 
462  Geant4UserEventAction* evt_action = new Geant4UserEventAction(ctx,krnl.eventAction(false));
463  run_action->eventAction = evt_action;
464  evt_action->runAction = run_action;
465  SetUserAction(evt_action);
466 
468  Geant4TrackingActionSequence* trk_action = krnl.trackingAction(false);
469  if ( trk_action ) {
470  Geant4UserTrackingAction* action = new Geant4UserTrackingAction(ctx, trk_action);
471  SetUserAction(action);
472  }
474  Geant4SteppingActionSequence* stp_action = krnl.steppingAction(false);
475  if ( stp_action ) {
476  Geant4UserSteppingAction* action = new Geant4UserSteppingAction(ctx, stp_action);
477  SetUserAction(action);
478  }
480  Geant4StackingActionSequence* stk_action = krnl.stackingAction(false);
481  if ( stk_action ) {
482  Geant4UserStackingAction* action = new Geant4UserStackingAction(ctx, stk_action);
483  SetUserAction(action);
484  }
485 
486  }
487 
490  if ( m_sequence ) {
491  m_sequence->info("+++ Executing Geant4UserActionInitialization::BuildForMaster....");
492  m_sequence->buildMaster();
493  }
494  }
495 
497 
503  public:
505  Geant4Compatibility() = default;
507  virtual ~Geant4Compatibility() = default;
509  Geant4DetectorConstructionSequence* buildDefaultDetectorConstruction(Geant4Kernel& kernel);
510  };
511 
512  }
513 }
514 
515 #include <DD4hep/Detector.h>
516 #include <DD4hep/Plugins.h>
518 #include <DDG4/Geant4Kernel.h>
519 
520 using namespace dd4hep::sim;
521 
522 // Geant4 include files
523 #include <G4RunManager.hh>
524 #include <G4PhysListFactory.hh>
525 
528  Geant4Action* cr;
530  Geant4Context* ctx = kernel.workerContext();
532  printout(WARNING, "Geant4Exec", "+++ Building default Geant4DetectorConstruction for single threaded compatibility.");
533 
535  cr = PluginService::Create<Geant4Action*>("Geant4DetectorGeometryConstruction",ctx,std::string("ConstructGeometry"));
536  det_cr = dynamic_cast<Geant4DetectorConstruction*>(cr);
537  if ( det_cr )
538  seq->adopt(det_cr);
539  else
540  throw std::runtime_error("Panic! Failed to build Geant4DetectorGeometryConstruction.");
542  cr = PluginService::Create<Geant4Action*>("Geant4DetectorSensitivesConstruction",ctx,std::string("ConstructSensitives"));
543  det_cr = dynamic_cast<Geant4DetectorConstruction*>(cr);
544  if ( det_cr )
545  seq->adopt(det_cr);
546  else
547  throw std::runtime_error("Panic! Failed to build Geant4DetectorSensitivesConstruction.");
548  return seq;
549 }
550 
553  Detector& description = kernel.detectorDescription();
554  Geant4Context* ctx = kernel.workerContext();
555  Geant4Random* rndm = Geant4Random::instance(false);
556 
557  if ( !rndm ) {
558  rndm = new Geant4Random(ctx, "Geant4Random");
560  rndm->initialize();
561  }
563  kernel.executePhase("configure",0);
564 
566  G4RunManager& runManager = kernel.runManager();
567 
569  if (description.sensitiveDetectors().size() <= 1) {
570  printout(WARNING, "Geant4Exec", "+++ Only %d subdetectors present. "
571  "You sure you loaded the geometry properly?",
572  int(description.sensitiveDetectors().size()));
573  }
574 
577  if ( nullptr == user_det && kernel.isMultiThreaded() ) {
578  throw std::runtime_error("Panic! No valid detector construction sequencer present. [Mandatory MT]");
579  }
580  if ( nullptr == user_det && !kernel.isMultiThreaded() ) {
582  }
584  runManager.SetUserInitialization(det_seq);
585 
587  Geant4PhysicsListActionSequence* phys_seq = kernel.physicsList(false);
588  if ( nullptr == phys_seq ) {
589  std::string phys_model = "QGSP_BERT";
590  phys_seq = kernel.physicsList(true);
591  phys_seq->property("extends").set(phys_model);
592  }
593  G4VUserPhysicsList* physics = phys_seq->extensionList();
594  if (nullptr == physics) {
595  throw std::runtime_error("Panic! No valid user physics list present!");
596  }
597 #if 0
598  printout(INFO, "Geant4Exec", "+++ PhysicsList RangeCut: %f", phys_seq->m_rangecut );
600  physics->SetDefaultCutValue(phys_seq->m_rangecut);
601  physics->SetCuts();
602  if( DEBUG == printLevel() ) physics->DumpCutValuesTable();
603 #endif
604  phys_seq->enable(physics);
605  runManager.SetUserInitialization(physics);
606 
608  Geant4UserInitializationSequence* user_init = kernel.userInitialization(false);
609  if ( nullptr == user_init && kernel.isMultiThreaded() ) {
610  throw std::runtime_error("Panic! No valid user initialization sequencer present. [Mandatory MT]");
611  }
612  else if ( nullptr == user_init && !kernel.isMultiThreaded() ) {
614  user_init = kernel.userInitialization(true);
615  }
617  runManager.SetUserInitialization(init);
618  return 1;
619 }
620 
624  G4RunManager& runManager = kernel.runManager();
628  kernel.applyInterruptHandlers();
629  kernel.executePhase("initialize",0);
630  runManager.Initialize();
631  return 1;
632 }
633 
636  Property& p = kernel.property("UI");
637  std::string value = p.value<std::string>();
638 
639  kernel.executePhase("start",0);
640  if ( !value.empty() ) {
641  Geant4Action* ui = kernel.globalAction(value);
642  if ( ui ) {
643  Geant4Call* c = dynamic_cast<Geant4Call*>(ui);
644  if ( c ) {
645  (*c)(nullptr);
646  kernel.executePhase("stop",0);
647  return 1;
648  }
649  ui->except("++ Geant4Exec: Failed to start UI interface.");
650  }
651  throw std::runtime_error(format("Geant4Exec","++ Failed to locate UI interface %s.",value.c_str()));
652  }
653  long nevt = kernel.property("NumEvents").value<long>();
654  kernel.applyInterruptHandlers();
655  kernel.runManager().BeamOn(nevt);
656  kernel.executePhase("stop",0);
657  return 1;
658 }
659 
662  kernel.executePhase("terminate",0);
663  return 1;
664 }
dd4hep::sim::SequenceHdl::context
Geant4Context * context() const
Access reference to the current active Geant4Context structure.
Definition: Geant4Exec.cpp:103
dd4hep::sim::Geant4UserGeneratorAction::Geant4UserGeneratorAction
Geant4UserGeneratorAction(Geant4Context *ctxt, Geant4GeneratorActionSequence *seq)
Standard constructor.
Definition: Geant4Exec.cpp:283
dd4hep::sim::Geant4UserStackingAction::ClassifyNewTrack
virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *track) override final
Definition: Geant4Exec.cpp:262
dd4hep::sim::Geant4Compatibility::Geant4Compatibility
Geant4Compatibility()=default
Default constructor.
Geant4DetectorConstruction.h
dd4hep::sim::TrackClassification::value
G4ClassificationOfNewTrack value
Definition: Geant4StackingAction.h:40
dd4hep::sim::Geant4Context::setEvent
void setEvent(Geant4Event *new_event)
Set the geant4 event reference.
Definition: Geant4Context.cpp:79
dd4hep::sim::Geant4DetectorConstructionSequence::constructField
virtual void constructField(Geant4DetectorConstructionContext *ctxt)
Electromagnetic field construction callback. Called at "ConstructSDandField()".
Definition: Geant4DetectorConstruction.cpp:128
dd4hep::sim::Geant4UserEventAction
Concrete implementation of the Geant4 event action.
Definition: Geant4Exec.cpp:184
dd4hep::sim::Geant4TrackingActionSequence::end
virtual void end(const G4Track *track)
Post-tracking action callback.
Definition: Geant4TrackingAction.cpp:88
dd4hep::sim::Geant4Kernel::setWorld
void setWorld(G4VPhysicalVolume *volume)
Set the geometry world.
Definition: Geant4Kernel.cpp:262
dd4hep::sim::Geant4Call
Callback interface class with argument.
Definition: Geant4Call.h:29
dd4hep::Property
The property class to assign options to actions.
Definition: ComponentProperties.h:48
dd4hep::sim::Geant4Exec::configure
static int configure(Geant4Kernel &kernel)
Configure the application.
Definition: Geant4Exec.cpp:552
dd4hep::sim::Geant4Run
User run context for DDG4.
Definition: Geant4Context.h:69
dd4hep::sim::Geant4Random::instance
static Geant4Random * instance(bool throw_exception=true)
Access the main Geant4 random generator instance. Must be created before used!
Definition: Geant4Random.cpp:113
dd4hep::sim::Geant4UserDetectorConstruction::ConstructSDandField
virtual void ConstructSDandField() final
Call the actions for the construction of the sensitive detectors and the field.
Definition: Geant4Exec.cpp:413
dd4hep::sim::Geant4UserInitializationSequence
Class to orchestrate a modular initializion of a multi- or single threaded Geant4 application.
Definition: Geant4UserInitialization.h:52
dd4hep::sim::Geant4UserStackingAction
Concrete implementation of the Geant4 stacking action sequence.
Definition: Geant4Exec.cpp:243
dd4hep::sim::Geant4StackingActionSequence
Concrete implementation of the Geant4 stacking action sequence.
Definition: Geant4StackingAction.h:128
dd4hep::sim::Geant4Kernel::id
unsigned long id() const
Access worker identifier.
Definition: Geant4Kernel.h:209
dd4hep::sim::Geant4ActionContainer::runAction
Geant4RunActionSequence * runAction(bool create)
Access run action sequence.
Definition: Geant4ActionContainer.cpp:92
Detector.h
dd4hep::sim::Geant4Exec::run
static int run(Geant4Kernel &kernel)
Run the application and simulate events.
Definition: Geant4Exec.cpp:635
dd4hep::sim::Geant4PhysicsListActionSequence::extensionList
G4VUserPhysicsList * extensionList()
Extend physics list from factory:
Definition: Geant4PhysicsList.cpp:340
dd4hep::sim::Geant4UserRunAction
Concrete implementation of the Geant4 run action.
Definition: Geant4Exec.cpp:157
dd4hep::sim::Geant4Context::setRun
void setRun(Geant4Run *new_run)
Set the geant4 run reference.
Definition: Geant4Context.cpp:67
dd4hep::sim::Geant4UserStackingAction::~Geant4UserStackingAction
virtual ~Geant4UserStackingAction()
Default destructor.
Definition: Geant4Exec.cpp:252
dd4hep::sim::Geant4UserDetectorConstruction::Geant4UserDetectorConstruction
Geant4UserDetectorConstruction(Geant4Context *ctxt, Geant4DetectorConstructionSequence *seq)
Standard constructor.
Definition: Geant4Exec.cpp:335
dd4hep::sim::Geant4UserActionInitialization::BuildForMaster
virtual void BuildForMaster() const final
Build the action sequences for the master thread.
Definition: Geant4Exec.cpp:489
dd4hep::sim::Geant4ActionContainer::stackingAction
Geant4StackingActionSequence * stackingAction(bool create)
Access stacking action sequence.
Definition: Geant4ActionContainer.cpp:120
Geant4TrackingAction.h
dd4hep::sim::Geant4UserStackingAction::Geant4UserStackingAction
Geant4UserStackingAction(Geant4Context *ctxt, Geant4StackingActionSequence *seq)
Standard constructor.
Definition: Geant4Exec.cpp:246
dd4hep::sim::Geant4Kernel::property
Property & property(const std::string &name)
Access single property.
Definition: Geant4Kernel.cpp:298
Handle.h
Geant4RunAction.h
Geant4EventAction.h
dd4hep::sim::Geant4UserStackingAction::PrepareNewEvent
virtual void PrepareNewEvent() override final
Preparation callback.
Definition: Geant4Exec.cpp:259
dd4hep::sim::Geant4Kernel
Class, which allows all Geant4Action derivatives to access the DDG4 kernel structures.
Definition: Geant4Kernel.h:64
dd4hep::sim::SequenceHdl::~SequenceHdl
virtual ~SequenceHdl()
Default destructor.
Definition: Geant4Exec.cpp:81
dd4hep::sim::Geant4ActionContainer::trackingAction
Geant4TrackingActionSequence * trackingAction(bool create)
Access tracking action sequence.
Definition: Geant4ActionContainer.cpp:113
dd4hep::sim::Geant4Kernel::executePhase
virtual bool executePhase(const std::string &name, const void **args) const
Execute phase action if it exists.
Definition: Geant4Kernel.cpp:519
dd4hep::sim::SequenceHdl::Base
SequenceHdl< T > Base
Definition: Geant4Exec.cpp:69
dd4hep::sim::Geant4Action::property
Property & property(const std::string &name)
Access single property.
Definition: Geant4Action.cpp:99
dd4hep::sim::Geant4UserTrackingAction
Concrete implementation of the Geant4 tracking action.
Definition: Geant4Exec.cpp:211
dd4hep::sim::Geant4Compatibility::~Geant4Compatibility
virtual ~Geant4Compatibility()=default
Default destructor.
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
Geant4PhysicsList.h
dd4hep::sim::Geant4UserTrackingAction::PreUserTrackingAction
virtual void PreUserTrackingAction(const G4Track *trk) final
Pre-track action callback.
Definition: Geant4Exec.cpp:223
dd4hep::sim::SequenceHdl::destroyClientContext
void destroyClientContext(const G4Event *)
Destroy Geant4 event context.
Definition: Geant4Exec.cpp:135
dd4hep::sim::Geant4TrackingActionSequence::begin
virtual void begin(const G4Track *track)
Pre-tracking action callback.
Definition: Geant4TrackingAction.cpp:81
dd4hep::sim::Geant4UserEventAction::EndOfEventAction
virtual void EndOfEventAction(const G4Event *evt) final
End-of-event callback.
Definition: Geant4Exec.cpp:395
dd4hep::sim::Geant4DetectorConstructionSequence::updateContext
virtual void updateContext(Geant4Context *ctxt) override
Set or update client context.
Definition: Geant4DetectorConstruction.cpp:96
dd4hep::sim::Geant4UserActionInitialization::Build
virtual void Build() const final
Build the actions for the worker thread.
Definition: Geant4Exec.cpp:439
dd4hep::sim::Geant4ActionContainer::workerContext
Geant4Context * workerContext()
Thread's Geant4 execution context.
Definition: Geant4ActionContainer.cpp:65
Geant4SteppingAction.h
dd4hep::sim::Geant4UserSteppingAction::UserSteppingAction
virtual void UserSteppingAction(const G4Step *s) final
User stepping callback.
Definition: Geant4Exec.cpp:316
dd4hep::sim::SequenceHdl::createClientContext
void createClientContext(const G4Run *run)
Create Geant4 run context.
Definition: Geant4Exec.cpp:117
dd4hep::sim::Geant4TrackingActionSequence
Concrete implementation of the Geant4 tracking action sequence.
Definition: Geant4TrackingAction.h:114
dd4hep::sim::Geant4Kernel::detectorDescription
Detector & detectorDescription() const
Access to detector description.
Definition: Geant4Kernel.h:201
dd4hep::sim::Geant4Kernel::worker
Geant4Kernel & worker(unsigned long thread_identifier, bool create_if=false)
Access worker instance by its identifier.
Definition: Geant4Kernel.cpp:230
dd4hep::sim::Geant4DetectorConstructionContext::world
G4VPhysicalVolume * world
Reference to the world after construction.
Definition: Geant4DetectorConstruction.h:70
dd4hep::sim::Geant4Action::info
void info(const char *fmt,...) const
Support of info messages.
Definition: Geant4Action.cpp:215
dd4hep::sim::Geant4UserSteppingAction
Concrete implementation of the Geant4 stepping action.
Definition: Geant4Exec.cpp:304
dd4hep::sim::Geant4Action::except
void except(const char *fmt,...) const
Support of exceptions: Print fatal message and throw runtime_error.
Definition: Geant4Action.cpp:256
dd4hep::sim::Geant4DetectorConstructionContext
Geant4 detector construction context definition.
Definition: Geant4DetectorConstruction.h:61
dd4hep::sim::Geant4PhysicsListActionSequence::m_rangecut
double m_rangecut
global range cut for secondary productions
Definition: Geant4PhysicsList.h:246
Geant4Random.h
Geant4GeneratorAction.h
dd4hep::sim::Geant4GeneratorActionSequence
Concrete implementation of the Geant4 generator action sequence.
Definition: Geant4GeneratorAction.h:115
dd4hep::sim::Geant4ActionContainer::detectorConstruction
Geant4DetectorConstructionSequence * detectorConstruction(bool create)
Access detector construcion action sequence (geometry+sensitives+field)
Definition: Geant4ActionContainer.cpp:127
dd4hep::sim::Geant4DetectorConstructionSequence::constructGeo
virtual void constructGeo(Geant4DetectorConstructionContext *ctxt)
Geometry construction callback. Called at "Construct()".
Definition: Geant4DetectorConstruction.cpp:123
dd4hep::sim::Geant4UserRunAction::Geant4UserRunAction
Geant4UserRunAction(Geant4Context *ctxt, Geant4RunActionSequence *seq)
Standard constructor.
Definition: Geant4Exec.cpp:161
Geant4StackingAction.h
dd4hep::sim::Geant4UserEventAction::BeginOfEventAction
virtual void BeginOfEventAction(const G4Event *evt) final
Begin-of-event callback.
Definition: Geant4Exec.cpp:389
dd4hep::sim::Geant4UserSteppingAction::Geant4UserSteppingAction
Geant4UserSteppingAction(Geant4Context *ctxt, Geant4SteppingActionSequence *seq)
Standard constructor.
Definition: Geant4Exec.cpp:307
dd4hep::sim::Geant4ActionContainer::eventAction
Geant4EventActionSequence * eventAction(bool create)
Access run action sequence.
Definition: Geant4ActionContainer.cpp:99
dd4hep::sim::Geant4UserEventAction::runAction
Geant4UserRunAction * runAction
Definition: Geant4Exec.cpp:186
dd4hep::sim::Geant4Random::setMainInstance
static Geant4Random * setMainInstance(Geant4Random *ptr)
Make this random generator instance the one used by Geant4.
Definition: Geant4Random.cpp:121
dd4hep::sim::Geant4UserGeneratorAction
Concrete implementation of the Geant4 generator action.
Definition: Geant4Exec.cpp:280
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4RunActionSequence
Concrete basic implementation of the Geant4 run action sequencer.
Definition: Geant4RunAction.h:117
dd4hep::sim::SequenceHdl
Sequence handler implementing common actions to all sequences.
Definition: Geant4Exec.cpp:67
dd4hep::sim::SequenceHdl::destroyClientContext
void destroyClientContext(const G4Run *)
Destroy Geant4 run context.
Definition: Geant4Exec.cpp:122
dd4hep::sim::Geant4StackingActionSequence::prepare
virtual void prepare(G4StackManager *stackManager)
Preparation callback.
Definition: Geant4StackingAction.cpp:155
dd4hep::sim::Geant4UserDetectorConstruction::Construct
virtual G4VPhysicalVolume * Construct() final
Call the actions to construct the detector geometry.
Definition: Geant4Exec.cpp:424
dd4hep::sim::Geant4DetectorConstructionSequence::adopt
void adopt(Geant4DetectorConstruction *action)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4DetectorConstruction.cpp:102
dd4hep::sim::Geant4PhysicsListActionSequence
The implementation of the single Geant4 physics list action sequence.
Definition: Geant4PhysicsList.h:223
Plugins.h
dd4hep::sim::Geant4DetectorConstructionSequence::constructSensitives
virtual void constructSensitives(Geant4DetectorConstructionContext *ctxt)
Sensitive detector construction callback. Called at "ConstructSDandField()".
Definition: Geant4DetectorConstruction.cpp:133
dd4hep::sim::Geant4Exec::terminate
static int terminate(Geant4Kernel &kernel)
Terminate the application.
Definition: Geant4Exec.cpp:661
dd4hep::sim::Geant4UserDetectorConstruction::~Geant4UserDetectorConstruction
virtual ~Geant4UserDetectorConstruction()
Default destructor.
Definition: Geant4Exec.cpp:341
dd4hep::Detector::sensitiveDetectors
virtual const HandleMap & sensitiveDetectors() const =0
Accessor to the map of sub-detectors.
dd4hep::sim::Geant4UserTrackingAction::PostUserTrackingAction
virtual void PostUserTrackingAction(const G4Track *trk) final
Post-track action callback.
Definition: Geant4Exec.cpp:228
dd4hep::sim::SequenceHdl::configureFiber
void configureFiber(Geant4Context *ctxt)
G4 callback in multi threaded mode to configure thread fiber.
Definition: Geant4Exec.cpp:111
G4UserStackingAction
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:31
dd4hep::sim::Geant4Random
Mini interface to THE random generator of the application.
Definition: Geant4Random.h:59
dd4hep::sim::Geant4Action
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:113
dd4hep::sim::Geant4UserRunAction::BeginOfRunAction
virtual void BeginOfRunAction(const G4Run *run) final
Begin-of-run callback.
Definition: Geant4Exec.cpp:374
dd4hep::sim::Geant4Kernel::thread_self
static unsigned long int thread_self()
Access thread identifier.
Definition: Geant4Kernel.cpp:211
dd4hep::sim::SequenceHdl::createClientContext
void createClientContext(const G4Event *evt)
Create Geant4 event context.
Definition: Geant4Exec.cpp:130
dd4hep::sim::Geant4DetectorConstructionSequence
Concrete basic implementation of the Geant4 detector construction sequencer.
Definition: Geant4DetectorConstruction.h:135
dd4hep::sim::Geant4UserSteppingAction::~Geant4UserSteppingAction
virtual ~Geant4UserSteppingAction()
Default destructor.
Definition: Geant4Exec.cpp:313
dd4hep::sim::SequenceHdl::SequenceHdl
SequenceHdl()
Default constructor.
Definition: Geant4Exec.cpp:73
dd4hep::sim::Geant4UserDetectorConstruction
Concrete implementation of the Geant4 user detector construction action sequence.
Definition: Geant4Exec.cpp:330
dd4hep::sim::Geant4UserRunAction::EndOfRunAction
virtual void EndOfRunAction(const G4Run *run) final
End-of-run callback.
Definition: Geant4Exec.cpp:382
dd4hep::sim::Geant4ActionContainer::userInitialization
Geant4UserInitializationSequence * userInitialization(bool create)
Access to the user initialization object.
Definition: Geant4ActionContainer.cpp:157
dd4hep::sim::Geant4Exec::initialize
static int initialize(Geant4Kernel &kernel)
Initialize the application.
Definition: Geant4Exec.cpp:622
dd4hep::sim::Geant4UserRunAction::~Geant4UserRunAction
virtual ~Geant4UserRunAction()
Default destructor.
Definition: Geant4Exec.cpp:167
G4UserSteppingAction
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:35
G4UserTrackingAction
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:39
dd4hep::sim::Geant4Kernel::isMultiThreaded
bool isMultiThreaded() const
Definition: Geant4Kernel.h:161
dd4hep::sim::Geant4Kernel::globalAction
Geant4Action * globalAction(const std::string &action_name, bool throw_if_not_present=true)
Retrieve action from repository.
Definition: Geant4Kernel.cpp:476
dd4hep::Property::value
TYPE value() const
Retrieve value.
Definition: ComponentProperties.h:126
Primitives.h
dd4hep::sim::Geant4UserGeneratorAction::~Geant4UserGeneratorAction
virtual ~Geant4UserGeneratorAction()
Default destructor.
Definition: Geant4Exec.cpp:289
dd4hep::sim::Geant4Context::runPtr
Geant4Run * runPtr() const
Access the geant4 run by ptr. Must be checked by clients!
Definition: Geant4Context.h:225
dd4hep::Property::set
void set(const TYPE &value)
Set value of this property.
Definition: ComponentProperties.h:102
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::SequenceHdl::SequenceHdl
SequenceHdl(Geant4Context *ctxt, T *seq)
Initializing constructor.
Definition: Geant4Exec.cpp:77
dd4hep::sim::Geant4Context::kernel
Geant4Kernel & kernel() const
Access to the kernel object.
Definition: Geant4Context.h:233
dd4hep::sim::Geant4ActionContainer::steppingAction
Geant4SteppingActionSequence * steppingAction(bool create)
Access stepping action sequence.
Definition: Geant4ActionContainer.cpp:106
dd4hep::sim::Geant4UserEventAction::Geant4UserEventAction
Geant4UserEventAction(Geant4Context *ctxt, Geant4EventActionSequence *seq)
Standard constructor.
Definition: Geant4Exec.cpp:188
G4UserRunAction
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:27
dd4hep::sim::SequenceHdl::kernel
Geant4Kernel & kernel() const
Access reference to the current active Geant4Kernel structure.
Definition: Geant4Exec.cpp:107
dd4hep::sim::Geant4UserEventAction::~Geant4UserEventAction
virtual ~Geant4UserEventAction()
Default destructor.
Definition: Geant4Exec.cpp:194
dd4hep::sim::Geant4ActionContainer::physicsList
Geant4PhysicsListActionSequence * physicsList(bool create)
Access to the physics list.
Definition: Geant4ActionContainer.cpp:150
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::SequenceHdl::m_activeContext
Geant4Context * m_activeContext
Definition: Geant4Exec.cpp:71
dd4hep::sim::SequenceHdl::updateContext
void updateContext(Geant4Context *ctxt)
Update Geant4Context for current call.
Definition: Geant4Exec.cpp:96
Geant4UserInitialization.h
dd4hep::sim::Geant4Kernel::setTrackMgr
void setTrackMgr(G4TrackingManager *mgr)
Access the tracking manager.
Definition: Geant4Kernel.h:205
G4VUserDetectorConstruction
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:67
dd4hep::sim::Geant4PhysicsListActionSequence::enable
virtual void enable(G4VUserPhysicsList *physics)
Enable physics list: actions necessary to be propagated to Geant4.
Definition: Geant4PhysicsList.cpp:445
dd4hep::sim::Geant4Context::eventPtr
Geant4Event * eventPtr() const
Access the geant4 event by ptr. Must be checked by clients!
Definition: Geant4Context.h:231
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::sim::Geant4EventActionSequence
Concrete implementation of the Geant4 event action sequence.
Definition: Geant4EventAction.h:124
Geant4Kernel.h
dd4hep::sim::Geant4UserDetectorConstruction::m_ctxt
Geant4DetectorConstructionContext m_ctxt
Definition: Geant4Exec.cpp:332
dd4hep::sim::Geant4StackingActionSequence::newStage
virtual void newStage(G4StackManager *stackManager)
New-stage callback.
Definition: Geant4StackingAction.cpp:149
dd4hep::sim::Geant4Compatibility::buildDefaultDetectorConstruction
Geant4DetectorConstructionSequence * buildDefaultDetectorConstruction(Geant4Kernel &kernel)
Detector construction invocation in compatibility mode.
Definition: Geant4Exec.cpp:527
G4VUserActionInitialization
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:63
dd4hep::sim::Geant4UserActionInitialization
Concrete implementation of the Geant4 user initialization action sequence.
Definition: Geant4Exec.cpp:358
G4UserEventAction
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:19
InstanceCount.h
dd4hep::sim::NoTrackClassification
@ NoTrackClassification
Definition: Geant4StackingAction.h:37
dd4hep::sim::Geant4Kernel::runManager
G4RunManager & runManager()
Access to the Geant4 run manager.
Definition: Geant4Kernel.cpp:322
dd4hep::sim::Geant4Compatibility
Compatibility actions for running Geant4 in single threaded mode.
Definition: Geant4Exec.cpp:502
dd4hep::sim::Geant4DetectorConstruction
Basic implementation of the Geant4 detector construction action.
Definition: Geant4DetectorConstruction.h:102
dd4hep::sim::Geant4UserGeneratorAction::GeneratePrimaries
virtual void GeneratePrimaries(G4Event *event) final
Generate primary particles.
Definition: Geant4Exec.cpp:402
dd4hep::sim::Geant4UserActionInitialization::Geant4UserActionInitialization
Geant4UserActionInitialization(Geant4Context *ctxt, Geant4UserInitializationSequence *seq)
Standard constructor.
Definition: Geant4Exec.cpp:361
dd4hep::sim::Geant4UserTrackingAction::~Geant4UserTrackingAction
virtual ~Geant4UserTrackingAction()
Default destructor.
Definition: Geant4Exec.cpp:220
dd4hep::sim::Geant4SteppingActionSequence
Concrete implementation of the Geant4 stepping action sequence.
Definition: Geant4SteppingAction.h:104
dd4hep::sim::Geant4UserTrackingAction::Geant4UserTrackingAction
Geant4UserTrackingAction(Geant4Context *ctxt, Geant4TrackingActionSequence *seq)
Standard constructor.
Definition: Geant4Exec.cpp:214
dd4hep::sim::Geant4Random::initialize
void initialize()
Initialize the instance.
Definition: Geant4Random.cpp:158
dd4hep::sim::Geant4UserStackingAction::NewStage
virtual void NewStage() override final
New-stage callback.
Definition: Geant4Exec.cpp:255
dd4hep::sim::Geant4Event
User event context for DDG4.
Definition: Geant4Context.h:121
dd4hep::sim::Geant4StackingActionSequence::classifyNewTrack
virtual TrackClassification classifyNewTrack(G4StackManager *stackManager, const G4Track *track)
Classify new track: The first call in the sequence returning non-null pointer wins!
Definition: Geant4StackingAction.cpp:162
Printout.h
dd4hep::sim::SequenceHdl::_release
void _release()
Release object.
Definition: Geant4Exec.cpp:91
dd4hep::sim::Geant4Kernel::applyInterruptHandlers
void applyInterruptHandlers()
(Re-)apply registered interrupt handlers to override potentially later registrations by other librari...
Definition: Geant4Kernel.cpp:206
dd4hep::sim::Geant4UserActionInitialization::~Geant4UserActionInitialization
virtual ~Geant4UserActionInitialization()
Default destructor.
Definition: Geant4Exec.cpp:365
Geant4UIManager.h
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270
dd4hep::sim::Geant4ActionContainer::generatorAction
Geant4GeneratorActionSequence * generatorAction(bool create)
Access generator action sequence.
Definition: Geant4ActionContainer.cpp:85
G4VUserPrimaryGeneratorAction
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:71
dd4hep::sim::SequenceHdl::m_sequence
T * m_sequence
Definition: Geant4Exec.cpp:70
dd4hep::sim::SequenceHdl::_aquire
void _aquire(T *s)
Aquire object reference.
Definition: Geant4Exec.cpp:85
dd4hep::sim::Geant4UserRunAction::eventAction
Geant4UserEventAction * eventAction
Definition: Geant4Exec.cpp:159