CMS 3D CMS Logo

deep_helpers.cc
Go to the documentation of this file.
4 
5 namespace btagbtvdeep {
6 
7  constexpr static int qualityMap[8] = {1, 0, 1, 1, 4, 4, 5, 6};
8 
16  muonFlagsMask = 0x0600,
18  };
19 
20  // remove infs and NaNs with value (adapted from DeepNTuples)
21  const float catch_infs(const float in, const float replace_value) {
22  if (edm::isNotFinite(in))
23  return replace_value;
24  if (in < -1e32 || in > 1e32)
25  return replace_value;
26  return in;
27  }
28 
29  // remove infs/NaN and bound (adapted from DeepNTuples)
30  const float catch_infs_and_bound(const float in,
31  const float replace_value,
32  const float lowerbound,
33  const float upperbound,
34  const float offset,
35  const bool use_offsets) {
36  float withoutinfs = catch_infs(in, replace_value);
37  if (withoutinfs + offset < lowerbound)
38  return lowerbound;
39  if (withoutinfs + offset > upperbound)
40  return upperbound;
41  if (use_offsets)
42  withoutinfs += offset;
43  return withoutinfs;
44  }
45 
46  // 2D distance between SV and PV (adapted from DeepNTuples)
48  VertexDistanceXY dist;
50  svcand.fillVertexCovariance(csv);
51  reco::Vertex svtx(svcand.vertex(), csv);
52  return dist.distance(svtx, pv);
53  }
54 
55  //3D distance between SV and PV (adapted from DeepNTuples)
57  VertexDistance3D dist;
59  svcand.fillVertexCovariance(csv);
60  reco::Vertex svtx(svcand.vertex(), csv);
61  return dist.distance(svtx, pv);
62  }
63 
64  // dot product between SV and PV (adapted from DeepNTuples)
66  reco::Candidate::Vector p = sv.momentum();
67  reco::Candidate::Vector d(sv.vx() - pv.x(), sv.vy() - pv.y(), sv.vz() - pv.z());
68  return p.Unit().Dot(d.Unit());
69  }
70 
71  // compute minimum dr between SVs and a candidate (from DeepNTuples, now polymorphic)
72  float mindrsvpfcand(const std::vector<reco::VertexCompositePtrCandidate> &svs,
73  const reco::Candidate *cand,
74  float mindr) {
75  for (unsigned int i0 = 0; i0 < svs.size(); ++i0) {
76  float tempdr = reco::deltaR(svs[i0], *cand);
77  if (tempdr < mindr) {
78  mindr = tempdr;
79  }
80  }
81  return mindr;
82  }
83 
84  // instantiate template
85  template bool sv_vertex_comparator<reco::VertexCompositePtrCandidate, reco::Vertex>(
87 
88  float vtx_ass_from_pfcand(const reco::PFCandidate &pfcand, int pv_ass_quality, const reco::VertexRef &pv) {
89  float vtx_ass = pat::PackedCandidate::PVAssociationQuality(qualityMap[pv_ass_quality]);
90  if (pfcand.trackRef().isNonnull() && pv->trackWeight(pfcand.trackRef()) > 0.5 && pv_ass_quality == 7) {
92  }
93  return vtx_ass;
94  }
95 
97  const auto &pseudo_track = (pfcand.bestTrack()) ? *pfcand.bestTrack() : reco::Track();
98  // conditions from PackedCandidate producer
99  bool highPurity = pfcand.trackRef().isNonnull() && pseudo_track.quality(reco::Track::highPurity);
100  // do same bit operations than in PackedCandidate
101  uint16_t qualityFlags = 0;
102  qualityFlags = (qualityFlags & ~trackHighPurityMask) | ((highPurity << trackHighPurityShift) & trackHighPurityMask);
103  bool isHighPurity = (qualityFlags & trackHighPurityMask) >> trackHighPurityShift;
104  // to do as in TrackBase
105  uint8_t quality = (1 << reco::TrackBase::loose);
106  if (isHighPurity) {
108  }
109  return quality;
110  }
111 
113  const auto &pseudo_track = (pfcand.bestTrack()) ? *pfcand.bestTrack() : reco::Track();
114  // conditions from PackedCandidate producer
115  bool highPurity = pfcand.trackRef().isNonnull() && pseudo_track.quality(reco::Track::highPurity);
116  // do same bit operations than in PackedCandidate
117  uint16_t qualityFlags = 0;
118  qualityFlags = (qualityFlags & ~trackHighPurityMask) | ((highPurity << trackHighPurityShift) & trackHighPurityMask);
119  return int16_t((qualityFlags & lostInnerHitsMask) >> lostInnerHitsShift) - 1;
120  }
121 
122 } // 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
edm::isNotFinite
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
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:47
btagbtvdeep::muonFlagsMask
Definition: deep_helpers.cc:16
btagbtvdeep::trackHighPurityShift
Definition: deep_helpers.cc:13
reco::Vertex::CovarianceMatrix
math::Error< dimension >::type CovarianceMatrix
covariance error matrix (3x3)
Definition: Vertex.h:46
btagbtvdeep::lostInnerHitsMask
Definition: deep_helpers.cc:14
btagbtvdeep::qualityMap
constexpr static int qualityMap[8]
Definition: deep_helpers.cc:7
reco::VertexCompositePtrCandidate
Definition: VertexCompositePtrCandidate.h:16
edm::Ref< VertexCollection >
pfDeepBoostedJetPreprocessParams_cfi.pfcand
pfcand
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:8
quality
const uint32_t *__restrict__ Quality * quality
Definition: CAHitNtupletGeneratorKernelsImpl.h:122
btagbtvdeep::qualityFlagsShiftsAndMasks
qualityFlagsShiftsAndMasks
Definition: deep_helpers.cc:9
btagbtvdeep::lostInnerHitsShift
Definition: deep_helpers.cc:15
pfDeepBoostedJetPreprocessParams_cfi.sv
sv
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:352
reco::Track
Definition: Track.h:27
pat::PackedCandidate::PVAssociationQuality
PVAssociationQuality
Definition: PackedCandidate.h:722
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:30
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:88
btagbtvdeep::assignmentQualityMask
Definition: deep_helpers.cc:10
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
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:21
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:72
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
isFinite.h
MTVHistoProducerAlgoForTrackerBlock_cfi.mindr
mindr
Definition: MTVHistoProducerAlgoForTrackerBlock_cfi.py:79
btagbtvdeep::quality_from_pfcand
float quality_from_pfcand(const reco::PFCandidate &pfcand)
Definition: deep_helpers.cc:96
btagbtvdeep::vertexD3d
Measurement1D vertexD3d(const reco::VertexCompositePtrCandidate &svcand, const reco::Vertex &pv)
Definition: deep_helpers.cc:56
reco::deltaR
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
btagbtvdeep::muonFlagsShift
Definition: deep_helpers.cc:17
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:728
btagbtvdeep::assignmentQualityShift
Definition: deep_helpers.cc:11
btagbtvdeep::lost_inner_hits_from_pfcand
float lost_inner_hits_from_pfcand(const reco::PFCandidate &pfcand)
Definition: deep_helpers.cc:112
reco::Vertex
Definition: Vertex.h:35
btagbtvdeep::trackHighPurityMask
Definition: deep_helpers.cc:12
btagbtvdeep::vertexDdotP
float vertexDdotP(const reco::VertexCompositePtrCandidate &sv, const reco::Vertex &pv)
Definition: deep_helpers.cc:65
reco::TrackBase::highPurity
Definition: TrackBase.h:154