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
ch::syst::bin::get
static type get(ch::Process *p)
Definition: Systematics.h:13
ch::syst::SystMapFunc::ValU
double ValU(ch::Process *) const
Definition: Systematics.h:227
ch::syst::SystMapAsymm::ValU
double ValU(ch::Process *p) const
Definition: Systematics.h:163
ch::syst::SystMap
Definition: Systematics.h:70
ch::syst::SystMapAsymm
Definition: Systematics.h:135
ch::syst::mass::get
static type get(ch::Process *p)
Definition: Systematics.h:33
ch::syst::SystMapFunc::GetTupleSet
std::set< std::tuple< typename T::type... > > GetTupleSet() const
Definition: Systematics.h:254
ch::syst::analysis::type
std::string type
Definition: Systematics.h:17
ch::syst::mass
Definition: Systematics.h:31
ch::syst::SystMap::Contains
bool Contains(ch::Process *p) const
Definition: Systematics.h:83
ch::syst::SystMap::GetTuple
auto GetTuple(ch::Process *p) const -> decltype(std::make_tuple(T::get(p)...))
Definition: Systematics.h:125
ch::syst::process::get
static type get(ch::Process *p)
Definition: Systematics.h:38
ch::syst::SystMapAsymm::ValD
double ValD(ch::Process *p) const
Definition: Systematics.h:156
ch::syst::SystMapAsymm::GetTupleSet
std::set< std::tuple< typename T::type... > > GetTupleSet() const
Definition: Systematics.h:187
ch::Object::era
virtual std::string const & era() const
Definition: Object.h:29
ch::syst::SystMap::GetTupleSet
std::set< std::tuple< typename T::type... > > GetTupleSet() const
Definition: Systematics.h:119
ch::syst::channel::get
static type get(ch::Process *p)
Definition: Systematics.h:28
Process.h
ch::syst::bin_id::type
int type
Definition: Systematics.h:43
ch::Object::bin
virtual std::string const & bin() const
Definition: Object.h:17
ch::syst::era
Definition: Systematics.h:21
FNERROR
#define FNERROR(x)
Definition: Logging.h:9
ch::syst::SystMapFunc::operator()
SystMapFunc & operator()(std::vector< typename T::type >... input, std::string formula, std::string args)
Definition: Systematics.h:208
ch::syst::SystMapAsymm::GetTuple
auto GetTuple(ch::Process *p) const -> decltype(std::make_tuple(T::get(p)...))
Definition: Systematics.h:193
ch::syst::SystMapFunc::Args
std::string Args(ch::Process *p) const
Definition: Systematics.h:238
ch::Object::channel
virtual std::string const & channel() const
Definition: Object.h:32
ch::syst::SystMapFunc::GetTuple
auto GetTuple(ch::Process *p) const -> decltype(std::make_tuple(T::get(p)...))
Definition: Systematics.h:260
ch::syst::SystMapAsymm::Contains
bool Contains(ch::Process *p) const
Definition: Systematics.h:148
ch::Process
Definition: Process.h:15
ch::syst::bin_id::get
static type get(ch::Process *p)
Definition: Systematics.h:44
ch::syst::analysis::get
static type get(ch::Process *p)
Definition: Systematics.h:18
ch::syst::channel
Definition: Systematics.h:26
ch::syst::SystMap::IsAsymm
bool IsAsymm() const
Definition: Systematics.h:117
ch::syst::SystMapFunc
Definition: Systematics.h:203
ch::syst::era::type
std::string type
Definition: Systematics.h:22
ch::syst::bin_id
Definition: Systematics.h:41
ch::syst::SystMap::ValU
double ValU(ch::Process *p) const
Definition: Systematics.h:91
ch::syst::era::get
static type get(ch::Process *p)
Definition: Systematics.h:23
ch::Object::analysis
virtual std::string const & analysis() const
Definition: Object.h:26
ch::syst::SystMap::init
static SystMap< T... > init(std::vector< typename T::type >... input, double val)
Definition: Systematics.h:111
ch::syst::bin
Definition: Systematics.h:11
ch::syst::SystMapFunc::init
static SystMapFunc< T... > init(std::vector< typename T::type >... input, std::string formula, std::string args)
Definition: Systematics.h:246
ch::Object::mass
virtual std::string const & mass() const
Definition: Object.h:38
ch::syst::SystMapAsymm::operator()
SystMapAsymm & operator()(std::vector< typename T::type >... input, double val_d, double val_u)
Definition: Systematics.h:140
ch::syst::bin::type
std::string type
Definition: Systematics.h:12
ch::syst::SystMapFunc::Contains
bool Contains(ch::Process *p) const
Definition: Systematics.h:216
ch::syst::process
Definition: Systematics.h:36
ch::syst::detail::cross_imp
void cross_imp(F f)
Definition: Systematics.h:49
ch
Definition: Algorithm.h:10
ch::syst::mass::type
std::string type
Definition: Systematics.h:32
ch::syst::SystMapAsymm::Formula
std::string Formula(ch::Process *) const
Definition: Systematics.h:171
ch::syst::SystMap::ValD
double ValD(ch::Process *) const
Definition: Systematics.h:99
ch::syst::SystMap::Formula
std::string Formula(ch::Process *) const
Definition: Systematics.h:103
ch::syst::process::type
std::string type
Definition: Systematics.h:37
ch::Object::bin_id
virtual int bin_id() const
Definition: Object.h:35
ch::syst::SystMapAsymm::IsAsymm
bool IsAsymm() const
Definition: Systematics.h:185
ch::syst::SystMapAsymm::init
static SystMapAsymm< T... > init(std::vector< typename T::type >... input, double val_d, double val_u)
Definition: Systematics.h:179
ch::syst::SystMapAsymm::Args
std::string Args(ch::Process *) const
Definition: Systematics.h:175
ch::syst::SystMapFunc::IsAsymm
bool IsAsymm() const
Definition: Systematics.h:252
ch::syst::SystMapFunc::Formula
std::string Formula(ch::Process *p) const
Definition: Systematics.h:231
ch::syst::SystMapFunc::ValD
double ValD(ch::Process *) const
Definition: Systematics.h:224
ch::syst::analysis
Definition: Systematics.h:16
ch::syst::channel::type
std::string type
Definition: Systematics.h:27
ch::syst::detail::cross
std::vector< std::tuple< Ts... > > cross(std::vector< Ts > const &... in)
Definition: Systematics.h:60
ch::syst::SystMap::operator()
SystMap & operator()(std::vector< typename T::type >... input, double val)
Definition: Systematics.h:75
ch::Object::process
virtual std::string const & process() const
Definition: Object.h:20
ch::syst::SystMap::Args
std::string Args(ch::Process *) const
Definition: Systematics.h:107
Logging.h