Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 23:31:22

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 G4VProcess;
0011 class G4TrackToParticleID;
0012 /** The part of the information about a SimTrack that we need from
0013  *  a G4Track
0014  */
0015 
0016 class TrackWithHistory {
0017 public:
0018   /** The constructor is called at PreUserTrackingAction time, 
0019      *  when some of the information is not available yet.
0020      */
0021   TrackWithHistory(const G4Track *g4track);
0022   ~TrackWithHistory() {}
0023 
0024   inline void *operator new(size_t);
0025   inline void operator delete(void *TrackWithHistory);
0026 
0027   void save() { saved_ = true; }
0028   unsigned int trackID() const { return trackID_; }
0029   int particleID() const { return particleID_; }
0030   int parentID() const { return parentID_; }
0031   int genParticleID() const { return genParticleID_; }
0032   const math::XYZVectorD &momentum() const { return momentum_; }
0033   double totalEnergy() const { return totalEnergy_; }
0034   const math::XYZVectorD &vertexPosition() const { return vertexPosition_; }
0035   double globalTime() const { return globalTime_; }
0036   double localTime() const { return localTime_; }
0037   double properTime() const { return properTime_; }
0038   const G4VProcess *creatorProcess() const { return creatorProcess_; }
0039   double weight() const { return weight_; }
0040   void setTrackID(int i) { trackID_ = i; }
0041   void setParentID(int i) { parentID_ = i; }
0042   void setGenParticleID(int i) { genParticleID_ = i; }
0043   bool storeTrack() const { return storeTrack_; }
0044   bool saved() const { return saved_; }
0045 
0046   // Boundary crossing variables
0047   void setCrossedBoundaryPosMom(int id,
0048                                 const math::XYZTLorentzVectorF position,
0049                                 const math::XYZTLorentzVectorF momentum) {
0050     crossedBoundary_ = true;
0051     idAtBoundary_ = id;
0052     positionAtBoundary_ = position;
0053     momentumAtBoundary_ = momentum;
0054   }
0055   bool crossedBoundary() const { return crossedBoundary_; }
0056   const math::XYZTLorentzVectorF &getPositionAtBoundary() const { return positionAtBoundary_; }
0057   const math::XYZTLorentzVectorF &getMomentumAtBoundary() const { return momentumAtBoundary_; }
0058   int getIDAtBoundary() const { return idAtBoundary_; }
0059   /** Internal consistency check (optional).
0060      *  Method called at PostUserTrackingAction time, to check
0061      *  if the information is consistent with that provided
0062      *  to the constructor.
0063      */
0064   void checkAtEnd(const G4Track *);
0065 
0066 private:
0067   unsigned int trackID_;
0068   int particleID_;
0069   int parentID_;
0070   int genParticleID_;
0071   math::XYZVectorD momentum_;
0072   double totalEnergy_;
0073   math::XYZVectorD vertexPosition_;
0074   double globalTime_;
0075   double localTime_;
0076   double properTime_;
0077   const G4VProcess *creatorProcess_;
0078   double weight_;
0079   bool storeTrack_;
0080   bool saved_;
0081 
0082   bool isPrimary_;
0083   bool crossedBoundary_;
0084   int idAtBoundary_;
0085   math::XYZTLorentzVectorF positionAtBoundary_;
0086   math::XYZTLorentzVectorF momentumAtBoundary_;
0087 
0088   int extractGenID(const G4Track *gt) const;
0089 };
0090 
0091 extern G4ThreadLocal G4Allocator<TrackWithHistory> *fpTrackWithHistoryAllocator;
0092 
0093 inline void *TrackWithHistory::operator new(size_t) {
0094   if (!fpTrackWithHistoryAllocator)
0095     fpTrackWithHistoryAllocator = new G4Allocator<TrackWithHistory>;
0096   return (void *)fpTrackWithHistoryAllocator->MallocSingle();
0097 }
0098 
0099 inline void TrackWithHistory::operator delete(void *aTwH) {
0100   fpTrackWithHistoryAllocator->FreeSingle((TrackWithHistory *)aTwH);
0101 }
0102 
0103 #endif