DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4TrackHandler.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_GEANT4TRACKHANDLER_H
14 #define DDG4_GEANT4TRACKHANDLER_H
15 
16 // Framework include files
17 #include <DDG4/Defs.h>
18 
19 // Geant4 include files
20 #include <G4Track.hh>
21 #include <G4TrajectoryPoint.hh>
22 #include <G4VTouchable.hh>
23 #include <G4VSensitiveDetector.hh>
24 #include <G4ParticleDefinition.hh>
25 #include <G4DynamicParticle.hh>
26 #include <G4VProcess.hh>
27 
28 // C/C++ include files
29 #include <stdexcept>
30 
31 // Forward declarations
32 class G4VTouchableHandle;
34 
36 namespace dd4hep {
37 
39  namespace sim {
40 
41  // Forward declarations;
42  class Geant4TrackHandler;
43 
45 
54  public:
56  typedef G4ReferenceCountedHandle<G4VTouchable> Touchable;
58  const G4Track* track;
60  Geant4TrackHandler() = delete;
62  Geant4TrackHandler(const G4Track* t) : track(t) {
64  if ( 0 == t ) {
65  throw std::runtime_error("Geant4TrackHandler: NULL pointer passed to constructor!");
66  }
67  }
68  const char* statusName() const {
69  switch( track->GetTrackStatus() ) {
70  case fAlive: return "Alive";
71  case fStopButAlive: return "StopButAlive";
72  case fStopAndKill: return "StopAndKill";
73  case fKillTrackAndSecondaries: return "KillTrackAndSecondaries";
74  case fSuspend: return "Suspend";
75  case fPostponeToNextEvent: return "PostponeToNextEvent";
76  default: return "UNKNOWN";
77  }
78  }
79 
81  operator const G4Track*() const {
82  return track;
83  }
85  int id() const {
86  return track->GetTrackID();
87  }
89  int parent() const {
90  return track->GetParentID();
91  }
93  G4ParticleDefinition* trackDef() const {
94  return track->GetDefinition();
95  }
97  const std::string& name() const {
98  return trackDef()->GetParticleName();
99  }
101  const std::string& type() const {
102  return trackDef()->GetParticleType();
103  }
105  const G4ThreeVector& position() const {
106  return track->GetPosition();
107  }
109  const G4ThreeVector& vertex() const {
110  return track->GetVertexPosition();
111  }
113  double globalTime() const {
114  return track->GetGlobalTime();
115  }
117  double properTime() const {
118  return track->GetProperTime();
119  }
121  double energy() const {
122  return track->GetTotalEnergy();
123  }
125  double kineticEnergy() const {
126  return track->GetKineticEnergy();
127  }
129  double velocity() const {
130  return track->GetVelocity();
131  }
133  double length() const {
134  return track->GetTrackLength();
135  }
137  double time() const {
138  return track->GetGlobalTime();
139  }
141  double charge() const {
142  G4ParticleDefinition* def = trackDef();
143  return def ? def->GetPDGCharge() : 0;
144  }
146  double mass() const {
147  G4ParticleDefinition* def = trackDef();
148  return def ? def->GetPDGMass() : 0;
149  }
151  G4VPhysicalVolume* vol() const {
152  return track->GetVolume();
153  }
154  G4ThreeVector momentum() const {
155  return track->GetMomentum();
156  }
158  G4VPhysicalVolume* nextVol() const {
159  return track->GetNextVolume();
160  }
162  const G4LogicalVolume* vertexVol() const {
163  return track->GetLogicalVolumeAtVertex();
164  }
166  const Touchable& touchable() const {
167  return track->GetTouchableHandle();
168  }
170  const Touchable& nextTouchable() const {
171  return track->GetNextTouchableHandle();
172  }
174  const G4VProcess* creatorProcess() const {
175  return track->GetCreatorProcess();
176  }
178  const std::string creatorName() const {
179  const G4VProcess* p = creatorProcess();
180  if ( p ) return p->GetProcessName();
181  return "";
182  }
184  Info* userInfo() const {
185  return track->GetUserInformation();
186  }
188  template <typename T> T* info() const {
189  return (T*) userInfo();
190  }
192  const G4Step* step() const {
193  return track->GetStep();
194  }
196  G4int stepNumber() const {
197  return track->GetCurrentStepNumber();
198  }
200  int pdgID() const {
201  G4ParticleDefinition* def = trackDef();
202  return def ? def->GetPDGEncoding() : 0;
203  }
205  const G4DynamicParticle* dynamic() const {
206  return track->GetDynamicParticle();
207  }
209  const G4PrimaryParticle* primary() const {
210  const G4DynamicParticle* d = track->GetDynamicParticle();
211  if ( d ) return d->GetPrimaryParticle();
212  return 0;
213  }
214  };
215 
216  } // End namespace sim
217 } // End namespace dd4hep
218 #endif // DDG4_GEANT4TRACKHANDLER_H
dd4hep::sim::Geant4TrackHandler::Geant4TrackHandler
Geant4TrackHandler()=delete
Inhibit default constructor.
dd4hep::sim::Geant4TrackHandler::stepNumber
G4int stepNumber() const
Step number.
Definition: Geant4TrackHandler.h:196
dd4hep::sim::Geant4TrackHandler::vol
G4VPhysicalVolume * vol() const
Physical (original) volume of the track.
Definition: Geant4TrackHandler.h:151
dd4hep::sim::Geant4TrackHandler::touchable
const Touchable & touchable() const
Touchable of the track.
Definition: Geant4TrackHandler.h:166
dd4hep::sim::Geant4TrackHandler::kineticEnergy
double kineticEnergy() const
Track's kinetic energy.
Definition: Geant4TrackHandler.h:125
dd4hep::sim::Geant4TrackHandler::position
const G4ThreeVector & position() const
Track's position.
Definition: Geant4TrackHandler.h:105
dd4hep::sim::Geant4TrackHandler::globalTime
double globalTime() const
Track global time.
Definition: Geant4TrackHandler.h:113
G4VUserTrackInformation
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:75
dd4hep::sim::Geant4TrackHandler::step
const G4Step * step() const
Step information.
Definition: Geant4TrackHandler.h:192
dd4hep::sim::Geant4TrackHandler::Geant4TrackHandler
Geant4TrackHandler(const G4Track *t)
Initializing constructor.
Definition: Geant4TrackHandler.h:62
dd4hep::sim::Geant4TrackHandler::parent
int parent() const
Track's parent identifier.
Definition: Geant4TrackHandler.h:89
dd4hep::sim::Geant4TrackHandler::time
double time() const
Track time.
Definition: Geant4TrackHandler.h:137
dd4hep::sim::Geant4TrackHandler::Info
G4VUserTrackInformation Info
Definition: Geant4TrackHandler.h:55
dd4hep::sim::Geant4TrackHandler::vertex
const G4ThreeVector & vertex() const
Track's vertex position, where the track was created.
Definition: Geant4TrackHandler.h:109
dd4hep::sim::Geant4TrackHandler::name
const std::string & name() const
Track's particle name.
Definition: Geant4TrackHandler.h:97
dd4hep::sim::Geant4TrackHandler::charge
double charge() const
Track charge.
Definition: Geant4TrackHandler.h:141
dd4hep::sim::Geant4TrackHandler::creatorProcess
const G4VProcess * creatorProcess() const
Physical process of the track generation.
Definition: Geant4TrackHandler.h:174
dd4hep::sim::Geant4TrackHandler
Helper class to ease the extraction of information from a G4Track object.
Definition: Geant4TrackHandler.h:53
dd4hep::sim::Geant4TrackHandler::track
const G4Track * track
Reference to the track object.
Definition: Geant4TrackHandler.h:58
dd4hep::sim::Geant4TrackHandler::pdgID
int pdgID() const
Access the PDG particle identification.
Definition: Geant4TrackHandler.h:200
dd4hep::sim::Geant4TrackHandler::velocity
double velocity() const
Track velocity.
Definition: Geant4TrackHandler.h:129
dd4hep::sim::Geant4TrackHandler::info
T * info() const
Specific user information block.
Definition: Geant4TrackHandler.h:188
dd4hep::sim::Geant4TrackHandler::statusName
const char * statusName() const
Definition: Geant4TrackHandler.h:68
dd4hep::sim::Geant4TrackHandler::momentum
G4ThreeVector momentum() const
Definition: Geant4TrackHandler.h:154
dd4hep::sim::Geant4TrackHandler::length
double length() const
Track length.
Definition: Geant4TrackHandler.h:133
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4TrackHandler::trackDef
G4ParticleDefinition * trackDef() const
Track's particle definition.
Definition: Geant4TrackHandler.h:93
dd4hep::sim::Geant4TrackHandler::vertexVol
const G4LogicalVolume * vertexVol() const
Logical volume of the origine vertex.
Definition: Geant4TrackHandler.h:162
dd4hep::sim::Geant4TrackHandler::userInfo
Info * userInfo() const
User information block.
Definition: Geant4TrackHandler.h:184
dd4hep::sim::Geant4TrackHandler::nextTouchable
const Touchable & nextTouchable() const
Next touchable of the track.
Definition: Geant4TrackHandler.h:170
dd4hep::sim::Geant4TrackHandler::primary
const G4PrimaryParticle * primary() const
Access the primary particle of the track object (if present)
Definition: Geant4TrackHandler.h:209
dd4hep::sim::Geant4TrackHandler::properTime
double properTime() const
Track proper time.
Definition: Geant4TrackHandler.h:117
dd4hep::sim::Geant4TrackHandler::dynamic
const G4DynamicParticle * dynamic() const
Access the dynamic particle of the track object.
Definition: Geant4TrackHandler.h:205
dd4hep::sim::Geant4TrackHandler::mass
double mass() const
Track charge.
Definition: Geant4TrackHandler.h:146
dd4hep::sim::Geant4TrackHandler::id
int id() const
Track's identifier.
Definition: Geant4TrackHandler.h:85
dd4hep::sim::Geant4TrackHandler::Touchable
G4ReferenceCountedHandle< G4VTouchable > Touchable
Definition: Geant4TrackHandler.h:56
dd4hep::sim::Geant4TrackHandler::energy
double energy() const
Track's energy.
Definition: Geant4TrackHandler.h:121
dd4hep::sim::Geant4TrackHandler::type
const std::string & type() const
Track's particle type.
Definition: Geant4TrackHandler.h:101
dd4hep::sim::Geant4TrackHandler::creatorName
const std::string creatorName() const
Physical process of the track generation.
Definition: Geant4TrackHandler.h:178
Defs.h
dd4hep::sim::Geant4TrackHandler::nextVol
G4VPhysicalVolume * nextVol() const
Next physical volume of the track.
Definition: Geant4TrackHandler.h:158