File indexing completed on 2025-01-18 09:55:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DDG4_GEANT4FASTSIMSPOT_H
0014 #define DDG4_GEANT4FASTSIMSPOT_H
0015
0016
0017 #include <DDG4/Defs.h>
0018
0019
0020 #include <G4Version.hh>
0021
0022 #if G4VERSION_NUMBER < 1070
0023
0024 #include <G4ThreeVector.hh>
0025
0026 class G4FastHit
0027 {
0028 public:
0029 G4FastHit() = default;
0030 G4FastHit(const G4ThreeVector& aPosition, G4double aEnergy)
0031 : fEnergy(aEnergy), fPosition(aPosition) {}
0032 G4FastHit(const G4ThreeVector& aPosition, G4double aEnergy, G4bool )
0033 : fEnergy(aEnergy), fPosition(aPosition) {}
0034 virtual ~G4FastHit() = default;
0035
0036
0037 inline void SetEnergy(const G4double& aEnergy) { fEnergy = aEnergy; }
0038
0039 inline G4double GetEnergy() const { return fEnergy; }
0040
0041 inline void SetPosition(const G4ThreeVector& aPosition) { fPosition = aPosition; }
0042
0043 inline G4ThreeVector GetPosition() const { return fPosition; }
0044 private:
0045
0046 G4double fEnergy {0e0};
0047
0048 G4ThreeVector fPosition { };
0049 };
0050 #else
0051 #include <G4FastHit.hh>
0052 #endif
0053
0054 #include <G4Track.hh>
0055 #include <G4FastTrack.hh>
0056 #include <G4ThreeVector.hh>
0057 #include <G4TouchableHandle.hh>
0058
0059
0060 namespace dd4hep {
0061
0062
0063 namespace sim {
0064
0065
0066
0067
0068
0069
0070
0071 class Geant4FastSimSpot {
0072 public:
0073
0074 Geant4FastSimSpot() = delete;
0075
0076 Geant4FastSimSpot(const G4FastHit* h, const G4FastTrack* trk);
0077
0078 Geant4FastSimSpot(const G4FastHit* h, const G4FastTrack* trk, G4VTouchable* t);
0079
0080 ~Geant4FastSimSpot() = default;
0081
0082
0083 G4ThreeVector hitPosition() const { return hit->GetPosition(); }
0084
0085 double energy() const { return hit->GetEnergy(); }
0086
0087 G4VPhysicalVolume* volume() const { return touchable->GetVolume(); }
0088
0089
0090 G4ThreeVector trackPosition() const { return primary->GetPosition(); }
0091
0092 G4ThreeVector trackMomentum() const { return primary->GetMomentum(); }
0093
0094 double kineticEnergy() const { return primary->GetKineticEnergy(); }
0095
0096 const G4ParticleDefinition* trackDefinition() const
0097 { return primary->GetParticleDefinition(); }
0098
0099 G4ThreeVector particleLocalDirection() const
0100 { return track->GetPrimaryTrackLocalDirection(); }
0101
0102 G4ThreeVector particleLocalMomentum() const
0103 { return track->GetPrimaryTrackLocalMomentum(); }
0104
0105 G4ThreeVector particleLocalPosition() const
0106 { return track->GetPrimaryTrackLocalPosition(); }
0107
0108
0109 double distanceToOut() const;
0110
0111 G4ThreeVector particleDirection() const;
0112
0113 G4ThreeVector particleMomentum() const;
0114
0115 G4ThreeVector particlePosition() const;
0116
0117 public:
0118 const G4FastHit* hit { nullptr };
0119 const G4FastTrack* track { nullptr };
0120 const G4Track* primary { nullptr };
0121 G4VTouchable* touchable { nullptr };
0122 };
0123
0124
0125 inline Geant4FastSimSpot::Geant4FastSimSpot(const G4FastHit* h,
0126 const G4FastTrack* trk,
0127 G4VTouchable* t)
0128 : hit(h), track(trk), primary(trk->GetPrimaryTrack()), touchable(t)
0129 {
0130 }
0131
0132
0133 inline Geant4FastSimSpot::Geant4FastSimSpot(const G4FastHit* h,
0134 const G4FastTrack* trk)
0135 : hit(h), track(trk), primary(trk->GetPrimaryTrack())
0136 {
0137 }
0138
0139
0140 inline G4ThreeVector Geant4FastSimSpot::particleMomentum() const {
0141 auto mom = track->GetPrimaryTrackLocalMomentum();
0142 return track->GetInverseAffineTransformation()->TransformPoint(mom);
0143 }
0144
0145
0146 inline G4ThreeVector Geant4FastSimSpot::particleDirection() const {
0147 auto dir = track->GetPrimaryTrackLocalDirection();
0148 return track->GetInverseAffineTransformation()->TransformPoint(dir);
0149 }
0150
0151
0152 inline G4ThreeVector Geant4FastSimSpot::particlePosition() const {
0153 auto pos = track->GetPrimaryTrackLocalPosition();
0154 return track->GetInverseAffineTransformation()->TransformPoint(pos);
0155 }
0156
0157
0158 inline double Geant4FastSimSpot::distanceToOut() const {
0159 auto pos = track->GetPrimaryTrackLocalPosition();
0160 auto dir = track->GetPrimaryTrackLocalDirection();
0161 return track->GetEnvelopeSolid()->DistanceToOut(pos, dir);
0162 }
0163
0164
0165 }
0166 }
0167 #endif