Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef SimG4Core_TrackInformation_H
0002 #define SimG4Core_TrackInformation_H
0003 
0004 #include "G4VUserTrackInformation.hh"
0005 #include "G4Allocator.hh"
0006 #include "G4Track.hh"
0007 #include "DataFormats/Math/interface/Vector3D.h"
0008 #include "DataFormats/Math/interface/LorentzVector.h"
0009 
0010 class TrackInformation : public G4VUserTrackInformation {
0011 public:
0012   TrackInformation(){};
0013   ~TrackInformation() override = default;
0014   inline void *operator new(std::size_t);
0015   inline void operator delete(void *TrackInformation);
0016 
0017   bool storeTrack() const { return storeTrack_; }
0018   /// can only be set to true, cannot be reset to false!
0019   void setStoreTrack() {
0020     storeTrack_ = true;
0021     isInHistory_ = true;
0022   }
0023 
0024   bool isPrimary() const { return isPrimary_; }
0025   void setPrimary(bool v) { isPrimary_ = v; }
0026 
0027   bool hasHits() const { return hasHits_; }
0028   void setHasHits(bool v) { hasHits_ = v; }
0029 
0030   bool isGeneratedSecondary() const { return isGeneratedSecondary_; }
0031   void setGeneratedSecondary(bool v) { isGeneratedSecondary_ = v; }
0032 
0033   bool isInHistory() const { return isInHistory_; }
0034   void putInHistory() { isInHistory_ = true; }
0035 
0036   bool isAncestor() const { return flagAncestor_; }
0037   void setAncestor() { flagAncestor_ = true; }
0038 
0039   int mcTruthID() const { return mcTruthID_; }
0040   void setMCTruthID(int id) { mcTruthID_ = id; }
0041 
0042   // Calo section
0043   int getIDonCaloSurface() const { return idOnCaloSurface_; }
0044   void setIDonCaloSurface(int id, int ical, int last, int pdgID, double p) {
0045     idOnCaloSurface_ = id;
0046     idCaloVolume_ = ical;
0047     idLastVolume_ = last;
0048     caloSurfaceParticlePID_ = pdgID;
0049     caloSurfaceParticleP_ = p;
0050   }
0051   int getIDCaloVolume() const { return idCaloVolume_; }
0052   int getIDLastVolume() const { return idLastVolume_; }
0053   bool caloIDChecked() const { return caloIDChecked_; }
0054   void setCaloIDChecked(bool f) { caloIDChecked_ = f; }
0055   int caloSurfaceParticlePID() const { return caloSurfaceParticlePID_; }
0056   void setCaloSurfaceParticlePID(int id) { caloSurfaceParticlePID_ = id; }
0057   double caloSurfaceParticleP() const { return caloSurfaceParticleP_; }
0058   void setCaloSurfaceParticleP(double p) { caloSurfaceParticleP_ = p; }
0059 
0060   // Boundary crossing variables
0061   void setCrossedBoundary(const G4Track *track);
0062   bool crossedBoundary() const { return crossedBoundary_; }
0063   const math::XYZTLorentzVectorF &getPositionAtBoundary() const { return positionAtBoundary_; }
0064   const math::XYZTLorentzVectorF &getMomentumAtBoundary() const { return momentumAtBoundary_; }
0065   bool startedInFineVolume() const { return startedInFineVolume_; }
0066   void setStartedInFineVolume(bool flag = true) {
0067     startedInFineVolume_ = flag;
0068     startedInFineVolumeIsSet_ = true;
0069   }
0070   bool startedInFineVolumeIsSet() { return startedInFineVolumeIsSet_; }
0071 
0072   // Generator information
0073   int genParticlePID() const { return genParticlePID_; }
0074   void setGenParticlePID(int id) { genParticlePID_ = id; }
0075   double genParticleP() const { return genParticleP_; }
0076   void setGenParticleP(double p) { genParticleP_ = p; }
0077 
0078   // remember the PID of particle entering the CASTOR detector. This is needed
0079   // in order to scale the hadronic response
0080   bool hasCastorHit() const { return hasCastorHit_; }
0081   void setCastorHitPID(const int pid) {
0082     hasCastorHit_ = true;
0083     castorHitPID_ = pid;
0084   }
0085   int getCastorHitPID() const { return castorHitPID_; }
0086 
0087   // methods for MTD info management
0088   //
0089   void setFromTtoBTL() { mtdStatus_ |= 1 << 0; }  // 1st bit
0090   bool isFromTtoBTL() const { return (mtdStatus_ >> 0) & 1; }
0091   void setFromBTLtoT() { mtdStatus_ |= 1 << 1; }  // 2nd bit
0092   bool isFromBTLtoT() const { return (mtdStatus_ >> 1) & 1; }
0093   void setBTLlooper() { mtdStatus_ |= 1 << 2; }  // 3th bit
0094   bool isBTLlooper() const { return (mtdStatus_ >> 2) & 1; }
0095   void setInTrkFromBackscattering() { mtdStatus_ |= 1 << 3; }  // 4th bit
0096   bool isInTrkFromBackscattering() const { return (mtdStatus_ >> 3) & 1; }
0097   void setExtSecondary() { mtdStatus_ |= 1 << 4; }  //5th bit
0098   bool isExtSecondary() const { return (mtdStatus_ >> 4) & 1; }
0099 
0100   void Print() const override;
0101 
0102 private:
0103   bool storeTrack_{false};
0104   bool isPrimary_{false};
0105   bool hasHits_{false};
0106   bool isGeneratedSecondary_{false};
0107   bool isInHistory_{false};
0108   bool flagAncestor_{false};
0109   bool caloIDChecked_{false};
0110   bool crossedBoundary_{false};
0111   bool startedInFineVolume_{false};
0112   bool startedInFineVolumeIsSet_{false};
0113   bool hasCastorHit_{false};
0114   int idOnCaloSurface_{0};
0115   int idCaloVolume_{-1};
0116   int idLastVolume_{-1};
0117   int genParticlePID_{-1};
0118   int mcTruthID_{-1};
0119   int caloSurfaceParticlePID_{0};
0120   int castorHitPID_{0};
0121   uint8_t mtdStatus_{0};
0122   double genParticleP_{0.};
0123   double caloSurfaceParticleP_{0.};
0124   math::XYZTLorentzVectorF positionAtBoundary_;
0125   math::XYZTLorentzVectorF momentumAtBoundary_;
0126 };
0127 
0128 extern G4ThreadLocal G4Allocator<TrackInformation> *fpTrackInformationAllocator;
0129 
0130 inline void *TrackInformation::operator new(std::size_t) {
0131   if (!fpTrackInformationAllocator)
0132     fpTrackInformationAllocator = new G4Allocator<TrackInformation>;
0133   return (void *)fpTrackInformationAllocator->MallocSingle();
0134 }
0135 
0136 inline void TrackInformation::operator delete(void *trkInfo) {
0137   fpTrackInformationAllocator->FreeSingle((TrackInformation *)trkInfo);
0138 }
0139 
0140 #endif