Back to home page

EIC code displayed by LXR

 
 

    


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

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_GEANT4TRACKHANDLER_H
0014 #define DDG4_GEANT4TRACKHANDLER_H
0015 
0016 // Framework include files
0017 #include <DDG4/Defs.h>
0018 
0019 // Geant4 include files
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 // C/C++ include files
0029 #include <stdexcept>
0030 
0031 // Forward declarations
0032 class G4VTouchableHandle;
0033 class G4VUserTrackInformation;
0034 
0035 /// Namespace for the AIDA detector description toolkit
0036 namespace dd4hep {
0037 
0038   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0039   namespace sim {
0040 
0041     // Forward declarations;
0042     class Geant4TrackHandler;
0043 
0044     /// Helper class to ease the extraction of information from a G4Track object.
0045     /**
0046      * Tiny helper/utility class to easily access Geant4 track information.
0047      * Born by lazyness: Avoid typing millions of statements!
0048      *
0049      *  \author  M.Frank
0050      *  \version 1.0
0051      *  \ingroup DD4HEP_SIMULATION
0052      */
0053     class Geant4TrackHandler {
0054     public:
0055       typedef G4VUserTrackInformation Info;
0056       typedef G4ReferenceCountedHandle<G4VTouchable> Touchable;
0057       /// Reference to the track object
0058       const G4Track* track;
0059       /// Inhibit default constructor
0060       Geant4TrackHandler() = delete;
0061       /// Initializing constructor
0062       Geant4TrackHandler(const G4Track* t) : track(t) {
0063         /// Should test here if the track pointer is valid to avoind any later trouble
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       /// Conversion to G4Track
0081       operator const G4Track*() const {
0082         return track;
0083       }
0084       /// Track's identifier
0085       int id() const  {
0086         return track->GetTrackID();
0087       }
0088       /// Track's parent identifier
0089       int parent()  const  {
0090         return track->GetParentID();
0091       }
0092       /// Track's particle definition
0093       G4ParticleDefinition* trackDef() const {
0094         return track->GetDefinition();
0095       }
0096       /// Track's particle name
0097       const std::string& name()  const  {
0098         return trackDef()->GetParticleName();
0099       }
0100       /// Track's particle type
0101       const std::string& type()  const  {
0102         return trackDef()->GetParticleType();
0103       }
0104       /// Track's position
0105       const G4ThreeVector& position() const {
0106         return track->GetPosition();
0107       }
0108       /// Track's vertex position, where the track was created
0109       const G4ThreeVector& vertex() const {
0110         return track->GetVertexPosition();
0111       }
0112       /// Track global time
0113       double globalTime() const  {
0114         return track->GetGlobalTime();
0115       }
0116       /// Track proper time
0117       double properTime() const  {
0118         return track->GetProperTime();
0119       }
0120       /// Track's energy
0121       double energy() const {
0122         return track->GetTotalEnergy();
0123       }
0124       /// Track's kinetic energy
0125       double kineticEnergy() const {
0126         return track->GetKineticEnergy();
0127       }
0128       /// Track velocity
0129       double velocity() const {
0130         return track->GetVelocity();
0131       }
0132       /// Track length
0133       double length() const {
0134         return track->GetTrackLength();
0135       }
0136       /// Track time
0137       double time() const {
0138         return track->GetGlobalTime();
0139       }
0140       /// Track charge
0141       double charge() const {
0142         G4ParticleDefinition* def = trackDef();
0143         return def ? def->GetPDGCharge() : 0;
0144       }
0145       /// Track charge
0146       double mass() const {
0147         G4ParticleDefinition* def = trackDef();
0148         return def ? def->GetPDGMass() : 0;
0149       }
0150       /// Physical (original) volume of the track
0151       G4VPhysicalVolume* vol() const {
0152         return track->GetVolume();
0153       }
0154       G4ThreeVector momentum() const  {
0155         return track->GetMomentum();
0156       }
0157       /// Next physical volume of the track
0158       G4VPhysicalVolume* nextVol() const {
0159         return track->GetNextVolume();
0160       }
0161       /// Logical volume of the origine vertex
0162       const G4LogicalVolume* vertexVol() const {
0163         return track->GetLogicalVolumeAtVertex();
0164       }
0165       /// Touchable of the track
0166       const Touchable& touchable() const {
0167         return track->GetTouchableHandle();
0168       }
0169       /// Next touchable of the track
0170       const Touchable& nextTouchable() const {
0171         return track->GetNextTouchableHandle();
0172       }
0173       /// Physical process of the track generation
0174       const G4VProcess* creatorProcess() const {
0175         return track->GetCreatorProcess();
0176       }
0177       /// Physical process of the track generation
0178       const std::string creatorName() const {
0179         const G4VProcess* p = creatorProcess();
0180         if ( p ) return p->GetProcessName();
0181         return "";
0182       }
0183       /// User information block
0184       Info* userInfo() const {
0185         return track->GetUserInformation();
0186       }
0187       /// Specific user information block
0188       template <typename T> T* info() const {
0189         return (T*) userInfo();
0190       }
0191       /// Step information
0192       const G4Step* step() const {
0193         return track->GetStep();
0194       }
0195       /// Step number
0196       G4int stepNumber() const {
0197         return track->GetCurrentStepNumber();
0198       }
0199       /// Access the PDG particle identification
0200       int pdgID() const {
0201         G4ParticleDefinition* def = trackDef();
0202         return def ? def->GetPDGEncoding() : 0;
0203       }
0204       /// Access the dynamic particle of the track object
0205       const G4DynamicParticle* dynamic() const  {
0206         return track->GetDynamicParticle();
0207       }
0208       /// Access the primary particle of the track object (if present)
0209       const G4PrimaryParticle* primary() const  {
0210         const G4DynamicParticle* d = track->GetDynamicParticle();
0211         if ( d ) return d->GetPrimaryParticle();
0212         return 0;
0213       }
0214     };
0215 
0216   }    // End namespace sim
0217 }      // End namespace dd4hep
0218 #endif // DDG4_GEANT4TRACKHANDLER_H