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  trackJetDecayLen_(0) {}
32 
34  const math::XYZVector &jetDir,
35  GlobalVector refjetdirection,
36  const reco::Vertex &pv) {
37  TVector3 jetDir3(jetDir.x(), jetDir.y(), jetDir.z());
38 
39  // deal with PAT/AOD polymorphism to get track
40  const reco::Track *track_ptr = nullptr;
41  auto packed_candidate = dynamic_cast<const pat::PackedCandidate *>(candidate);
42  auto pf_candidate = dynamic_cast<const reco::PFCandidate *>(candidate);
43  if (pf_candidate) {
44  track_ptr = pf_candidate->bestTrack(); // trackRef was sometimes null
45  } else if (packed_candidate && packed_candidate->hasTrackDetails()) {
46  // if PackedCandidate does not have TrackDetails this gives an Exception
47  // because unpackCovariance might be called for pseudoTrack/bestTrack
48  track_ptr = &(packed_candidate->pseudoTrack());
49  }
50 
51  if (!track_ptr) {
52  TVector3 trackMom3(candidate->momentum().x(), candidate->momentum().y(), candidate->momentum().z());
53  trackMomentum_ = candidate->p();
54  trackEta_ = candidate->eta();
55  trackEtaRel_ = reco::btau::etaRel(jetDir, candidate->momentum());
56  trackPtRel_ = trackMom3.Perp(jetDir3);
57  trackPPar_ = jetDir.Dot(candidate->momentum());
58  trackDeltaR_ = reco::deltaR(candidate->momentum(), jetDir);
59  trackPtRatio_ = trackMom3.Perp(jetDir3) / candidate->p();
60  trackPParRatio_ = jetDir.Dot(candidate->momentum()) / candidate->p();
61  trackSip2dVal_ = 0.;
62  trackSip2dSig_ = 0.;
63  trackSip3dVal_ = 0.;
64  trackSip3dSig_ = 0.;
65  trackJetDistVal_ = 0.;
66  trackJetDistSig_ = 0.;
67  trackJetDecayLen_ = 0.;
68  return;
69  }
70 
71  math::XYZVector trackMom = track_ptr->momentum();
72  double trackMag = std::sqrt(trackMom.Mag2());
73  TVector3 trackMom3(trackMom.x(), trackMom.y(), trackMom.z());
74 
75  trackMomentum_ = std::sqrt(trackMom.Mag2());
76  trackEta_ = trackMom.Eta();
77  trackEtaRel_ = reco::btau::etaRel(jetDir, trackMom);
78  trackPtRel_ = trackMom3.Perp(jetDir3);
79  trackPPar_ = jetDir.Dot(trackMom);
80  trackDeltaR_ = reco::deltaR(trackMom, jetDir);
81  trackPtRatio_ = trackMom3.Perp(jetDir3) / trackMag;
82  trackPParRatio_ = jetDir.Dot(trackMom) / trackMag;
83 
84  reco::TransientTrack transientTrack;
85  transientTrack = builder_->build(*track_ptr);
86  Measurement1D meas_ip2d = IPTools::signedTransverseImpactParameter(transientTrack, refjetdirection, pv).second;
87  Measurement1D meas_ip3d = IPTools::signedImpactParameter3D(transientTrack, refjetdirection, pv).second;
88  Measurement1D jetdist = IPTools::jetTrackDistance(transientTrack, refjetdirection, pv).second;
89  Measurement1D decayl = IPTools::signedDecayLength3D(transientTrack, refjetdirection, pv).second;
90  trackSip2dVal_ = static_cast<float>(meas_ip2d.value());
91  trackSip2dSig_ = static_cast<float>(meas_ip2d.significance());
92  trackSip3dVal_ = static_cast<float>(meas_ip3d.value());
93  trackSip3dSig_ = static_cast<float>(meas_ip3d.significance());
94  trackJetDistVal_ = static_cast<float>(jetdist.value());
95  trackJetDistSig_ = static_cast<float>(jetdist.significance());
96 
97  trackJetDecayLen_ = static_cast<float>(decayl.value());
98  }
99 
100 } // 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 > signedDecayLength3D(const TrajectoryStateOnSurface &state, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:105
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