CMS 3D CMS Logo

anautil.cc
Go to the documentation of this file.
1 #include "anautil.h"
2 
3 bool PASS() { return true; }
4 float UNITY() { return 1; }
5 
6 //_______________________________________________________________________________________________________
8  : cuttree("Root"),
9  last_active_cut(0),
10  ofile(0),
11  t(0),
12  tx(0),
13  iseventlistbooked(false),
14  seterrorcount(0),
15  doskipsysthist(0),
16  dosavettreex(0),
17  cutflow_booked(false) {
18  cuttreemap["Root"] = &cuttree;
19 }
20 
21 //_______________________________________________________________________________________________________
23  : cuttree("Root"),
24  last_active_cut(0),
25  ofile(o),
26  t(0),
27  tx(0),
28  iseventlistbooked(false),
29  seterrorcount(0),
30  doskipsysthist(0),
31  dosavettreex(0),
32  cutflow_booked(false) {
33  cuttreemap["Root"] = &cuttree;
34 }
35 
36 //_______________________________________________________________________________________________________
38  if (booked_histograms.size() > 0) {
39  for (auto& [k, v] : booked_histograms) {
40  delete v;
41  }
42  }
43  if (booked_2dhistograms.size() > 0) {
44  for (auto& [k, v] : booked_2dhistograms) {
45  delete v;
46  }
47  }
48 }
49 
50 //_______________________________________________________________________________________________________
52  if (cuttreemap.find(n.Data()) == cuttreemap.end())
53  cuttreemap[n.Data()] = cuttree.getCutPointer(n);
54  else
55  error(TString::Format("Cut %s already exists! no duplicate cut names allowed!", n.Data()));
56 }
57 
58 //_______________________________________________________________________________________________________
59 void RooUtil::Cutflow::setLastActiveCut(TString n) { last_active_cut = cuttree.getCutPointer(n); }
60 
61 //_______________________________________________________________________________________________________
62 void RooUtil::Cutflow::printCuts() { cuttree.printCuts(); }
63 
64 //_______________________________________________________________________________________________________
66  RooUtil::CutTree& c = cuttree.getCut(n);
67  setLastActiveCut(n);
68  return c;
69 }
70 
71 #ifdef USE_CUTLAMBDA
72 //_______________________________________________________________________________________________________
73 void RooUtil::Cutflow::addCut(TString n, std::function<bool()> cut, std::function<float()> weight) {
74  cuttree.addCut(n);
75  addToCutTreeMap(n);
76  setLastActiveCut(n);
77  setCut(n, cut, weight);
78 }
79 
80 //_______________________________________________________________________________________________________
82  last_active_cut->addCut(n);
83  addToCutTreeMap(n);
84  setLastActiveCut(n);
85  setCut(n, cut, weight);
86 }
87 
88 #else
89 
90 //_______________________________________________________________________________________________________
91 void RooUtil::Cutflow::addCut(TString n) {
92  cuttree.addCut(n);
93  addToCutTreeMap(n);
94  setLastActiveCut(n);
95 }
96 
97 //_______________________________________________________________________________________________________
99  last_active_cut->addCut(n);
100  addToCutTreeMap(n);
101  setLastActiveCut(n);
102 }
103 
104 #endif
105 
106 //_______________________________________________________________________________________________________
108  RooUtil::CutTree* c = cuttree.getCutPointer(n);
109  c->parent->children.erase(std::find(c->parent->children.begin(), c->parent->children.end(), c));
110  cuttreemap.erase(cuttreemap.find(n.Data()));
111 }
112 
113 //_______________________________________________________________________________________________________
114 void RooUtil::Cutflow::filterCuts(std::vector<TString> ns) {
115  //
116  std::vector<TString> to_not_remove;
117  for (auto& n : ns) {
118  std::vector<TString> cutlist = cuttree.getCutList(n);
119  for (auto& cut : cutlist) {
120  to_not_remove.push_back(cut);
121  }
122  }
123 
124  for (auto& n : ns) {
125  std::vector<TString> cutlist = cuttree.getCutList(n);
126  for (unsigned int i = 0; i < cutlist.size() - 1; ++i) {
127  RooUtil::CutTree* cut = cuttree.getCutPointer(cutlist[i]);
128  std::vector<RooUtil::CutTree*> toremove;
129  for (auto& child : cut->children) {
130  if (not child->name.EqualTo(cutlist[i + 1])) {
131  if (std::find(to_not_remove.begin(), to_not_remove.end(), child->name) == to_not_remove.end())
132  toremove.push_back(child);
133  }
134  }
135  for (auto& child : toremove) {
136  cut->children.erase(std::find(cut->children.begin(), cut->children.end(), child));
137  cuttreemap.erase(cuttreemap.find(child->name.Data()));
138  }
139  }
140  }
141 }
142 
143 //_______________________________________________________________________________________________________
144 void RooUtil::Cutflow::setCutLists(std::vector<TString> regions) {
145  for (auto& region : regions) {
146  cutlists[region] = cuttree.getCutList(region);
147  // std::cout << region << std::endl;
148  // for (auto& cutname : cutlists[region])
149  // std::cout << cutname << std::endl;
150  }
151  for (auto& region : regions) {
152  for (auto& cutname : cutlists[region]) {
153  cuttreelists[region].push_back(cuttreemap[cutname.Data()]);
154  }
155  }
156 }
157 
158 //_______________________________________________________________________________________________________
160  if (std::find(cutflow_nofill_cut_list.begin(), cutflow_nofill_cut_list.end(), n) == cutflow_nofill_cut_list.end())
161  cutflow_nofill_cut_list.push_back(n);
162 }
163 
164 //_______________________________________________________________________________________________________
166  if (!t) {
167  ofile->cd();
168  t = new TTree("cut_tree", "cut_tree");
169  t->SetDirectory(0);
170  }
171  if (!tx) {
172  ofile->cd();
173  tx = new TTreeX(t);
174  }
176  createWgtSystBranches();
177  // t->Print();
178 }
179 
180 //_______________________________________________________________________________________________________
182  if (cutflow_booked) {
183  error("bookCutflowHistograms():: cutflows already booked! yet you called again to book it! Check your user code!");
184  }
185  cutflow_booked = true;
186  bookCutflowHistograms_v1();
187 }
188 
189 //_______________________________________________________________________________________________________
191  ofile->cd();
192 
193  // Nominal
194  for (auto& cuttreelist : cuttreelists) {
195  THist* h = new THist(cuttreelist.first + "_cutflow", "", cuttreelist.second.size(), 0, cuttreelist.second.size());
196  THist* h_raw =
197  new THist(cuttreelist.first + "_rawcutflow", "", cuttreelist.second.size(), 0, cuttreelist.second.size());
198  h->Sumw2();
199  h_raw->Sumw2();
200  h->SetDirectory(0);
201  h_raw->SetDirectory(0);
202  std::vector<int*> passes;
203  std::vector<float*> weights;
204  for (auto& ct : cuttreelist.second) {
205  passes.push_back(&(ct->pass));
206  weights.push_back(&(ct->weight));
207  }
208  cutflow_histograms_v2.push_back(std::make_tuple(h, passes, weights, UNITY));
209  rawcutflow_histograms_v2.push_back(std::make_tuple(h_raw, passes));
210  }
211 
212  // Wgt varying systematic cutflow
213  for (auto& syst : systs) {
214  for (auto& cuttreelist : cuttreelists) {
215  THist* h =
216  new THist(cuttreelist.first + syst + "_cutflow", "", cuttreelist.second.size(), 0, cuttreelist.second.size());
217  THist* h_raw = new THist(
218  cuttreelist.first + syst + "_rawcutflow", "", cuttreelist.second.size(), 0, cuttreelist.second.size());
219  h->Sumw2();
220  h_raw->Sumw2();
221  h->SetDirectory(0);
222  h_raw->SetDirectory(0);
223  std::vector<int*> passes;
224  std::vector<float*> weights;
225  for (auto& ct : cuttreelist.second) {
226  passes.push_back(&(ct->pass));
227  weights.push_back(&(ct->weight));
228  }
229  cutflow_histograms_v2.push_back(std::make_tuple(h, passes, weights, systs_funcs[syst]));
230  rawcutflow_histograms_v2.push_back(std::make_tuple(h_raw, passes));
231  }
232  }
233 
234  // Nominal
235  for (unsigned int i = 0; i < cutsysts.size(); ++i) {
236  TString cutsyst = cutsysts[i];
237  for (auto& cuttreelist : cuttreelists) {
238  THist* h = new THist(
239  cuttreelist.first + cutsyst + "_cutflow", "", cuttreelist.second.size(), 0, cuttreelist.second.size());
240  THist* h_raw = new THist(
241  cuttreelist.first + cutsyst + "_rawcutflow", "", cuttreelist.second.size(), 0, cuttreelist.second.size());
242  h->Sumw2();
243  h_raw->Sumw2();
244  h->SetDirectory(0);
245  h_raw->SetDirectory(0);
246  std::vector<int*> passes;
247  std::vector<float*> weights;
248  for (auto& ct : cuttreelist.second) {
249  passes.push_back(&(ct->systpasses[i]));
250  weights.push_back(&(ct->systweights[i]));
251  }
252  cutflow_histograms_v2.push_back(std::make_tuple(h, passes, weights, UNITY));
253  rawcutflow_histograms_v2.push_back(std::make_tuple(h_raw, passes));
254  }
255  }
256 }
257 
258 //_______________________________________________________________________________________________________
260  ofile->cd();
261 
262  std::tie(cutflow_histograms, rawcutflow_histograms) = RooUtil::CutflowUtil::createCutflowHistograms(cutlists);
263 
264  for (auto& syst : systs) {
265  std::map<CUTFLOWMAPSTRING, THist*> cutflow_histograms_tmp;
266  std::map<CUTFLOWMAPSTRING, THist*> rawcutflow_histograms_tmp;
267  std::tie(cutflow_histograms_tmp, rawcutflow_histograms_tmp) =
269  cutflow_histograms.insert(cutflow_histograms_tmp.begin(), cutflow_histograms_tmp.end());
270  rawcutflow_histograms.insert(rawcutflow_histograms_tmp.begin(), rawcutflow_histograms_tmp.end());
271  }
272 
273  for (auto& cutsyst : cutsysts) {
274  std::map<CUTFLOWMAPSTRING, THist*> cutflow_histograms_tmp;
275  std::map<CUTFLOWMAPSTRING, THist*> rawcutflow_histograms_tmp;
276  std::tie(cutflow_histograms_tmp, rawcutflow_histograms_tmp) =
278  cutflow_histograms.insert(cutflow_histograms_tmp.begin(), cutflow_histograms_tmp.end());
279  rawcutflow_histograms.insert(rawcutflow_histograms_tmp.begin(), rawcutflow_histograms_tmp.end());
280  }
281 
282  for (auto& cutflow_histogram : cutflow_histograms) {
283  TString msg = "Booked cutflow histogram for cut = " + cutflow_histogram.first;
284  print(msg);
285  }
286  for (auto& rawcutflow_histogram : rawcutflow_histograms) {
287  TString msg = "Booked rawcutflow histogram for cut = " + rawcutflow_histogram.first;
288  print(msg);
289  }
290 }
291 
292 //_______________________________________________________________________________________________________
294  setCutLists(regions);
295  bookCutflowTree();
296  bookCutflowHistograms();
297 }
298 
299 //_______________________________________________________________________________________________________
301  std::vector<TString> regions = cuttree.getEndCuts();
302  setCutLists(regions);
303  bookCutflowTree();
304  bookCutflowHistograms();
305 }
306 
307 //_______________________________________________________________________________________________________
309  saveCutflows();
310  saveHistograms();
311  saveTTreeX();
312  TString filename = ofile->GetName();
313  TString msg = "Wrote output to " + filename;
314  print(msg);
315 }
316 
317 //_______________________________________________________________________________________________________
319  // Save cutflow histograms
320  ofile->cd();
321  RooUtil::CutflowUtil::saveCutflowHistograms(cutflow_histograms, rawcutflow_histograms);
322 }
323 
324 //_______________________________________________________________________________________________________
326  ofile->cd();
327  for (auto& pair : booked_histograms)
328  pair.second->Write();
329  for (auto& pair : booked_2dhistograms)
330  pair.second->Write();
331 }
332 
333 //_______________________________________________________________________________________________________
335  if (dosavettreex) {
336  ofile->cd();
337  tx->save(ofile);
338  }
339 }
340 
341 #ifdef USE_CUTLAMBDA
342 //_______________________________________________________________________________________________________
343 void RooUtil::Cutflow::setCut(TString cutname, std::function<bool()> pass, std::function<float()> weight) {
344  cuttreemap[cutname.Data()]->pass_this_cut_func = pass;
345  cuttreemap[cutname.Data()]->weight_this_cut_func = weight;
346 }
347 
348 //_______________________________________________________________________________________________________
349 void RooUtil::Cutflow::setCutSyst(TString cutname,
350  TString syst,
351  std::function<bool()> pass,
352  std::function<float()> weight) {
353  if (cuttreemap[cutname.Data()]->systs.find(syst) == cuttreemap[cutname.Data()]->systs.end()) {
354  error(
355  TString::Format("setCutSyst():: Did not find syst=%s from the cut=%s! Did you actually book this syst for the "
356  "cut properly using addCutSyst() ?",
357  syst.Data(),
358  cutname.Data()));
359  }
360  cuttreemap[cutname.Data()]->systs[syst]->pass_this_cut_func = pass;
361  cuttreemap[cutname.Data()]->systs[syst]->weight_this_cut_func = weight;
362 }
363 
364 #else
365 
366 //_______________________________________________________________________________________________________
367 void RooUtil::Cutflow::setCut(TString cutname, bool pass, float weight) {
368  if (!tx) {
369  TString msg = "No TTreeX object set, setCut() for " + cutname;
370  printSetFunctionError(msg);
371  return;
372  }
373 
374 #ifdef USE_TTREEX
375  tx->setBranch<bool>(cutname, pass, false, true);
376  tx->setBranch<float>(cutname + "_weight", weight, false, true);
377 #else
378  cuttreemap[cutname.Data()]->pass_this_cut = pass;
379  cuttreemap[cutname.Data()]->weight_this_cut = weight;
380 #endif
381 }
382 
383 //_______________________________________________________________________________________________________
384 void RooUtil::Cutflow::setCutSyst(TString cutname, TString syst, bool pass, float weight) {
385  if (!tx) {
386  TString msg = "No TTreeX object set, setCutSyst() for " + cutname + ", " + syst;
387  printSetFunctionError(msg);
388  return;
389  }
390 #ifdef USE_TTREEX
391  tx->setBranch<bool>(cutname + syst, pass, false, true);
392  tx->setBranch<float>(cutname + syst + "_weight", weight, false, true);
393 #else
394  cuttreemap[cutname.Data()]->systs[syst]->pass_this_cut = pass;
395  cuttreemap[cutname.Data()]->systs[syst]->weight_this_cut = weight;
396 #endif
397 }
398 
399 #endif // USE_CUTLAMBDA
400 
401 //_______________________________________________________________________________________________________
402 void RooUtil::Cutflow::setWgtSyst(TString syst, float weight) {
403  if (!tx) {
404  TString msg = "No TTreeX object set, setWgtSyst() for " + syst;
405  printSetFunctionError(msg);
406  return;
407  }
408  tx->setBranch<float>(syst, weight, false, true);
409 }
410 
411 //_______________________________________________________________________________________________________
412 void RooUtil::Cutflow::addCutSyst(TString syst, std::vector<TString> pattern, std::vector<TString> vetopattern) {
413  cutsysts.push_back(syst);
414  cuttree.addSyst(syst, pattern, vetopattern);
415 }
416 
417 #ifdef USE_CUTLAMBDA
418 //_______________________________________________________________________________________________________
419 void RooUtil::Cutflow::addWgtSyst(TString syst, std::function<float()> weight) {
420  systs.push_back(syst);
421  systs_funcs[syst] = weight;
422 }
423 #else
424 //_______________________________________________________________________________________________________
425 void RooUtil::Cutflow::addWgtSyst(TString syst) { systs.push_back(syst); }
426 #endif
427 
428 //_______________________________________________________________________________________________________
430  for (auto& syst : systs) {
431  if (!tx->hasBranch<float>(syst))
432  tx->createBranch<float>(syst);
433  }
434 }
435 
436 //_______________________________________________________________________________________________________
437 void RooUtil::Cutflow::setVariable(TString varname, float val) {
438  if (!tx) {
439  TString msg = "No TTreeX object set, setVariable() for " + varname;
440  printSetFunctionError(msg);
441  return;
442  }
443  tx->setBranch<float>(varname, val, false, true);
444 }
445 
446 //_______________________________________________________________________________________________________
447 void RooUtil::Cutflow::setEventID(int run, int lumi, unsigned long long evt) {
448  if (!tx) {
449  TString msg = "No TTreeX object set, setEventID()";
450  printSetFunctionError(msg);
451  return;
452  }
453  tx->setBranch<int>("run", run, false, true);
454  tx->setBranch<int>("lumi", lumi, false, true);
455  tx->setBranch<unsigned long long>("evt", evt, false, true);
456 }
457 
458 //_______________________________________________________________________________________________________
460  if (!tx)
461  error("bookEventLists():: No TTreeX has been set. Forgot to call bookCutflows()?");
462  if (!tx->hasBranch<int>("run"))
463  tx->createBranch<int>("run");
464  if (!tx->hasBranch<int>("lumi"))
465  tx->createBranch<int>("lumi");
466  if (!tx->hasBranch<unsigned long long>("evt"))
467  tx->createBranch<unsigned long long>("evt");
468  iseventlistbooked = true;
469 }
470 
471 //_______________________________________________________________________________________________________
473 #ifdef USE_TTREEX
474  if (!tx) {
475  TString msg = "No TTreeX object set, fill()";
476  printSetFunctionError(msg);
477  return;
478  }
479  tx->setBranch<bool>("Root", 1); // Root is internally set
480  tx->setBranch<float>("Root_weight", 1); // Root is internally set
481 #else
482  cuttreemap["Root"]->pass_this_cut = 1;
483  cuttreemap["Root"]->weight_this_cut = 1;
484 #endif
485 
486  // Evaluate nominal selection cutflows (the non cut varying selections)
487  cuttree.evaluate(*tx, "", iseventlistbooked);
488 
489  // Nominal cutflow
490  fillCutflows();
491 
492  // Wgt systematic variations
493  for (auto& syst : systs)
494  fillCutflows(syst);
495 
496  // Fill nominal histograms
497  fillHistograms();
498 
499  if (not doskipsysthist) {
500  // Wgt systematic variations
501  for (auto& syst : systs)
502  fillHistograms(syst);
503  }
504 
505  for (auto& cutsyst : cutsysts) {
506  cuttree.evaluate(*tx, cutsyst, iseventlistbooked);
507  fillCutflows(cutsyst, false);
508  if (not doskipsysthist)
509  fillHistograms(cutsyst, false);
510  }
511 
512  if (tx) {
513  if (dosavettreex)
514  tx->fill();
515 
516  tx->clear();
517  }
518 }
519 
520 #ifdef USE_CUTLAMBDA
521 //_______________________________________________________________________________________________________
522 void RooUtil::Cutflow::fillCutflows(TString syst, bool iswgtsyst) { fillCutflows_v2(syst, iswgtsyst); }
523 
524 //_______________________________________________________________________________________________________
525 void RooUtil::Cutflow::fillCutflows_v1(TString syst, bool iswgtsyst) {
526  for (auto& pair : cutlists) {
527  const TString& region_name = pair.first;
528  std::vector<TString>& cutlist = pair.second;
529  float wgtsyst = (!syst.IsNull() and iswgtsyst) ? systs_funcs[syst]() : 1;
531  cutflow_histograms[(region_name + syst).Data()],
532  rawcutflow_histograms[(region_name + syst).Data()],
533  wgtsyst);
534  }
535 }
536 
537 //_______________________________________________________________________________________________________
538 void RooUtil::Cutflow::fillCutflows_v2(TString syst, bool iswgtsyst) {
539  for (auto& pair : cuttreelists) {
540  const TString& region_name = pair.first;
541  std::vector<RooUtil::CutTree*>& cuttreelist = pair.second;
542  float wgtsyst = (!syst.IsNull() and iswgtsyst) ? systs_funcs[syst]() : 1;
543  fillCutflow_v2(cuttreelist,
544  cutflow_histograms[(region_name + syst).Data()],
545  rawcutflow_histograms[(region_name + syst).Data()],
546  wgtsyst);
547  }
548 }
549 #else
550 //_______________________________________________________________________________________________________
551 void RooUtil::Cutflow::fillCutflows(TString syst, bool iswgtsyst) {
552  for (auto& pair : cutlists) {
553  const TString& region_name = pair.first;
554  std::vector<TString>& cutlist = pair.second;
555  float wgtsyst = (!syst.IsNull() and iswgtsyst) ? tx->getBranch<float>(syst) : 1;
557  cutflow_histograms[(region_name + syst).Data()],
558  rawcutflow_histograms[(region_name + syst).Data()],
559  wgtsyst);
560  }
561 }
562 #endif
563 
564 //_______________________________________________________________________________________________________
565 void RooUtil::Cutflow::fillCutflow(std::vector<TString>& cutlist, THist* h, THist* hraw, float wgtsyst) {
566  for (unsigned int i = 0; i < cutlist.size(); ++i) {
567  int& pass = cuttreemap[cutlist[i].Data()]->pass;
568  if (pass) {
569  float& weight = cuttreemap[cutlist[i].Data()]->weight;
570  h->Fill(i, weight * wgtsyst);
571  hraw->Fill(i, 1);
572  } else {
573  return;
574  }
575  }
576 }
577 
578 //_______________________________________________________________________________________________________
579 void RooUtil::Cutflow::fillCutflow_v2(std::vector<RooUtil::CutTree*>& cuttreelist,
580  THist* h,
581  THist* hraw,
582  float wgtsyst) {
583  for (unsigned int i = 0; i < cuttreelist.size(); ++i) {
584  RooUtil::CutTree* ct = cuttreelist[i];
585  // if (std::find(cutflow_nofill_cut_list.begin(), cutflow_nofill_cut_list.end(), ct->name) != cutflow_nofill_cut_list.end())
586  // continue;
587  int& pass = ct->pass;
588  if (pass) {
589  float& weight = ct->weight;
590  h->Fill(i, weight * wgtsyst);
591  hraw->Fill(i, 1);
592  } else {
593  return;
594  }
595  }
596 }
597 
598 //_______________________________________________________________________________________________________
599 void RooUtil::Cutflow::fillHistograms(TString syst, bool iswgtsyst) {
600 #ifdef USE_CUTLAMBDA
601  float wgtsyst = (!syst.IsNull() and iswgtsyst) ? systs_funcs[syst]() : 1;
602  cuttree.fillHistograms(syst, wgtsyst);
603 #else
604  float wgtsyst = (!syst.IsNull() and iswgtsyst) ? tx->getBranch<float>(syst) : 1.;
605  cuttree.fillHistograms(*tx, syst, wgtsyst);
606 #endif
607 
608  // for (auto& key1d : booked_histograms_nominal_keys)
609  // {
610  // TString cutname = std::get<0>(key1d);
611  // std::get<1>(key1d) = syst;
612  // TString varname = std::get<2>(key1d);
613  // bool& passed = cuttreemap[cutname.Data()]->pass;
614  // if (!passed)
615  // continue;
616  // float& weight = cuttreemap[cutname.Data()]->weight;
617  // float wgtsyst = (!syst.IsNull() and iswgtsyst)? tx->getBranch<float>(syst) : 1.;
618  // THist* h = booked_histograms[key1d];
619  // h->Fill(tx->getBranch<float>(varname), weight * wgtsyst);
620  // }
621  //
622  // for (auto& key2d : booked_2dhistograms_nominal_keys)
623  // {
624  // TString cutname = std::get<0>(key2d);
625  // std::get<1>(key2d) = syst;
626  // TString varname = std::get<2>(key2d);
627  // TString varnamey = std::get<3>(key2d);
628  // bool& passed = cuttreemap[cutname.Data()]->pass;
629  // if (!passed)
630  // continue;
631  // float& weight = cuttreemap[cutname.Data()]->weight;
632  // float wgtsyst = (!syst.IsNull() and iswgtsyst)? tx->getBranch<float>(syst) : 1.;
633  // TH2F* h = booked_2dhistograms[key2d];
634  // h->Fill(tx->getBranch<float>(varname), tx->getBranch<float>(varnamey), weight * wgtsyst);
635  // }
636 
637  // for (auto& pair : booked_histograms)
638  // {
639  // TString cutname = std::get<0>(pair.first);
640  // TString sysname = std::get<1>(pair.first);
641  // TString varname = std::get<2>(pair.first);
642  // THist* h = pair.second;
643  // bool& passed = cuttreemap[cutname.DATA()]->pass;
644  // float& weight = cuttreemap[cutname.DATA()]->weight;
645  // float wgtsyst = sysname.IsNull() ? 1. : tx->getBranch<float>(sysname);
646  // if (passed)
647  // h->Fill(tx->getBranch<float>(varname), weight * wgtsyst);
648  // }
649  //
650  // for (auto& pair : booked_2dhistograms)
651  // {
652  // TString cutname = std::get<0>(pair.first);
653  // TString sysname = std::get<1>(pair.first);
654  // TString varname = std::get<2>(pair.first);
655  // TString varnamey = std::get<3>(pair.first);
656  // TH2F* h = pair.second;
657  // bool& passed = cuttreemap[cutname.DATA()]->pass;
658  // float& weight = cuttreemap[cutname.DATA()]->weight;
659  // float wgtsyst = sysname.IsNull() ? 1. : tx->getBranch<float>(sysname);
660  // if (passed)
661  // h->Fill(tx->getBranch<float>(varname), tx->getBranch<float>(varnamey), weight * wgtsyst);
662  // }
663 }
664 
665 //_______________________________________________________________________________________________________
667  std::vector<TString> regions = cuttree.getEndCuts();
668  for (auto& region : regions) {
669  std::vector<TString> cutlist = cuttree.getCutList(region);
671  }
672 }
673 
674 //_______________________________________________________________________________________________________
676  for (auto& cut : cutlist) {
677  bookHistogramsForCut(histograms, cut);
678  }
679 }
680 
681 #ifdef USE_CUTLAMBDA
682 //_______________________________________________________________________________________________________
684  std::pair<TString, std::tuple<unsigned, float, float, std::function<float()>>> key,
685  TString syst) {
686  TString varname = key.first;
687  unsigned int nbin = std::get<0>(key.second);
688  float min = std::get<1>(key.second);
689  float max = std::get<2>(key.second);
690  std::function<float()> vardef = std::get<3>(key.second);
691  TString histname = cut + syst + "__" + varname;
692  if (booked_histograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data())) == booked_histograms.end()) {
693  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())] =
694  new THist(histname, "", nbin, min, max);
695  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->SetDirectory(0);
696  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->Sumw2();
697  if (syst.IsNull()) {
698  booked_histograms_nominal_keys.push_back(std::make_tuple(cut.Data(), syst.Data(), varname.Data()));
699  }
700  cuttreemap[cut.Data()]->addHist1D(
701  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())], vardef, syst);
702  }
703 }
704 
705 //_______________________________________________________________________________________________________
707  TString cut,
708  std::pair<
709  TString,
710  std::tuple<unsigned, float, float, std::function<std::vector<float>()>, std::function<std::vector<float>()>>>
711  key,
712  TString syst) {
713  TString varname = key.first;
714  unsigned int nbin = std::get<0>(key.second);
715  float min = std::get<1>(key.second);
716  float max = std::get<2>(key.second);
717  std::function<std::vector<float>()> vardef = std::get<3>(key.second);
718  std::function<std::vector<float>()> wgtdef = std::get<4>(key.second);
719  TString histname = cut + syst + "__" + varname;
720  if (booked_histograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data())) == booked_histograms.end()) {
721  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())] =
722  new THist(histname, "", nbin, min, max);
723  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->SetDirectory(0);
724  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->Sumw2();
725  if (syst.IsNull()) {
726  booked_histograms_nominal_keys.push_back(std::make_tuple(cut.Data(), syst.Data(), varname.Data()));
727  }
728  cuttreemap[cut.Data()]->addHist1DVec(
729  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())], vardef, wgtdef, syst);
730  }
731 }
732 
733 //_______________________________________________________________________________________________________
735  std::pair<TString, std::tuple<std::vector<float>, std::function<float()>>> key,
736  TString syst) {
737  TString varname = key.first;
738  std::vector<float> boundaries = std::get<0>(key.second);
739  std::function<float()> vardef = std::get<1>(key.second);
740  TString histname = cut + syst + "__" + varname;
741  if (booked_histograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data())) == booked_histograms.end()) {
742  Float_t bounds[boundaries.size()];
743  for (unsigned int i = 0; i < boundaries.size(); ++i)
744  bounds[i] = boundaries[i];
745  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())] =
746  new THist(histname, "", boundaries.size() - 1, bounds);
747  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->SetDirectory(0);
748  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->Sumw2();
749  if (syst.IsNull()) {
750  booked_histograms_nominal_keys.push_back(std::make_tuple(cut.Data(), syst.Data(), varname.Data()));
751  }
752  cuttreemap[cut.Data()]->addHist1D(
753  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())], vardef, syst);
754  }
755 }
756 
757 //_______________________________________________________________________________________________________
759  TString cut,
760  std::pair<TString,
761  std::tuple<std::vector<float>, std::function<std::vector<float>()>, std::function<std::vector<float>()>>>
762  key,
763  TString syst) {
764  TString varname = key.first;
765  std::vector<float> boundaries = std::get<0>(key.second);
766  std::function<std::vector<float>()> vardef = std::get<1>(key.second);
767  std::function<std::vector<float>()> wgtdef = std::get<2>(key.second);
768  TString histname = cut + syst + "__" + varname;
769  if (booked_histograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data())) == booked_histograms.end()) {
770  Float_t bounds[boundaries.size()];
771  for (unsigned int i = 0; i < boundaries.size(); ++i)
772  bounds[i] = boundaries[i];
773  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())] =
774  new THist(histname, "", boundaries.size() - 1, bounds);
775  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->SetDirectory(0);
776  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->Sumw2();
777  if (syst.IsNull()) {
778  booked_histograms_nominal_keys.push_back(std::make_tuple(cut.Data(), syst.Data(), varname.Data()));
779  }
780  cuttreemap[cut.Data()]->addHist1DVec(
781  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())], vardef, wgtdef, syst);
782  }
783 }
784 
785 //_______________________________________________________________________________________________________
787  TString cut,
788  std::pair<std::pair<TString, TString>,
789  std::tuple<unsigned, float, float, unsigned, float, float, std::function<float()>, std::function<float()>>>
790  key,
791  TString syst) {
792  TString varname = key.first.first;
793  TString varnamey = key.first.second;
794  unsigned int nbin = std::get<0>(key.second);
795  float min = std::get<1>(key.second);
796  float max = std::get<2>(key.second);
797  unsigned int nbiny = std::get<3>(key.second);
798  float miny = std::get<4>(key.second);
799  float maxy = std::get<5>(key.second);
800  std::function<float()> varxdef = std::get<6>(key.second);
801  std::function<float()> varydef = std::get<7>(key.second);
802  TString histname = cut + syst + "__" + varname + "_v_" + varnamey;
803  if (booked_2dhistograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())) ==
804  booked_2dhistograms.end()) {
805  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())] =
806  new TH2F(histname, "", nbin, min, max, nbiny, miny, maxy);
807  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())]->SetDirectory(0);
808  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())]->Sumw2();
809  if (syst.IsNull()) {
810  booked_2dhistograms_nominal_keys.push_back(
811  std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data()));
812  }
813  cuttreemap[cut.Data()]->addHist2D(
814  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())],
815  varxdef,
816  varydef,
817  syst);
818  }
819 }
820 
821 //_______________________________________________________________________________________________________
823  std::pair<std::pair<TString, TString>,
824  std::tuple<unsigned,
825  float,
826  float,
827  unsigned,
828  float,
829  float,
830  std::function<std::vector<float>()>,
831  std::function<std::vector<float>()>,
832  std::function<std::vector<float>()>>> key,
833  TString syst) {
834  TString varname = key.first.first;
835  TString varnamey = key.first.second;
836  unsigned int nbin = std::get<0>(key.second);
837  float min = std::get<1>(key.second);
838  float max = std::get<2>(key.second);
839  unsigned int nbiny = std::get<3>(key.second);
840  float miny = std::get<4>(key.second);
841  float maxy = std::get<5>(key.second);
842  std::function<std::vector<float>()> varxdef = std::get<6>(key.second);
843  std::function<std::vector<float>()> varydef = std::get<7>(key.second);
844  std::function<std::vector<float>()> elemwgt = std::get<8>(key.second);
845  TString histname = cut + syst + "__" + varname + "_v_" + varnamey;
846  if (booked_2dhistograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())) ==
847  booked_2dhistograms.end()) {
848  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())] =
849  new TH2F(histname, "", nbin, min, max, nbiny, miny, maxy);
850  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())]->SetDirectory(0);
851  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())]->Sumw2();
852  if (syst.IsNull()) {
853  booked_2dhistograms_nominal_keys.push_back(
854  std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data()));
855  }
856  cuttreemap[cut.Data()]->addHist2DVec(
857  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())],
858  varxdef,
859  varydef,
860  elemwgt,
861  syst);
862  }
863 }
864 //_______________________________________________________________________________________________________
866  std::pair<std::pair<TString, TString>,
867  std::tuple<std::vector<float>,
868  unsigned,
869  float,
870  float,
871  std::function<std::vector<float>()>,
872  std::function<std::vector<float>()>,
873  std::function<std::vector<float>()>>> key,
874  TString syst) {
875  TString varname = key.first.first;
876  TString varnamey = key.first.second;
877  std::vector<float> xboundaries = std::get<0>(key.second);
878  unsigned int nbiny = std::get<1>(key.second);
879  float miny = std::get<2>(key.second);
880  float maxy = std::get<3>(key.second);
881  std::function<std::vector<float>()> varxdef = std::get<4>(key.second);
882  std::function<std::vector<float>()> varydef = std::get<5>(key.second);
883  std::function<std::vector<float>()> elemwgt = std::get<6>(key.second);
884  TString histname = cut + syst + "__" + varname + "_v_" + varnamey;
885  if (booked_2dhistograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())) ==
886  booked_2dhistograms.end()) {
887  Double_t xbounds[xboundaries.size()];
888  for (unsigned int i = 0; i < xboundaries.size(); ++i)
889  xbounds[i] = xboundaries[i];
890  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())] =
891  new TH2F(histname, "", xboundaries.size() - 1, xbounds, nbiny, miny, maxy);
892  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())]->SetDirectory(0);
893  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())]->Sumw2();
894  if (syst.IsNull()) {
895  booked_2dhistograms_nominal_keys.push_back(
896  std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data()));
897  }
898  cuttreemap[cut.Data()]->addHist2DVec(
899  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())],
900  varxdef,
901  varydef,
902  elemwgt,
903  syst);
904  }
905 }
906 #else
907 //_______________________________________________________________________________________________________
909  std::pair<TString, std::tuple<unsigned, float, float>> key,
910  TString syst) {
911  TString varname = key.first;
912  unsigned int nbin = std::get<0>(key.second);
913  float min = std::get<1>(key.second);
914  float max = std::get<2>(key.second);
915  TString histname = cut + syst + "__" + varname;
916  if (booked_histograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data())) == booked_histograms.end()) {
917  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())] =
918  new THist(histname, "", nbin, min, max);
919  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->SetDirectory(0);
920  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->Sumw2();
921  if (syst.IsNull()) {
922  booked_histograms_nominal_keys.push_back(std::make_tuple(cut.Data(), syst.Data(), varname.Data()));
923  }
924  if (!tx)
925  error("bookHistogram():: No TTreeX has been set. Forgot to call bookCutflows()?");
926  if (!tx->hasBranch<float>(varname))
927  tx->createBranch<float>(varname);
928  cuttreemap[cut.Data()]->addHist1D(
929  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())], varname, syst);
930  }
931 }
932 
933 //_______________________________________________________________________________________________________
934 void RooUtil::Cutflow::bookHistogram(TString cut, std::pair<TString, std::vector<float>> key, TString syst) {
935  TString varname = key.first;
936  std::vector<float> boundaries = key.second;
937  TString histname = cut + syst + "__" + varname;
938  if (booked_histograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data())) == booked_histograms.end()) {
939  Float_t bounds[boundaries.size()];
940  for (unsigned int i = 0; i < boundaries.size(); ++i)
941  bounds[i] = boundaries[i];
942  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())] =
943  new THist(histname, "", boundaries.size() - 1, bounds);
944  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->SetDirectory(0);
945  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())]->Sumw2();
946  if (syst.IsNull()) {
947  booked_histograms_nominal_keys.push_back(std::make_tuple(cut.Data(), syst.Data(), varname.Data()));
948  }
949  if (!tx)
950  error("bookHistogram():: No TTreeX has been set. Forgot to call bookCutflows()?");
951  if (!tx->hasBranch<float>(varname))
952  tx->createBranch<float>(varname);
953  cuttreemap[cut.Data()]->addHist1D(
954  booked_histograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data())], varname, syst);
955  }
956 }
957 
958 //_______________________________________________________________________________________________________
960  TString cut,
961  std::pair<std::pair<TString, TString>, std::tuple<unsigned, float, float, unsigned, float, float>> key,
962  TString syst) {
963  TString varname = key.first.first;
964  TString varnamey = key.first.second;
965  unsigned int nbin = std::get<0>(key.second);
966  float min = std::get<1>(key.second);
967  float max = std::get<2>(key.second);
968  unsigned int nbiny = std::get<0>(key.second);
969  float miny = std::get<1>(key.second);
970  float maxy = std::get<2>(key.second);
971  TString histname = cut + syst + "__" + varname + "_v_" + varnamey;
972  if (booked_2dhistograms.find(std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())) ==
973  booked_2dhistograms.end()) {
974  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())] =
975  new TH2F(histname, "", nbin, min, max, nbiny, miny, maxy);
976  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())]->SetDirectory(0);
977  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())]->Sumw2();
978  if (syst.IsNull()) {
979  booked_2dhistograms_nominal_keys.push_back(
980  std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data()));
981  }
982  if (!tx)
983  error("book2DHistogram():: No TTreeX has been set. Forgot to call bookCutflows()?");
984  if (!tx->hasBranch<float>(varname))
985  tx->createBranch<float>(varname);
986  if (!tx->hasBranch<float>(varnamey))
987  tx->createBranch<float>(varnamey);
988  cuttreemap[cut.Data()]->addHist2D(
989  booked_2dhistograms[std::make_tuple(cut.Data(), syst.Data(), varname.Data(), varnamey.Data())],
990  varname,
991  varnamey,
992  syst);
993  }
994 }
995 #endif
996 
997 //_______________________________________________________________________________________________________
999  for (auto& key : histograms.th1fs)
1000  bookHistogram(cut, key);
1001  for (auto& key : histograms.th1fs_varbin)
1002  bookHistogram(cut, key);
1003  for (auto& key : histograms.th1vecfs)
1004  bookVecHistogram(cut, key);
1005  for (auto& key : histograms.th1vecfs_varbin)
1006  bookVecHistogram(cut, key);
1007  for (auto& key : histograms.th2fs)
1008  book2DHistogram(cut, key);
1009  for (auto& key : histograms.th2vecfs)
1010  book2DVecHistogram(cut, key);
1011  for (auto& key : histograms.th2vecfs_xvarbin)
1012  book2DVecHistogram(cut, key);
1013  if (not doskipsysthist) {
1014  for (auto& syst : systs) {
1015  for (auto& key : histograms.th1fs)
1016  bookHistogram(cut, key, syst);
1017  for (auto& key : histograms.th1fs_varbin)
1018  bookHistogram(cut, key, syst);
1019  for (auto& key : histograms.th1vecfs)
1020  bookVecHistogram(cut, key, syst);
1021  for (auto& key : histograms.th1vecfs_varbin)
1022  bookVecHistogram(cut, key, syst);
1023  for (auto& key : histograms.th2fs)
1024  book2DHistogram(cut, key, syst);
1025  for (auto& key : histograms.th2vecfs)
1026  book2DVecHistogram(cut, key, syst);
1027  for (auto& key : histograms.th2vecfs_xvarbin)
1028  book2DVecHistogram(cut, key, syst);
1029  }
1030  for (auto& cutsyst : cutsysts) {
1031  for (auto& key : histograms.th1fs)
1032  bookHistogram(cut, key, cutsyst);
1033  for (auto& key : histograms.th1fs_varbin)
1034  bookHistogram(cut, key, cutsyst);
1035  for (auto& key : histograms.th1vecfs)
1036  bookVecHistogram(cut, key, cutsyst);
1037  for (auto& key : histograms.th1vecfs_varbin)
1038  bookVecHistogram(cut, key, cutsyst);
1039  for (auto& key : histograms.th2fs)
1040  book2DHistogram(cut, key, cutsyst);
1041  for (auto& key : histograms.th2vecfs)
1042  book2DVecHistogram(cut, key, cutsyst);
1043  for (auto& key : histograms.th2vecfs_xvarbin)
1044  book2DVecHistogram(cut, key, cutsyst);
1045  }
1046  }
1047 }
1048 
1049 //_______________________________________________________________________________________________________
1051  std::vector<TString> cutlist = cuttree.getCutListBelow(cut);
1052  for (auto& c : cutlist) {
1053  bookHistogramsForCut(histograms, c);
1054  }
1055 }
1056 
1057 //_______________________________________________________________________________________________________
1059  error("bookHistogramsForCutAndAbove not yet implemented");
1060 }
1061 
1062 //_______________________________________________________________________________________________________
1064  std::vector<TString> regions = cuttree.getEndCuts();
1065  for (auto& region : regions) {
1066  bookHistogramsForCut(histograms, region);
1067  }
1068 }
1069 
1070 //_______________________________________________________________________________________________________
1071 void RooUtil::Cutflow::setSkipSystematicHistograms(bool v) { doskipsysthist = v; }
1072 
1073 //_______________________________________________________________________________________________________
1074 void RooUtil::Cutflow::setSaveTTreeX(bool v) { dosavettreex = v; }
1075 
1076 //_______________________________________________________________________________________________________
1078  if (seterrorcount < 100) {
1079  print(msg);
1080  seterrorcount++;
1081  } else if (seterrorcount == 100) {
1082  print(msg);
1083  print("Suppressing Cutflow::set\"Func\"() errors ... ");
1084  seterrorcount++;
1085  } else {
1086  return;
1087  }
1088 }
1089 
1090 //_______________________________________________________________________________________________________
1092  for (auto& pair : booked_histograms)
1093  pair.second->SetCanExtend(TH1::kAllAxes);
1094 }
1095 
1096 //_______________________________________________________________________________________________________
1098 
1099 //_______________________________________________________________________________________________________
1101 
1102 #ifdef USE_CUTLAMBDA
1103 //_______________________________________________________________________________________________________
1105  TString name, unsigned int n, float min, float max, std::function<float()> vardef) {
1106  if (th1fs.find(name) == th1fs.end()) {
1107  th1fs[name] = std::make_tuple(n, min, max, vardef);
1108  } else {
1109  error(TString::Format("histogram already exists name = %s", name.Data()));
1110  }
1111 }
1112 
1113 //_______________________________________________________________________________________________________
1115  unsigned int n,
1116  float min,
1117  float max,
1118  std::function<std::vector<float>()> vardef,
1119  std::function<std::vector<float>()> wgt) {
1120  if (th1vecfs.find(name) == th1vecfs.end()) {
1121  th1vecfs[name] = std::make_tuple(n, min, max, vardef, wgt);
1122  } else {
1123  error(TString::Format("histogram already exists name = %s", name.Data()));
1124  }
1125 }
1126 
1127 //_______________________________________________________________________________________________________
1128 void RooUtil::Histograms::addHistogram(TString name, std::vector<float> boundaries, std::function<float()> vardef) {
1129  if (th1fs_varbin.find(name) == th1fs_varbin.end()) {
1130  th1fs_varbin[name] = std::make_tuple(boundaries, vardef);
1131  } else {
1132  error(TString::Format("histogram already exists name = %s", name.Data()));
1133  }
1134 }
1135 
1136 //_______________________________________________________________________________________________________
1138  std::vector<float> boundaries,
1139  std::function<std::vector<float>()> vardef,
1140  std::function<std::vector<float>()> wgt) {
1141  if (th1vecfs_varbin.find(name) == th1vecfs_varbin.end()) {
1142  th1vecfs_varbin[name] = std::make_tuple(boundaries, vardef, wgt);
1143  } else {
1144  error(TString::Format("histogram already exists name = %s", name.Data()));
1145  }
1146 }
1147 
1148 //_______________________________________________________________________________________________________
1150  unsigned int n,
1151  float min,
1152  float max,
1153  TString namey,
1154  unsigned int ny,
1155  float miny,
1156  float maxy,
1157  std::function<float()> varxdef,
1158  std::function<float()> varydef) {
1159  if (th2fs.find(std::make_pair(name, namey)) == th2fs.end()) {
1160  th2fs[std::make_pair(name, namey)] = std::make_tuple(n, min, max, ny, miny, maxy, varxdef, varydef);
1161  } else {
1162  error(TString::Format("histogram already exists name = %s", (name + "_v_" + namey).Data()));
1163  }
1164 }
1165 
1166 //_______________________________________________________________________________________________________
1168  unsigned int n,
1169  float min,
1170  float max,
1171  TString namey,
1172  unsigned int ny,
1173  float miny,
1174  float maxy,
1175  std::function<std::vector<float>()> varxdef,
1176  std::function<std::vector<float>()> varydef,
1177  std::function<std::vector<float>()> elem_wgt) {
1178  if (th2vecfs.find(std::make_pair(name, namey)) == th2vecfs.end()) {
1179  th2vecfs[std::make_pair(name, namey)] = std::make_tuple(n, min, max, ny, miny, maxy, varxdef, varydef, elem_wgt);
1180  } else {
1181  error(TString::Format("histogram already exists name = %s", (name + "_v_" + namey).Data()));
1182  }
1183 }
1184 
1185 //_______________________________________________________________________________________________________
1187  std::vector<float> xboundaries,
1188  TString namey,
1189  unsigned int ny,
1190  float miny,
1191  float maxy,
1192  std::function<std::vector<float>()> varxdef,
1193  std::function<std::vector<float>()> varydef,
1194  std::function<std::vector<float>()> elem_wgt) {
1195  if (th2vecfs_xvarbin.find(std::make_pair(name, namey)) == th2vecfs_xvarbin.end()) {
1196  th2vecfs_xvarbin[std::make_pair(name, namey)] =
1197  std::make_tuple(xboundaries, ny, miny, maxy, varxdef, varydef, elem_wgt);
1198  } else {
1199  error(TString::Format("histogram already exists name = %s", (name + "_v_" + namey).Data()));
1200  }
1201 }
1202 #else
1203 //_______________________________________________________________________________________________________
1204 void RooUtil::Histograms::addHistogram(TString name, unsigned int n, float min, float max) {
1205  if (th1fs.find(name) == th1fs.end())
1206  th1fs[name] = std::make_tuple(n, min, max);
1207  else
1208  error(TString::Format("histogram already exists name = %s", name.Data()));
1209 }
1210 
1211 //_______________________________________________________________________________________________________
1212 void RooUtil::Histograms::addHistogram(TString name, std::vector<float> boundaries) {
1213  if (th1fs_varbin.find(name) == th1fs_varbin.end())
1214  th1fs_varbin[name] = boundaries;
1215  else
1216  error(TString::Format("histogram already exists name = %s", name.Data()));
1217 }
1218 
1219 //_______________________________________________________________________________________________________
1221  TString name, unsigned int n, float min, float max, TString namey, unsigned int ny, float miny, float maxy) {
1222  if (th2fs.find(std::make_pair(name, namey)) == th2fs.end())
1223  th2fs[std::make_pair(name, namey)] = std::make_tuple(n, min, max, ny, miny, maxy);
1224  else
1225  error(TString::Format("histogram already exists name = %s", (name + "_v_" + namey).Data()));
1226 }
1227 #endif
void bookHistogramsForCutAndAbove(Histograms &histograms, TString)
Definition: anautil.cc:1058
void setVariable(TString varname, float)
Definition: anautil.cc:437
void bookCutflowHistograms()
Definition: anautil.cc:181
void setCut(TString cutname, std::function< bool()> pass, std::function< float()> weight)
Definition: anautil.cc:343
void bookHistogramsForEndCuts(Histograms &histograms)
Definition: anautil.cc:1063
void bookHistogramsForCutAndBelow(Histograms &histograms, TString)
Definition: anautil.cc:1050
float UNITY()
Definition: anautil.cc:4
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
void addToCutTreeMap(TString n)
Definition: anautil.cc:51
void removeCut(TString n)
Definition: anautil.cc:107
void print(TString msg="", const char *fname="", int flush_before=0, int flush_after=0)
Definition: printutil.cc:23
void saveOutput()
Definition: anautil.cc:308
void bookCutflowHistograms_v1()
Definition: anautil.cc:259
void saveCutflowHistograms(std::map< TString, TH1D *> &cutflows, std::map< TString, TH1D *> &rawcutflows)
Definition: cutflowutil.cc:123
void addHistogram(TString, unsigned int, float, float, std::function< float()>)
Definition: anautil.cc:1104
void book2DVecHistogram(TString, std::pair< std::pair< TString, TString >, std::tuple< unsigned, float, float, unsigned, float, float, std::function< std::vector< float >()>, std::function< std::vector< float >()>, std::function< std::vector< float >()>>>, TString="")
Definition: anautil.cc:822
CutTree & getCut(TString n)
Definition: anautil.cc:65
void setLastActiveCut(TString n)
Definition: anautil.cc:59
Definition: weight.py:1
void error(TString msg, const char *fname="", int is_error=1)
Definition: printutil.cc:44
void setSaveTTreeX(bool=true)
Definition: anautil.cc:1074
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void filterCuts(std::vector< TString > ns)
Definition: anautil.cc:114
bool PASS()
Definition: anautil.cc:3
void setSkipSystematicHistograms(bool=true)
Definition: anautil.cc:1071
example_stream void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void bookCutflowsForRegions(std::vector< TString > regions)
Definition: anautil.cc:293
void fillCutflow(std::vector< TString > &cutlist, TH1D *h, TH1D *hraw, float wgtsyst=1)
Definition: anautil.cc:565
void saveTTreeX()
Definition: anautil.cc:334
void add2DHistogram(TString, unsigned int, float, float, TString, unsigned int, float, float, std::function< float()>, std::function< float()>)
Definition: anautil.cc:1149
void addCutSyst(TString syst, std::vector< TString > pattern, std::vector< TString > vetopattern=std::vector< TString >())
Definition: anautil.cc:412
void bookCutflows()
Definition: anautil.cc:300
void fillCutflow_v2(std::vector< CutTree *> &cutlist, TH1D *h, TH1D *hraw, float wgtsyst=1)
Definition: anautil.cc:579
void printSetFunctionError(TString msg)
Definition: anautil.cc:1077
void saveCutflows()
Definition: anautil.cc:318
void printCuts()
Definition: anautil.cc:62
key
prepare the HTCondor submission files and eventually submit them
void bookHistogram(TString, std::pair< TString, std::tuple< unsigned, float, float, std::function< float()>>>, TString="")
Definition: anautil.cc:683
void createWgtSystBranches()
Definition: anautil.cc:429
#define THist
Definition: cutflowutil.h:21
def saveHistograms(tdirectory, histos)
void bookHistogramsForCut(Histograms &histograms, TString)
Definition: anautil.cc:998
void addVecHistogram(TString, unsigned int, float, float, std::function< std::vector< float >()>, std::function< std::vector< float >()> wgt=nullptr)
Definition: anautil.cc:1114
void add2DVecHistogram(TString, unsigned int, float, float, TString, unsigned int, float, float, std::function< std::vector< float >()>, std::function< std::vector< float >()>, std::function< std::vector< float >()> wgt=nullptr)
Definition: anautil.cc:1167
void setCutLists(std::vector< TString > regions)
Definition: anautil.cc:144
void setCutSyst(TString cutname, TString syst, std::function< bool()> pass, std::function< float()> weight)
Definition: anautil.cc:349
void bookVecHistogram(TString, std::pair< TString, std::tuple< unsigned, float, float, std::function< std::vector< float >()>, std::function< std::vector< float >()>>>, TString="")
Definition: anautil.cc:706
void createCutflowBranches(CutNameListMap &cutlists, RooUtil::TTreeX &tx)
Definition: cutflowutil.cc:18
void bookCutflowHistograms_v2()
Definition: anautil.cc:190
void book2DHistogram(TString, std::pair< std::pair< TString, TString >, std::tuple< unsigned, float, float, unsigned, float, float, std::function< float()>, std::function< float()>>>, TString="")
Definition: anautil.cc:786
void addCutToSkipCutflowList(TString n)
Definition: anautil.cc:159
tuple msg
Definition: mps_check.py:286
void setHistsAxesExtendable()
Definition: anautil.cc:1091
void fillCutflows_v1(TString syst="", bool iswgtsyst=true)
Definition: anautil.cc:525
void addCutToLastActiveCut(TString n, std::function< bool()> pass, std::function< float()> weight)
Definition: anautil.cc:81
void bookCutflowTree()
Definition: anautil.cc:165
void fillHistograms(TString syst="", bool iswgtsyst=true)
Definition: anautil.cc:599
void addWgtSyst(TString syst, std::function< float()>)
Definition: anautil.cc:419
void bookEventLists()
Definition: anautil.cc:459
void setEventID(int, int, unsigned long long)
Definition: anautil.cc:447
CutTree cuttree
Definition: anautil.h:115
void fillCutflows(TString syst="", bool iswgtsyst=true)
Definition: anautil.cc:522
void saveHistograms()
Definition: anautil.cc:325
void setWgtSyst(TString syst, float weight)
Definition: anautil.cc:402
void bookHistograms(Histograms &histograms)
Definition: anautil.cc:666
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void fillCutflows_v2(TString syst="", bool iswgtsyst=true)
Definition: anautil.cc:538
void addCut(TString n, std::function< bool()> pass, std::function< float()> weight)
Definition: anautil.cc:73
std::map< std::string, CutTree * > cuttreemap
Definition: anautil.h:117