CMS 3D CMS Logo

deep_helpers.cc
Go to the documentation of this file.
3 
4 namespace btagbtvdeep {
5 
6  constexpr static int qualityMap[8] = {1,0,1,1,4,4,5,6};
7 
15  muonFlagsMask = 0x0600,
17  };
18 
19 
20  // remove infs and NaNs with value (adapted from DeepNTuples)
21  const float catch_infs(const float in,
22  const float replace_value) {
23  if(in==in){ // check if NaN
24  if(std::isinf(in))
25  return replace_value;
26  else if(in < -1e32 || in > 1e32)
27  return replace_value;
28  return in;
29  }
30  return replace_value;
31  }
32 
33  // remove infs/NaN and bound (adapted from DeepNTuples)
34  const float catch_infs_and_bound(const float in,
35  const float replace_value,
36  const float lowerbound,
37  const float upperbound,
38  const float offset,
39  const bool use_offsets){
40  float withoutinfs=catch_infs(in,replace_value);
41  if(withoutinfs+offset<lowerbound) return lowerbound;
42  if(withoutinfs+offset>upperbound) return upperbound;
43  if(use_offsets)
44  withoutinfs+=offset;
45  return withoutinfs;
46  }
47 
48 
49  // 2D distance between SV and PV (adapted from DeepNTuples)
51  VertexDistanceXY dist;
53  reco::Vertex svtx(svcand.vertex(), csv);
54  return dist.distance(svtx, pv);
55  }
56 
57  //3D distance between SV and PV (adapted from DeepNTuples)
59  VertexDistance3D dist;
61  reco::Vertex svtx(svcand.vertex(), csv);
62  return dist.distance(svtx, pv);
63  }
64 
65  // dot product between SV and PV (adapted from DeepNTuples)
68  reco::Candidate::Vector d(sv.vx() - pv.x(), sv.vy() - pv.y(), sv.vz() - pv.z());
69  return p.Unit().Dot(d.Unit());
70  }
71 
72  // compute minimum dr between SVs and a candidate (from DeepNTuples, now polymorphic)
73  float mindrsvpfcand(const std::vector<reco::VertexCompositePtrCandidate> & svs,
74  const reco::Candidate* cand, float mindr) {
75 
76  for (unsigned int i0=0; i0<svs.size(); ++i0) {
77 
78  float tempdr = reco::deltaR(svs[i0],*cand);
79  if (tempdr<mindr) { mindr = tempdr; }
80 
81  }
82  return mindr;
83  }
84 
85  // instantiate template
86  template bool sv_vertex_comparator<reco::VertexCompositePtrCandidate, reco::Vertex>(const reco::VertexCompositePtrCandidate&,
87  const reco::VertexCompositePtrCandidate&,
88  const reco::Vertex&);
89 
90  float vtx_ass_from_pfcand(const reco::PFCandidate& pfcand, int pv_ass_quality, const reco::VertexRef & pv) {
91  float vtx_ass = pat::PackedCandidate::PVAssociationQuality(qualityMap[pv_ass_quality]);
92  if (pfcand.trackRef().isNonnull() &&
93  pv->trackWeight(pfcand.trackRef()) > 0.5 &&
94  pv_ass_quality == 7) {
96  }
97  return vtx_ass;
98  }
99 
101  const auto & pseudo_track = (pfcand.bestTrack()) ? *pfcand.bestTrack() : reco::Track();
102  // conditions from PackedCandidate producer
103  bool highPurity = pfcand.trackRef().isNonnull() && pseudo_track.quality(reco::Track::highPurity);
104  // do same bit operations than in PackedCandidate
105  uint16_t qualityFlags = 0;
106  qualityFlags = (qualityFlags & ~trackHighPurityMask) | ((highPurity << trackHighPurityShift) & trackHighPurityMask);
107  bool isHighPurity = (qualityFlags & trackHighPurityMask)>>trackHighPurityShift;
108  // to do as in TrackBase
109  uint8_t quality = (1 << reco::TrackBase::loose);
110  if (isHighPurity) {
111  quality |= (1 << reco::TrackBase::highPurity);
112  }
113  return quality;
114  }
115 
117  const auto & pseudo_track = (pfcand.bestTrack()) ? *pfcand.bestTrack() : reco::Track();
118  // conditions from PackedCandidate producer
119  bool highPurity = pfcand.trackRef().isNonnull() && pseudo_track.quality(reco::Track::highPurity);
120  // do same bit operations than in PackedCandidate
121  uint16_t qualityFlags = 0;
122  qualityFlags = (qualityFlags & ~trackHighPurityMask) | ((highPurity << trackHighPurityShift) & trackHighPurityMask);
123  return int16_t((qualityFlags & lostInnerHitsMask)>>lostInnerHitsShift)-1;
124  }
125 
126 }
127 
float quality_from_pfcand(const reco::PFCandidate &pfcand)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
float vertexDdotP(const reco::VertexCompositePtrCandidate &sv, const reco::Vertex &pv)
Definition: deep_helpers.cc:66
Measurement1D vertexD3d(const reco::VertexCompositePtrCandidate &svcand, const reco::Vertex &pv)
Definition: deep_helpers.cc:58
math::XYZVector Vector
point in the space
Definition: Candidate.h:43
void fillVertexCovariance(CovarianceMatrix &v) const override
fill SMatrix
const float catch_infs(const float in, const float replace_value=0.)
Definition: deep_helpers.cc:21
double vy() const override
y coordinate of vertex position
double y() const
y coordinate
Definition: Vertex.h:113
math::Error< dimension >::type CovarianceMatrix
covariance error matrix (3x3)
Definition: Vertex.h:45
#define constexpr
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:442
const float catch_infs_and_bound(const float in, const float replace_value, const float lowerbound, const float upperbound, const float offset=0., const bool use_offsets=true)
Definition: deep_helpers.cc:34
Vector momentum() const final
spatial momentum vector
qualityFlagsShiftsAndMasks
Definition: deep_helpers.cc:8
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
float mindrsvpfcand(const std::vector< reco::VertexCompositePtrCandidate > &svs, const reco::Candidate *cand, float mindr=0.4)
Definition: deep_helpers.cc:73
Measurement1D vertexDxy(const reco::VertexCompositePtrCandidate &svcand, const reco::Vertex &pv)
Definition: deep_helpers.cc:50
const Point & vertex() const override
vertex position (overwritten by PF...)
def pv(vc)
Definition: MetAnalyzer.py:6
double z() const
z coordinate
Definition: Vertex.h:115
float vtx_ass_from_pfcand(const reco::PFCandidate &pfcand, int pv_ass_quality, const reco::VertexRef &pv)
Definition: deep_helpers.cc:90
static int qualityMap[8]
Definition: deep_helpers.cc:6
double vz() const override
z coordinate of vertex position
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
double x() const
x coordinate
Definition: Vertex.h:111
float lost_inner_hits_from_pfcand(const reco::PFCandidate &pfcand)
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
const reco::Track * bestTrack() const override
Definition: PFCandidate.h:162
double vx() const override
x coordinate of vertex position