Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-12 23:42:12

0001 #ifndef SimG4Core_TrackWithHistory_H
0002 #define SimG4Core_TrackWithHistory_H
0003 
0004 #include "G4Track.hh"
0005 #include "DataFormats/Math/interface/Vector3D.h"
0006 #include "DataFormats/Math/interface/LorentzVector.h"
0007 
0008 #include "G4Allocator.hh"
0009 
0010 class G4PrimaryParticle;
0011 /** The part of the information about a SimTrack that we need from
0012  *  a G4Track
0013  */
0014 
0015 class TrackWithHistory {
0016 public:
0017   /** The constructor is called at time,
0018      *  when some of the information may not available yet.
0019      */
0020   TrackWithHistory(const G4Track *g4track, int pID);
0021   TrackWithHistory(const G4PrimaryParticle *, int trackID, const math::XYZVectorD &pos, const double time);
0022   ~TrackWithHistory() = default;
0023 
0024   inline void *operator new(std::size_t);
0025   inline void operator delete(void *TrackWithHistory);
0026 
0027   int trackID() const { return trackID_; }
0028   int particleID() const { return pdgID_; }
0029   int parentID() const { return parentID_; }
0030   int genParticleID() const { return isPrimary_ ? genParticleID_ : -1; }
0031   int vertexID() const { return vertexID_; }
0032   int processType() const { return procType_; }
0033   int getIDAtBoundary() const { return idAtBoundary_; }
0034 
0035   void setTrackID(int i) { trackID_ = i; }
0036   void setParentID(int i) { parentID_ = i; }
0037   void setVertexID(int i) { vertexID_ = i; }
0038   void setGenParticleID(int i) { genParticleID_ = i; }
0039 
0040   double totalEnergy() const { return totalEnergy_; }
0041   double time() const { return time_; }
0042   double weight() const { return weight_; }
0043   void setToBeSaved() { saved_ = true; }
0044   bool storeTrack() const { return storeTrack_; }
0045   bool saved() const { return saved_; }
0046   bool crossedBoundary() const { return crossedBoundary_; }
0047 
0048   const math::XYZVectorD &momentum() const { return momentum_; }
0049   const math::XYZVectorD &vertexPosition() const { return vertexPosition_; }
0050 
0051   // Boundary crossing variables
0052   void setCrossedBoundaryPosMom(int id,
0053                                 const math::XYZTLorentzVectorF &position,
0054                                 const math::XYZTLorentzVectorF &momentum) {
0055     crossedBoundary_ = true;
0056     idAtBoundary_ = id;
0057     positionAtBoundary_ = position;
0058     momentumAtBoundary_ = momentum;
0059   }
0060   const math::XYZTLorentzVectorF &getPositionAtBoundary() const { return positionAtBoundary_; }
0061   const math::XYZTLorentzVectorF &getMomentumAtBoundary() const { return momentumAtBoundary_; }
0062 
0063   // tracker surface
0064   const math::XYZVectorD &trackerSurfacePosition() const { return tkSurfacePosition_; }
0065   const math::XYZTLorentzVectorD &trackerSurfaceMomentum() const { return tkSurfaceMomentum_; }
0066   void setSurfacePosMom(const math::XYZVectorD &pos, const math::XYZTLorentzVectorD &mom) {
0067     tkSurfacePosition_ = pos;
0068     tkSurfaceMomentum_ = mom;
0069   }
0070   bool isFromBackScattering() const { return isFromBackScattering_; }
0071   void setFromBackScattering() { isFromBackScattering_ = true; }
0072   bool isPrimary() const { return isPrimary_; }
0073   void setIsPrimary() { isPrimary_ = true; }
0074   int getPrimaryID() const { return genParticleID_; }
0075 
0076 private:
0077   int trackID_;
0078   int pdgID_;
0079   int parentID_;
0080   int genParticleID_{-1};
0081   int vertexID_{-1};
0082   int idAtBoundary_{-1};
0083   int procType_{0};
0084   double totalEnergy_;
0085   double time_;  // lab system
0086   double weight_;
0087   math::XYZVectorD momentum_;
0088   math::XYZVectorD vertexPosition_;
0089   math::XYZTLorentzVectorF positionAtBoundary_{math::XYZTLorentzVectorF(0.f, 0.f, 0.f, 0.f)};
0090   math::XYZTLorentzVectorF momentumAtBoundary_{math::XYZTLorentzVectorF(0.f, 0.f, 0.f, 0.f)};
0091   math::XYZVectorD tkSurfacePosition_{math::XYZVectorD(0., 0., 0.)};
0092   math::XYZTLorentzVectorD tkSurfaceMomentum_{math::XYZTLorentzVectorD(0., 0., 0., 0.)};
0093   bool storeTrack_{false};
0094   bool saved_{false};
0095   bool crossedBoundary_{false};
0096   bool isFromBackScattering_{false};
0097   bool isPrimary_{false};
0098 };
0099 
0100 extern G4ThreadLocal G4Allocator<TrackWithHistory> *fpTrackWithHistoryAllocator;
0101 
0102 inline void *TrackWithHistory::operator new(std::size_t) {
0103   if (!fpTrackWithHistoryAllocator)
0104     fpTrackWithHistoryAllocator = new G4Allocator<TrackWithHistory>;
0105   return (void *)fpTrackWithHistoryAllocator->MallocSingle();
0106 }
0107 
0108 inline void TrackWithHistory::operator delete(void *aTwH) {
0109   fpTrackWithHistoryAllocator->FreeSingle((TrackWithHistory *)aTwH);
0110 }
0111 
0112 #endif