Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:23

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 #ifndef DDG4_GEANT4FASTSIMSPOT_H
0014 #define DDG4_GEANT4FASTSIMSPOT_H
0015 
0016 // Framework include files
0017 #include <DDG4/Defs.h>
0018 
0019 // Geant4 include files
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 /* aDebug */)
0033     : fEnergy(aEnergy), fPosition(aPosition) {}
0034   virtual ~G4FastHit() = default;
0035 
0036   /// Set energy
0037   inline void SetEnergy(const G4double& aEnergy) { fEnergy = aEnergy; }
0038   /// Get energy
0039   inline G4double GetEnergy() const { return fEnergy; }
0040   /// Set position
0041   inline void SetPosition(const G4ThreeVector& aPosition) { fPosition = aPosition; }
0042   /// Get position
0043   inline G4ThreeVector GetPosition() const { return fPosition; }
0044  private:
0045   /// energy
0046   G4double fEnergy  {0e0};
0047   /// position
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 /// Namespace for the AIDA detector description toolkit
0060 namespace dd4hep {
0061 
0062   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0063   namespace sim {
0064 
0065     /// Spot definition for fast simulation and GFlash
0066     /**
0067      *  \author  M.Frank
0068      *  \version 1.0
0069      *  \ingroup DD4HEP_SIMULATION
0070      */
0071     class Geant4FastSimSpot   {
0072     public:
0073       /// Default constructor disabled
0074       Geant4FastSimSpot() = delete;
0075       /// Initializing constructor
0076       Geant4FastSimSpot(const G4FastHit* h, const G4FastTrack* trk);
0077       /// Initializing constructor
0078       Geant4FastSimSpot(const G4FastHit* h, const G4FastTrack* trk, G4VTouchable* t);
0079       /// Default destructor
0080       ~Geant4FastSimSpot() = default;
0081 
0082       /// Spot's hit position
0083       G4ThreeVector hitPosition() const    { return hit->GetPosition();          }
0084       /// Energy deposit of the spot
0085       double        energy() const         { return hit->GetEnergy();            }
0086       /// Access the physical volume of the hit
0087       G4VPhysicalVolume* volume() const    { return touchable->GetVolume();      }
0088 
0089       /// Primary track position
0090       G4ThreeVector trackPosition() const  { return primary->GetPosition();      }
0091       /// Primary track momentum
0092       G4ThreeVector trackMomentum() const  { return primary->GetMomentum();      }
0093       /// Primary track kinetic energy
0094       double kineticEnergy() const         { return primary->GetKineticEnergy(); }
0095       /// Primary track particle definition
0096       const G4ParticleDefinition* trackDefinition() const 
0097       { return primary->GetParticleDefinition();                                 }
0098       /// Particle's local direction in the region's envelope solid
0099       G4ThreeVector particleLocalDirection()  const
0100       { return track->GetPrimaryTrackLocalDirection();                           }
0101       /// Particle's local momentum in the region's envelope solid
0102       G4ThreeVector particleLocalMomentum()  const
0103       { return track->GetPrimaryTrackLocalMomentum();                            }
0104       /// Particle's local position in the region's envelope solid
0105       G4ThreeVector particleLocalPosition()  const
0106       { return track->GetPrimaryTrackLocalPosition();                            }
0107 
0108       /// Distance to exit point from the region's envelope solid
0109       double distanceToOut()   const;
0110       /// Particle's global direction in the region's envelope solid
0111       G4ThreeVector particleDirection()  const;
0112       /// Particle's global momentum in the region's envelope solid
0113       G4ThreeVector particleMomentum()  const;
0114       /// Particle's global position in the region's envelope solid
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     /// Initializing constructor
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     /// Initializing constructor
0133     inline Geant4FastSimSpot::Geant4FastSimSpot(const G4FastHit* h,
0134                         const G4FastTrack* trk)
0135       : hit(h), track(trk), primary(trk->GetPrimaryTrack())
0136     {
0137     }
0138 
0139     /// Particle's global momentum in the region's envelope solid
0140     inline G4ThreeVector Geant4FastSimSpot::particleMomentum()  const    {
0141       auto mom = track->GetPrimaryTrackLocalMomentum();
0142       return track->GetInverseAffineTransformation()->TransformPoint(mom);
0143     }
0144 
0145     /// Particle's global direction in the region's envelope solid
0146     inline G4ThreeVector Geant4FastSimSpot::particleDirection()  const    {
0147       auto dir = track->GetPrimaryTrackLocalDirection();
0148       return track->GetInverseAffineTransformation()->TransformPoint(dir);
0149     }
0150 
0151     /// Particle's global position in the region's envelope solid
0152     inline G4ThreeVector Geant4FastSimSpot::particlePosition()  const    {
0153       auto pos = track->GetPrimaryTrackLocalPosition();
0154       return track->GetInverseAffineTransformation()->TransformPoint(pos);
0155     }
0156 
0157     /// Distance to exit point from the region's envelope solid
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   }    // End namespace sim
0166 }      // End namespace dd4hep
0167 #endif // DDG4_GEANT4FASTSIMSPOT_H