Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-02 01:32:06

0001 #ifndef SimG4Core_TrackInformation_H
0002 #define SimG4Core_TrackInformation_H
0003 
0004 #include "FWCore/Utilities/interface/Exception.h"
0005 #include "G4VUserTrackInformation.hh"
0006 #include "G4Allocator.hh"
0007 #include "G4Track.hh"
0008 #include "DataFormats/Math/interface/Vector3D.h"
0009 #include "DataFormats/Math/interface/LorentzVector.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 
0012 class TrackInformation : public G4VUserTrackInformation {
0013 public:
0014   ~TrackInformation() override {}
0015   inline void *operator new(size_t);
0016   inline void operator delete(void *TrackInformation);
0017 
0018   bool storeTrack() const { return storeTrack_; }
0019   /// can only be set to true, cannot be reset to false!
0020   void storeTrack(bool v) {
0021     if (v)
0022       storeTrack_ = v;
0023     if (v == true)
0024       putInHistory();
0025   }
0026 
0027   bool isPrimary() const { return isPrimary_; }
0028   void isPrimary(bool v) { isPrimary_ = v; }
0029 
0030   bool hasHits() const { return hasHits_; }
0031   void hasHits(bool v) { hasHits_ = v; }
0032 
0033   bool isGeneratedSecondary() const { return isGeneratedSecondary_; }
0034   void isGeneratedSecondary(bool v) { isGeneratedSecondary_ = v; }
0035 
0036   bool isInHistory() const { return isInHistory_; }
0037   void putInHistory() { isInHistory_ = true; }
0038 
0039   bool isAncestor() const { return flagAncestor_; }
0040   void setAncestor() { flagAncestor_ = true; }
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     crossedBoundary_ = true;
0063     positionAtBoundary_ = math::XYZTLorentzVectorF(track->GetPosition().x() / CLHEP::cm,
0064                                                    track->GetPosition().y() / CLHEP::cm,
0065                                                    track->GetPosition().z() / CLHEP::cm,
0066                                                    track->GetGlobalTime());
0067     momentumAtBoundary_ = math::XYZTLorentzVectorF(track->GetMomentum().x() / CLHEP::GeV,
0068                                                    track->GetMomentum().y() / CLHEP::GeV,
0069                                                    track->GetMomentum().z() / CLHEP::GeV,
0070                                                    track->GetTotalEnergy() / CLHEP::GeV);
0071   }
0072   bool crossedBoundary() const { return crossedBoundary_; }
0073   const math::XYZTLorentzVectorF &getPositionAtBoundary() const { return positionAtBoundary_; }
0074   const math::XYZTLorentzVectorF &getMomentumAtBoundary() const { return momentumAtBoundary_; }
0075   bool startedInFineVolume() const { return startedInFineVolume_; }
0076   void setStartedInFineVolume(bool flag = true) {
0077     startedInFineVolume_ = flag;
0078     startedInFineVolumeIsSet_ = true;
0079   }
0080   bool startedInFineVolumeIsSet() { return startedInFineVolumeIsSet_; }
0081 
0082   // Generator information
0083   int genParticlePID() const { return genParticlePID_; }
0084   void setGenParticlePID(int id) { genParticlePID_ = id; }
0085   double genParticleP() const { return genParticleP_; }
0086   void setGenParticleP(double p) { genParticleP_ = p; }
0087 
0088   // remember the PID of particle entering the CASTOR detector. This is needed
0089   // in order to scale the hadronic response
0090   bool hasCastorHit() const { return hasCastorHit_; }
0091   void setCastorHitPID(const int pid) {
0092     hasCastorHit_ = true;
0093     castorHitPID_ = pid;
0094   }
0095   int getCastorHitPID() const { return castorHitPID_; }
0096 
0097   void Print() const override;
0098 
0099 private:
0100   bool storeTrack_;
0101   bool isPrimary_;
0102   bool hasHits_;
0103   bool isGeneratedSecondary_;
0104   bool isInHistory_;
0105   bool flagAncestor_;
0106   int idOnCaloSurface_;
0107   int idCaloVolume_;
0108   int idLastVolume_;
0109   bool caloIDChecked_;
0110   bool crossedBoundary_;
0111   math::XYZTLorentzVectorF positionAtBoundary_;
0112   math::XYZTLorentzVectorF momentumAtBoundary_;
0113   bool startedInFineVolume_;
0114   bool startedInFineVolumeIsSet_;
0115 
0116   int genParticlePID_, caloSurfaceParticlePID_;
0117   double genParticleP_, caloSurfaceParticleP_;
0118 
0119   bool hasCastorHit_;
0120   int castorHitPID_;
0121 
0122   // Restrict construction to friends
0123   TrackInformation()
0124       : G4VUserTrackInformation(),
0125         storeTrack_(false),
0126         isPrimary_(false),
0127         hasHits_(false),
0128         isGeneratedSecondary_(false),
0129         isInHistory_(false),
0130         flagAncestor_(false),
0131         idOnCaloSurface_(0),
0132         idCaloVolume_(-1),
0133         idLastVolume_(-1),
0134         caloIDChecked_(false),
0135         crossedBoundary_(false),
0136         startedInFineVolume_(false),
0137         startedInFineVolumeIsSet_(false),
0138         genParticlePID_(-1),
0139         caloSurfaceParticlePID_(0),
0140         genParticleP_(0),
0141         caloSurfaceParticleP_(0),
0142         hasCastorHit_(false),
0143         castorHitPID_(0) {}
0144   friend class NewTrackAction;
0145 };
0146 
0147 extern G4ThreadLocal G4Allocator<TrackInformation> *fpTrackInformationAllocator;
0148 
0149 inline void *TrackInformation::operator new(size_t) {
0150   if (!fpTrackInformationAllocator)
0151     fpTrackInformationAllocator = new G4Allocator<TrackInformation>;
0152   return (void *)fpTrackInformationAllocator->MallocSingle();
0153 }
0154 
0155 inline void TrackInformation::operator delete(void *trkInfo) {
0156   fpTrackInformationAllocator->FreeSingle((TrackInformation *)trkInfo);
0157 }
0158 
0159 #endif