Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:46:24

0001 #ifndef TRACKINFO_TPTORECOTRACK_H
0002 #define TRACKINFO_TPTORECOTRACK_H
0003 
0004 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0005 #include "DataFormats/TrackReco/interface/Track.h"
0006 #include "DataFormats/VertexReco/interface/Vertex.h"
0007 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0008 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0009 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0010 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
0011 #include "SimDataFormats/TrackingAnalysis/interface/TrackingVertex.h"
0012 #include "SimDataFormats/TrackingAnalysis/interface/TrackingVertexContainer.h"
0013 #include "DataFormats/Math/interface/Vector3D.h"
0014 #include "DataFormats/Math/interface/Point3D.h"
0015 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0016 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
0017 #include "TMath.h"
0018 //#include <vector>
0019 
0020 class TPtoRecoTrack {
0021 public:
0022   TPtoRecoTrack();
0023   ~TPtoRecoTrack();
0024 
0025   void SetTrackingParticle(TrackingParticleRef tp) { trackingParticle_ = tp; }
0026 
0027   void SetRecoTrack_AlgoA(reco::TrackBaseRef track) { recoTrack_AlgoA_ = track; }
0028   void SetRecoTrack_AlgoB(reco::TrackBaseRef track) { recoTrack_AlgoB_ = track; }
0029 
0030   void SetShared_AlgoA(const float &mA) { sharedA_ = mA; }
0031   void SetShared_AlgoB(const float &mB) { sharedB_ = mB; }
0032 
0033   void SetRecoVertex_AlgoA(reco::VertexRef vertex) { recoVertex_AlgoA_ = vertex; }
0034   void SetRecoVertex_AlgoB(reco::VertexRef vertex) { recoVertex_AlgoB_ = vertex; }
0035 
0036   void SetBeamSpot(const math::XYZPoint &bs) { beamSpot_ = bs; }
0037 
0038   // Interogation Functions
0039   reco::Track RTA() const { return recoTrack_AlgoA_.isNonnull() ? *recoTrack_AlgoA_ : reco::Track(); }
0040   reco::Track RTB() const { return recoTrack_AlgoB_.isNonnull() ? *recoTrack_AlgoB_ : reco::Track(); }
0041   TrackingParticle TP() const { return trackingParticle_.isNonnull() ? *trackingParticle_ : TrackingParticle(); }
0042   reco::Vertex RVA() const { return recoVertex_AlgoA_.isNonnull() ? *recoVertex_AlgoA_ : reco::Vertex(); }
0043   reco::Vertex RVB() const { return recoVertex_AlgoB_.isNonnull() ? *recoVertex_AlgoB_ : reco::Vertex(); }
0044   math::XYZPoint BeamSpot() const { return beamSpot_; }
0045 
0046   bool matched() const { return matchedA() && matchedB(); }
0047   bool matchedA() const { return trackingParticle_.isNonnull() && recoTrack_AlgoA_.isNonnull(); }
0048   bool matchedB() const { return trackingParticle_.isNonnull() && recoTrack_AlgoB_.isNonnull(); }
0049   bool matchedAnotB() const { return matchedA() && !matchedB(); }
0050   bool matchedBnotA() const { return matchedB() && !matchedA(); }
0051   bool hasRVA() const {
0052     return recoVertex_AlgoA_.isNonnull() && fabs(recoVertex_AlgoA_->position().Mag2()) > 0.0;
0053   }  // position is ROOT::MATH::Cartesian3D<double>
0054   bool hasRVB() const {
0055     return recoVertex_AlgoB_.isNonnull() && fabs(recoVertex_AlgoB_->position().Mag2()) > 0.0;
0056   }  // position is ROOT::MATH::Cartesian3D<double>
0057   bool hasRV() const { return hasRVA() && hasRVB(); }
0058   bool hasPCA() const { return s_pca().mag() < 9999.0; }
0059   bool allmatchedA() const { return matchedA() && hasRVA(); }
0060   bool allmatchedB() const { return matchedB() && hasRVA(); }
0061   bool allmatched() const { return matched() && hasRV(); }
0062   float GetSharedA() const { return sharedA_; }
0063   float GetSharedB() const { return sharedB_; }
0064 
0065   // These members for reco d0 and dz are the TIP and LIP w.r.t the reconstructed BeamSpot (as opposed to (0,0,0) ).
0066   double rA_dxy() const { return RTA().dxy(BeamSpot()); }
0067   double rB_dxy() const { return RTB().dxy(BeamSpot()); }
0068   double rA_dsz() const { return RTA().dsz(BeamSpot()); }
0069   double rB_dsz() const { return RTB().dsz(BeamSpot()); }
0070   double rA_d0() const { return -1.0 * rA_dxy(); }
0071   double rB_d0() const { return -1.0 * rB_dxy(); }
0072   double rA_dz() const { return RTA().dz(BeamSpot()); }
0073   double rB_dz() const { return RTB().dz(BeamSpot()); }
0074 
0075   // These members for reco d0 and dz are the TIP and LIP w.r.t the reconstructed vertex (as opposed to (0,0,0) ).
0076   double rA_d02() const { return -1.0 * RTA().dxy(RVA().position()); }
0077   double rA_dz2() const { return RTA().dz(RVA().position()); }
0078   double rB_d02() const { return -1.0 * RTB().dxy(RVB().position()); }
0079   double rB_dz2() const { return RTB().dz(RVB().position()); }
0080 
0081   // These members for sim d0 and dz are not included in the TrackingParticle class and must be included seperately.
0082   void SetTrackingParticleMomentumPCA(const GlobalVector &p) { simMomPCA_ = p; }
0083   void SetTrackingParticlePCA(const GlobalPoint &v) { simPCA_ = v; }
0084 
0085   GlobalVector s_p() const { return simMomPCA_; }
0086   GlobalPoint s_pca() const { return simPCA_; }
0087   GlobalPoint s_v() const {
0088     return GlobalPoint(s_pca().x() - BeamSpot().x(), s_pca().y() - BeamSpot().y(), s_pca().z() - BeamSpot().z());
0089   }
0090 
0091   double s_qoverp() const { return TP().charge() / s_p().mag(); }
0092   double s_theta() const { return s_p().theta(); }
0093   double s_lambda() const { return M_PI / 2 - s_p().theta(); }
0094   double s_phi() const { return s_p().phi(); }
0095   double s_eta() const { return -1.0 * log(tan(0.5 * s_p().theta())); }
0096 
0097   double s_dxy() const { return (-s_v().x() * s_p().y() + s_v().y() * s_p().x()) / s_p().perp(); }
0098   double s_dsz() const {
0099     return s_v().z() * s_p().perp() / s_p().mag() -
0100            ((s_v().x() * s_p().x() + s_v().y() * s_p().y()) / s_p().perp()) * s_p().z() / s_p().mag();
0101   }
0102   double s_d0() const { return -1.0 * s_dxy(); }
0103   double s_dz() const {
0104     return s_v().z() - (s_v().x() * s_p().x() + s_v().y() * s_p().y()) / s_p().perp() * s_p().z() / s_p().perp();
0105   }
0106 
0107   // Short cut methods to get TP truth info
0108   TrackingParticle TPMother(unsigned short i) const;
0109   TrackingParticle TPMother() const { return numTPMothers() == 1 ? TPMother(0) : TrackingParticle(); }
0110   int numTPSourceTracks() const { return TP().parentVertex()->nSourceTracks(); }
0111   int numTPMothers() const;
0112   bool hasTPMother() const { return numTPMothers() > 0; }
0113 
0114 protected:
0115   reco::TrackBaseRef recoTrack_AlgoA_;
0116   reco::VertexRef recoVertex_AlgoA_;
0117 
0118   reco::TrackBaseRef recoTrack_AlgoB_;
0119   reco::VertexRef recoVertex_AlgoB_;
0120 
0121   TrackingParticleRef trackingParticle_;
0122 
0123   GlobalVector simMomPCA_;   // Momentum at point of closest approach to the beamspot of the trackingParticle.
0124   GlobalPoint simPCA_;       // Point of closest approach to the BeamSpot of the TrackingParticle.
0125   math::XYZPoint beamSpot_;  // I use type XYZPoint to faciliate the use of the recoTrack memeber dxy(XYZPoint).
0126   float sharedA_;            // Number of shared hits with track A
0127   float sharedB_;            // Number of shared hits with track B
0128 };
0129 
0130 #endif  // TRACKINFO_TPTORECOTRACK_H