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 
33  const math::XYZVector &jetDir,
34  GlobalVector refjetdirection,
35  const reco::Vertex &pv) {
36  TVector3 jetDir3(jetDir.x(), jetDir.y(), jetDir.z());
37 
38  // deal with PAT/AOD polymorphism to get track
39  const reco::Track *track_ptr = nullptr;
40  auto packed_candidate = dynamic_cast<const pat::PackedCandidate *>(candidate);
41  auto pf_candidate = dynamic_cast<const reco::PFCandidate *>(candidate);
42  if (pf_candidate) {
43  track_ptr = pf_candidate->bestTrack(); // trackRef was sometimes null
44  } else if (packed_candidate && packed_candidate->hasTrackDetails()) {
45  // if PackedCandidate does not have TrackDetails this gives an Exception
46  // because unpackCovariance might be called for pseudoTrack/bestTrack
47  track_ptr = &(packed_candidate->pseudoTrack());
48  }
49 
50  if (!track_ptr) {
51  TVector3 trackMom3(candidate->momentum().x(), candidate->momentum().y(), candidate->momentum().z());
52  trackMomentum_ = candidate->p();
53  trackEta_ = candidate->eta();
54  trackEtaRel_ = reco::btau::etaRel(jetDir, candidate->momentum());
55  trackPtRel_ = trackMom3.Perp(jetDir3);
56  trackPPar_ = jetDir.Dot(candidate->momentum());
57  trackDeltaR_ = reco::deltaR(candidate->momentum(), jetDir);
58  trackPtRatio_ = trackMom3.Perp(jetDir3) / candidate->p();
59  trackPParRatio_ = jetDir.Dot(candidate->momentum()) / candidate->p();
60  trackSip2dVal_ = 0.;
61  trackSip2dSig_ = 0.;
62  trackSip3dVal_ = 0.;
63  trackSip3dSig_ = 0.;
64  trackJetDistVal_ = 0.;
65  trackJetDistSig_ = 0.;
66  return;
67  }
68 
69  math::XYZVector trackMom = track_ptr->momentum();
70  double trackMag = std::sqrt(trackMom.Mag2());
71  TVector3 trackMom3(trackMom.x(), trackMom.y(), trackMom.z());
72 
73  trackMomentum_ = std::sqrt(trackMom.Mag2());
74  trackEta_ = trackMom.Eta();
75  trackEtaRel_ = reco::btau::etaRel(jetDir, trackMom);
76  trackPtRel_ = trackMom3.Perp(jetDir3);
77  trackPPar_ = jetDir.Dot(trackMom);
78  trackDeltaR_ = reco::deltaR(trackMom, jetDir);
79  trackPtRatio_ = trackMom3.Perp(jetDir3) / trackMag;
80  trackPParRatio_ = jetDir.Dot(trackMom) / trackMag;
81 
82  reco::TransientTrack transientTrack;
83  transientTrack = builder_->build(*track_ptr);
84  Measurement1D meas_ip2d = IPTools::signedTransverseImpactParameter(transientTrack, refjetdirection, pv).second;
85  Measurement1D meas_ip3d = IPTools::signedImpactParameter3D(transientTrack, refjetdirection, pv).second;
86  Measurement1D jetdist = IPTools::jetTrackDistance(transientTrack, refjetdirection, pv).second;
87  trackSip2dVal_ = static_cast<float>(meas_ip2d.value());
88  trackSip2dSig_ = static_cast<float>(meas_ip2d.significance());
89  trackSip3dVal_ = static_cast<float>(meas_ip3d.value());
90  trackSip3dSig_ = static_cast<float>(meas_ip3d.significance());
91  trackJetDistVal_ = static_cast<float>(jetdist.value());
92  trackJetDistSig_ = static_cast<float>(jetdist.significance());
93  }
94 
95 } // namespace btagbtvdeep
void buildTrackInfo(const reco::Candidate *candidate, const math::XYZVector &jetDir, GlobalVector refjetdirection, const reco::Vertex &pv)
const reco::Track * bestTrack() const override
Definition: PFCandidate.h:150
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:57
std::pair< bool, Measurement1D > signedImpactParameter3D(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:81
edm::ESHandle< TransientTrackBuilder > builder_
std::pair< double, Measurement1D > jetTrackDistance(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:206
reco::TransientTrack build(const reco::Track *p) const
virtual double p() const =0
magnitude of momentum vector
virtual Vector momentum() const =0
spatial momentum vector
TrackInfoBuilder(edm::ESHandle< TransientTrackBuilder > &build)
T sqrt(T t)
Definition: SSEVec.h:19
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
double value() const
Definition: Measurement1D.h:25
double significance() const
Definition: Measurement1D.h:29
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
virtual double eta() const =0
momentum pseudorapidity