DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4Context.h
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 #ifndef DDG4_GEANT4CONTEXT_H
15 #define DDG4_GEANT4CONTEXT_H
16 
17 // Framework incloude files
18 #include <DD4hep/Primitives.h>
20 
21 // Forward declarations
22 class G4Run;
23 class G4Track;
24 class G4Event;
25 class G4VTrajectory;
26 class G4VPhysicalVolume;
27 class G4TrackingManager;
28 
30 namespace dd4hep {
31 
32  // Forward declarations
33  class Detector;
34  class DetElement;
35 
37  namespace sim {
38 
39  class Geant4Run;
40  class Geant4Event;
41  class Geant4Kernel;
42  class Geant4Random;
43  class ContextUpdate;
44  class Geant4RunActionSequence;
45  class Geant4EventActionSequence;
46  class Geant4SteppingActionSequence;
47  class Geant4TrackingActionSequence;
48  class Geant4StackingActionSequence;
49  class Geant4GeneratorActionSequence;
50  class Geant4SensDetSequences;
51 
53 
69  class Geant4Run : public ObjectExtensions {
71  const G4Run* m_run { nullptr };
72  protected:
73 
74  public:
76  Geant4Run(const G4Run* run);
78  virtual ~Geant4Run();
80  operator const G4Run&() const { return *m_run; }
82  const G4Run& run() const { return *m_run; }
84  void* addExtension(unsigned long long int k, ExtensionEntry* e) {
85  return ObjectExtensions::addExtension(k, e);
86  }
88  template <typename T> T* addExtension(T* ptr, bool take_ownership=true) {
89  ExtensionEntry* e = take_ownership
92  return (T*)ObjectExtensions::addExtension(detail::typeHash64<T>(),e);
93  }
95  template <typename T> T* extension(bool alert=true) {
96  return (T*)ObjectExtensions::extension(detail::typeHash64<T>(),alert);
97  }
98  };
99 
101 
121  class Geant4Event : public ObjectExtensions {
123  const G4Event* m_event { nullptr };
125  Geant4Random* m_random { nullptr };
126 
127  public:
129  Geant4Event(const G4Event* run, Geant4Random* rndm);
131  virtual ~Geant4Event();
133  operator const G4Event&() const { return *m_event; }
135  const G4Event& event() const { return *m_event; }
137  Geant4Random& random() const { return *m_random; }
138 
140  void* addExtension(unsigned long long int k, ExtensionEntry* e) {
141  return ObjectExtensions::addExtension(k, e);
142  }
144  template <typename T> T* addExtension(T* ptr, bool take_ownership=true) {
145  ExtensionEntry* e = take_ownership
148  return (T*)ObjectExtensions::addExtension(detail::typeHash64<T>(),e);
149  }
151  template <typename T> T* extension(bool alert=true) {
152  return (T*)ObjectExtensions::extension(detail::typeHash64<T>(),alert);
153  }
154  };
155 
157 
202  public:
203  friend class Geant4Kernel;
204  typedef std::pair<void*, const std::type_info*> UserFramework;
205 
206  protected:
213 
216 
217  public:
219  virtual ~Geant4Context();
221  void setRun(Geant4Run* new_run);
223  Geant4Run& run() const;
225  Geant4Run* runPtr() const { return m_run; }
227  void setEvent(Geant4Event* new_event);
229  Geant4Event& event() const;
231  Geant4Event* eventPtr() const { return m_event; }
233  Geant4Kernel& kernel() const { return *m_kernel; }
235  G4VPhysicalVolume* world() const;
236 
238  template <typename T> T& framework() const;
240  UserFramework& userFramework() const;
242  Detector& detectorDescription() const;
244  G4TrackingManager* trackMgr() const;
246  virtual G4VTrajectory* createTrajectory(const G4Track* track) const;
261  };
262 
263  } // End namespace sim
264 } // End namespace dd4hep
265 
266 #endif // DDG4_GEANT4CONTEXT_H
dd4hep::sim::Geant4Context::runAction
Geant4RunActionSequence & runAction() const
Access to the main run action sequence from the kernel object.
Definition: Geant4Context.cpp:113
dd4hep::sim::Geant4Event::m_random
Geant4Random * m_random
Reference to the main random number generator.
Definition: Geant4Context.h:125
dd4hep::ExtensionEntry
Definition of the extension entry interface class.
Definition: ExtensionEntry.h:40
dd4hep::sim::Geant4Context::setEvent
void setEvent(Geant4Event *new_event)
Set the geant4 event reference.
Definition: Geant4Context.cpp:79
dd4hep::sim::Geant4Run
User run context for DDG4.
Definition: Geant4Context.h:69
dd4hep::sim::Geant4Context::detectorDescription
Detector & detectorDescription() const
Access to detector description.
Definition: Geant4Context.cpp:91
dd4hep::sim::Geant4StackingActionSequence
Concrete implementation of the Geant4 stacking action sequence.
Definition: Geant4StackingAction.h:128
dd4hep::ObjectExtensions
Implementation of an object supporting arbitrary user extensions.
Definition: ObjectExtensions.h:33
dd4hep::sim::Geant4Run::addExtension
T * addExtension(T *ptr, bool take_ownership=true)
Add user extension object. Ownership is transferred!
Definition: Geant4Context.h:88
ObjectExtensions.h
dd4hep::sim::Geant4Context::m_kernel
Geant4Kernel * m_kernel
Reference to the kernel object.
Definition: Geant4Context.h:208
dd4hep::sim::Geant4Context::run
Geant4Run & run() const
Access the geant4 run – valid only between BeginRun() and EndRun()!
Definition: Geant4Context.cpp:72
dd4hep::sim::Geant4Context::setRun
void setRun(Geant4Run *new_run)
Set the geant4 run reference.
Definition: Geant4Context.cpp:67
dd4hep::sim::Geant4Event::addExtension
T * addExtension(T *ptr, bool take_ownership=true)
Add user extension object. Ownership is transferred and object deleted at the end of the event.
Definition: Geant4Context.h:144
dd4hep::sim::Geant4Run::run
const G4Run & run() const
Access the G4Event directly: Explicit G4Run accessor.
Definition: Geant4Context.h:82
dd4hep::sim::Geant4Kernel
Class, which allows all Geant4Action derivatives to access the DDG4 kernel structures.
Definition: Geant4Kernel.h:64
dd4hep::sim::Geant4Context::m_run
Geant4Run * m_run
Transient context variable - depending on the thread context: run reference.
Definition: Geant4Context.h:210
dd4hep::sim::Geant4Context::event
Geant4Event & event() const
Access the geant4 event – valid only between BeginEvent() and EndEvent()!
Definition: Geant4Context.cpp:84
dd4hep::detail::SimpleExtension
Implementation class for the object extension mechanism.
Definition: ExtensionEntry.h:78
dd4hep::sim::Geant4Event::random
Geant4Random & random() const
Access the random number generator.
Definition: Geant4Context.h:137
dd4hep::sim::Geant4Context::world
G4VPhysicalVolume * world() const
Access to geometry world.
Definition: Geant4Context.cpp:62
dd4hep::sim::Geant4Context::sensitiveActions
Geant4SensDetSequences & sensitiveActions() const
Access to the sensitive detector sequences from the kernel object.
Definition: Geant4Context.cpp:143
dd4hep::sim::Geant4Context::Geant4Context
Geant4Context(Geant4Kernel *kernel)
Default constructor.
Definition: Geant4Context.cpp:50
dd4hep::sim::Geant4TrackingActionSequence
Concrete implementation of the Geant4 tracking action sequence.
Definition: Geant4TrackingAction.h:114
dd4hep::sim::Geant4Event::m_event
const G4Event * m_event
Reference to the original Geant4 event object.
Definition: Geant4Context.h:123
dd4hep::sim::Geant4Event::extension
T * extension(bool alert=true)
Access to type safe extension object. Exception is thrown if the object is invalid.
Definition: Geant4Context.h:151
dd4hep::sim::Geant4Run::addExtension
void * addExtension(unsigned long long int k, ExtensionEntry *e)
Add an extension object to the detector element.
Definition: Geant4Context.h:84
dd4hep::sim::Geant4GeneratorActionSequence
Concrete implementation of the Geant4 generator action sequence.
Definition: Geant4GeneratorAction.h:115
dd4hep::sim::Geant4Event::~Geant4Event
virtual ~Geant4Event()
Default destructor.
Definition: Geant4Context.cpp:45
dd4hep::detail::DeleteExtension
Implementation class for the object extension mechanism.
Definition: ExtensionEntry.h:123
dd4hep::sim::Geant4RunActionSequence
Concrete basic implementation of the Geant4 run action sequencer.
Definition: Geant4RunAction.h:117
dd4hep::sim::Geant4SensDetSequences
Geant4SensDetSequences: class to access groups of sensitive actions.
Definition: Geant4SensDetAction.h:464
dd4hep::sim::Geant4Context::m_event
Geant4Event * m_event
Transient context variable - depending on the thread context: event reference.
Definition: Geant4Context.h:212
dd4hep::sim::Geant4Random
Mini interface to THE random generator of the application.
Definition: Geant4Random.h:59
dd4hep::sim::Geant4Run::Geant4Run
Geant4Run(const G4Run *run)
Intializing constructor.
Definition: Geant4Context.cpp:26
dd4hep::sim::Geant4Event::Geant4Event
Geant4Event(const G4Event *run, Geant4Random *rndm)
Intializing constructor.
Definition: Geant4Context.cpp:38
dd4hep::sim::Geant4Run::extension
T * extension(bool alert=true)
Access to type safe extension object. Exception is thrown if the object is invalid.
Definition: Geant4Context.h:95
dd4hep::sim::Geant4Run::m_run
const G4Run * m_run
Reference to the original Geant4 run object.
Definition: Geant4Context.h:71
dd4hep::sim::Geant4Run::~Geant4Run
virtual ~Geant4Run()
Default destructor.
Definition: Geant4Context.cpp:33
dd4hep::sim::Geant4Context::createTrajectory
virtual G4VTrajectory * createTrajectory(const G4Track *track) const
Create a user trajectory.
Definition: Geant4Context.cpp:101
dd4hep::sim::Geant4Event::addExtension
void * addExtension(unsigned long long int k, ExtensionEntry *e)
Add an extension object to the detector element.
Definition: Geant4Context.h:140
Primitives.h
dd4hep::sim::Geant4Context::runPtr
Geant4Run * runPtr() const
Access the geant4 run by ptr. Must be checked by clients!
Definition: Geant4Context.h:225
dd4hep::sim::Geant4Context::kernel
Geant4Kernel & kernel() const
Access to the kernel object.
Definition: Geant4Context.h:233
dd4hep::sim::Geant4Context::userFramework
UserFramework & userFramework() const
Generic framework access.
Definition: Geant4Context.cpp:96
dd4hep::sim::Geant4Context::stackingAction
Geant4StackingActionSequence & stackingAction() const
Access to the main stacking action sequence from the kernel object.
Definition: Geant4Context.cpp:133
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4Event::event
const G4Event & event() const
Access the G4Event directly: Explicit G4Event accessor.
Definition: Geant4Context.h:135
dd4hep::sim::Geant4Context::~Geant4Context
virtual ~Geant4Context()
Default destructor.
Definition: Geant4Context.cpp:56
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::Geant4Context::trackMgr
G4TrackingManager * trackMgr() const
Access the tracking manager.
Definition: Geant4Context.cpp:108
dd4hep::sim::Geant4EventActionSequence
Concrete implementation of the Geant4 event action sequence.
Definition: Geant4EventAction.h:124
dd4hep::sim::Geant4Context::steppingAction
Geant4SteppingActionSequence & steppingAction() const
Access to the main stepping action sequence from the kernel object.
Definition: Geant4Context.cpp:123
dd4hep::sim::Geant4Context::generatorAction
Geant4GeneratorActionSequence & generatorAction() const
Access to the main generator action sequence from the kernel object.
Definition: Geant4Context.cpp:138
dd4hep::sim::Geant4Context::trackingAction
Geant4TrackingActionSequence & trackingAction() const
Access to the main tracking action sequence from the kernel object.
Definition: Geant4Context.cpp:128
dd4hep::sim::Geant4Context::framework
T & framework() const
Access to the user framework. Specialized function to be implemented by the client.
dd4hep::sim::Geant4SteppingActionSequence
Concrete implementation of the Geant4 stepping action sequence.
Definition: Geant4SteppingAction.h:104
dd4hep::sim::Geant4Event
User event context for DDG4.
Definition: Geant4Context.h:121
dd4hep::ObjectExtensions::addExtension
void * addExtension(unsigned long long int key, ExtensionEntry *entry)
Add an extension object to the detector element.
Definition: ObjectExtensions.cpp:67
dd4hep::sim::Geant4Context::eventAction
Geant4EventActionSequence & eventAction() const
Access to the main event action sequence from the kernel object.
Definition: Geant4Context.cpp:118
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::ObjectExtensions::extension
void * extension(unsigned long long int key, bool alert) const
Access an existing extension object from the detector element.
Definition: ObjectExtensions.cpp:119
dd4hep::sim::Geant4Context::UserFramework
std::pair< void *, const std::type_info * > UserFramework
Definition: Geant4Context.h:204