CombineHarvester
Systematics.h
Go to the documentation of this file.
1 #ifndef CombineTools_Systematics_h
2 #define CombineTools_Systematics_h
3 #include <vector>
4 #include <string>
7 
8 namespace ch {
9 namespace syst {
10 
11  struct bin {
12  typedef std::string type;
13  inline static type get(ch::Process *p) { return p->bin(); }
14  };
15 
16  struct analysis {
17  typedef std::string type;
18  inline static type get(ch::Process *p) { return p->analysis(); }
19  };
20 
21  struct era {
22  typedef std::string type;
23  inline static type get(ch::Process *p) { return p->era(); }
24  };
25 
26  struct channel {
27  typedef std::string type;
28  inline static type get(ch::Process *p) { return p->channel(); }
29  };
30 
31  struct mass {
32  typedef std::string type;
33  inline static type get(ch::Process *p) { return p->mass(); }
34  };
35 
36  struct process {
37  typedef std::string type;
38  inline static type get(ch::Process *p) { return p->process(); }
39  };
40 
41  class bin_id {
42  public:
43  typedef int type;
44  inline static type get(ch::Process *p) { return p->bin_id(); }
45  };
46 
47  namespace detail {
48  template <typename F>
49  inline void cross_imp(F f) {
50  f();
51  }
52  template <typename F, typename H, typename... Ts>
53  inline void cross_imp(F f, std::vector<H> const &h,
54  std::vector<Ts> const &... t) {
55  for (H const &he : h)
56  cross_imp([&](Ts const &... ts) { f(he, ts...); }, t...);
57  }
58 
59  template <typename... Ts>
60  std::vector<std::tuple<Ts...>> cross(std::vector<Ts> const &... in) {
61  std::vector<std::tuple<Ts...>> res;
62  cross_imp([&](Ts const &... ts) {
63  res.emplace_back(ts...);
64  }, in...);
65  return res;
66  }
67  }
68 
69  template<class... T>
70  class SystMap {
71  private:
72  std::map<std::tuple<typename T::type...>, double> tmap_;
73 
74  public:
75  SystMap& operator()(std::vector<typename T::type>... input, double val) {
76  auto res = ch::syst::detail::cross(input...);
77  for (auto const& a : res) {
78  tmap_.insert(std::make_pair(a, val));
79  }
80  return *this;
81  }
82 
83  bool Contains(ch::Process *p) const {
84  if (p) {
85  return tmap_.count(std::make_tuple(T::get(p)...));
86  } else {
87  return false;
88  }
89  }
90 
91  double ValU(ch::Process *p) const {
92  if (p) {
93  return tmap_.find(std::make_tuple(T::get(p)...))->second;
94  } else {
95  return 0.0;
96  }
97  }
98 
99  double ValD(ch::Process * /*p*/) const {
100  return 0.0;
101  }
102 
103  std::string Formula(ch::Process * /*p*/) const {
104  return std::string("");
105  }
106 
107  std::string Args(ch::Process * /*p*/) const {
108  return std::string("");
109  }
110 
111  static SystMap<T...> init(std::vector<typename T::type>... input,
112  double val) {
113  SystMap<T...> x;
114  return x(input..., val);
115  }
116 
117  bool IsAsymm() const { return false; }
118 
119  std::set<std::tuple<typename T::type...>> GetTupleSet() const {
120  std::set<std::tuple<typename T::type...>> res;
121  for (auto const& x : tmap_) res.insert(x.first);
122  return res;
123  }
124 
125  auto GetTuple(ch::Process *p) const -> decltype( std::make_tuple(T::get(p)...) ) {
126  if (p) {
127  return std::make_tuple(T::get(p)...);
128  } else {
129  throw std::runtime_error(FNERROR("Supplied pointer is null"));
130  }
131  }
132  };
133 
134  template<class... T>
135  class SystMapAsymm {
136  private:
137  std::map<std::tuple<typename T::type...>, std::pair<double, double>> tmap_;
138 
139  public:
140  SystMapAsymm &operator()(std::vector<typename T::type>... input,
141  double val_d, double val_u) {
142  auto res = ch::syst::detail::cross(input...);
143  for (auto const& a : res)
144  tmap_.insert(std::make_pair(a, std::make_pair(val_d, val_u)));
145  return *this;
146  }
147 
148  bool Contains(ch::Process *p) const {
149  if (p) {
150  return tmap_.count(std::make_tuple(T::get(p)...));
151  } else {
152  return false;
153  }
154  }
155 
156  double ValD(ch::Process *p) const {
157  if (p) {
158  return tmap_.find(std::make_tuple(T::get(p)...))->second.first;
159  } else {
160  return 0.0;
161  }
162  }
163  double ValU(ch::Process *p) const {
164  if (p) {
165  return tmap_.find(std::make_tuple(T::get(p)...))->second.second;
166  } else {
167  return 0.0;
168  }
169  }
170 
171  std::string Formula(ch::Process * /*p*/) const {
172  return std::string("");
173  }
174 
175  std::string Args(ch::Process * /*p*/) const {
176  return std::string("");
177  }
178 
179  static SystMapAsymm<T...> init(std::vector<typename T::type>... input,
180  double val_d, double val_u) {
181  SystMapAsymm<T...> x;
182  return x(input..., val_d, val_u);
183  }
184 
185  bool IsAsymm() const { return true; }
186 
187  std::set<std::tuple<typename T::type...>> GetTupleSet() const {
188  std::set<std::tuple<typename T::type...>> res;
189  for (auto const& x : tmap_) res.insert(x.first);
190  return res;
191  }
192 
193  auto GetTuple(ch::Process *p) const -> decltype( std::make_tuple(T::get(p)...) ) {
194  if (p) {
195  return std::make_tuple(T::get(p)...);
196  } else {
197  throw std::runtime_error(FNERROR("Supplied pointer is null"));
198  }
199  }
200  };
201 
202  template<class... T>
203  class SystMapFunc {
204  private:
205  std::map<std::tuple<typename T::type...>, std::pair<std::string, std::string>> tmap_;
206 
207  public:
208  SystMapFunc &operator()(std::vector<typename T::type>... input,
209  std::string formula, std::string args) {
210  auto res = ch::syst::detail::cross(input...);
211  for (auto const& a : res)
212  tmap_.insert(std::make_pair(a, std::make_pair(formula, args)));
213  return *this;
214  }
215 
216  bool Contains(ch::Process *p) const {
217  if (p) {
218  return tmap_.count(std::make_tuple(T::get(p)...));
219  } else {
220  return false;
221  }
222  }
223 
224  double ValD(ch::Process * /*p*/) const {
225  return 0.0;
226  }
227  double ValU(ch::Process * /*p*/) const {
228  return 0.0;
229  }
230 
231  std::string Formula(ch::Process *p) const {
232  if (p) {
233  return tmap_.find(std::make_tuple(T::get(p)...))->second.first;
234  } else {
235  return std::string("");
236  }
237  }
238  std::string Args(ch::Process *p) const {
239  if (p) {
240  return tmap_.find(std::make_tuple(T::get(p)...))->second.second;
241  } else {
242  return std::string("");
243  }
244  }
245 
246  static SystMapFunc<T...> init(std::vector<typename T::type>... input,
247  std::string formula, std::string args) {
248  SystMapFunc<T...> x;
249  return x(input..., formula, args);
250  }
251 
252  bool IsAsymm() const { return false; }
253 
254  std::set<std::tuple<typename T::type...>> GetTupleSet() const {
255  std::set<std::tuple<typename T::type...>> res;
256  for (auto const& x : tmap_) res.insert(x.first);
257  return res;
258  }
259 
260  auto GetTuple(ch::Process *p) const -> decltype( std::make_tuple(T::get(p)...) ) {
261  if (p) {
262  return std::make_tuple(T::get(p)...);
263  } else {
264  throw std::runtime_error(FNERROR("Supplied pointer is null"));
265  }
266  }
267  };
268 }
269 }
270 
271 #endif
#define FNERROR(x)
Definition: Logging.h:9
virtual std::string const & process() const
Definition: Object.h:20
virtual std::string const & bin() const
Definition: Object.h:17
virtual int bin_id() const
Definition: Object.h:35
virtual std::string const & analysis() const
Definition: Object.h:26
virtual std::string const & era() const
Definition: Object.h:29
virtual std::string const & mass() const
Definition: Object.h:38
virtual std::string const & channel() const
Definition: Object.h:32
std::string Args(ch::Process *) const
Definition: Systematics.h:175
std::string Formula(ch::Process *) const
Definition: Systematics.h:171
double ValD(ch::Process *p) const
Definition: Systematics.h:156
static SystMapAsymm< T... > init(std::vector< typename T::type >... input, double val_d, double val_u)
Definition: Systematics.h:179
bool Contains(ch::Process *p) const
Definition: Systematics.h:148
std::set< std::tuple< typename T::type... > > GetTupleSet() const
Definition: Systematics.h:187
auto GetTuple(ch::Process *p) const -> decltype(std::make_tuple(T::get(p)...))
Definition: Systematics.h:193
double ValU(ch::Process *p) const
Definition: Systematics.h:163
SystMapAsymm & operator()(std::vector< typename T::type >... input, double val_d, double val_u)
Definition: Systematics.h:140
bool IsAsymm() const
Definition: Systematics.h:185
std::string Args(ch::Process *p) const
Definition: Systematics.h:238
bool Contains(ch::Process *p) const
Definition: Systematics.h:216
std::string Formula(ch::Process *p) const
Definition: Systematics.h:231
double ValU(ch::Process *) const
Definition: Systematics.h:227
double ValD(ch::Process *) const
Definition: Systematics.h:224
SystMapFunc & operator()(std::vector< typename T::type >... input, std::string formula, std::string args)
Definition: Systematics.h:208
auto GetTuple(ch::Process *p) const -> decltype(std::make_tuple(T::get(p)...))
Definition: Systematics.h:260
std::set< std::tuple< typename T::type... > > GetTupleSet() const
Definition: Systematics.h:254
bool IsAsymm() const
Definition: Systematics.h:252
static SystMapFunc< T... > init(std::vector< typename T::type >... input, std::string formula, std::string args)
Definition: Systematics.h:246
std::set< std::tuple< typename T::type... > > GetTupleSet() const
Definition: Systematics.h:119
auto GetTuple(ch::Process *p) const -> decltype(std::make_tuple(T::get(p)...))
Definition: Systematics.h:125
bool Contains(ch::Process *p) const
Definition: Systematics.h:83
double ValD(ch::Process *) const
Definition: Systematics.h:99
std::string Args(ch::Process *) const
Definition: Systematics.h:107
std::string Formula(ch::Process *) const
Definition: Systematics.h:103
SystMap & operator()(std::vector< typename T::type >... input, double val)
Definition: Systematics.h:75
double ValU(ch::Process *p) const
Definition: Systematics.h:91
bool IsAsymm() const
Definition: Systematics.h:117
static SystMap< T... > init(std::vector< typename T::type >... input, double val)
Definition: Systematics.h:111
static type get(ch::Process *p)
Definition: Systematics.h:44
void cross_imp(F f)
Definition: Systematics.h:49
std::vector< std::tuple< Ts... > > cross(std::vector< Ts > const &... in)
Definition: Systematics.h:60
Definition: Algorithm.h:10
std::string type
Definition: Systematics.h:17
static type get(ch::Process *p)
Definition: Systematics.h:18
std::string type
Definition: Systematics.h:12
static type get(ch::Process *p)
Definition: Systematics.h:13
static type get(ch::Process *p)
Definition: Systematics.h:28
std::string type
Definition: Systematics.h:27
static type get(ch::Process *p)
Definition: Systematics.h:23
std::string type
Definition: Systematics.h:22
std::string type
Definition: Systematics.h:32
static type get(ch::Process *p)
Definition: Systematics.h:33
static type get(ch::Process *p)
Definition: Systematics.h:38
std::string type
Definition: Systematics.h:37