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  // struct to hold preprocessing parameters
80  struct VarInfo {
81  VarInfo() {}
82  VarInfo(float median, float norm_factor, float replace_inf_value, float lower_bound, float upper_bound, float pad)
83  : center(median),
88  pad(pad) {}
89  float center = 0;
90  float norm_factor = 1;
91  float replace_inf_value = 0;
92  float lower_bound = -5;
93  float upper_bound = 5;
94  float pad = 0;
95  };
96 
97  unsigned min_length = 0;
98  unsigned max_length = 0;
99  std::vector<std::string> var_names;
100  std::unordered_map<std::string, VarInfo> var_info_map;
101 
102  VarInfo info(const std::string &name) const { return var_info_map.at(name); }
103  };
104 
105 } // namespace btagbtvdeep
106 #endif //RecoBTag_FeatureTools_deep_helpers_h
btagbtvdeep::PreprocessParams::VarInfo::VarInfo
VarInfo(float median, float norm_factor, float replace_inf_value, float lower_bound, float upper_bound, float pad)
Definition: deep_helpers.h:82
btagbtvdeep
Definition: BoostedDoubleSVTagInfoFeatures.h:4
Measurement1D
Definition: Measurement1D.h:11
mps_fire.i
i
Definition: mps_fire.py:428
btagbtvdeep::PreprocessParams
Definition: deep_helpers.h:79
btagbtvdeep::dump_vector
int dump_vector(reco::TaggingVariableList &from, T *to, reco::btau::TaggingVariableName name, const size_t max)
Definition: deep_helpers.h:57
btagbtvdeep::PreprocessParams::VarInfo::lower_bound
float lower_bound
Definition: deep_helpers.h:92
btagbtvdeep::PreprocessParams::info
VarInfo info(const std::string &name) const
Definition: deep_helpers.h:102
PFCandidate.h
CandIPTagInfo.h
min
T min(T a, T b)
Definition: MathUtil.h:58
btagbtvdeep::PreprocessParams::var_info_map
std::unordered_map< std::string, VarInfo > var_info_map
Definition: deep_helpers.h:100
pfDeepBoostedJetPreprocessParams_cfi.median
median
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:12
reco::TaggingVariableList
Definition: TaggingVariable.h:194
btagbtvdeep::vertexDxy
Measurement1D vertexDxy(const reco::VertexCompositePtrCandidate &svcand, const reco::Vertex &pv)
Definition: deep_helpers.cc:49
Measurement1D.h
to
btagbtvdeep::PreprocessParams::VarInfo
Definition: deep_helpers.h:80
btagbtvdeep::sv_vertex_comparator
bool sv_vertex_comparator(const SVType &sva, const SVType &svb, const PVType &pv)
Definition: deep_helpers.h:42
btagbtvdeep::PreprocessParams::VarInfo::VarInfo
VarInfo()
Definition: deep_helpers.h:81
reco::TaggingVariableList::getList
std::vector< TaggingValue > getList(TaggingVariableName tag, bool throwOnEmptyList=true) const
Definition: TaggingVariable.cc:375
reco::VertexCompositePtrCandidate
Definition: VertexCompositePtrCandidate.h:16
edm::Ref< VertexCollection >
pfDeepBoostedJetPreprocessParams_cfi.pfcand
pfcand
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:8
btagbtvdeep::PreprocessParams::VarInfo::pad
float pad
Definition: deep_helpers.h:94
btagbtvdeep::PreprocessParams::VarInfo::upper_bound
float upper_bound
Definition: deep_helpers.h:93
btagbtvdeep::PreprocessParams::VarInfo::norm_factor
float norm_factor
Definition: deep_helpers.h:90
btagbtvdeep::PreprocessParams::min_length
unsigned min_length
Definition: deep_helpers.h:97
pfDeepBoostedJetPreprocessParams_cfi.sv
sv
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:352
VertexCompositePtrCandidate.h
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
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
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
btagbtvdeep::PreprocessParams::VarInfo::replace_inf_value
float replace_inf_value
Definition: deep_helpers.h:91
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
Jet.h
btagbtvdeep::PreprocessParams::VarInfo::center
float center
Definition: deep_helpers.h:89
reco::Candidate
Definition: Candidate.h:27
VertexFwd.h
IPTools.h
MTVHistoProducerAlgoForTrackerBlock_cfi.mindr
mindr
Definition: MTVHistoProducerAlgoForTrackerBlock_cfi.py:79
T
long double T
Definition: Basic3DVectorLD.h:48
btagbtvdeep::quality_from_pfcand
float quality_from_pfcand(const reco::PFCandidate &pfcand)
Definition: deep_helpers.cc:98
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
btagbtvdeep::vertexD3d
Measurement1D vertexD3d(const reco::VertexCompositePtrCandidate &svcand, const reco::Vertex &pv)
Definition: deep_helpers.cc:58
btagbtvdeep::PreprocessParams::var_names
std::vector< std::string > var_names
Definition: deep_helpers.h:99
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
TaggingVariable.h
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
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
reco::btau::TaggingVariableName
TaggingVariableName
Definition: TaggingVariable.h:30
btagbtvdeep::PreprocessParams::max_length
unsigned max_length
Definition: deep_helpers.h:98
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
btagbtvdeep::vertexDdotP
float vertexDdotP(const reco::VertexCompositePtrCandidate &sv, const reco::Vertex &pv)
Definition: deep_helpers.cc:67