Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:26

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 genParticleID_; }
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 
0071 private:
0072   int trackID_;
0073   int pdgID_;
0074   int parentID_;
0075   int genParticleID_{-1};
0076   int vertexID_{-1};
0077   int idAtBoundary_{-1};
0078   int procType_{0};
0079   double totalEnergy_;
0080   double time_;  // lab system
0081   double weight_;
0082   math::XYZVectorD momentum_;
0083   math::XYZVectorD vertexPosition_;
0084   math::XYZTLorentzVectorF positionAtBoundary_{math::XYZTLorentzVectorF(0.f, 0.f, 0.f, 0.f)};
0085   math::XYZTLorentzVectorF momentumAtBoundary_{math::XYZTLorentzVectorF(0.f, 0.f, 0.f, 0.f)};
0086   math::XYZVectorD tkSurfacePosition_{math::XYZVectorD(0., 0., 0.)};
0087   math::XYZTLorentzVectorD tkSurfaceMomentum_{math::XYZTLorentzVectorD(0., 0., 0., 0.)};
0088   bool storeTrack_{false};
0089   bool saved_{false};
0090   bool crossedBoundary_{false};
0091 };
0092 
0093 extern G4ThreadLocal G4Allocator<TrackWithHistory> *fpTrackWithHistoryAllocator;
0094 
0095 inline void *TrackWithHistory::operator new(std::size_t) {
0096   if (!fpTrackWithHistoryAllocator)
0097     fpTrackWithHistoryAllocator = new G4Allocator<TrackWithHistory>;
0098   return (void *)fpTrackWithHistoryAllocator->MallocSingle();
0099 }
0100 
0101 inline void TrackWithHistory::operator delete(void *aTwH) {
0102   fpTrackWithHistoryAllocator->FreeSingle((TrackWithHistory *)aTwH);
0103 }
0104 
0105 #endif