File indexing completed on 2025-01-18 09:55:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DDG4_GEANT4TRACKHANDLER_H
0014 #define DDG4_GEANT4TRACKHANDLER_H
0015
0016
0017 #include <DDG4/Defs.h>
0018
0019
0020 #include <G4Track.hh>
0021 #include <G4TrajectoryPoint.hh>
0022 #include <G4VTouchable.hh>
0023 #include <G4VSensitiveDetector.hh>
0024 #include <G4ParticleDefinition.hh>
0025 #include <G4DynamicParticle.hh>
0026 #include <G4VProcess.hh>
0027
0028
0029 #include <stdexcept>
0030
0031
0032 class G4VTouchableHandle;
0033 class G4VUserTrackInformation;
0034
0035
0036 namespace dd4hep {
0037
0038
0039 namespace sim {
0040
0041
0042 class Geant4TrackHandler;
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 class Geant4TrackHandler {
0054 public:
0055 typedef G4VUserTrackInformation Info;
0056 typedef G4ReferenceCountedHandle<G4VTouchable> Touchable;
0057
0058 const G4Track* track;
0059
0060 Geant4TrackHandler() = delete;
0061
0062 Geant4TrackHandler(const G4Track* t) : track(t) {
0063
0064 if ( 0 == t ) {
0065 throw std::runtime_error("Geant4TrackHandler: NULL pointer passed to constructor!");
0066 }
0067 }
0068 const char* statusName() const {
0069 switch( track->GetTrackStatus() ) {
0070 case fAlive: return "Alive";
0071 case fStopButAlive: return "StopButAlive";
0072 case fStopAndKill: return "StopAndKill";
0073 case fKillTrackAndSecondaries: return "KillTrackAndSecondaries";
0074 case fSuspend: return "Suspend";
0075 case fPostponeToNextEvent: return "PostponeToNextEvent";
0076 default: return "UNKNOWN";
0077 }
0078 }
0079
0080
0081 operator const G4Track*() const {
0082 return track;
0083 }
0084
0085 int id() const {
0086 return track->GetTrackID();
0087 }
0088
0089 int parent() const {
0090 return track->GetParentID();
0091 }
0092
0093 G4ParticleDefinition* trackDef() const {
0094 return track->GetDefinition();
0095 }
0096
0097 const std::string& name() const {
0098 return trackDef()->GetParticleName();
0099 }
0100
0101 const std::string& type() const {
0102 return trackDef()->GetParticleType();
0103 }
0104
0105 const G4ThreeVector& position() const {
0106 return track->GetPosition();
0107 }
0108
0109 const G4ThreeVector& vertex() const {
0110 return track->GetVertexPosition();
0111 }
0112
0113 double globalTime() const {
0114 return track->GetGlobalTime();
0115 }
0116
0117 double properTime() const {
0118 return track->GetProperTime();
0119 }
0120
0121 double energy() const {
0122 return track->GetTotalEnergy();
0123 }
0124
0125 double kineticEnergy() const {
0126 return track->GetKineticEnergy();
0127 }
0128
0129 double velocity() const {
0130 return track->GetVelocity();
0131 }
0132
0133 double length() const {
0134 return track->GetTrackLength();
0135 }
0136
0137 double time() const {
0138 return track->GetGlobalTime();
0139 }
0140
0141 double charge() const {
0142 G4ParticleDefinition* def = trackDef();
0143 return def ? def->GetPDGCharge() : 0;
0144 }
0145
0146 double mass() const {
0147 G4ParticleDefinition* def = trackDef();
0148 return def ? def->GetPDGMass() : 0;
0149 }
0150
0151 G4VPhysicalVolume* vol() const {
0152 return track->GetVolume();
0153 }
0154 G4ThreeVector momentum() const {
0155 return track->GetMomentum();
0156 }
0157
0158 G4VPhysicalVolume* nextVol() const {
0159 return track->GetNextVolume();
0160 }
0161
0162 const G4LogicalVolume* vertexVol() const {
0163 return track->GetLogicalVolumeAtVertex();
0164 }
0165
0166 const Touchable& touchable() const {
0167 return track->GetTouchableHandle();
0168 }
0169
0170 const Touchable& nextTouchable() const {
0171 return track->GetNextTouchableHandle();
0172 }
0173
0174 const G4VProcess* creatorProcess() const {
0175 return track->GetCreatorProcess();
0176 }
0177
0178 const std::string creatorName() const {
0179 const G4VProcess* p = creatorProcess();
0180 if ( p ) return p->GetProcessName();
0181 return "";
0182 }
0183
0184 Info* userInfo() const {
0185 return track->GetUserInformation();
0186 }
0187
0188 template <typename T> T* info() const {
0189 return (T*) userInfo();
0190 }
0191
0192 const G4Step* step() const {
0193 return track->GetStep();
0194 }
0195
0196 G4int stepNumber() const {
0197 return track->GetCurrentStepNumber();
0198 }
0199
0200 int pdgID() const {
0201 G4ParticleDefinition* def = trackDef();
0202 return def ? def->GetPDGEncoding() : 0;
0203 }
0204
0205 const G4DynamicParticle* dynamic() const {
0206 return track->GetDynamicParticle();
0207 }
0208
0209 const G4PrimaryParticle* primary() const {
0210 const G4DynamicParticle* d = track->GetDynamicParticle();
0211 if ( d ) return d->GetPrimaryParticle();
0212 return 0;
0213 }
0214 };
0215
0216 }
0217 }
0218 #endif