CMS 3D CMS Logo

cutflowutil.h
Go to the documentation of this file.
1 #ifndef cutflowutil_h
2 #define cutflowutil_h
3 
4 #include "ttreex.h"
5 #include "printutil.h"
6 #include <tuple>
7 #include <vector>
8 #include <map>
9 #include "TH1.h"
10 #include "TString.h"
11 #include <iostream>
12 #include <algorithm>
13 #include <sys/ioctl.h>
14 #include <functional>
15 
16 //#define USE_TTREEX
17 #define USE_CUTLAMBDA
18 #define TREEMAPSTRING std::string
19 #define CUTFLOWMAPSTRING TString
20 #define DATA c_str
21 #define THist TH1D
22 
23 namespace RooUtil {
24  namespace CutflowUtil {
25 
26  class CutNameList {
27  public:
28  std::vector<TString> cutlist;
30  CutNameList(const CutNameList& cutnamelist) { cutlist = cutnamelist.cutlist; }
31  void clear() { cutlist.clear(); }
32  void addCutName(TString cutname) { cutlist.push_back(cutname); }
33  void print() {
34  for (auto& str : cutlist)
35  std::cout << str << std::endl;
36  }
37  };
38 
40  public:
41  std::map<TString, CutNameList> cutlists;
42  std::vector<TString> cutlist;
43  CutNameList& operator[](TString name) { return cutlists[name]; }
44  void clear() { cutlists.clear(); }
45  void print() {
46  for (auto& cl : cutlists) {
47  std::cout << "CutNameList - " << cl.first << std::endl;
48  cl.second.print();
49  }
50  }
51  std::map<TString, std::vector<TString>> getStdVersion() {
52  std::map<TString, std::vector<TString>> obj_cutlists;
53  for (auto& cl : cutlists)
54  obj_cutlists[cl.first] = cl.second.cutlist;
55  return obj_cutlists;
56  }
57  };
58 
59  void createCutflowBranches(CutNameListMap& cutlists, RooUtil::TTreeX& tx);
60  void createCutflowBranches(std::map<TString, std::vector<TString>>& cutlists, RooUtil::TTreeX& tx);
61  std::tuple<std::vector<bool>, std::vector<float>> getCutflow(std::vector<TString> cutlist, RooUtil::TTreeX& tx);
62  std::pair<bool, float> passCuts(std::vector<TString> cutlist, RooUtil::TTreeX& tx);
63  void fillCutflow(std::vector<TString> cutlist, RooUtil::TTreeX& tx, THist* h);
64  void fillRawCutflow(std::vector<TString> cutlist, RooUtil::TTreeX& tx, THist* h);
65  std::tuple<std::map<CUTFLOWMAPSTRING, THist*>, std::map<CUTFLOWMAPSTRING, THist*>> createCutflowHistograms(
66  CutNameListMap& cutlists, TString syst = "");
67  std::tuple<std::map<CUTFLOWMAPSTRING, THist*>, std::map<CUTFLOWMAPSTRING, THist*>> createCutflowHistograms(
68  std::map<TString, std::vector<TString>>& cutlists, TString syst = "");
69  void saveCutflowHistograms(std::map<CUTFLOWMAPSTRING, THist*>& cutflows,
70  std::map<CUTFLOWMAPSTRING, THist*>& rawcutflows);
71  // void fillCutflowHistograms(CutNameListMap& cutlists, RooUtil::TTreeX& tx, std::map<TString, THist*>& cutflows, std::map<TString, THist*>& rawcutflows);
72  // void fillCutflowHistograms(std::map<TString, std::vector<TString>>& cutlists, RooUtil::TTreeX& tx, std::map<TString, THist*>& cutflows, std::map<TString, THist*>& rawcutflows);
73 
74  } // namespace CutflowUtil
75 
76  class CutTree {
77  public:
78  TString name;
80  std::vector<CutTree*> parents;
81  std::vector<CutTree*> children;
82  std::vector<TString> systcutnames;
83  std::vector<CutTree*> systcuts;
84  std::map<TString, CutTree*> systs;
85  int pass;
86  float weight;
87  std::vector<int> systpasses;
88  std::vector<float> systweights;
91  std::function<bool()> pass_this_cut_func;
92  std::function<float()> weight_this_cut_func;
93 // std::vector<TString> hists1d;
94 // std::vector<std::tuple<TString, TString>> hists2d;
95 #ifdef USE_CUTLAMBDA
96  std::map<TString, std::vector<std::tuple<THist*, std::function<float()>>>> hists1d;
97  std::map<TString,
98  std::vector<std::tuple<THist*, std::function<std::vector<float>()>, std::function<std::vector<float>()>>>>
100  std::map<TString, std::vector<std::tuple<TH2F*, std::function<float()>, std::function<float()>>>> hists2d;
101  std::map<TString,
102  std::vector<std::tuple<TH2F*,
103  std::function<std::vector<float>()>,
104  std::function<std::vector<float>()>,
105  std::function<std::vector<float>()>>>>
107 #else
108  std::map<TString, std::vector<std::tuple<THist*, TString>>> hists1d;
109  std::map<TString, std::vector<std::tuple<TH2F*, TString, TString>>> hists2d;
110 #endif
111  std::vector<std::tuple<int, int, unsigned long long>> eventlist;
112  CutTree(TString n) : name(n), parent(0), pass(false), weight(0) {}
114  for (auto& child : children) {
115  if (child)
116  delete child;
117  }
118  }
119  void printCuts(int indent = 0, std::vector<int> multichild = std::vector<int>()) {
120  struct winsize w;
121  ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
122  int colsize = std::min(w.ws_col - 100, 600);
123  if (indent == 0) {
124  TString header = "Cut name";
125  int extra = colsize - header.Length();
126  for (int i = 0; i < extra; ++i)
127  header += " ";
128  header += "|pass|weight|systs";
129  print(header);
130  TString delimiter = "";
131  for (int i = 0; i < w.ws_col - 10; ++i)
132  delimiter += "=";
133  print(delimiter);
134  }
135  TString msg = "";
136  for (int i = 0; i < indent; ++i) {
137  if (std::find(multichild.begin(), multichild.end(), i + 1) != multichild.end()) {
138  if (indent == i + 1)
139  msg += " +";
140  else
141  msg += " |";
142  } else
143  msg += " ";
144  }
145  msg += name;
146  int extrapad = colsize - msg.Length() > 0 ? colsize - msg.Length() : 0;
147  for (int i = 0; i < extrapad; ++i)
148  msg += " ";
149  //msg += TString::Format("| %d | %.5f|", pass, weight);
150  msg += TString::Format("| %d | %f|", pass, weight);
151  for (auto& key : systs) {
152  msg += key.first + " ";
153  }
154  print(msg);
155  if (children.size() > 1)
156  multichild.push_back(indent + 1);
157  for (auto& child : children) {
158  (*child).printCuts(indent + 1, multichild);
159  }
160  }
161  void printEventList() {
162  print(TString::Format("Print event list for the cut = %s", name.Data()));
163  for (auto& eventid : eventlist) {
164  int run = std::get<0>(eventid);
165  int lumi = std::get<1>(eventid);
166  unsigned long long evt = std::get<2>(eventid);
167  TString msg = TString::Format("%d:%d:%llu", run, lumi, evt);
168  std::cout << msg << std::endl;
169  }
170  }
171  void writeEventList(TString ofilename) {
172  std::ofstream outFile(ofilename);
173  for (auto& tuple : eventlist) {
174  int run = std::get<0>(tuple);
175  int lumi = std::get<1>(tuple);
176  unsigned long long evt = std::get<2>(tuple);
177  outFile << run << ":" << lumi << ":" << evt << std::endl;
178  }
179  outFile.close();
180  }
181  void addCut(TString n) {
182  CutTree* obj = new CutTree(n);
183  obj->parent = this;
184  obj->parents.push_back(this);
185  children.push_back(obj);
186  }
187  void addSyst(TString syst) {
188  // If already added ignore
189  if (systs.find(syst) != systs.end())
190  return;
191  // Syst CutTree object knows the parents, and children, however, the children does not know the syst-counter-part parent, nor the parent knows the syste-counter-part children.
192  CutTree* obj = new CutTree(this->name + syst);
193  systs[syst] = obj;
194  systcutnames.push_back(syst);
195  systcuts.push_back(obj);
196  systpasses.push_back(1);
197  systweights.push_back(1);
198  obj->children = this->children;
199  obj->parents = this->parents;
200  obj->parent = this->parent;
201  }
202 #ifdef USE_CUTLAMBDA
203  void addHist1D(THist* h, std::function<float()> var, TString syst) {
204  if (syst.IsNull())
205  hists1d["Nominal"].push_back(std::make_tuple(h, var));
206  else
207  hists1d[syst].push_back(std::make_tuple(h, var));
208  }
210  std::function<std::vector<float>()> var,
211  std::function<std::vector<float>()> wgt,
212  TString syst) {
213  if (syst.IsNull())
214  hists1dvec["Nominal"].push_back(std::make_tuple(h, var, wgt));
215  else
216  hists1dvec[syst].push_back(std::make_tuple(h, var, wgt));
217  }
218  void addHist2D(TH2F* h, std::function<float()> varx, std::function<float()> vary, TString syst) {
219  if (syst.IsNull())
220  hists2d["Nominal"].push_back(std::make_tuple(h, varx, vary));
221  else
222  hists2d[syst].push_back(std::make_tuple(h, varx, vary));
223  }
224  void addHist2DVec(TH2F* h,
225  std::function<std::vector<float>()> varx,
226  std::function<std::vector<float>()> vary,
227  std::function<std::vector<float>()> elemwgt,
228  TString syst) {
229  if (syst.IsNull())
230  hists2dvec["Nominal"].push_back(std::make_tuple(h, varx, vary, elemwgt));
231  else
232  hists2dvec[syst].push_back(std::make_tuple(h, varx, vary, elemwgt));
233  }
234 #else
235  void addHist1D(THist* h, TString var, TString syst) {
236  if (syst.IsNull())
237  hists1d["Nominal"].push_back(std::make_tuple(h, var));
238  else
239  hists1d[syst].push_back(std::make_tuple(h, var));
240  }
241  void addHist2D(TH2F* h, TString varx, TString vary, TString syst) {
242  if (syst.IsNull())
243  hists2d["Nominal"].push_back(std::make_tuple(h, varx, vary));
244  else
245  hists2d[syst].push_back(std::make_tuple(h, varx, vary));
246  }
247 #endif
248  CutTree* getCutPointer(TString n) {
249  // If the name match then return itself
250  if (name.EqualTo(n)) {
251  return this;
252  } else {
253  // Otherwise, loop over the children an if a children has the correct one return the found CutTree
254  for (auto& child : children) {
255  CutTree* c = child->getCutPointer(n);
256  if (c)
257  return c;
258  }
259  return 0;
260  }
261  }
262  // Wrapper to return the object instead of pointer
263  CutTree& getCut(TString n) {
264  CutTree* c = getCutPointer(n);
265  if (c) {
266  return *c;
267  } else {
268  RooUtil::error(TString::Format("Asked for %s cut, but did not find the cut", n.Data()));
269  return *this;
270  }
271  }
272  std::vector<TString> getCutList(TString n, std::vector<TString> cut_list = std::vector<TString>()) {
273  // Main idea: start from the end node provided by the first argument "n", and work your way up to the root node.
274  //
275  // The algorithm will first determine whether I am starting from a specific cut requested by the user or within in recursion.
276  // If the cut_list.size() == 0, the function is called by the user (since no list is aggregated so far)
277  // In that case, first find the pointer to the object we want and set it to "c"
278  // If cut_list.size() is non-zero then take this as the cut that I am starting and I go up the chain to aggregate all the cuts prior to the requested cut
279  CutTree* c = 0;
280  if (cut_list.size() == 0) {
281  c = &getCut(n);
282  cut_list.push_back(c->name);
283  } else {
284  c = this;
285  cut_list.push_back(n);
286  }
287  if (c->parent) {
288  return (c->parent)->getCutList((c->parent)->name, cut_list);
289  } else {
290  std::reverse(cut_list.begin(), cut_list.end());
291  return cut_list;
292  }
293  }
294  std::vector<TString> getEndCuts(std::vector<TString> endcuts = std::vector<TString>()) {
295  if (children.size() == 0) {
296  endcuts.push_back(name);
297  return endcuts;
298  }
299  for (auto& child : children)
300  endcuts = child->getEndCuts(endcuts);
301  return endcuts;
302  }
303  std::vector<TString> getCutListBelow(TString n, std::vector<TString> cut_list = std::vector<TString>()) {
304  // Main idea: start from the node provided by the first argument "n", and work your way down to the ends.
305  CutTree* c = 0;
306  if (cut_list.size() == 0) {
307  c = &getCut(n);
308  cut_list.push_back(c->name);
309  } else {
310  c = this;
311  cut_list.push_back(n);
312  }
313  if (children.size() > 0) {
314  for (auto& child : c->children) {
315  cut_list = child->getCutListBelow(child->name, cut_list);
316  }
317  return cut_list;
318  } else {
319  return cut_list;
320  }
321  }
322  void clear() {
323  pass = false;
324  weight = 0;
325  for (auto& child : children)
326  child->clear();
327  }
328  void addSyst(TString syst,
329  std::vector<TString> patterns,
330  std::vector<TString> vetopatterns = std::vector<TString>()) {
331  for (auto& pattern : patterns)
332  if (name.Contains(pattern)) {
333  bool veto = false;
334  for (auto& vetopattern : vetopatterns) {
335  if (name.Contains(vetopattern))
336  veto = true;
337  }
338  if (not veto)
339  addSyst(syst);
340  }
341  for (auto& child : children)
342  child->addSyst(syst, patterns, vetopatterns);
343  }
344  void clear_passbits() {
345  pass = 0;
346  weight = 0;
347  for (auto& child : children)
348  child->clear_passbits();
349  }
351  TString cutsystname = "",
352  bool doeventlist = false,
353  bool aggregated_pass = true,
354  float aggregated_weight = 1) {
355 #ifdef USE_TTREEX
356  evaluate_use_ttreex(tx, cutsystname, doeventlist, aggregated_pass, aggregated_weight);
357 #else
358 #ifdef USE_CUTLAMBDA
359  evaluate_use_lambda(tx, cutsystname, doeventlist, aggregated_pass, aggregated_weight);
360 #else
361  evaluate_use_internal_variable(tx, cutsystname, doeventlist, aggregated_pass, aggregated_weight);
362 #endif
363 #endif
364  }
366  TString cutsystname = "",
367  bool doeventlist = false,
368  bool aggregated_pass = true,
369  float aggregated_weight = 1) {
370  if (!parent) {
371  clear_passbits();
372  pass = 1;
373  weight = 1;
374  } else {
375  if (cutsystname.IsNull()) {
376  if (pass_this_cut_func) {
377  pass = pass_this_cut_func() && aggregated_pass;
378  weight = weight_this_cut_func() * aggregated_weight;
379  if (!pass)
380  return;
381  } else {
382  TString msg = "cowardly passing the event because cut and weight func not set! cut name = " + name;
383  warning(msg);
384  pass = aggregated_pass;
385  weight = aggregated_weight;
386  }
387  } else {
388  if (systs.find(cutsystname) == systs.end()) {
389  if (pass_this_cut_func) {
390  pass = pass_this_cut_func() && aggregated_pass;
391  weight = weight_this_cut_func() * aggregated_weight;
392  if (!pass)
393  return;
394  } else {
395  TString msg = "cowardly passing the event because cut and weight func not set! cut name = " + name;
396  warning(msg);
397  pass = aggregated_pass;
398  weight = aggregated_weight;
399  }
400  } else {
401  if (systs[cutsystname]->pass_this_cut_func) {
402  pass = systs[cutsystname]->pass_this_cut_func() && aggregated_pass;
403  weight = systs[cutsystname]->weight_this_cut_func() * aggregated_weight;
404  if (!pass)
405  return;
406  } else {
407  TString msg = "cowardly passing the event because cut and weight func not set! cut name = " + name +
408  " syst name = " + cutsystname;
409  warning(msg);
410  pass = aggregated_pass;
411  weight = aggregated_weight;
412  }
413  }
414  }
415  }
416  if (doeventlist and pass and cutsystname.IsNull()) {
417  if (tx.hasBranch<int>("run") && tx.hasBranch<int>("lumi") && tx.hasBranch<unsigned long long>("evt")) {
418  eventlist.push_back(std::make_tuple(
419  tx.getBranch<int>("run"), tx.getBranch<int>("lumi"), tx.getBranch<unsigned long long>("evt")));
420  }
421  }
422  for (auto& child : children)
423  child->evaluate_use_lambda(tx, cutsystname, doeventlist, pass, weight);
424  }
426  TString cutsystname = "",
427  bool doeventlist = false,
428  bool aggregated_pass = true,
429  float aggregated_weight = 1) {
430  if (!parent) {
431  clear_passbits();
432  pass = 1;
433  weight = 1;
434  } else {
435  if (cutsystname.IsNull()) {
436  pass = pass_this_cut && aggregated_pass;
437  weight = weight_this_cut * aggregated_weight;
438  if (!pass)
439  return;
440  } else {
441  if (systs.find(cutsystname) == systs.end()) {
442  pass = pass_this_cut && aggregated_pass;
443  weight = weight_this_cut * aggregated_weight;
444  if (!pass)
445  return;
446  } else {
447  pass = systs[cutsystname]->pass_this_cut && aggregated_pass;
448  weight = systs[cutsystname]->weight_this_cut * aggregated_weight;
449  if (!pass)
450  return;
451  }
452  }
453  }
454  if (doeventlist and pass and cutsystname.IsNull()) {
455  if (tx.hasBranch<int>("run") && tx.hasBranch<int>("lumi") && tx.hasBranch<unsigned long long>("evt")) {
456  eventlist.push_back(std::make_tuple(
457  tx.getBranch<int>("run"), tx.getBranch<int>("lumi"), tx.getBranch<unsigned long long>("evt")));
458  }
459  }
460  for (auto& child : children)
461  child->evaluate_use_internal_variable(tx, cutsystname, doeventlist, pass, weight);
462  }
464  TString cutsystname = "",
465  bool doeventlist = false,
466  bool aggregated_pass = true,
467  float aggregated_weight = 1) {
468  if (!parent) {
469  pass = tx.getBranch<bool>(name);
470  weight = tx.getBranch<float>(name + "_weight");
471  } else {
472  if (cutsystname.IsNull()) {
473  if (!tx.hasBranch<bool>(name))
474  return;
475  pass = tx.getBranch<bool>(name) && aggregated_pass;
476  weight = tx.getBranch<float>(name + "_weight") * aggregated_weight;
477  } else {
478  if (systs.find(cutsystname) == systs.end()) {
479  if (!tx.hasBranch<bool>(name))
480  return;
481  pass = tx.getBranch<bool>(name) && aggregated_pass;
482  weight = tx.getBranch<float>(name + "_weight") * aggregated_weight;
483  } else {
484  if (!tx.hasBranch<bool>(name + cutsystname))
485  return;
486  pass = tx.getBranch<bool>(name + cutsystname) && aggregated_pass;
487  weight = tx.getBranch<float>(name + cutsystname + "_weight") * aggregated_weight;
488  }
489  }
490  }
491  if (doeventlist and pass and cutsystname.IsNull()) {
492  if (tx.hasBranch<int>("run") && tx.hasBranch<int>("lumi") && tx.hasBranch<unsigned long long>("evt")) {
493  eventlist.push_back(std::make_tuple(
494  tx.getBranch<int>("run"), tx.getBranch<int>("lumi"), tx.getBranch<unsigned long long>("evt")));
495  }
496  }
497  for (auto& child : children)
498  child->evaluate_use_ttreex(tx, cutsystname, doeventlist, pass, weight);
499  }
500  void sortEventList() {
501  std::sort(
502  eventlist.begin(),
503  eventlist.end(),
504  [](const std::tuple<int, int, unsigned long long>& a, const std::tuple<int, int, unsigned long long>& b) {
505  if (std::get<0>(a) != std::get<0>(b))
506  return std::get<0>(a) < std::get<0>(b);
507  else if (std::get<1>(a) != std::get<1>(b))
508  return std::get<1>(a) < std::get<1>(b);
509  else if (std::get<2>(a) != std::get<2>(b))
510  return std::get<2>(a) < std::get<2>(b);
511  else
512  return true;
513  });
514  }
515  void clearEventList() { eventlist.clear(); }
516  void addEventList(int run, int lumi, unsigned long long evt) {
517  eventlist.push_back(std::make_tuple(run, lumi, evt));
518  }
519 #ifdef USE_CUTLAMBDA
520  void fillHistograms(TString syst, float extrawgt) {
521  // If the cut didn't pass then stop
522  if (!pass)
523  return;
524 
525  if (hists1d.size() != 0 or hists2d.size() != 0 or hists2dvec.size() != 0 or hists1dvec.size() != 0) {
526  TString systkey = syst.IsNull() ? "Nominal" : syst;
527  for (auto& tuple : hists1d[systkey]) {
528  THist* h = std::get<0>(tuple);
529  std::function<float()> vardef = std::get<1>(tuple);
530  h->Fill(vardef(), weight * extrawgt);
531  }
532  for (auto& tuple : hists2d[systkey]) {
533  TH2F* h = std::get<0>(tuple);
534  std::function<float()> varxdef = std::get<1>(tuple);
535  std::function<float()> varydef = std::get<2>(tuple);
536  h->Fill(varxdef(), varydef(), weight * extrawgt);
537  }
538  for (auto& tuple : hists1dvec[systkey]) {
539  THist* h = std::get<0>(tuple);
540  std::function<std::vector<float>()> vardef = std::get<1>(tuple);
541  std::function<std::vector<float>()> wgtdef = std::get<2>(tuple);
542  std::vector<float> varx = vardef();
543  std::vector<float> elemwgts;
544  if (wgtdef)
545  elemwgts = wgtdef();
546  for (unsigned int i = 0; i < varx.size(); ++i) {
547  if (wgtdef)
548  h->Fill(varx[i], weight * extrawgt * elemwgts[i]);
549  else
550  h->Fill(varx[i], weight * extrawgt);
551  }
552  }
553  for (auto& tuple : hists2dvec[systkey]) {
554  TH2F* h = std::get<0>(tuple);
555  std::function<std::vector<float>()> varxdef = std::get<1>(tuple);
556  std::function<std::vector<float>()> varydef = std::get<2>(tuple);
557  std::function<std::vector<float>()> wgtdef = std::get<3>(tuple);
558  std::vector<float> varx = varxdef();
559  std::vector<float> vary = varydef();
560  if (varx.size() != vary.size()) {
561  TString msg =
562  "the vector input to be looped over do not have same length for x and y! check the variable definition "
563  "for histogram ";
564  msg += h->GetName();
565  warning(msg);
566  }
567  std::vector<float> elemwgts;
568  if (wgtdef)
569  elemwgts = wgtdef();
570  for (unsigned int i = 0; i < varx.size(); ++i) {
571  if (wgtdef)
572  h->Fill(varx[i], vary[i], weight * extrawgt * elemwgts[i]);
573  else
574  h->Fill(varx[i], vary[i], weight * extrawgt);
575  }
576  }
577  }
578  for (auto& child : children)
579  child->fillHistograms(syst, extrawgt);
580  }
581 #else
582  void fillHistograms(RooUtil::TTreeX& tx, TString syst, float extrawgt) {
583  // If the cut didn't pass then stop
584  if (!pass)
585  return;
586 
587  if (hists1d.size() != 0 or hists2d.size() != 0) {
588  TString systkey = syst.IsNull() ? "Nominal" : syst;
589  for (auto& tuple : hists1d[systkey]) {
590  THist* h = std::get<0>(tuple);
591  TString varname = std::get<1>(tuple);
592  h->Fill(tx.getBranch<float>(varname), weight * extrawgt);
593  }
594  for (auto& tuple : hists2d[systkey]) {
595  TH2F* h = std::get<0>(tuple);
596  TString varname = std::get<1>(tuple);
597  TString varnamey = std::get<2>(tuple);
598  h->Fill(tx.getBranch<float>(varname), tx.getBranch<float>(varnamey), weight * extrawgt);
599  }
600  }
601  for (auto& child : children)
602  child->fillHistograms(tx, syst, extrawgt);
603 
604  // if (!parent)
605  // {
606  // pass = pass_this_cut;
607  // weight = weight_this_cut;
608  // }
609  // else
610  // {
611  // if (cutsystname.IsNull())
612  // {
613  // pass = pass_this_cut && aggregated_pass;
614  // weight = weight_this_cut * aggregated_weight;
615  // }
616  // else
617  // {
618  // if (systs.find(cutsystname) == systs.end())
619  // {
620  // pass = pass_this_cut && aggregated_pass;
621  // weight = weight_this_cut * aggregated_weight;
622  // }
623  // else
624  // {
625  // pass = systs[cutsystname]->pass_this_cut && aggregated_pass;
626  // weight = systs[cutsystname]->weight_this_cut * aggregated_weight;
627  // }
628  // }
629  // }
630  }
631 #endif
632  };
633 } // namespace RooUtil
634 
635 #endif
CutNameList & operator[](TString name)
Definition: cutflowutil.h:43
void fillHistograms(TString syst, float extrawgt)
Definition: cutflowutil.h:520
void addHist2D(TH2F *h, std::function< float()> varx, std::function< float()> vary, TString syst)
Definition: cutflowutil.h:218
std::map< TString, std::vector< std::tuple< TH1D *, std::function< float()> > > > hists1d
Definition: cutflowutil.h:96
void fillCutflow(std::vector< TString > cutlist, RooUtil::TTreeX &tx, TH1D *h)
Definition: cutflowutil.cc:53
std::tuple< std::map< TString, TH1D * >, std::map< TString, TH1D * > > createCutflowHistograms(CutNameListMap &cutlists, TString syst="")
Definition: cutflowutil.cc:78
std::vector< int > systpasses
Definition: cutflowutil.h:87
CutTree & getCut(TString n)
Definition: cutflowutil.h:263
void evaluate(RooUtil::TTreeX &tx, TString cutsystname="", bool doeventlist=false, bool aggregated_pass=true, float aggregated_weight=1)
Definition: cutflowutil.h:350
CutTree(TString n)
Definition: cutflowutil.h:112
void clearEventList()
Definition: cutflowutil.h:515
std::vector< TString > getCutListBelow(TString n, std::vector< TString > cut_list=std::vector< TString >())
Definition: cutflowutil.h:303
void evaluate_use_lambda(RooUtil::TTreeX &tx, TString cutsystname="", bool doeventlist=false, bool aggregated_pass=true, float aggregated_weight=1)
Definition: cutflowutil.h:365
void warning(TString msg, const char *fname="")
Definition: printutil.cc:38
T w() const
void print(TString msg="", const char *fname="", int flush_before=0, int flush_after=0)
Definition: printutil.cc:23
void fillRawCutflow(std::vector< TString > cutlist, RooUtil::TTreeX &tx, TH1D *h)
Definition: cutflowutil.cc:65
std::vector< TString > systcutnames
Definition: cutflowutil.h:82
void printCuts(int indent=0, std::vector< int > multichild=std::vector< int >())
Definition: cutflowutil.h:119
const T & getBranch(TString, bool=true)
void saveCutflowHistograms(std::map< TString, TH1D *> &cutflows, std::map< TString, TH1D *> &rawcutflows)
Definition: cutflowutil.cc:123
CutNameList(const CutNameList &cutnamelist)
Definition: cutflowutil.h:30
void addHist1DVec(TH1D *h, std::function< std::vector< float >()> var, std::function< std::vector< float >()> wgt, TString syst)
Definition: cutflowutil.h:209
std::map< TString, std::vector< std::tuple< TH2F *, std::function< float()>, std::function< float()> > > > hists2d
Definition: cutflowutil.h:100
void addEventList(int run, int lumi, unsigned long long evt)
Definition: cutflowutil.h:516
Definition: weight.py:1
void error(TString msg, const char *fname="", int is_error=1)
Definition: printutil.cc:44
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void addSyst(TString syst, std::vector< TString > patterns, std::vector< TString > vetopatterns=std::vector< TString >())
Definition: cutflowutil.h:328
float weight_this_cut
Definition: cutflowutil.h:90
std::vector< TString > cutlist
Definition: cutflowutil.h:42
std::map< TString, CutNameList > cutlists
Definition: cutflowutil.h:41
std::map< TString, std::vector< std::tuple< TH2F *, std::function< std::vector< float >)>, std::function< std::vector< float >)>, std::function< std::vector< float >)> > > > hists2dvec
Definition: cutflowutil.h:106
std::function< float()> weight_this_cut_func
Definition: cutflowutil.h:92
std::vector< float > systweights
Definition: cutflowutil.h:88
std::map< TString, std::vector< std::tuple< TH1D *, std::function< std::vector< float >)>, std::function< std::vector< float >)> > > > hists1dvec
Definition: cutflowutil.h:99
void sortEventList()
Definition: cutflowutil.h:500
std::vector< CutTree * > parents
Definition: cutflowutil.h:80
std::tuple< std::vector< bool >, std::vector< float > > getCutflow(std::vector< TString > cutlist, RooUtil::TTreeX &tx)
Definition: cutflowutil.cc:24
std::vector< std::tuple< int, int, unsigned long long > > eventlist
Definition: cutflowutil.h:111
std::vector< CutTree * > children
Definition: cutflowutil.h:81
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void addSyst(TString syst)
Definition: cutflowutil.h:187
key
prepare the HTCondor submission files and eventually submit them
bool hasBranch(TString)
std::function< bool()> pass_this_cut_func
Definition: cutflowutil.h:91
#define THist
Definition: cutflowutil.h:21
void evaluate_use_ttreex(RooUtil::TTreeX &tx, TString cutsystname="", bool doeventlist=false, bool aggregated_pass=true, float aggregated_weight=1)
Definition: cutflowutil.h:463
void addCutName(TString cutname)
Definition: cutflowutil.h:32
void addCut(TString n)
Definition: cutflowutil.h:181
std::map< TString, CutTree * > systs
Definition: cutflowutil.h:84
void createCutflowBranches(CutNameListMap &cutlists, RooUtil::TTreeX &tx)
Definition: cutflowutil.cc:18
void printEventList()
Definition: cutflowutil.h:161
double b
Definition: hdecay.h:120
void addHist1D(TH1D *h, std::function< float()> var, TString syst)
Definition: cutflowutil.h:203
std::vector< TString > cutlist
Definition: cutflowutil.h:28
tuple msg
Definition: mps_check.py:286
std::vector< TString > getCutList(TString n, std::vector< TString > cut_list=std::vector< TString >())
Definition: cutflowutil.h:272
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
double a
Definition: hdecay.h:121
void addHist2DVec(TH2F *h, std::function< std::vector< float >()> varx, std::function< std::vector< float >()> vary, std::function< std::vector< float >()> elemwgt, TString syst)
Definition: cutflowutil.h:224
CutTree * parent
Definition: cutflowutil.h:79
std::vector< CutTree * > systcuts
Definition: cutflowutil.h:83
std::map< TString, std::vector< TString > > getStdVersion()
Definition: cutflowutil.h:51
std::vector< TString > getEndCuts(std::vector< TString > endcuts=std::vector< TString >())
Definition: cutflowutil.h:294
std::pair< bool, float > passCuts(std::vector< TString > cutlist, RooUtil::TTreeX &tx)
Definition: cutflowutil.cc:42
void evaluate_use_internal_variable(RooUtil::TTreeX &tx, TString cutsystname="", bool doeventlist=false, bool aggregated_pass=true, float aggregated_weight=1)
Definition: cutflowutil.h:425
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
CutTree * getCutPointer(TString n)
Definition: cutflowutil.h:248
#define str(s)
void clear_passbits()
Definition: cutflowutil.h:344
void writeEventList(TString ofilename)
Definition: cutflowutil.h:171