DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4StepHandler.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 #ifndef DDG4_GEANT4STEPHANDLER_H
14 #define DDG4_GEANT4STEPHANDLER_H
15 
16 // Framework include files
17 #include <DDG4/Geant4HitHandler.h>
18 
19 // Geant4 include files
20 #include <G4Step.hh>
21 #include <G4StepPoint.hh>
22 #include <G4VTouchable.hh>
23 #include <G4VSensitiveDetector.hh>
24 #include <G4EmSaturation.hh>
25 #include <G4Version.hh>
26 
28 namespace dd4hep {
29 
31  namespace sim {
32 
33  // Forward declarations;
34  class Geant4StepHandler;
35 
37 
47  public:
48  const G4Step* step;
49  G4StepPoint* pre;
50  G4StepPoint* post;
53  Geant4StepHandler() = delete;
55  Geant4StepHandler(const G4Step* s)
56  : Geant4HitHandler(s->GetTrack(), (s->GetPreStepPoint()->GetTouchableHandle())()),
57  step(s), pre(s->GetPreStepPoint()), post(s->GetPostStepPoint())
58  {
59  applyBirksLaw = false;
60  }
69 
71  static const char* stepStatus(G4StepStatus status);
73  const char* preStepStatus() const;
75  const char* postStepStatus() const;
77  double totalEnergy() const {
78  if(applyBirksLaw == true)
79  return this->birkAttenuation();
80  else
81  return step->GetTotalEnergyDeposit();
82  }
84  Position prePos() const {
85  const G4ThreeVector& p = pre->GetPosition();
86  return Position(p.x(), p.y(), p.z());
87  }
89  const G4ThreeVector& prePosG4() const {
90  return pre->GetPosition();
91  }
93  Position postPos() const {
94  const G4ThreeVector& p = post->GetPosition();
95  return Position(p.x(), p.y(), p.z());
96  }
98  const G4ThreeVector& postPosG4() const {
99  return post->GetPosition();
100  }
102  G4ThreeVector avgPositionG4() const {
103  const G4ThreeVector& p1 = pre->GetPosition();
104  const G4ThreeVector& p2 = post->GetPosition();
105  G4ThreeVector r = 0.5*(p2+p1);
106  return r;
107  }
110  const G4ThreeVector& p1 = pre->GetPosition();
111  const G4ThreeVector& p2 = post->GetPosition();
112  G4ThreeVector r = 0.5*(p2+p1);
113  return Position(r.x(),r.y(),r.z());
114  }
116  Position direction() const {
117  const G4ThreeVector& p1 = pre->GetPosition();
118  const G4ThreeVector& p2 = post->GetPosition();
119  G4ThreeVector r = (p2-p1);
120  double len = r.r();
121  if ( len > 1e-15 ) {
122  r /= len;
123  return Position(r.x(),r.y(),r.z());
124  }
125  return Position();
126  }
127  Momentum preMom() const {
128  const G4ThreeVector& p = pre->GetMomentum();
129  return Momentum(p.x(), p.y(), p.z());
130  }
131  Momentum postMom() const {
132  const G4ThreeVector& p = post->GetMomentum();
133  return Momentum(p.x(), p.y(), p.z());
134  }
135  double deposit() const {
136  return step->GetTotalEnergyDeposit();
137  }
138  double stepLength() const {
139  return step->GetStepLength();
140  }
141  const G4VTouchable* preTouchable() const {
142  return pre->GetTouchable();
143  }
144  const G4VTouchable* postTouchable() const {
145  return post->GetTouchable();
146  }
147  const char* volName(const G4StepPoint* p, const char* undefined = "") const {
148  G4VPhysicalVolume* v = volume(p);
149  return v ? v->GetName().c_str() : undefined;
150  }
151  G4VPhysicalVolume* volume(const G4StepPoint* p) const {
152  return p->GetTouchableHandle()->GetVolume();
153  }
154  G4VSolid* solid(const G4StepPoint* p) const {
155  return p->GetTouchableHandle()->GetSolid();
156  }
157  G4VPhysicalVolume* physvol(const G4StepPoint* p) const {
158  return p->GetPhysicalVolume();
159  }
160  G4LogicalVolume* logvol(const G4StepPoint* p) const {
161  G4VPhysicalVolume* pv = physvol(p);
162  return pv ? pv->GetLogicalVolume() : 0;
163  }
164  G4VSensitiveDetector* sd(const G4StepPoint* p) const {
165  G4LogicalVolume* lv = logvol(p);
166  return lv ? lv->GetSensitiveDetector() : 0;
167  }
168  std::string sdName(const G4StepPoint* p, const std::string& undefined = "") const {
169  G4VSensitiveDetector* s = sd(p);
170  return s ? s->GetName().c_str() : undefined;
171  }
172  bool isSensitive(const G4StepPoint* point) const {
173  return point ? this->Geant4HitHandler::isSensitive(volume(point)) : false;
174  }
175  G4VPhysicalVolume* preVolume() const {
176  return volume(pre);
177  }
179  return sd(pre);
180  }
181  G4VPhysicalVolume* postVolume() const {
182  return volume(post);
183  }
185  return sd(post);
186  }
187  bool firstInVolume() const {
188  return step->IsFirstStepInVolume();
189  }
190  bool lastInVolume() const {
191  return step->IsLastStepInVolume();
192  }
194  double birkAttenuation() const;
196  void doApplyBirksLaw(void) {
197  applyBirksLaw = true;
198  }
199  };
200 
201  } // End namespace sim
202 } // End namespace dd4hep
203 
204 #endif // DDG4_GEANT4STEPHANDLER_H
dd4hep::sim::Geant4StepHandler::Geant4StepHandler
Geant4StepHandler(const Geant4StepHandler &copy)=delete
No copy constructor.
dd4hep::sim::Geant4StepHandler::prePos
Position prePos() const
Returns the pre-step position.
Definition: Geant4StepHandler.h:84
v
View * v
Definition: MultiView.cpp:28
dd4hep::sim::Momentum
Position Momentum
Definition: Defs.h:27
dd4hep::sim::Geant4StepHandler::pre
G4StepPoint * pre
Definition: Geant4StepHandler.h:49
dd4hep::sim::Geant4StepHandler::operator=
Geant4StepHandler & operator=(Geant4StepHandler &&copy)=delete
Move operator inhibited. Should not be copied.
dd4hep::sim::Geant4StepHandler::preMom
Momentum preMom() const
Definition: Geant4StepHandler.h:127
dd4hep::sim::Geant4StepHandler::volName
const char * volName(const G4StepPoint *p, const char *undefined="") const
Definition: Geant4StepHandler.h:147
dd4hep::sim::Geant4StepHandler::Geant4StepHandler
Geant4StepHandler()=delete
Inhibit default constructor.
Geant4HitHandler.h
dd4hep::sim::Geant4StepHandler::postMom
Momentum postMom() const
Definition: Geant4StepHandler.h:131
dd4hep::sim::Geant4StepHandler::isSensitive
bool isSensitive(const G4StepPoint *point) const
Definition: Geant4StepHandler.h:172
dd4hep::sim::Geant4StepHandler::applyBirksLaw
bool applyBirksLaw
Definition: Geant4StepHandler.h:51
dd4hep::sim::Geant4StepHandler::postTouchable
const G4VTouchable * postTouchable() const
Definition: Geant4StepHandler.h:144
dd4hep::sim::Geant4StepHandler::prePosG4
const G4ThreeVector & prePosG4() const
Returns the pre-step position as a G4ThreeVector.
Definition: Geant4StepHandler.h:89
dd4hep::sim::Geant4StepHandler::volume
G4VPhysicalVolume * volume(const G4StepPoint *p) const
Definition: Geant4StepHandler.h:151
dd4hep::sim::Geant4StepHandler::preVolume
G4VPhysicalVolume * preVolume() const
Definition: Geant4StepHandler.h:175
dd4hep::sim::Geant4StepHandler::lastInVolume
bool lastInVolume() const
Definition: Geant4StepHandler.h:190
dd4hep::sim::Geant4StepHandler::postStepStatus
const char * postStepStatus() const
Returns the post-step status in form of a string.
Definition: Geant4StepHandler.cpp:63
dd4hep::sim::Geant4StepHandler
Helper class to ease the extraction of information from a G4Step object.
Definition: Geant4StepHandler.h:46
dd4hep::sim::Geant4StepHandler::avgPositionG4
G4ThreeVector avgPositionG4() const
Average position vector of the step.
Definition: Geant4StepHandler.h:102
dd4hep::sim::Geant4StepHandler::post
G4StepPoint * post
Definition: Geant4StepHandler.h:50
dd4hep::sim::Geant4StepHandler::Geant4StepHandler
Geant4StepHandler(Geant4StepHandler &&copy)=delete
No move constructor.
dd4hep::sim::Geant4StepHandler::stepLength
double stepLength() const
Definition: Geant4StepHandler.h:138
dd4hep::sim::Geant4HitHandler
Helper class to ease the extraction of information from a G4Hit object.
Definition: Geant4HitHandler.h:42
G4VSensitiveDetector
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:59
dd4hep::sim::Geant4StepHandler::physvol
G4VPhysicalVolume * physvol(const G4StepPoint *p) const
Definition: Geant4StepHandler.h:157
dd4hep::sim::Geant4StepHandler::solid
G4VSolid * solid(const G4StepPoint *p) const
Definition: Geant4StepHandler.h:154
dd4hep::sim::Geant4StepHandler::operator=
Geant4StepHandler & operator=(const Geant4StepHandler &copy)=delete
Assignment operator inhibited. Should not be copied.
dd4hep::sim::Geant4HitHandler::isSensitive
bool isSensitive(const G4LogicalVolume *lv) const
Definition: Geant4HitHandler.h:102
dd4hep::sim::Geant4StepHandler::postVolume
G4VPhysicalVolume * postVolume() const
Definition: Geant4StepHandler.h:181
dd4hep::sim::Geant4StepHandler::postPosG4
const G4ThreeVector & postPosG4() const
Returns the post-step position as a G4ThreeVector.
Definition: Geant4StepHandler.h:98
dd4hep::sim::Geant4StepHandler::deposit
double deposit() const
Definition: Geant4StepHandler.h:135
dd4hep::sim::Geant4StepHandler::postPos
Position postPos() const
Returns the post-step position.
Definition: Geant4StepHandler.h:93
dd4hep::sim::Geant4StepHandler::birkAttenuation
double birkAttenuation() const
Apply BirksLaw.
Definition: Geant4StepHandler.cpp:68
dd4hep::sim::Geant4StepHandler::direction
Position direction() const
Direction calculated from the post- and pre-position ofthe step.
Definition: Geant4StepHandler.h:116
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:81
dd4hep::sim::Geant4StepHandler::step
const G4Step * step
Definition: Geant4StepHandler.h:48
dd4hep::sim::Geant4StepHandler::preSD
G4VSensitiveDetector * preSD() const
Definition: Geant4StepHandler.h:178
dd4hep::sim::Geant4StepHandler::stepStatus
static const char * stepStatus(G4StepStatus status)
Returns the step status (argument) in form of a string.
Definition: Geant4StepHandler.cpp:27
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4StepHandler::sdName
std::string sdName(const G4StepPoint *p, const std::string &undefined="") const
Definition: Geant4StepHandler.h:168
dd4hep::sim::Geant4StepHandler::doApplyBirksLaw
void doApplyBirksLaw(void)
Set applyBirksLaw to ture.
Definition: Geant4StepHandler.h:196
dd4hep::sim::Geant4StepHandler::postSD
G4VSensitiveDetector * postSD() const
Definition: Geant4StepHandler.h:184
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
dd4hep::sim::Geant4StepHandler::preStepStatus
const char * preStepStatus() const
Returns the pre-step status in form of a string.
Definition: Geant4StepHandler.cpp:58
dd4hep::sim::Geant4StepHandler::Geant4StepHandler
Geant4StepHandler(const G4Step *s)
Initializing constructor.
Definition: Geant4StepHandler.h:55
dd4hep::sim::Geant4StepHandler::avgPosition
Position avgPosition() const
Average position vector of the step.
Definition: Geant4StepHandler.h:109
dd4hep::sim::Geant4StepHandler::preTouchable
const G4VTouchable * preTouchable() const
Definition: Geant4StepHandler.h:141
dd4hep::sim::Geant4StepHandler::sd
G4VSensitiveDetector * sd(const G4StepPoint *p) const
Definition: Geant4StepHandler.h:164
dd4hep::sim::Geant4StepHandler::totalEnergy
double totalEnergy() const
Returns total energy deposit.
Definition: Geant4StepHandler.h:77
dd4hep::sim::Geant4StepHandler::firstInVolume
bool firstInVolume() const
Definition: Geant4StepHandler.h:187
dd4hep::sim::Geant4StepHandler::logvol
G4LogicalVolume * logvol(const G4StepPoint *p) const
Definition: Geant4StepHandler.h:160