CP3-llbb Framework
BTaggingScaleFactors.h
1 #pragma once
2 
3 #include <FWCore/ParameterSet/interface/ParameterSet.h>
4 #include <FWCore/Utilities/interface/EDMException.h>
5 
6 #include <cp3_llbb/Framework/interface/Histogram.h>
7 #include <cp3_llbb/Framework/interface/BinnedValues.h>
8 #include <cp3_llbb/TreeWrapper/interface/TreeWrapper.h>
9 
10 #include <boost/property_tree/ptree.hpp>
11 
12 #include <array>
13 #include <memory>
14 #include <tuple>
15 
16 enum class Algorithm {
17  UNKNOWN = -1,
18  CSV = 0,
19  CSVv2,
20  JP,
21  cMVAv2,
22  DeepCSV
23 };
24 
25 enum class Flavor {
26  B = 0,
27  C = 1,
28  LIGHT = 2
29 };
30 
31 enum class SystFlavor {
32  HEAVY = 1,
33  LIGHT = 2
34 };
35 
37 
38  public:
39  typedef std::tuple<Algorithm, SystFlavor, std::string> branch_key_type;
40  typedef std::tuple<Algorithm, Flavor, std::string> sf_key_type;
41 
42  static std::array<SystFlavor, 2> SystFlavors;
43 
44  BTaggingScaleFactors(ROOT::TreeGroup& tree):
45  m_tree(tree) {
46  // Empty
47  }
48 
49  virtual void create_branches(const edm::ParameterSet&) final;
50 
51  virtual void store_scale_factors(Algorithm algo, Flavor flavor, const Parameters&, bool isData) final;
52 
53  virtual bool has_scale_factors(Algorithm algo) final {
54  return m_algos.count(algo) != 0;
55  }
56 
57  protected:
58  virtual float get_scale_factor(Algorithm algo, Flavor flavor, const std::string& wp, size_t index, Variation variation = Variation::Nominal) final;
59 
60  private:
61  ROOT::TreeGroup& m_tree;
62 
63  std::map<branch_key_type, std::vector<std::vector<float>>*> m_branches;
64  std::map<sf_key_type, std::unique_ptr<BinnedValues>> m_scale_factors;
65 
66  std::map<Algorithm, std::vector<std::string>> m_algos;
67 
68  public:
69  static inline std::string algorithm_to_string(Algorithm algo) {
70  switch (algo) {
71  case Algorithm::CSV:
72  return "csv";
73 
74  case Algorithm::CSVv2:
75  return "csvv2";
76 
77  case Algorithm::JP:
78  return "jp";
79 
80  case Algorithm::cMVAv2:
81  return "cmvav2";
82 
83  case Algorithm::DeepCSV:
84  return "deepCSV";
85 
86  default:
87  return "unknown";
88  }
89  }
90 
91  static inline Algorithm string_to_algorithm(const std::string& algo) {
92  if ((algo == "csv") || (algo == "combinedSecondaryVertexBJetTags"))
93  return Algorithm::CSV;
94 
95  if ((algo == "csvv2") || (algo == "pfCombinedInclusiveSecondaryVertexV2BJetTags"))
96  return Algorithm::CSVv2;
97 
98  if ((algo == "jp") || (algo == "pfJetProbabilityBJetTags"))
99  return Algorithm::JP;
100 
101  if ((algo == "cmvav2") || (algo == "pfCombinedMVAV2BJetTags"))
102  return Algorithm::cMVAv2;
103 
104  if ((algo == "deepCSV") || (algo == "pfDeepCSVJetTags:probb"))
105  return Algorithm::DeepCSV;
106 
107  return Algorithm::UNKNOWN;
108  }
109 
110  static inline std::string flavor_to_string(Flavor flavor) {
111  switch (flavor) {
112  case Flavor::B:
113  return "bjets";
114 
115  case Flavor::C:
116  return "cjets";
117 
118  case Flavor::LIGHT:
119  return "lightjets";
120  }
121 
122  throw edm::Exception(edm::errors::NotFound, "Unsupported flavor");
123  }
124 
125  static inline SystFlavor flavor_to_syst_flavor(Flavor flavor) {
126  switch (flavor) {
127  case Flavor::B:
128  case Flavor::C:
129  return SystFlavor::HEAVY;
130 
131  case Flavor::LIGHT:
132  return SystFlavor::LIGHT;
133  }
134 
135  throw edm::Exception(edm::errors::NotFound, "Unsupported flavor");
136  }
137 
138  static inline std::string syst_flavor_to_string(SystFlavor flavor) {
139  switch (flavor) {
140  case SystFlavor::HEAVY:
141  return "heavyjet";
142 
143  case SystFlavor::LIGHT:
144  return "lightjet";
145  }
146 
147  throw edm::Exception(edm::errors::NotFound, "Unsupported syst flavor");
148  }
149 
150  static inline Flavor string_to_flavor(const std::string& flavor) {
151  if (flavor == "bjets")
152  return Flavor::B;
153  else if (flavor == "cjets")
154  return Flavor::C;
155  else if (flavor == "lightjets")
156  return Flavor::LIGHT;
157 
158  throw edm::Exception(edm::errors::NotFound, "Unsupported flavor: " + flavor);
159  }
160 
161  static inline Flavor get_flavor(int hadron_flavor) {
162  switch (hadron_flavor) {
163  case 5:
164  return Flavor::B;
165 
166  case 4:
167  return Flavor::C;
168 
169  default:
170  return Flavor::LIGHT;
171  }
172  }
173 };
Definition: BTaggingScaleFactors.h:36
Definition: BinnedValues.h:67