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
Geant4TestActions.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/InstanceCount.h"
18 #include "DDG4/Geant4TestActions.h"
19 #include "G4Run.hh"
20 #include "G4Event.hh"
21 #include "G4Step.hh"
22 #include "G4Track.hh"
23 
24 // C/C++ include files
25 #include <stdexcept>
26 
27 using namespace std;
28 using namespace DD4hep::Simulation;
29 using namespace DD4hep::Simulation::Test;
30 
31 namespace {
32  struct TestHit {
33  TestHit() {
34  }
35  virtual ~TestHit() {
36  }
37  };
38 }
39 
40 #define PRINT print
41 
42 
44 Geant4TestBase::Geant4TestBase(Geant4Action* a, const std::string& typ)
45  : m_type(typ) {
46  a->declareProperty("Property_int", m_value1 = 0);
47  a->declareProperty("Property_double", m_value2 = 0e0);
48  a->declareProperty("Property_string", m_value3);
50 }
54 }
55 
58  : Geant4GeneratorAction(c, n), Geant4TestBase(this, "Geant4TestGeneratorAction") {
60 }
61 
65 }
66 
69  PRINT("%s> calling Geant4TestGeneratorAction(event_id=%d Context: run=%p evt=%p)",
70  m_type.c_str(), evt->GetEventID(), context()->runPtr(), context()->eventPtr());
71 }
72 
75  : Geant4RunAction(c, n), Geant4TestBase(this, "Geant4TestRunAction") {
77 }
78 
82 }
83 
85 void Geant4TestRunAction::begin(const G4Run* run) {
86  PRINT("%s> calling begin(run_id=%d,num_event=%d Context:%p)", m_type.c_str(), run->GetRunID(),
87  run->GetNumberOfEventToBeProcessed(), &context()->run());
88 }
89 
91 void Geant4TestRunAction::end(const G4Run* run) {
92  PRINT("%s> calling end(run_id=%d, num_event=%d Context:%p)",
93  m_type.c_str(), run->GetRunID(), run->GetNumberOfEvent(), &context()->run());
94 }
95 
97 void Geant4TestRunAction::beginEvent(const G4Event* evt) {
98  PRINT("%s> calling beginEvent(event_id=%d Context: run=%p evt=%p)",
99  m_type.c_str(), evt->GetEventID(), context()->runPtr(), context()->eventPtr());
100 }
101 
103 void Geant4TestRunAction::endEvent(const G4Event* evt) {
104  PRINT("%s> calling endEvent(event_id=%d Context: run=%p evt=%p)",
105  m_type.c_str(), evt->GetEventID(), context()->runPtr(), context()->eventPtr());
106 }
107 
110  : Geant4EventAction(c, n), Geant4TestBase(this, "Geant4TestEventAction") {
112 }
113 
117 }
119 void Geant4TestEventAction::begin(const G4Event* evt) {
120  PRINT("%s> calling begin(event_id=%d Context: run=%p (%d) evt=%p (%d))",
121  m_type.c_str(), evt->GetEventID(),
122  &context()->run(), context()->run().run().GetRunID(),
123  &context()->event(), context()->event().event().GetEventID());
124 }
125 
127 void Geant4TestEventAction::end(const G4Event* evt) {
128  PRINT("%s> calling end(event_id=%d Context: run=%p (%d) evt=%p (%d))",
129  m_type.c_str(), evt->GetEventID(), &context()->run(), &context()->event(),
130  &context()->run(), context()->run().run().GetRunID(),
131  &context()->event(), context()->event().event().GetEventID());
132 }
133 
135 void Geant4TestEventAction::beginRun(const G4Run* run) {
136  PRINT("%s> calling beginRun(run_id=%d,num_event=%d Context:%p)",
137  m_type.c_str(), run->GetRunID(),
138  run->GetNumberOfEventToBeProcessed(), context()->runPtr());
139 }
140 
142 void Geant4TestEventAction::endRun(const G4Run* run) {
143  PRINT("%s> calling endRun(run_id=%d, num_event=%d Context:%p)",
144  m_type.c_str(), run->GetRunID(),
145  run->GetNumberOfEvent(), context()->runPtr());
146 }
147 
150  : Geant4TrackingAction(c, n), Geant4TestBase(this, "Geant4TestTrackAction") {
152 }
153 
157 }
159 void Geant4TestTrackAction::begin(const G4Track* trk) {
160  PRINT("%s> calling begin(track=%d, parent=%d, position=(%f,%f,%f) Context: run=%p evt=%p)",
161  m_type.c_str(), trk->GetTrackID(),
162  trk->GetParentID(), trk->GetPosition().x(), trk->GetPosition().y(), trk->GetPosition().z(),
163  &context()->run(), &context()->event());
164 }
165 
167 void Geant4TestTrackAction::end(const G4Track* trk) {
168  PRINT("%s> calling end(track=%d, parent=%d, position=(%f,%f,%f) Context: run=%p evt=%p)",
169  m_type.c_str(), trk->GetTrackID(),
170  trk->GetParentID(), trk->GetPosition().x(), trk->GetPosition().y(), trk->GetPosition().z(),
171  &context()->run(), &context()->event());
172 }
173 
176  : Geant4SteppingAction(c, n), Geant4TestBase(this, "Geant4TestStepAction") {
178 }
179 
183 }
185 void Geant4TestStepAction::operator()(const G4Step*, G4SteppingManager*) {
186  PRINT("%s> calling operator()", m_type.c_str());
187 }
188 
191  : Geant4Sensitive(c, n, det, lcdd), Geant4TestBase(this, "Geant4TestSensitive") {
193  m_collectionID = defineCollection < TestHit > (n);
194  PRINT("%s> Collection ID is %d", m_type.c_str(), int(m_collectionID));
195 }
196 
200 }
201 
203 void Geant4TestSensitive::begin(G4HCofThisEvent* hce) {
205  PRINT("%s> calling begin(num_coll=%d, coll=%s Context: run=%p evt=%p)",
206  m_type.c_str(), hce->GetNumberOfCollections(),
207  c ? c->GetName().c_str() : "None", &context()->run(), &context()->event());
208 }
209 
211 void Geant4TestSensitive::end(G4HCofThisEvent* hce) {
213  PRINT("%s> calling end(num_coll=%d, coll=%s Context: run=%p evt=%p)",
214  m_type.c_str(), hce->GetNumberOfCollections(),
215  c ? c->GetName().c_str() : "None", &context()->run(), &context()->event());
216 }
217 
219 bool Geant4TestSensitive::process(G4Step* step, G4TouchableHistory*) {
221  PRINT("%s> calling process(track=%d, dE=%f, dT=%f len=%f, First,last in Vol=(%c,%c), coll=%s Context: run=%p evt=%p)",
222  m_type.c_str(), step->GetTrack()->GetTrackID(),
223  step->GetTotalEnergyDeposit(), step->GetDeltaTime(),
224  step->GetStepLength(), step->IsFirstStepInVolume() ? 'Y' : 'N',
225  step->IsLastStepInVolume() ? 'Y' : 'N',
226  c ? c->GetName().c_str() : "None", &context()->run(), &context()->event());
227  return true;
228 }
virtual void begin(const G4Event *)
begin-of-event callback
Geant4TestSensitive(Geant4Context *c, const std::string &n, DetElement det, LCDD &lcdd)
Standard constructor with initializing arguments.
Geant4Event & event() const
Access the geant4 event – valid only between BeginEvent() and EndEvent()!
Geant4TestStepAction(Geant4Context *c, const std::string &n)
Standard constructor with initializing arguments.
virtual ~Geant4TestEventAction()
Default destructor.
HitCollection * collection(size_t which)
Retrieve the hits collection associated with this detector by its serial number.
static void decrement(T *)
Decrement count according to type information.
Common base class for test action.
Default base class for all geant 4 tracking actions used in DDG4.
virtual bool process(G4Step *, G4TouchableHistory *)
Method for generating hit(s) using the information of G4Step object.
const G4Run & run() const
Access the G4Event directly: Explicit G4Run accessor.
Definition: Geant4Context.h:84
Concrete basic implementation of the Geant4 run action base class.
Concrete basic implementation of the Geant4 event action.
void beginRun(const G4Run *)
begin-of-run callback
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:261
Concrete implementation of the Geant4 stepping action sequence.
Geant4TestEventAction(Geant4Context *c, const std::string &n)
Standard constructor with initializing arguments.
virtual void begin(G4HCofThisEvent *)
Begin-of-tracking callback.
void endEvent(const G4Event *)
End-of-event callback.
Geant4TestGeneratorAction(Geant4Context *c, const std::string &n)
Standard constructor with initializing arguments.
HitCollection * collectionByID(size_t id)
Retrieve the hits collection associated with this detector by its collection identifier.
The base class for Geant4 sensitive detector actions implemented by users.
void beginEvent(const G4Event *)
begin-of-event callback
Geant4Run & run() const
Access the geant4 run – valid only between BeginRun() and EndRun()!
void begin(const G4Run *)
begin-of-run callback
virtual void end(G4HCofThisEvent *)
End-of-tracking callback.
void end(const G4Run *)
End-of-run callback.
Concrete implementation of the Geant4 generator action base class.
const G4Event & event() const
Access the G4Event directly: Explicit G4Event accessor.
Generic hit container class using Geant4HitWrapper objects.
void endRun(const G4Run *)
End-of-run callback.
void operator()(const G4Step *, G4SteppingManager *)
User stepping callback.
virtual void operator()(G4Event *)
Callback to generate primary particles.
virtual ~Geant4TestTrackAction()
Default destructor.
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
Handle class describing a detector element.
Definition: Detector.h:172
Geant4Event * eventPtr() const
Access the geant4 event by ptr. Must be checked by clients!
Geant4TestTrackAction(Geant4Context *c, const std::string &n)
Standard constructor with initializing arguments.
virtual void end(const G4Event *)
End-of-event callback.
Generic context to extend user, run and event information.
Geant4TestRunAction(Geant4Context *c, const std::string &n)
Standard constructor with initializing arguments.
The main interface to the DD4hep detector description package.
Definition: LCDD.h:82
#define PRINT
virtual ~Geant4TestRunAction()
Default destructor.
virtual ~Geant4TestSensitive()
Default destructor.
virtual void begin(const G4Track *)
Begin-of-tracking callback.
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
Definition: Geant4Action.h:358
virtual ~Geant4TestBase()
Default destructor.
virtual ~Geant4TestStepAction()
Default destructor.
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:91
Geant4Run * runPtr() const
Access the geant4 run by ptr. Must be checked by clients!
virtual void end(const G4Track *)
End-of-tracking callback.