Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-20 02:50:31

0001 #ifndef SimDataFormats_TrackingParticle_h
0002 #define SimDataFormats_TrackingParticle_h
0003 
0004 #include <vector>
0005 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
0006 #include "DataFormats/Math/interface/Point3D.h"
0007 #include "DataFormats/Math/interface/Vector3D.h"
0008 #include "DataFormats/Math/interface/LorentzVector.h"
0009 #include "SimDataFormats/TrackingAnalysis/interface/TrackingVertexContainer.h"
0010 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0011 
0012 //
0013 // Forward declarations
0014 //
0015 class TrackingVertex;
0016 class SimTrack;
0017 class EncodedEventId;
0018 
0019 /** @brief Monte Carlo truth information used for tracking validation.
0020  *
0021  * Object with references to the original SimTrack and parent and daughter TrackingVertices.
0022  * Simulation with high (~100) pileup was taking too much memory so the class was slimmed down
0023  * and copies of the SimHits were removed.
0024  *
0025  * @author original author unknown, re-engineering and slimming by Subir Sarkar (subir.sarkar@cern.ch),
0026  * some tweaking and documentation by Mark Grimes (mark.grimes@bristol.ac.uk).
0027  * @date original date unknown, re-engineering Jan-May 2013
0028  */
0029 class TrackingParticle {
0030   friend std::ostream& operator<<(std::ostream& s, TrackingParticle const& tp);
0031 
0032 public:
0033   typedef int Charge;                                       ///< electric charge type
0034   typedef math::XYZTLorentzVectorD LorentzVector;           ///< Lorentz vector
0035   typedef math::PtEtaPhiMLorentzVector PolarLorentzVector;  ///< Lorentz vector
0036   typedef math::XYZPointD Point;                            ///< point in the space
0037   typedef math::XYZVectorD Vector;                          ///< point in the space
0038 
0039   /// reference to reco::GenParticle
0040   typedef reco::GenParticleRefVector::iterator genp_iterator;
0041   typedef std::vector<SimTrack>::const_iterator g4t_iterator;
0042 
0043   /** @brief Default constructor. Note that the object will be useless until it is provided
0044      * with a SimTrack and parent TrackingVertex.
0045      *
0046      * Most of the methods assume there is a SimTrack and parent TrackingVertex set, so will either
0047      * crash or give undefined results if this isn't true. This constructor should only be used to
0048      * create a placeholder until setParentVertex() and addG4Track() can be called.
0049      */
0050   TrackingParticle();
0051 
0052   TrackingParticle(const SimTrack& simtrk, const TrackingVertexRef& parentVertex);
0053 
0054   // destructor
0055   ~TrackingParticle();
0056 
0057   /** @brief PDG ID.
0058      *
0059      * Returns the PDG ID of the first associated gen particle. If there are no gen particles associated
0060      * then it returns type() from the first SimTrack. */
0061   int pdgId() const {
0062     if (genParticles_.empty())
0063       return g4Tracks_[0].type();
0064     else
0065       return (*genParticles_.begin())->pdgId();
0066   }
0067 
0068   /** @brief Signal source, crossing number.
0069      *
0070      * Note this is taken from the first SimTrack only, but there shouldn't be any SimTracks from different
0071      * crossings in the TrackingParticle. */
0072   EncodedEventId eventId() const { return g4Tracks_[0].eventId(); }
0073 
0074   // Setters for G4 and reco::GenParticle
0075   void addGenParticle(const reco::GenParticleRef& ref);
0076   void addG4Track(const SimTrack& t);
0077   /// iterators
0078   genp_iterator genParticle_begin() const;
0079   genp_iterator genParticle_end() const;
0080   g4t_iterator g4Track_begin() const;
0081   g4t_iterator g4Track_end() const;
0082   void setParentVertex(const TrackingVertexRef& ref);
0083   void addDecayVertex(const TrackingVertexRef& ref);
0084   void clearParentVertex();
0085   void clearDecayVertices();
0086 
0087   // Getters for Embd and Sim Tracks
0088   const reco::GenParticleRefVector& genParticles() const { return genParticles_; }
0089   const std::vector<SimTrack>& g4Tracks() const { return g4Tracks_; }
0090   const TrackingVertexRef& parentVertex() const { return parentVertex_; }
0091 
0092   // Accessors for vector of decay vertices
0093   const TrackingVertexRefVector& decayVertices() const { return decayVertices_; }
0094   tv_iterator decayVertices_begin() const { return decayVertices_.begin(); }
0095   tv_iterator decayVertices_end() const { return decayVertices_.end(); }
0096 
0097   /// @brief Electric charge. Note this is taken from the first SimTrack only.
0098   float charge() const { return g4Tracks_[0].charge(); }
0099   /// Gives charge in unit of quark charge (should be 3 times "charge()")
0100   int threeCharge() const { return lrintf(3.f * charge()); }
0101 
0102   /// @brief Four-momentum Lorentz vector. Note this is taken from the first SimTrack only.
0103   const LorentzVector& p4() const { return g4Tracks_[0].momentum(); }
0104 
0105   /// @brief spatial momentum vector
0106   Vector momentum() const { return p4().Vect(); }
0107 
0108   /// @brief Vector to boost to the particle centre of mass frame.
0109   Vector boostToCM() const { return p4().BoostToCM(); }
0110 
0111   /// @brief Magnitude of momentum vector. Note this is taken from the first SimTrack only.
0112   double p() const { return p4().P(); }
0113 
0114   /// @brief Quotient of the electric charge over the magnitude of the momentum vector. Note this is taken from the first SimTrack only.
0115   double qoverp() const { return charge() / p(); }
0116 
0117   /// @brief Energy. Note this is taken from the first SimTrack only.
0118   double energy() const { return p4().E(); }
0119 
0120   /// @brief Transverse energy. Note this is taken from the first SimTrack only.
0121   double et() const { return p4().Et(); }
0122 
0123   /// @brief Mass. Note this is taken from the first SimTrack only.
0124   double mass() const { return p4().M(); }
0125 
0126   /// @brief Mass squared. Note this is taken from the first SimTrack only.
0127   double massSqr() const { return pow(mass(), 2); }
0128 
0129   /// @brief Transverse mass. Note this is taken from the first SimTrack only.
0130   double mt() const { return p4().Mt(); }
0131 
0132   /// @brief Transverse mass squared. Note this is taken from the first SimTrack only.
0133   double mtSqr() const { return p4().Mt2(); }
0134 
0135   /// @brief x coordinate of momentum vector. Note this is taken from the first SimTrack only.
0136   double px() const { return p4().Px(); }
0137 
0138   /// @brief y coordinate of momentum vector. Note this is taken from the first SimTrack only.
0139   double py() const { return p4().Py(); }
0140 
0141   /// @brief z coordinate of momentum vector. Note this is taken from the first SimTrack only.
0142   double pz() const { return p4().Pz(); }
0143 
0144   /// @brief Transverse momentum. Note this is taken from the first SimTrack only.
0145   double pt() const { return p4().Pt(); }
0146 
0147   /// @brief Momentum azimuthal angle. Note this is taken from the first SimTrack only.
0148   double phi() const { return p4().Phi(); }
0149 
0150   /// @brief Momentum polar angle. Note this is taken from the first SimTrack only.
0151   double theta() const { return p4().Theta(); }
0152 
0153   /// @brief Momentum pseudorapidity. Note this is taken from the first SimTrack only.
0154   double eta() const { return p4().Eta(); }
0155 
0156   /// @brief Lambda angle. Note this is taken from the first SimTrack only.
0157   double lambda() const { return M_PI_2 - theta(); }
0158 
0159   /// @brief tangent of the lambda angle. Note this is taken from the first SimTrack only.
0160   double tanl() const { return tan(lambda()); }
0161 
0162   /// @brief Rapidity. Note this is taken from the first SimTrack only.
0163   double rapidity() const { return p4().Rapidity(); }
0164 
0165   /// @brief Same as rapidity().
0166   double y() const { return rapidity(); }
0167 
0168   /// @brief Parent vertex position
0169   Point vertex() const {
0170     const TrackingVertex::LorentzVector& p = (*parentVertex_).position();
0171     return Point(p.x(), p.y(), p.z());
0172   }
0173 
0174   /// @brief x coordinate of parent vertex position
0175   double vx() const {
0176     const TrackingVertex& r = (*parentVertex_);
0177     return r.position().X();
0178   }
0179 
0180   /// @brief y coordinate of parent vertex position
0181   double vy() const {
0182     const TrackingVertex& r = (*parentVertex_);
0183     return r.position().Y();
0184   }
0185 
0186   /// @brief z coordinate of parent vertex position
0187   double vz() const {
0188     const TrackingVertex& r = (*parentVertex_);
0189     return r.position().Z();
0190   }
0191 
0192   /// @brief dxy parameter.
0193   double dxy() const { return (-vx() * py() + vy() * px()) / pt(); }
0194 
0195   /// @brief dxy parameter in perigee convention (d0 = -dxy)
0196   double d0() const { return -dxy(); }
0197 
0198   /// @brief dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to (0,0,0).
0199   double dz() const { return vz() - (vx() * px() + vy() * py()) * pz() / p4().Perp2(); }
0200 
0201   /// @brief z0 parameter
0202   double z0() const { return dz(); }
0203 
0204   /** @brief Status word.
0205      *
0206      * Returns status() from the first gen particle, or -99 if there are no gen particles attached. */
0207   int status() const { return genParticles_.empty() ? -99 : (*genParticles_[0]).status(); }
0208 
0209   static const unsigned int longLivedTag;  ///< long lived flag
0210 
0211   /// is long lived?
0212   bool longLived() const { return status() & longLivedTag; }
0213 
0214   /** @brief Gives the total number of hits, including muon hits. Hits on overlaps in the same layer count separately.
0215     *
0216     * Equivalent to trackPSimHit().size() in the old TrackingParticle implementation. */
0217   int numberOfHits() const { return numberOfHits_; }
0218 
0219   /** @brief The number of hits in the tracker. Hits on overlaps in the same layer count separately.
0220     *
0221     * Equivalent to trackPSimHit(DetId::Tracker).size() in the old TrackingParticle implementation. */
0222   int numberOfTrackerHits() const { return numberOfTrackerHits_; }
0223 
0224   /** @deprecated The number of hits in the tracker but taking account of overlaps.
0225     * Deprecated in favour of the more aptly named numberOfTrackerLayers(). */
0226   int matchedHit() const;
0227 
0228   /** @brief The number of tracker layers with a hit.
0229     *
0230     * Different from numberOfTrackerHits because this method counts multiple hits on overlaps in the layer as one hit. */
0231   int numberOfTrackerLayers() const { return numberOfTrackerLayers_; }
0232 
0233   void setNumberOfHits(int numberOfHits);
0234   void setNumberOfTrackerHits(int numberOfTrackerHits);
0235   void setNumberOfTrackerLayers(const int numberOfTrackerLayers);
0236 
0237 private:
0238   int numberOfHits_;           ///< @brief The total number of hits
0239   int numberOfTrackerHits_;    ///< @brief The number of tracker only hits
0240   int numberOfTrackerLayers_;  ///< @brief The number of tracker layers with hits. Equivalent to the old matchedHit.
0241 
0242   /// references to G4 and reco::GenParticle tracks
0243   std::vector<SimTrack> g4Tracks_;
0244   reco::GenParticleRefVector genParticles_;
0245 
0246   // Source and decay vertices
0247   TrackingVertexRef parentVertex_;
0248   TrackingVertexRefVector decayVertices_;
0249 };
0250 
0251 #endif  // SimDataFormats_TrackingParticle_H