DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4TestActions.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/InstanceCount.h>
17 #include <DDG4/Geant4TestActions.h>
18 #include <G4Run.hh>
19 #include <G4Event.hh>
20 #include <G4Step.hh>
21 #include <G4Track.hh>
22 
23 // C/C++ include files
24 #include <stdexcept>
25 
26 using namespace dd4hep::sim::Test;
27 
28 namespace {
29  struct TestHit {
30  TestHit() {
31  }
32  virtual ~TestHit() {
33  }
34  };
35 }
36 
37 #define PRINT print
38 
39 
41 Geant4TestBase::Geant4TestBase(Geant4Action* a, const std::string& typ)
42  : m_type(typ) {
43  a->declareProperty("Property_int", m_value1 = 0);
44  a->declareProperty("Property_double", m_value2 = 0e0);
45  a->declareProperty("Property_string", m_value3);
47 }
50  printout(VERBOSE, m_type, "properties at destruction: %d, %f, %s", m_value1, m_value2, m_value3.c_str());
52 }
53 
56  : Geant4GeneratorAction(c, n), Geant4TestBase(this, "Geant4TestGeneratorAction") {
58 }
59 
63 }
64 
67  PRINT("%s> calling Geant4TestGeneratorAction(event_id=%d Context: run=%p evt=%p)",
68  m_type.c_str(), evt->GetEventID(), context()->runPtr(), context()->eventPtr());
69 }
70 
73  : Geant4RunAction(c, n), Geant4TestBase(this, "Geant4TestRunAction") {
75 }
76 
80 }
81 
83 void Geant4TestRunAction::begin(const G4Run* run) {
84  PRINT("%s> calling begin(run_id=%d,num_event=%d Context:%p)", m_type.c_str(), run->GetRunID(),
85  run->GetNumberOfEventToBeProcessed(), &context()->run());
86 }
87 
89 void Geant4TestRunAction::end(const G4Run* run) {
90  PRINT("%s> calling end(run_id=%d, num_event=%d Context:%p)",
91  m_type.c_str(), run->GetRunID(), run->GetNumberOfEvent(), &context()->run());
92 }
93 
95 void Geant4TestRunAction::beginEvent(const G4Event* evt) {
96  PRINT("%s> calling beginEvent(event_id=%d Context: run=%p evt=%p)",
97  m_type.c_str(), evt->GetEventID(), context()->runPtr(), context()->eventPtr());
98 }
99 
101 void Geant4TestRunAction::endEvent(const G4Event* evt) {
102  PRINT("%s> calling endEvent(event_id=%d Context: run=%p evt=%p)",
103  m_type.c_str(), evt->GetEventID(), context()->runPtr(), context()->eventPtr());
104 }
105 
108  : Geant4EventAction(c, n), Geant4TestBase(this, "Geant4TestEventAction") {
110 }
111 
115 }
117 void Geant4TestEventAction::begin(const G4Event* evt) {
118  PRINT("%s> calling begin(event_id=%d Context: run=%p (%d) evt=%p (%d))",
119  m_type.c_str(), evt->GetEventID(),
120  &context()->run(), context()->run().run().GetRunID(),
121  &context()->event(), context()->event().event().GetEventID());
122 }
123 
125 void Geant4TestEventAction::end(const G4Event* evt) {
126  PRINT("%s> calling end(event_id=%d Context: run=%p (%d) evt=%p (%d))",
127  m_type.c_str(), evt->GetEventID(), &context()->run(), &context()->event(),
128  &context()->run(), context()->run().run().GetRunID(),
129  &context()->event(), context()->event().event().GetEventID());
130 }
131 
133 void Geant4TestEventAction::beginRun(const G4Run* run) {
134  PRINT("%s> calling beginRun(run_id=%d,num_event=%d Context:%p)",
135  m_type.c_str(), run->GetRunID(),
136  run->GetNumberOfEventToBeProcessed(), context()->runPtr());
137 }
138 
140 void Geant4TestEventAction::endRun(const G4Run* run) {
141  PRINT("%s> calling endRun(run_id=%d, num_event=%d Context:%p)",
142  m_type.c_str(), run->GetRunID(),
143  run->GetNumberOfEvent(), context()->runPtr());
144 }
145 
148  : Geant4TrackingAction(c, n), Geant4TestBase(this, "Geant4TestTrackAction") {
150 }
151 
155 }
157 void Geant4TestTrackAction::begin(const G4Track* trk) {
158  PRINT("%s> calling begin(track=%d, parent=%d, position=(%f,%f,%f) Context: run=%p evt=%p)",
159  m_type.c_str(), trk->GetTrackID(),
160  trk->GetParentID(), trk->GetPosition().x(), trk->GetPosition().y(), trk->GetPosition().z(),
161  &context()->run(), &context()->event());
162 }
163 
165 void Geant4TestTrackAction::end(const G4Track* trk) {
166  PRINT("%s> calling end(track=%d, parent=%d, position=(%f,%f,%f) Context: run=%p evt=%p)",
167  m_type.c_str(), trk->GetTrackID(),
168  trk->GetParentID(), trk->GetPosition().x(), trk->GetPosition().y(), trk->GetPosition().z(),
169  &context()->run(), &context()->event());
170 }
171 
174  : Geant4SteppingAction(c, n), Geant4TestBase(this, "Geant4TestStepAction") {
176 }
177 
181 }
183 void Geant4TestStepAction::operator()(const G4Step*, G4SteppingManager*) {
184  PRINT("%s> calling operator()", m_type.c_str());
185 }
186 
189  : Geant4StackingAction(c, n), Geant4TestBase(this, "Geant4TestStackAction") {
191 }
192 
196 }
198 void Geant4TestStackAction::newStage(G4StackManager*) {
199  PRINT("%s> calling newStage()", m_type.c_str());
200 }
202 void Geant4TestStackAction::prepare(G4StackManager*) {
203  PRINT("%s> calling prepare()", m_type.c_str());
204 }
207  PRINT("%s> calling classifyNewTrack(track=%d, parent=%d, position=(%f,%f,%f) Context: run=%p evt=%p)",
208  m_type.c_str(), trk->GetTrackID(),
209  trk->GetParentID(), trk->GetPosition().x(), trk->GetPosition().y(), trk->GetPosition().z(),
210  &context()->run(), &context()->event());
211  return TrackClassification();
212 }
213 
216  : Geant4Sensitive(c, n, det, description), Geant4TestBase(this, "Geant4TestSensitive") {
218  m_collectionID = defineCollection < TestHit > (n);
219  PRINT("%s> Collection ID is %d", m_type.c_str(), int(m_collectionID));
220 }
221 
225 }
226 
228 void Geant4TestSensitive::begin(G4HCofThisEvent* hce) {
230  PRINT("%s> calling begin(num_coll=%d, coll=%s Context: run=%p evt=%p)",
231  m_type.c_str(), hce->GetNumberOfCollections(),
232  c ? c->GetName().c_str() : "None", &context()->run(), &context()->event());
233 }
234 
236 void Geant4TestSensitive::end(G4HCofThisEvent* hce) {
238  PRINT("%s> calling end(num_coll=%d, coll=%s Context: run=%p evt=%p)",
239  m_type.c_str(), hce->GetNumberOfCollections(),
240  c ? c->GetName().c_str() : "None", &context()->run(), &context()->event());
241 }
242 
244 bool Geant4TestSensitive::process(const G4Step* step, G4TouchableHistory*) {
246  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)",
247  m_type.c_str(), step->GetTrack()->GetTrackID(),
248  step->GetTotalEnergyDeposit(), step->GetDeltaTime(),
249  step->GetStepLength(), step->IsFirstStepInVolume() ? 'Y' : 'N',
250  step->IsLastStepInVolume() ? 'Y' : 'N',
251  c ? c->GetName().c_str() : "None", &context()->run(), &context()->event());
252  return true;
253 }
dd4hep::sim::Test::Geant4TestStepAction::operator()
void operator()(const G4Step *, G4SteppingManager *) override
User stepping callback.
Definition: Geant4TestActions.cpp:183
dd4hep::sim::Test::Geant4TestBase::m_type
std::string m_type
Definition: Geant4TestActions.h:48
dd4hep::sim::Test::Geant4TestEventAction::end
virtual void end(const G4Event *) override
End-of-event callback.
Definition: Geant4TestActions.cpp:125
dd4hep::sim::Geant4SteppingAction
Concrete implementation of the Geant4 stepping action sequence.
Definition: Geant4SteppingAction.h:40
dd4hep::sim::Test::Geant4TestEventAction::Geant4TestEventAction
Geant4TestEventAction(Geant4Context *c, const std::string &n)
Standard constructor with initializing arguments.
Definition: Geant4TestActions.cpp:107
dd4hep::sim::Test::Geant4TestStepAction::Geant4TestStepAction
Geant4TestStepAction(Geant4Context *c, const std::string &n)
Standard constructor with initializing arguments.
Definition: Geant4TestActions.cpp:173
dd4hep::sim::Test::Geant4TestBase::m_value1
int m_value1
Definition: Geant4TestActions.h:45
dd4hep::sim::Test::Geant4TestTrackAction::begin
virtual void begin(const G4Track *) override
Begin-of-tracking callback.
Definition: Geant4TestActions.cpp:157
dd4hep::sim::Test::Geant4TestRunAction::begin
void begin(const G4Run *) override
begin-of-run callback
Definition: Geant4TestActions.cpp:83
dd4hep::sim::Test::Geant4TestBase::Geant4TestBase
Geant4TestBase(Geant4Action *action, const std::string &typ)
Standard constructor.
Definition: Geant4TestActions.cpp:41
dd4hep::sim::Test::Geant4TestSensitive::~Geant4TestSensitive
virtual ~Geant4TestSensitive()
Default destructor.
Definition: Geant4TestActions.cpp:223
dd4hep::sim::Geant4HitCollection
Generic hit container class using Geant4HitWrapper objects.
Definition: Geant4HitCollection.h:201
dd4hep::sim::Test::Geant4TestEventAction::endRun
void endRun(const G4Run *)
End-of-run callback.
Definition: Geant4TestActions.cpp:140
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Test::Geant4TestStackAction::prepare
virtual void prepare(G4StackManager *) override
Preparation callback.
Definition: Geant4TestActions.cpp:202
dd4hep::sim::Test::Geant4TestStackAction::newStage
virtual void newStage(G4StackManager *) override
New-stage callback.
Definition: Geant4TestActions.cpp:198
dd4hep::sim::Geant4Sensitive::collection
Geant4HitCollection * collection(std::size_t which)
Retrieve the hits collection associated with this detector by its serial number.
Definition: Geant4SensDetAction.cpp:196
dd4hep::sim::Test::Geant4TestStackAction::classifyNewTrack
virtual TrackClassification classifyNewTrack(G4StackManager *, const G4Track *) override
Return TrackClassification with enum G4ClassificationOfNewTrack or NoTrackClassification.
Definition: Geant4TestActions.cpp:206
dd4hep::sim::Test::Geant4TestTrackAction::~Geant4TestTrackAction
virtual ~Geant4TestTrackAction()
Default destructor.
Definition: Geant4TestActions.cpp:153
dd4hep::sim::Test::Geant4TestRunAction::~Geant4TestRunAction
virtual ~Geant4TestRunAction()
Default destructor.
Definition: Geant4TestActions.cpp:78
dd4hep::sim::Geant4EventAction
Concrete basic implementation of the Geant4 event action.
Definition: Geant4EventAction.h:53
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::sim::Test::Geant4TestRunAction::beginEvent
void beginEvent(const G4Event *)
begin-of-event callback
Definition: Geant4TestActions.cpp:95
dd4hep::sim::Test::Geant4TestStepAction::~Geant4TestStepAction
virtual ~Geant4TestStepAction()
Default destructor.
Definition: Geant4TestActions.cpp:179
dd4hep::sim::Test::Geant4TestBase::m_value2
double m_value2
Definition: Geant4TestActions.h:46
dd4hep::sim::Test::Geant4TestEventAction::begin
virtual void begin(const G4Event *) override
begin-of-event callback
Definition: Geant4TestActions.cpp:117
dd4hep::sim::Test::Geant4TestRunAction::endEvent
void endEvent(const G4Event *)
End-of-event callback.
Definition: Geant4TestActions.cpp:101
dd4hep::sim::Test::Geant4TestSensitive::Geant4TestSensitive
Geant4TestSensitive(Geant4Context *c, const std::string &n, DetElement det, Detector &description)
Standard constructor with initializing arguments.
Definition: Geant4TestActions.cpp:215
dd4hep::sim::Geant4Action::declareProperty
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
Definition: Geant4Action.h:366
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Test::Geant4TestStackAction::Geant4TestStackAction
Geant4TestStackAction(Geant4Context *c, const std::string &n)
Standard constructor with initializing arguments.
Definition: Geant4TestActions.cpp:188
dd4hep::sim::Geant4GeneratorAction
Concrete implementation of the Geant4 generator action base class.
Definition: Geant4GeneratorAction.h:47
dd4hep::sim::Test::Geant4TestGeneratorAction::~Geant4TestGeneratorAction
virtual ~Geant4TestGeneratorAction()
Default destructor.
Definition: Geant4TestActions.cpp:61
dd4hep::sim::Test::Geant4TestGeneratorAction::operator()
virtual void operator()(G4Event *) override
Callback to generate primary particles.
Definition: Geant4TestActions.cpp:66
dd4hep::sim::Geant4Action
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:113
dd4hep::sim::Test::Geant4TestBase::~Geant4TestBase
virtual ~Geant4TestBase()
Default destructor.
Definition: Geant4TestActions.cpp:49
dd4hep::sim::Test::Geant4TestRunAction::Geant4TestRunAction
Geant4TestRunAction(Geant4Context *c, const std::string &n)
Standard constructor with initializing arguments.
Definition: Geant4TestActions.cpp:72
dd4hep::sim::Test::Geant4TestSensitive::end
virtual void end(G4HCofThisEvent *) override
End-of-tracking callback.
Definition: Geant4TestActions.cpp:236
dd4hep::sim::Test::Geant4TestGeneratorAction::Geant4TestGeneratorAction
Geant4TestGeneratorAction(Geant4Context *c, const std::string &n)
Standard constructor with initializing arguments.
Definition: Geant4TestActions.cpp:55
dd4hep::sim::Test::Geant4TestEventAction::~Geant4TestEventAction
virtual ~Geant4TestEventAction()
Default destructor.
Definition: Geant4TestActions.cpp:113
PRINT
#define PRINT
Definition: Geant4TestActions.cpp:37
dd4hep::sim::Geant4TrackingAction
Default base class for all geant 4 tracking actions used in DDG4.
Definition: Geant4TrackingAction.h:41
Geant4TestActions.h
dd4hep::sim::TrackClassification
Definition: Geant4StackingAction.h:39
dd4hep::sim::Test::Geant4TestSensitive::begin
virtual void begin(G4HCofThisEvent *) override
Begin-of-tracking callback.
Definition: Geant4TestActions.cpp:228
dd4hep::sim::Test::Geant4TestRunAction::end
void end(const G4Run *) override
End-of-run callback.
Definition: Geant4TestActions.cpp:89
dd4hep::sim::Geant4RunAction
Concrete basic implementation of the Geant4 run action base class.
Definition: Geant4RunAction.h:45
det
DetElement::Object * det
Definition: AlignmentsCalculator.cpp:66
dd4hep::sim::Test::Geant4TestEventAction::beginRun
void beginRun(const G4Run *)
begin-of-run callback
Definition: Geant4TestActions.cpp:133
dd4hep::sim::Test::Geant4TestTrackAction::end
virtual void end(const G4Track *) override
End-of-tracking callback.
Definition: Geant4TestActions.cpp:165
dd4hep::sim::Test::Geant4TestSensitive::process
virtual bool process(const G4Step *, G4TouchableHistory *) override
Method for generating hit(s) using the information of G4Step object.
Definition: Geant4TestActions.cpp:244
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::sim::Geant4StackingAction
Concrete implementation of the Geant4 stacking action base class.
Definition: Geant4StackingAction.h:52
dd4hep::sim::Test
Convenience namespace to separate test classes from the DDG4 simulation toolkit.
Definition: Geant4TestActions.h:35
dd4hep::sim::Geant4Sensitive
The base class for Geant4 sensitive detector actions implemented by users.
Definition: Geant4SensDetAction.h:121
dd4hep::sim::Test::Geant4TestBase::m_value3
std::string m_value3
Definition: Geant4TestActions.h:47
dd4hep::sim::Test::Geant4TestStackAction::~Geant4TestStackAction
virtual ~Geant4TestStackAction()
Default destructor.
Definition: Geant4TestActions.cpp:194
InstanceCount.h
dd4hep::sim::Test::Geant4TestBase
Common base class for test action.
Definition: Geant4TestActions.h:43
dd4hep::sim::Test::Geant4TestSensitive::m_collectionID
size_t m_collectionID
Definition: Geant4TestActions.h:179
Printout.h
dd4hep::sim::Geant4Sensitive::collectionByID
Geant4HitCollection * collectionByID(std::size_t id)
Retrieve the hits collection associated with this detector by its collection identifier.
Definition: Geant4SensDetAction.cpp:201
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::Test::Geant4TestTrackAction::Geant4TestTrackAction
Geant4TestTrackAction(Geant4Context *c, const std::string &n)
Standard constructor with initializing arguments.
Definition: Geant4TestActions.cpp:147