CMS 3D CMS Logo

deep_helpers.h
Go to the documentation of this file.
1 #ifndef RecoBTag_FeatureTools_deep_helpers_h
2 #define RecoBTag_FeatureTools_deep_helpers_h
3 
6 
8 
10 
13 //#include "RecoVertex/VertexTools/interface/VertexDistanceXY.h"
14 
17 
18 namespace btagbtvdeep {
19 
20  // remove infs and NaNs with value (adapted from DeepNTuples)
21  const float catch_infs(const float in,
22  const float replace_value = 0.);
23 
24  // remove infs/NaN and bound (adapted from DeepNTuples)
25  const float catch_infs_and_bound(const float in,
26  const float replace_value,
27  const float lowerbound,
28  const float upperbound,
29  const float offset=0.,
30  const bool use_offsets = true);
31 
32  // 2D distance between SV and PV (adapted from DeepNTuples)
34 
35  //3D distance between SV and PV (adapted from DeepNTuples)
37 
38  // dot product between SV and PV (adapted from DeepNTuples)
40 
41  // helper to order vertices by significance (adapted from DeepNTuples)
42  template < typename SVType, typename PVType>
43  bool sv_vertex_comparator(const SVType & sva, const SVType & svb, const PVType & pv) {
44  auto adxy = vertexDxy(sva,pv);
45  auto bdxy = vertexDxy(svb,pv);
46  float aval= adxy.value();
47  float bval= bdxy.value();
48  float aerr= adxy.error();
49  float berr= bdxy.error();
50 
51  float asig= catch_infs(aval/aerr,0.);
52  float bsig= catch_infs(bval/berr,0.);
53  return bsig<asig;
54  }
55 
56  // write tagging variables to vector (adapted from DeepNTuples)
57  template <typename T>
60  std::vector<T> vals = from.getList(name ,false);
61  size_t size=std::min(vals.size(),max);
62  if(size > 0){
63  for(size_t i=0;i<vals.size();i++){
64  to[i]=catch_infs(vals[i],-0.1);
65  }
66  }
67  return size;
68  }
69 
70  // compute minimum dr between SVs and a candidate (from DeepNTuples, now polymorphic)
71  float mindrsvpfcand(const std::vector<reco::VertexCompositePtrCandidate> & svs,
72  const reco::Candidate* cand, float mindr=0.4);
73 
74  // mimic the calculation in PackedCandidate
75  float vtx_ass_from_pfcand(const reco::PFCandidate &pfcand, int pv_ass_quality, const reco::VertexRef & pv);
76  float quality_from_pfcand(const reco::PFCandidate &pfcand);
78 
79  // struct to hold preprocessing parameters
81  struct VarInfo {
82  VarInfo() {}
83  VarInfo(float median, float norm_factor, float replace_inf_value, float lower_bound, float upper_bound, float pad)
84  : center(median),
85  norm_factor(norm_factor),
86  replace_inf_value(replace_inf_value),
87  lower_bound(lower_bound),
88  upper_bound(upper_bound),
89  pad(pad) {}
90  float center = 0;
91  float norm_factor = 1;
92  float replace_inf_value = 0;
93  float lower_bound = -5;
94  float upper_bound = 5;
95  float pad = 0;
96  };
97 
98  unsigned min_length = 0;
99  unsigned max_length = 0;
100  std::vector<std::string> var_names;
101  std::unordered_map<std::string, VarInfo> var_info_map;
102 
103  VarInfo info(const std::string &name) const { return var_info_map.at(name); }
104  };
105 
106 } // namespace btagbtvdeep
107 #endif //RecoBTag_FeatureTools_deep_helpers_h
size
Write out results.
float quality_from_pfcand(const reco::PFCandidate &pfcand)
float vertexDdotP(const reco::VertexCompositePtrCandidate &sv, const reco::Vertex &pv)
Definition: deep_helpers.cc:66
std::vector< std::string > var_names
Definition: deep_helpers.h:100
Measurement1D vertexD3d(const reco::VertexCompositePtrCandidate &svcand, const reco::Vertex &pv)
Definition: deep_helpers.cc:58
std::unordered_map< std::string, VarInfo > var_info_map
Definition: deep_helpers.h:101
const float catch_infs(const float in, const float replace_value=0.)
Definition: deep_helpers.cc:21
int dump_vector(reco::TaggingVariableList &from, T *to, reco::btau::TaggingVariableName name, const size_t max)
Definition: deep_helpers.h:58
VarInfo info(const std::string &name) const
Definition: deep_helpers.h:103
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
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
def pv(vc)
Definition: MetAnalyzer.py:7
std::vector< TaggingValue > getList(TaggingVariableName tag, bool throwOnEmptyList=true) const
float vtx_ass_from_pfcand(const reco::PFCandidate &pfcand, int pv_ass_quality, const reco::VertexRef &pv)
Definition: deep_helpers.cc:90
T min(T a, T b)
Definition: MathUtil.h:58
bool sv_vertex_comparator(const SVType &sva, const SVType &svb, const PVType &pv)
Definition: deep_helpers.h:43
float lost_inner_hits_from_pfcand(const reco::PFCandidate &pfcand)
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
VarInfo(float median, float norm_factor, float replace_inf_value, float lower_bound, float upper_bound, float pad)
Definition: deep_helpers.h:83
long double T