CMS 3D CMS Logo

TrackInfoBuilder.cc
Go to the documentation of this file.
10 #include "TVector3.h"
11 
12 namespace btagbtvdeep{
13 
14 // adapted from DeepNtuples
16  builder_(build),
17  trackMomentum_(0),
18  trackEta_(0),
19  trackEtaRel_(0),
20  trackPtRel_(0),
21  trackPPar_(0),
22  trackDeltaR_(0),
23  trackPtRatio_(0),
24  trackPParRatio_(0),
25  trackSip2dVal_(0),
26  trackSip2dSig_(0),
27  trackSip3dVal_(0),
28  trackSip3dSig_(0),
29  trackJetDistVal_(0),
30  trackJetDistSig_(0)
31 {
32 
33 }
34 
35 
36  void TrackInfoBuilder::buildTrackInfo(const reco::Candidate * candidate ,const math::XYZVector& jetDir, GlobalVector refjetdirection, const reco::Vertex & pv){
37  TVector3 jetDir3(jetDir.x(),jetDir.y(),jetDir.z());
38 
39 
40  // deal with PAT/AOD polymorphism to get track
41  const reco::Track * track_ptr = nullptr;
42  auto packed_candidate = dynamic_cast<const pat::PackedCandidate *>(candidate);
43  auto pf_candidate = dynamic_cast<const reco::PFCandidate *>(candidate);
44  if (pf_candidate) {
45  track_ptr = pf_candidate->bestTrack(); // trackRef was sometimes null
46  } else if (packed_candidate && packed_candidate->hasTrackDetails()) {
47  // if PackedCandidate does not have TrackDetails this gives an Exception
48  // because unpackCovariance might be called for pseudoTrack/bestTrack
49  track_ptr = &(packed_candidate->pseudoTrack());
50  }
51 
52  if(!track_ptr) {
53  TVector3 trackMom3(
54  candidate->momentum().x(),
55  candidate->momentum().y(),
56  candidate->momentum().z()
57  );
58  trackMomentum_=candidate->p();
59  trackEta_= candidate->eta();
60  trackEtaRel_=reco::btau::etaRel(jetDir, candidate->momentum());
61  trackPtRel_=trackMom3.Perp(jetDir3);
62  trackPPar_=jetDir.Dot(candidate->momentum());
63  trackDeltaR_=reco::deltaR(candidate->momentum(), jetDir);
64  trackPtRatio_=trackMom3.Perp(jetDir3) / candidate->p();
65  trackPParRatio_=jetDir.Dot(candidate->momentum()) / candidate->p();
66  trackSip2dVal_=0.;
67  trackSip2dSig_=0.;
68  trackSip3dVal_=0.;
69  trackSip3dSig_=0.;
72  return;
73  }
74 
75  math::XYZVector trackMom = track_ptr->momentum();
76  double trackMag = std::sqrt(trackMom.Mag2());
77  TVector3 trackMom3(trackMom.x(),trackMom.y(),trackMom.z());
78 
79  trackMomentum_=std::sqrt(trackMom.Mag2());
80  trackEta_= trackMom.Eta();
81  trackEtaRel_=reco::btau::etaRel(jetDir, trackMom);
82  trackPtRel_=trackMom3.Perp(jetDir3);
83  trackPPar_=jetDir.Dot(trackMom);
84  trackDeltaR_=reco::deltaR(trackMom, jetDir);
85  trackPtRatio_=trackMom3.Perp(jetDir3) / trackMag;
86  trackPParRatio_=jetDir.Dot(trackMom) / trackMag;
87 
88  reco::TransientTrack transientTrack;
89  transientTrack=builder_->build(*track_ptr);
90  Measurement1D meas_ip2d=IPTools::signedTransverseImpactParameter(transientTrack, refjetdirection, pv).second;
91  Measurement1D meas_ip3d=IPTools::signedImpactParameter3D(transientTrack, refjetdirection, pv).second;
92  Measurement1D jetdist=IPTools::jetTrackDistance(transientTrack, refjetdirection, pv).second;
93  trackSip2dVal_=static_cast<float>(meas_ip2d.value());
94  trackSip2dSig_=static_cast<float>(meas_ip2d.significance());
95  trackSip3dVal_=static_cast<float>(meas_ip3d.value());
96  trackSip3dSig_=static_cast<float>(meas_ip3d.significance());
97  trackJetDistVal_=static_cast<float>(jetdist.value());
98  trackJetDistSig_=static_cast<float>(jetdist.significance());
99 
100  }
101 
102 
103 
104 
105 }
106 
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
std::pair< bool, Measurement1D > signedImpactParameter3D(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:71
edm::ESHandle< TransientTrackBuilder > builder_
std::pair< double, Measurement1D > jetTrackDistance(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:200
TrackInfoBuilder(edm::ESHandle< TransientTrackBuilder > &build)
T sqrt(T t)
Definition: SSEVec.h:18
def pv(vc)
Definition: MetAnalyzer.py:6
virtual double p() const =0
magnitude of momentum vector
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
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 reco::Track * bestTrack() const override
Definition: PFCandidate.h:162