CMS 3D CMS Logo

deep_helpers.h
Go to the documentation of this file.
1 #ifndef RecoBTag_DeepFlavour_deep_helpers_h
2 #define RecoBTag_DeepFlavour_deep_helpers_h
3 
7 
8 
9 
10 namespace btagbtvdeep {
11 
12  // remove infs and NaNs with value (adapted from DeepNTuples)
13  inline const float catch_infs(const float in,
14  const float replace_value) {
15  if(in==in){ // check if NaN
16  if(std::isinf(in))
17  return replace_value;
18  else if(in < -1e32 || in > 1e32)
19  return replace_value;
20  return in;
21  }
22  return replace_value;
23  }
24 
25  // remove infs/NaN and bound (adapted from DeepNTuples)
26  inline const float catch_infs_and_bound(const float in,
27  const float replace_value,
28  const float lowerbound,
29  const float upperbound,
30  const float offset=0.,
31  const bool use_offsets = true){
32  float withoutinfs=catch_infs(in,replace_value);
33  if(withoutinfs+offset<lowerbound) return lowerbound;
34  if(withoutinfs+offset>upperbound) return upperbound;
35  if(use_offsets)
36  withoutinfs+=offset;
37  return withoutinfs;
38  }
39 
40 
41  // 2D distance between SV and PV (adapted from DeepNTuples)
43  VertexDistanceXY dist;
45  reco::Vertex svtx(svcand.vertex(), csv);
46  return dist.distance(svtx, pv);
47  }
48 
49  //3D distance between SV and PV (adapted from DeepNTuples)
51  VertexDistance3D dist;
53  reco::Vertex svtx(svcand.vertex(), csv);
54  return dist.distance(svtx, pv);
55  }
56 
57  // dot product between SV and PV (adapted from DeepNTuples)
60  reco::Candidate::Vector d(sv.vx() - pv.x(), sv.vy() - pv.y(), sv.vz() - pv.z());
61  return p.Unit().Dot(d.Unit());
62  }
63 
64  // helper to order vertices by significance (adapted from DeepNTuples)
65  template < typename SVType, typename PVType>
66  bool sv_vertex_comparator(const SVType & sva, const SVType & svb, const PVType & pv) {
67  auto adxy = vertexDxy(sva,pv);
68  auto bdxy = vertexDxy(svb,pv);
69  float aval= adxy.value();
70  float bval= bdxy.value();
71  float aerr= adxy.error();
72  float berr= bdxy.error();
73 
74  float asig= catch_infs(aval/aerr,0.);
75  float bsig= catch_infs(bval/berr,0.);
76  return bsig<asig;
77  }
78 
79  // write tagging variables to vector (adapted from DeepNTuples)
80  template <typename T>
83  std::vector<T> vals = from.getList(name ,false);
84  size_t size=std::min(vals.size(),max);
85  if(size > 0){
86  for(size_t i=0;i<vals.size();i++){
87  to[i]=catch_infs(vals[i],-0.1);
88  }
89  }
90  return size;
91  }
92 
93  // compute minimum dr between SVs and a candidate (from DeepNTuples, now polymorphic)
94  float mindrsvpfcand(const std::vector<reco::VertexCompositePtrCandidate> & svs,
95  const reco::Candidate* cand, float mindr=0.4) {
96 
97  for (unsigned int i0=0; i0<svs.size(); ++i0) {
98 
99  float tempdr = reco::deltaR(svs[i0],*cand);
100  if (tempdr<mindr) { mindr = tempdr; }
101 
102  }
103  return mindr;
104  }
105 
106 
107 
108 }
109 
110 #endif //RecoBTag_DeepFlavour_deep_helpers_h
size
Write out results.
float vertexDdotP(const reco::VertexCompositePtrCandidate &sv, const reco::Vertex &pv)
Definition: deep_helpers.h:58
Measurement1D vertexD3d(const reco::VertexCompositePtrCandidate &svcand, const reco::Vertex &pv)
Definition: deep_helpers.h:50
math::XYZVector Vector
point in the space
Definition: Candidate.h:43
void fillVertexCovariance(CovarianceMatrix &v) const override
fill SMatrix
double vy() const override
y coordinate of vertex position
double y() const
y coordinate
Definition: Vertex.h:113
int dump_vector(reco::TaggingVariableList &from, T *to, reco::btau::TaggingVariableName name, const size_t max)
Definition: deep_helpers.h:81
math::Error< dimension >::type CovarianceMatrix
covariance error matrix (3x3)
Definition: Vertex.h:45
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
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.h:26
Vector momentum() const final
spatial momentum vector
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.h:94
Measurement1D vertexDxy(const reco::VertexCompositePtrCandidate &svcand, const reco::Vertex &pv)
Definition: deep_helpers.h:42
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
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
std::vector< TaggingValue > getList(TaggingVariableName tag, bool throwOnEmptyList=true) const
T min(T a, T b)
Definition: MathUtil.h:58
double vz() const override
z coordinate of vertex position
double x() const
x coordinate
Definition: Vertex.h:111
bool sv_vertex_comparator(const SVType &sva, const SVType &svb, const PVType &pv)
Definition: deep_helpers.h:66
const float catch_infs(const float in, const float replace_value)
Definition: deep_helpers.h:13
long double T
double vx() const override
x coordinate of vertex position