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