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 
0014 #ifndef DDG4_GEANT4DATA_H
0015 #define DDG4_GEANT4DATA_H
0016 
0017 // Framework include files
0018 #include <Math/Vector3D.h>
0019 
0020 // C/C++ include files
0021 #include <set>
0022 #include <vector>
0023 #include <memory>
0024 
0025 // Forward declarations
0026 class G4Step;
0027 class G4StepPoint;
0028 
0029 /// Namespace for the AIDA detector description toolkit
0030 namespace dd4hep {
0031 
0032   // Forward type definitions
0033   typedef ROOT::Math::XYZVector Position;
0034   typedef ROOT::Math::XYZVector Direction;
0035   
0036   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0037   namespace sim {
0038 
0039     // Forward declarations
0040     class Geant4FastSimSpot;
0041 
0042     /// Simple run description structure. Used in the default I/O mechanism.
0043     /**
0044      * Example class to store the run related information.
0045      *
0046      *  \author  M.Frank
0047      *  \version 1.0
0048      *  \ingroup DD4HEP_SIMULATION
0049      */
0050     class SimpleRun {
0051     public:
0052       /// Run identifiers
0053       int runID     { -1 };
0054       /// Number of events in this run
0055       int numEvents {  0 };
0056       /// Default constructor
0057       SimpleRun();
0058       /// Default destructor
0059       virtual ~SimpleRun();
0060     };
0061 
0062     /// Simple event description structure. Used in the default I/O mechanism.
0063     /**
0064      * Example class to store the event related information.
0065      *
0066      *  \author  M.Frank
0067      *  \version 1.0
0068      *  \ingroup DD4HEP_SIMULATION
0069      */
0070     class SimpleEvent {
0071     public:
0072       typedef std::vector<long> Seeds;
0073       /// Run identifiers
0074       int    runID   { -1 };
0075       /// Event identifier
0076       int    eventID { -1 };
0077       /// Random number generator seeds
0078       Seeds  seeds { };
0079       /// Default constructor
0080       SimpleEvent();
0081       /// Default destructor
0082       virtual ~SimpleEvent();
0083     };
0084 
0085     /// Generic user-extendible data extension class.
0086     /**
0087      *  \author  M.Frank
0088      *  \version 1.0
0089      *  \ingroup DD4HEP_SIMULATION
0090      */
0091     class DataExtension  {
0092     public:
0093       /// Default constructor
0094       DataExtension() {}
0095       /// Default destructor
0096       virtual ~DataExtension();
0097     };
0098 
0099     /// Base class for geant4 hit structures used by the default DDG4 sensitive detector implementations
0100     /*
0101      *  Base class for geant4 hit structures created by the
0102      *  example sensitive detectors. This is a generic class
0103      *  only dealing with the cellID. Users may add an extension
0104      *  object, which normally should not be necessary.
0105      *
0106      *  \author  M.Frank
0107      *  \version 1.0
0108      *  \ingroup DD4HEP_SIMULATION
0109      */
0110     class Geant4HitData {
0111     public:
0112       enum HitFlags {
0113         HIT_KILLED_TRACK    = 1<<0,
0114         HIT_SECONDARY_TRACK = 1<<1,
0115         HIT_NEW_TRACK       = 1<<2,
0116         HIT_STARTED_INSIDE  = 1<<10,
0117         HIT_STARTED_SURFACE = 1<<11,
0118         HIT_STARTED_OUTSIDE = 1<<12,
0119         HIT_ENDED_INSIDE    = 1<<13,
0120         HIT_ENDED_SURFACE   = 1<<14,
0121         HIT_ENDED_OUTSIDE   = 1<<15
0122       };
0123       /// cellID
0124       long long int cellID = 0;
0125       /// User flag to classify hits
0126       long flag = 0;
0127       /// Original Geant 4 track identifier of the creating track (debugging)
0128       long g4ID = -1;
0129       /// User data extension if required
0130       std::unique_ptr<DataExtension> extension;
0131 
0132       /// Utility class describing the monte carlo contribution of a given particle to a hit.
0133       /**
0134        *  \author  M.Frank
0135        *  \version 1.0
0136        *  \ingroup DD4HEP_SIMULATION
0137        */
0138       class MonteCarloContrib {
0139       public:
0140         /// Geant 4 Track identifier
0141         int trackID = -1;
0142         /// Particle ID from the PDG table
0143         int pdgID = -1;
0144         /// Total energy deposit in this hit
0145         double deposit = 0.0;
0146         /// Timestamp when this energy was deposited
0147         double time;
0148         /// Length of this step
0149         double length = 0.0;
0150         /// Proper position of the hit contribution
0151         float  x = 0.0, y = 0.0, z = 0.0;
0152         /// Proper particle momentum when generating the hit of the contributing particle
0153         float  px = 0.0, py = 0.0, pz = 0.0;
0154 
0155         /// Default constructor
0156         MonteCarloContrib() = default;
0157         /// Copy constructor
0158         MonteCarloContrib(const MonteCarloContrib& c) = default;
0159         /// Move constructor
0160         MonteCarloContrib(MonteCarloContrib&& c) = default;
0161 #if 0
0162         /// Initializing constructor
0163         MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, double len)
0164           : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), length(len) {
0165         }
0166 #endif
0167         /// Initializing constructor
0168         MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, double len, float* pos, float* mom)
0169           : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), length(len),
0170             x(pos[0]), y(pos[1]), z(pos[2]), px(mom[0]), py(mom[1]), pz(mom[2])
0171         {
0172         }
0173         /// Initializing constructor
0174         MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, double len, double* pos, double* mom)
0175           : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), length(len),
0176             x(float(pos[0])), y(float(pos[1])), z(float(pos[2])),
0177         px(float(mom[0])), py(float(mom[1])), pz(float(mom[2]))
0178         {
0179         }
0180         /// Initializing constructor
0181         MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, double len, const Position& pos, const Direction& mom)
0182           : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), length(len),
0183             x(float(pos.x())), y(float(pos.y())), z(float(pos.z())),
0184         px(float(mom.x())), py(float(mom.y())), pz(float(mom.z()))
0185         {
0186         }
0187         /// Assignment operator (move)
0188         MonteCarloContrib& operator=(MonteCarloContrib&& c) = default;
0189         /// Assignment operator (copy)
0190         MonteCarloContrib& operator=(const MonteCarloContrib& c) = default;
0191         /// Clear data content
0192         void clear() {
0193           x = y = z = 0.0;
0194           px = py = pz = 0.0;
0195           time  = deposit = length = 0.0;
0196           pdgID = trackID = -1;
0197         }
0198     /// Access position
0199     Position position() const   {
0200       return Position(x, y, z);
0201     }
0202     /// Set position of the contribution
0203     void setPosition(const Position& pos)   {
0204       x = pos.x();
0205       y = pos.y();
0206       z = pos.z();
0207     }
0208     /// Set position of the contribution
0209     void setPosition(double pos_x, double pos_y, double pos_z)   {
0210       x = float(pos_x);
0211       y = float(pos_y);
0212       z = float(pos_z);
0213     }
0214     /// Access momentum
0215     Direction momentum() const   {
0216       return Direction(px, py, pz);
0217     }
0218     /// Set memonetum of the contribution
0219     void setMomentum(const Direction& dir)   {
0220       px = dir.x();
0221       py = dir.y();
0222       pz = dir.z();
0223     }
0224     /// Set memonetum of the contribution
0225     void setMomentum(double mom_x, double mom_y, double mom_z)   {
0226       px = float(mom_x);
0227       py = float(mom_y);
0228       pz = float(mom_z);
0229     }
0230       };
0231       typedef MonteCarloContrib Contribution;
0232       typedef std::vector<MonteCarloContrib> Contributions;
0233     public:
0234       /// Default constructor
0235       Geant4HitData();
0236       /// Default destructor
0237       virtual ~Geant4HitData();
0238       /// Extract the MC contribution for a given hit from the step information
0239       static Contribution extractContribution(const G4Step* step);
0240       /// Extract the MC contribution for a given hit from the step information with BirksLaw option
0241       static Contribution extractContribution(const G4Step* step, bool ApplyBirksLaw);
0242       /// Extract the MC contribution for a given hit from the GFlash/FastSim spot information
0243       static Contribution extractContribution(const Geant4FastSimSpot* spot);
0244     };
0245 
0246     /// Helper class to define structures used by the generic DDG4 tracker sensitive detector
0247     /**
0248      *  \author  M.Frank
0249      *  \version 1.0
0250      *  \ingroup DD4HEP_SIMULATION
0251      */
0252     class Geant4Tracker {
0253     public:
0254       /// DDG4 tracker hit class used by the generic DDG4 tracker sensitive detector
0255       /**
0256        * Geant4 tracker hit class. Tracker hits contain the momentum
0257        * direction as well as the hit position.
0258        *
0259        *  \author  M.Frank
0260        *  \version 1.0
0261        *  \ingroup DD4HEP_SIMULATION
0262        */
0263       class Hit : public Geant4HitData {
0264       public:
0265         typedef Geant4HitData base_t;
0266 
0267         /// Hit position
0268         Position      position;
0269         /// Hit direction
0270         Direction     momentum;
0271         /// Length of the track segment contributing to this hit
0272         double        length  { 0e0 };
0273         /// Energy deposit in the tracker hit
0274         double        energyDeposit { 0e0 };
0275         /// Monte Carlo / Geant4 information
0276         Contribution  truth;
0277       public:
0278         /// Default constructor
0279         Hit();
0280         /// Move constructor
0281         Hit(Hit&& c) = delete;
0282         /// copy constructor
0283         Hit(const Hit& c) = delete;
0284         /// Initializing constructor
0285         Hit(int track_id, int pdg_id, double deposit, double time_stamp, double len=0.0, const Position& p={0.0, 0.0, 0.0}, const Direction& d={0.0, 0.0, 0.0});
0286     /// Optimized constructor for sensitive detectors
0287     Hit(const Geant4HitData::Contribution& contrib, const Direction& mom, double deposit);
0288         /// Default destructor
0289         virtual ~Hit();
0290         /// Move assignment operator
0291         Hit& operator=(Hit&& c) = delete;
0292         /// Copy assignment operator
0293         Hit& operator=(const Hit& c) = delete;
0294     /// Explicit assignment operation
0295     void copyFrom(const Hit& c);
0296         /// Clear hit content
0297         Hit& clear();
0298         /// Store Geant4 point and step information into tracker hit structure.
0299         Hit& storePoint(const G4Step* step, const G4StepPoint* point);
0300     /// Store Geant4 spot information into tracker hit structure.
0301     Hit& storePoint(const Geant4FastSimSpot* spot);
0302       };
0303     };
0304 
0305     /// Helper class to define structures used by the generic DDG4 calorimeter sensitive detector
0306     /**
0307      *  \author  M.Frank
0308      *  \version 1.0
0309      *  \ingroup DD4HEP_SIMULATION
0310      */
0311     class Geant4Calorimeter {
0312     public:
0313 
0314       /// DDG4 calorimeter hit class used by the generic DDG4 calorimeter sensitive detector
0315       /**
0316        * Geant4 tracker hit class. Calorimeter hits contain the momentum
0317        * direction as well as the hit position.
0318        *
0319        *  \author  M.Frank
0320        *  \version 1.0
0321        *  \ingroup DD4HEP_SIMULATION
0322        */
0323       class Hit : public Geant4HitData {
0324       public:
0325         typedef Geant4HitData base_t;
0326 
0327         /// Hit position
0328         Position      position      {     };
0329         /// Hit contributions by individual particles
0330         Contributions truth         {     };
0331         /// Total energy deposit
0332         double        energyDeposit { 0e0 };
0333       public:
0334         /// Default constructor (for ROOT)
0335         Hit();
0336         /// Move constructor
0337         Hit(Hit&& c) = delete;
0338         /// copy constructor
0339         Hit(const Hit& c) = delete;
0340         /// Standard constructor
0341         Hit(const Position& cell_pos);
0342         /// Default destructor
0343         virtual ~Hit();
0344         /// Move assignment operator
0345         Hit& operator=(Hit&& c) = delete;
0346         /// Copy assignment operator
0347         Hit& operator=(const Hit& c) = delete;
0348       };
0349     };
0350 
0351     /// Backward compatibility definitions
0352     typedef Geant4HitData SimpleHit;
0353     typedef Geant4Tracker SimpleTracker;
0354     typedef Geant4Calorimeter SimpleCalorimeter;
0355 
0356   }    // End namespace sim
0357 }      // End namespace dd4hep
0358 #endif // DDG4_GEANT4DATA_H