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  // remove infs and NaNs with value (adapted from DeepNTuples)
20  const float catch_infs(const float in, const float replace_value) {
21  if (in == in) { // check if NaN
22  if (std::isinf(in))
23  return replace_value;
24  else if (in < -1e32 || in > 1e32)
25  return replace_value;
26  return in;
27  }
28  return replace_value;
29  }
30 
31  // remove infs/NaN and bound (adapted from DeepNTuples)
32  const float catch_infs_and_bound(const float in,
33  const float replace_value,
34  const float lowerbound,
35  const float upperbound,
36  const float offset,
37  const bool use_offsets) {
38  float withoutinfs = catch_infs(in, replace_value);
39  if (withoutinfs + offset < lowerbound)
40  return lowerbound;
41  if (withoutinfs + offset > upperbound)
42  return upperbound;
43  if (use_offsets)
44  withoutinfs += offset;
45  return withoutinfs;
46  }
47 
48  // 2D distance between SV and PV (adapted from DeepNTuples)
50  VertexDistanceXY dist;
52  svcand.fillVertexCovariance(csv);
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  svcand.fillVertexCovariance(csv);
62  reco::Vertex svtx(svcand.vertex(), csv);
63  return dist.distance(svtx, pv);
64  }
65 
66  // dot product between SV and PV (adapted from DeepNTuples)
68  reco::Candidate::Vector p = sv.momentum();
69  reco::Candidate::Vector d(sv.vx() - pv.x(), sv.vy() - pv.y(), sv.vz() - pv.z());
70  return p.Unit().Dot(d.Unit());
71  }
72 
73  // compute minimum dr between SVs and a candidate (from DeepNTuples, now polymorphic)
74  float mindrsvpfcand(const std::vector<reco::VertexCompositePtrCandidate> &svs,
75  const reco::Candidate *cand,
76  float mindr) {
77  for (unsigned int i0 = 0; i0 < svs.size(); ++i0) {
78  float tempdr = reco::deltaR(svs[i0], *cand);
79  if (tempdr < mindr) {
80  mindr = tempdr;
81  }
82  }
83  return mindr;
84  }
85 
86  // instantiate template
87  template bool sv_vertex_comparator<reco::VertexCompositePtrCandidate, 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() && pv->trackWeight(pfcand.trackRef()) > 0.5 && pv_ass_quality == 7) {
94  }
95  return vtx_ass;
96  }
97 
99  const auto &pseudo_track = (pfcand.bestTrack()) ? *pfcand.bestTrack() : reco::Track();
100  // conditions from PackedCandidate producer
101  bool highPurity = pfcand.trackRef().isNonnull() && pseudo_track.quality(reco::Track::highPurity);
102  // do same bit operations than in PackedCandidate
103  uint16_t qualityFlags = 0;
104  qualityFlags = (qualityFlags & ~trackHighPurityMask) | ((highPurity << trackHighPurityShift) & trackHighPurityMask);
105  bool isHighPurity = (qualityFlags & trackHighPurityMask) >> trackHighPurityShift;
106  // to do as in TrackBase
107  uint8_t quality = (1 << reco::TrackBase::loose);
108  if (isHighPurity) {
110  }
111  return quality;
112  }
113 
115  const auto &pseudo_track = (pfcand.bestTrack()) ? *pfcand.bestTrack() : reco::Track();
116  // conditions from PackedCandidate producer
117  bool highPurity = pfcand.trackRef().isNonnull() && pseudo_track.quality(reco::Track::highPurity);
118  // do same bit operations than in PackedCandidate
119  uint16_t qualityFlags = 0;
120  qualityFlags = (qualityFlags & ~trackHighPurityMask) | ((highPurity << trackHighPurityShift) & trackHighPurityMask);
121  return int16_t((qualityFlags & lostInnerHitsMask) >> lostInnerHitsShift) - 1;
122  }
123 
124 } // namespace btagbtvdeep
btagbtvdeep
Definition: BoostedDoubleSVTagInfoFeatures.h:4
Measurement1D
Definition: Measurement1D.h:11
reco::Candidate::Vector
math::XYZVector Vector
point in the space
Definition: Candidate.h:42
reco::TrackBase::loose
Definition: TrackBase.h:152
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
VertexDistance3D::distance
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
Definition: VertexDistance3D.cc:17
btagbtvdeep::vertexDxy
Measurement1D vertexDxy(const reco::VertexCompositePtrCandidate &svcand, const reco::Vertex &pv)
Definition: deep_helpers.cc:49
btagbtvdeep::muonFlagsMask
Definition: deep_helpers.cc:15
btagbtvdeep::trackHighPurityShift
Definition: deep_helpers.cc:12
reco::Vertex::CovarianceMatrix
math::Error< dimension >::type CovarianceMatrix
covariance error matrix (3x3)
Definition: Vertex.h:46
btagbtvdeep::lostInnerHitsMask
Definition: deep_helpers.cc:13
btagbtvdeep::qualityMap
constexpr static int qualityMap[8]
Definition: deep_helpers.cc:6
reco::VertexCompositePtrCandidate
Definition: VertexCompositePtrCandidate.h:16
edm::Ref< VertexCollection >
pfDeepBoostedJetPreprocessParams_cfi.pfcand
pfcand
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:8
btagbtvdeep::qualityFlagsShiftsAndMasks
qualityFlagsShiftsAndMasks
Definition: deep_helpers.cc:8
btagbtvdeep::lostInnerHitsShift
Definition: deep_helpers.cc:14
pfDeepBoostedJetPreprocessParams_cfi.sv
sv
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:352
reco::Track
Definition: Track.h:27
pat::PackedCandidate::PVAssociationQuality
PVAssociationQuality
Definition: PackedCandidate.h:721
btagbtvdeep::catch_infs_and_bound
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:32
VertexDistance3D
Definition: VertexDistance3D.h:13
btagbtvdeep::vtx_ass_from_pfcand
float vtx_ass_from_pfcand(const reco::PFCandidate &pfcand, int pv_ass_quality, const reco::VertexRef &pv)
Definition: deep_helpers.cc:90
btagbtvdeep::assignmentQualityMask
Definition: deep_helpers.cc:9
PackedCandidate.h
recoMuon::in
Definition: RecoMuonEnumerators.h:6
cand
Definition: decayParser.h:32
btagbtvdeep::catch_infs
const float catch_infs(const float in, const float replace_value=0.)
Definition: deep_helpers.cc:20
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
btagbtvdeep::mindrsvpfcand
float mindrsvpfcand(const std::vector< reco::VertexCompositePtrCandidate > &svs, const reco::Candidate *cand, float mindr=0.4)
Definition: deep_helpers.cc:74
VertexDistanceXY
Definition: VertexDistanceXY.h:11
reco::LeafCandidate::vertex
const Point & vertex() const override
vertex position (overwritten by PF...)
Definition: LeafCandidate.h:165
reco::Candidate
Definition: Candidate.h:27
VertexDistanceXY::distance
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
Definition: VertexDistanceXY.cc:19
qcdUeDQM_cfi.quality
quality
Definition: qcdUeDQM_cfi.py:31
MTVHistoProducerAlgoForTrackerBlock_cfi.mindr
mindr
Definition: MTVHistoProducerAlgoForTrackerBlock_cfi.py:79
muons_cff.highPurity
highPurity
Definition: muons_cff.py:136
btagbtvdeep::quality_from_pfcand
float quality_from_pfcand(const reco::PFCandidate &pfcand)
Definition: deep_helpers.cc:98
btagbtvdeep::vertexD3d
Measurement1D vertexD3d(const reco::VertexCompositePtrCandidate &svcand, const reco::Vertex &pv)
Definition: deep_helpers.cc:58
reco::deltaR
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
btagbtvdeep::muonFlagsShift
Definition: deep_helpers.cc:16
deep_helpers.h
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
ztail.d
d
Definition: ztail.py:151
reco::VertexCompositePtrCandidate::fillVertexCovariance
void fillVertexCovariance(CovarianceMatrix &v) const override
fill SMatrix
Definition: VertexCompositePtrCandidate.cc:38
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
pat::PackedCandidate::UsedInFitTight
Definition: PackedCandidate.h:727
btagbtvdeep::assignmentQualityShift
Definition: deep_helpers.cc:10
btagbtvdeep::lost_inner_hits_from_pfcand
float lost_inner_hits_from_pfcand(const reco::PFCandidate &pfcand)
Definition: deep_helpers.cc:114
reco::Vertex
Definition: Vertex.h:35
btagbtvdeep::trackHighPurityMask
Definition: deep_helpers.cc:11
btagbtvdeep::vertexDdotP
float vertexDdotP(const reco::VertexCompositePtrCandidate &sv, const reco::Vertex &pv)
Definition: deep_helpers.cc:67
reco::TrackBase::highPurity
Definition: TrackBase.h:154