DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4SensDet.cpp
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 // Framework include files
16 #include "DD4hep/Printout.h"
17 #include "DD4hep/Primitives.h"
18 #include "DD4hep/InstanceCount.h"
19 
20 #include "DDG4/Geant4Kernel.h"
21 #include "DDG4/Geant4Context.h"
24 
25 // Geant4 include files
26 #include "G4VSensitiveDetector.hh"
27 #include "G4Event.hh"
28 #include "G4Run.hh"
29 
31 namespace DD4hep {
32 
34  namespace Simulation {
35 
37 
42  template <typename T> class RefCountedSequence {
43  public:
49  RefCountedSequence(T* seq) { _aquire(seq); }
51  virtual ~RefCountedSequence() { _release(); }
52  void _aquire(T* s) {
54  m_sequence = s;
55  m_sequence->addRef();
56  }
57  void _release() {
60  }
61  };
62 
64 
69  class Geant4SensDet : virtual public G4VSensitiveDetector,
70  virtual public G4VSDFilter,
71  virtual public Geant4ActionSD,
72  virtual public RefCountedSequence<Geant4SensDetActionSequence>
73  {
74  protected:
77  public:
79  Geant4SensDet(const std::string& nam, Geometry::LCDD& lcdd)
80  : G4VSensitiveDetector(nam), G4VSDFilter(nam),
81  Geant4Action(0,nam), Geant4ActionSD(nam), Base()
82  {
83  Geant4Kernel& master = Geant4Kernel::instance(lcdd);
84  Geant4Kernel& kernel = master.worker(Geant4Kernel::thread_self());
85  m_sensitive = lcdd.sensitiveDetector(nam);
86  m_context = kernel.workerContext();
87  m_outputLevel = kernel.getOutputLevel(nam);
88  _aquire(kernel.sensitiveAction(nam));
91  this->G4VSensitiveDetector::SetFilter(this);
92  }
93 
95  virtual ~Geant4SensDet() { }
97  inline G4String GetName() const
98  { return this->G4VSensitiveDetector::SensitiveDetectorName; }
100  virtual std::string path() const
101  { return this->G4VSensitiveDetector::GetPathName(); }
103  virtual std::string fullPath() const
104  { return this->G4VSensitiveDetector::GetFullPathName(); }
106  virtual bool isActive() const
107  { return this->G4VSensitiveDetector::isActive(); }
109  virtual G4int GetCollectionID(G4int i)
110  { return this->G4VSensitiveDetector::GetCollectionID(i); }
112  virtual G4VReadOutGeometry* readoutGeometry() const
113  { return this->G4VSensitiveDetector::GetROgeometry(); }
116  { return m_sensitive; }
118  virtual const std::string& sensitiveType() const
119  { return m_sequence->sensitiveType(); }
121  virtual G4bool Accept(const G4Step* step) const
122  { return m_sequence->accept(step); }
124  virtual void Initialize(G4HCofThisEvent* hce)
125  { m_sequence->begin(hce); }
127  virtual void EndOfEvent(G4HCofThisEvent* hce)
128  { m_sequence->end(hce); }
130  virtual G4bool ProcessHits(G4Step* step,G4TouchableHistory* hist)
131  { return m_sequence->process(step,hist); }
133  virtual void clear()
134  { m_sequence->clear(); }
136  virtual size_t defineCollection(const std::string& coll) {
137  if ( coll.empty() ) {
138  except("Geant4Sensitive: No collection defined for %s [Invalid name]",c_name());
139  }
140  collectionName.push_back(coll);
141  return collectionName.size()-1;
142  }
143 
144  };
145  } // End namespace Simulation
146 } // End namespace DD4hep
147 
148 
149 #include "DDG4/Factories.h"
150 
154 
Handle class to hold the information of a sensitive detector.
Definition: Detector.h:47
virtual void clear()
G4VSensitiveDetector interface: Method invoked if the event was aborted.
Geant4Kernel & worker(unsigned long thread_identifier, bool create_if=false)
Access worker instance by it's identifier.
static unsigned long int thread_self()
Access thread identifier.
bool accept(const G4Step *step) const
Callback before hit processing starts. Invoke all filters.
virtual ~RefCountedSequence()
Default destructor.
virtual void begin(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked at the begining of each event.
DD4hep::Simulation::Geant4SensDet Geant4SensDet
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:48
virtual void clear()
G4VSensitiveDetector interface: Method invoked if the event was aborted.
virtual const std::string & sensitiveType() const
Access to the sensitive type of the detector.
static void decrement(T *)
Decrement count according to type information.
#define DECLARE_GEANT4SENSITIVEDETECTOR(id)
Definition: Factories.h:154
Interface class to access properties of the underlying Geant4 sensitive detector structure.
virtual size_t defineCollection(const std::string &coll)
Initialize the usage of a hit collection. Returns the collection identifier.
virtual bool process(G4Step *step, G4TouchableHistory *hist)
Function to process hits.
virtual G4bool Accept(const G4Step *step) const
Callback if the sequence should be accepted or filtered off.
RefCountedSequence(T *seq)
Initializing constructor.
virtual void updateContext(Geant4Context *ctxt)
Set or update client context.
virtual void Initialize(G4HCofThisEvent *hce)
Method invoked at the begining of each event.
G4String GetName() const
Overload to avoid ambiguity between G4VSensitiveDetector and G4VSDFilter.
Geant4SensDetActionSequence * sensitiveAction(const std::string &name)
Access to the sensitive detector action from the actioncontainer object.
TGeoShape * s
Definition: Volumes.cpp:294
virtual SensitiveDetector sensitiveDetector(const std::string &name) const =0
Retrieve a sensitive detector by it's name from the detector description.
DD4hep::Simulation::Geant4SensDet Geant4tracker
virtual const std::string & sensitiveType() const
Access to the sensitive type of the detector.
const char * c_name() const
Access name of the action.
Definition: Geant4Action.h:275
Geant4Context * m_context
Reference to the Geant4 context.
Definition: Geant4Action.h:94
void except(const char *fmt,...) const
Support of exceptions: Print fatal message and throw runtime_error.
void releasePtr(T &p)
Helper to delete objects from heap and reset the pointer. Saves many many lines of code...
Definition: Primitives.h:316
virtual G4bool ProcessHits(G4Step *step, G4TouchableHistory *hist)
Method for generating hit(s) using the information of G4Step object.
int m_outputLevel
Default property: Output level.
Definition: Geant4Action.h:99
virtual SensitiveDetector sensitiveDetector() const
Access to the LCDD sensitive detector handle.
virtual G4VReadOutGeometry * readoutGeometry() const
Access to the readout geometry of the sensitive detector.
Class, which allows all Geant4Action derivatives to access the DDG4 kernel structures.
Definition: Geant4Kernel.h:43
virtual void end(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked at the end of each event.
SensitiveDetector m_sensitive
Access to the geant4 sensitive detector handle.
virtual bool isActive() const
Is the detector active?
DD4hep::Simulation::Geant4SensDet Geant4calorimeter
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:44
RefCountedSequence()
Default constructor.
virtual void EndOfEvent(G4HCofThisEvent *hce)
Method invoked at the end of each event.
virtual G4int GetCollectionID(G4int i)
This is a utility method which returns the hits collection ID.
Geant4Context * workerContext()
Thread's Geant4 execution context.
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
virtual std::string path() const
G4VSensitiveDetector internals: Access to the detector path name.
virtual ~Geant4SensDet()
Destructor.
virtual std::string fullPath() const
G4VSensitiveDetector internals: Access to the detector path name.
The main interface to the DD4hep detector description package.
Definition: LCDD.h:82
Private helper to support sequence reference counting.
Concrete implementation of the G4VSensitiveDetector calling the registered sequence object...
size_t defineCollections(Geant4ActionSD *sens_det)
Called at construction time of the sensitive detector to declare all hit collections.
static Geant4Kernel & instance(LCDD &lcdd)
Instance accessor.
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:91
Geant4SensDet(const std::string &nam, Geometry::LCDD &lcdd)
Constructor. The detector element is identified by the name.
PrintLevel getOutputLevel(const std::string object) const
Retrieve the global output level of a named object.