Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:32

0001 #ifndef TRACKINFO_RECOTRACKTOTP_H
0002 #define TRACKINFO_RECOTRACKTOTP_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 RecoTracktoTP {
0021 public:
0022   RecoTracktoTP();
0023   ~RecoTracktoTP();
0024 
0025   void SetTrackingParticle(TrackingParticleRef tp) { trackingParticle_ = tp; }
0026   void SetRecoTrack(reco::TrackBaseRef track) { recoTrack = track; }
0027   void SetRecoVertex(reco::VertexRef vertex) { recoVertex = vertex; }
0028   void SetBeamSpot(const math::XYZPoint &bs) { beamSpot_ = bs; }
0029   void SetShared(const float &m) { shared_ = m; }
0030 
0031   // Interogation Functions
0032   reco::Track RT() const { return recoTrack.isNonnull() ? *recoTrack : reco::Track(); }
0033   TrackingParticle TP() const { return trackingParticle_.isNonnull() ? *trackingParticle_ : TrackingParticle(); }
0034   reco::Vertex RV() const { return recoVertex.isNonnull() ? *recoVertex : reco::Vertex(); }
0035   math::XYZPoint BeamSpot() const { return beamSpot_; }
0036 
0037   bool matched() const { return trackingParticle_.isNonnull() && recoTrack.isNonnull(); }
0038   bool hasRV() const {
0039     return recoVertex.isNonnull() && fabs(recoVertex->position().Mag2()) > 0.0;
0040   }  // position is ROOT::MATH::Cartesian3D<double>
0041   bool hasPCA() const { return s_pca().mag() < 9999.0; }
0042   bool allmatched() const { return matched() && hasRV(); }
0043 
0044   // These members for reco d0 and dz are the TIP and LIP w.r.t the reconstructed BeamSpot (as opposed to (0,0,0) ).
0045   double r_dxy() const { return RT().dxy(BeamSpot()); }
0046   double r_dsz() const { return RT().dsz(BeamSpot()); }
0047   double r_d0() const { return -1.0 * r_dxy(); }
0048   double r_dz() const { return RT().dz(BeamSpot()); }
0049 
0050   // These members for reco d0 and dz are the TIP and LIP w.r.t the reconstructed vertex (as opposed to (0,0,0) ).
0051   double r_d02() const { return -1.0 * RT().dxy(RV().position()); }
0052   double r_dz2() const { return RT().dz(RV().position()); }
0053 
0054   // These members for sim d0 and dz are not included in the TrackingParticle class and must be included seperately.
0055   void SetTrackingParticleMomentumPCA(const GlobalVector &p) { simMomPCA_ = p; }
0056   void SetTrackingParticlePCA(const GlobalPoint &v) { simPCA_ = v; }
0057 
0058   GlobalVector s_p() const { return simMomPCA_; }
0059   GlobalPoint s_pca() const { return simPCA_; }
0060   GlobalPoint s_v() const {
0061     return GlobalPoint(s_pca().x() - BeamSpot().x(), s_pca().y() - BeamSpot().y(), s_pca().z() - BeamSpot().z());
0062   }
0063 
0064   double s_qoverp() const { return TP().charge() / s_p().mag(); }
0065   double s_theta() const { return s_p().theta(); }
0066   double s_lambda() const { return M_PI / 2 - s_p().theta(); }
0067   double s_phi() const { return s_p().phi(); }
0068   double s_eta() const { return -1.0 * log(tan(0.5 * s_p().theta())); }
0069 
0070   double s_dxy() const { return (-s_v().x() * s_p().y() + s_v().y() * s_p().x()) / s_p().perp(); }
0071   double s_dsz() const {
0072     return s_v().z() * s_p().perp() / s_p().mag() -
0073            ((s_v().x() * s_p().x() + s_v().y() * s_p().y()) / s_p().perp()) * s_p().z() / s_p().mag();
0074   }
0075   double s_d0() const { return -1.0 * s_dxy(); }
0076   double s_dz() const {
0077     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();
0078   }
0079   float GetShared() const { return shared_; }
0080 
0081   // Short cut methods to get TP truth info
0082   TrackingParticle TPMother(unsigned short i) const;
0083   TrackingParticle TPMother() const { return numTPMothers() == 1 ? TPMother(0) : TrackingParticle(); }
0084   int numTPSourceTracks() const { return TP().parentVertex()->nSourceTracks(); }
0085   int numTPMothers() const;
0086   bool hasTPMother() const { return numTPMothers() > 0; }
0087 
0088 protected:
0089   reco::TrackBaseRef recoTrack;
0090   reco::VertexRef recoVertex;
0091 
0092   TrackingParticleRef trackingParticle_;
0093 
0094   GlobalVector simMomPCA_;   // Momentum at point of closest approach to the beamspot of the trackingParticle.
0095   GlobalPoint simPCA_;       // Point of closest approach to the BeamSpot of the TrackingParticle.
0096   math::XYZPoint beamSpot_;  // I use type XYZPoint to faciliate the use of the recoTrack memeber dxy(XYZPoint).
0097   float shared_;             // Number of shared hits with TP
0098 };
0099 
0100 #endif  // TRACKINFO_RECOTRACKTOTP_H