CMS 3D CMS Logo

TrackInfoBuilder.h
Go to the documentation of this file.
1 #ifndef RecoBTag_DeepFlavour_TrackInfoBuilder_h
2 #define RecoBTag_DeepFlavour_TrackInfoBuilder_h
3 
6 
11 #include "TVector3.h"
12 
13 namespace btagbtvdeep{
14 
15 // adapted from DeepNtuples
17 public:
19  builder_(build),
20  trackMomentum_(0),
21  trackEta_(0),
22  trackEtaRel_(0),
23  trackPtRel_(0),
24  trackPPar_(0),
25  trackDeltaR_(0),
26  trackPtRatio_(0),
27  trackPParRatio_(0),
28  trackSip2dVal_(0),
29  trackSip2dSig_(0),
30  trackSip3dVal_(0),
31  trackSip3dSig_(0),
32 
35 {
36 
37 
38 }
39 
40  void buildTrackInfo(const reco::Candidate * candidate ,const math::XYZVector& jetDir, GlobalVector refjetdirection, const reco::Vertex & pv){
41  TVector3 jetDir3(jetDir.x(),jetDir.y(),jetDir.z());
42 
43 
44  // deal with PAT/AOD polymorphism to get track
45  const reco::Track * track_ptr = nullptr;
46  auto packed_candidate = dynamic_cast<const pat::PackedCandidate *>(candidate);
47  auto pf_candidate = dynamic_cast<const reco::PFCandidate *>(candidate);
48  if (pf_candidate) {
49  track_ptr = pf_candidate->bestTrack(); // trackRef was sometimes null
50  } else if (packed_candidate && packed_candidate->hasTrackDetails()) {
51  // if PackedCandidate does not have TrackDetails this gives an Exception
52  // because unpackCovariance might be called for pseudoTrack/bestTrack
53  track_ptr = &(packed_candidate->pseudoTrack());
54  }
55 
56  if(!track_ptr) {
57  TVector3 trackMom3(
58  candidate->momentum().x(),
59  candidate->momentum().y(),
60  candidate->momentum().z()
61  );
62  trackMomentum_=candidate->p();
63  trackEta_= candidate->eta();
64  trackEtaRel_=reco::btau::etaRel(jetDir, candidate->momentum());
65  trackPtRel_=trackMom3.Perp(jetDir3);
66  trackPPar_=jetDir.Dot(candidate->momentum());
67  trackDeltaR_=reco::deltaR(candidate->momentum(), jetDir);
68  trackPtRatio_=trackMom3.Perp(jetDir3) / candidate->p();
69  trackPParRatio_=jetDir.Dot(candidate->momentum()) / candidate->p();
70  trackSip2dVal_=0.;
71  trackSip2dSig_=0.;
72  trackSip3dVal_=0.;
73  trackSip3dSig_=0.;
76  return;
77  }
78 
79  math::XYZVector trackMom = track_ptr->momentum();
80  double trackMag = std::sqrt(trackMom.Mag2());
81  TVector3 trackMom3(trackMom.x(),trackMom.y(),trackMom.z());
82 
83  trackMomentum_=std::sqrt(trackMom.Mag2());
84  trackEta_= trackMom.Eta();
85  trackEtaRel_=reco::btau::etaRel(jetDir, trackMom);
86  trackPtRel_=trackMom3.Perp(jetDir3);
87  trackPPar_=jetDir.Dot(trackMom);
88  trackDeltaR_=reco::deltaR(trackMom, jetDir);
89  trackPtRatio_=trackMom3.Perp(jetDir3) / trackMag;
90  trackPParRatio_=jetDir.Dot(trackMom) / trackMag;
91 
92  reco::TransientTrack transientTrack;
93  transientTrack=builder_->build(*track_ptr);
94  Measurement1D meas_ip2d=IPTools::signedTransverseImpactParameter(transientTrack, refjetdirection, pv).second;
95  Measurement1D meas_ip3d=IPTools::signedImpactParameter3D(transientTrack, refjetdirection, pv).second;
96  Measurement1D jetdist=IPTools::jetTrackDistance(transientTrack, refjetdirection, pv).second;
97  trackSip2dVal_=static_cast<float>(meas_ip2d.value());
98  trackSip2dSig_=static_cast<float>(meas_ip2d.significance());
99  trackSip3dVal_=static_cast<float>(meas_ip3d.value());
100  trackSip3dSig_=static_cast<float>(meas_ip3d.significance());
101  trackJetDistVal_=static_cast<float>(jetdist.value());
102  trackJetDistSig_=static_cast<float>(jetdist.significance());
103 
104  }
105 
106  const float getTrackDeltaR() const {return trackDeltaR_;}
107  const float getTrackEta() const {return trackEta_;}
108  const float getTrackEtaRel() const {return trackEtaRel_;}
109  const float getTrackJetDistSig() const {return trackJetDistSig_;}
110  const float getTrackJetDistVal() const {return trackJetDistVal_;}
111  const float getTrackMomentum() const {return trackMomentum_;}
112  const float getTrackPPar() const {return trackPPar_;}
113  const float getTrackPParRatio() const {return trackPParRatio_;}
114  const float getTrackPtRatio() const {return trackPtRatio_;}
115  const float getTrackPtRel() const {return trackPtRel_;}
116  const float getTrackSip2dSig() const {return trackSip2dSig_;}
117  const float getTrackSip2dVal() const {return trackSip2dVal_;}
118  const float getTrackSip3dSig() const {return trackSip3dSig_;}
119  const float getTrackSip3dVal() const {return trackSip3dVal_;}
120 
121 private:
122 
124 
126  float trackEta_;
128  float trackPtRel_;
129  float trackPPar_;
137 
140 
141 };
142 
143 }
144 
145 #endif //RecoBTag_DeepFlavour_TrackInfoBuilder_h
void buildTrackInfo(const reco::Candidate *candidate, const math::XYZVector &jetDir, GlobalVector refjetdirection, const reco::Vertex &pv)
double etaRel(const math::XYZVector &dir, const math::XYZVector &track)
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:50
reco::TransientTrack build(const reco::Track *p) const
const float getTrackEta() const
std::pair< bool, Measurement1D > signedImpactParameter3D(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:71
const float getTrackMomentum() const
const float getTrackEtaRel() const
const float getTrackDeltaR() const
const float getTrackPParRatio() const
edm::ESHandle< TransientTrackBuilder > builder_
std::pair< double, Measurement1D > jetTrackDistance(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:200
const float getTrackSip2dSig() const
const float getTrackPPar() const
TrackInfoBuilder(edm::ESHandle< TransientTrackBuilder > &build)
T sqrt(T t)
Definition: SSEVec.h:18
def pv(vc)
Definition: MetAnalyzer.py:6
const float getTrackPtRatio() const
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
virtual double p() const =0
magnitude of momentum vector
const float getTrackSip3dVal() const
const float getTrackJetDistVal() const
double significance() const
Definition: Measurement1D.h:32
virtual double eta() const =0
momentum pseudorapidity
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
double value() const
Definition: Measurement1D.h:28
virtual Vector momentum() const =0
spatial momentum vector
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
const float getTrackJetDistSig() const
const float getTrackPtRel() const
const float getTrackSip2dVal() const
const reco::Track * bestTrack() const override
Definition: PFCandidate.h:162
const float getTrackSip3dSig() const