ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
table_preds.cxx
Go to the documentation of this file.
1 
5 #include <fstream>
6 #include <iostream>
7 #include <vector>
8 #include <ctime>
9 #include <iomanip> // setw
10 #include <chrono>
11 
12 #include <unistd.h>
13 #include <stdlib.h>
14 #include <getopt.h>
15 
16 #include "TError.h" // Controls error level reporting
17 #include "RooStats/NumberCountingUtils.h"
18 #include "TCanvas.h"
19 #include "TGraphAsymmErrors.h"
20 #include "TH1D.h"
21 #include "TLine.h"
22 #include "TLatex.h"
23 #include "TLegend.h"
24 
25 #include "core/utilities.hpp"
26 #include "core/baby.hpp"
27 #include "core/process.hpp"
28 #include "core/named_func.hpp"
29 #include "core/plot_maker.hpp"
30 #include "core/palette.hpp"
31 #include "core/table.hpp"
32 #include "core/abcd_method.hpp"
33 #include "core/styles.hpp"
34 #include "core/plot_opt.hpp"
35 
36 using namespace std;
37 
38 namespace{
39  bool only_mc = false;
40  bool only_kappa = false;
41  bool split_bkg = true;
42  bool only_dilepton = false;
43  bool do_leptons = false;
44  bool do_signal = true;
45  bool unblind = false;
46  bool debug = false;
47  bool do_ht = false;
48  TString skim = "standard";
49  TString json = "2p6";
50  TString only_method = "";
51  TString mc_lumi = "";
52  float lumi=100.;
53 }
54 
55 TString printTable(abcd_method &abcd, vector<vector<GammaParams> > &allyields,
56  vector<vector<vector<float> > > &kappas, vector<vector<vector<float> > > &preds);
57 void plotKappa(abcd_method &abcd, vector<vector<vector<float> > > &kappas);
58 void findPreds(abcd_method &abcd, vector<vector<GammaParams> > &allyields,
59  vector<vector<vector<float> > > &kappas, vector<vector<vector<float> > > &preds);
60 void printDebug(abcd_method &abcd, vector<vector<GammaParams> > &allyields, TString baseline,
61  vector<vector<vector<float> > > &kappas, vector<vector<vector<float> > > &preds);
62 TString Zbi(double Nobs, double Nbkg, double Eup_bkg, double Edown_bkg);
63 
64 void GetOptions(int argc, char *argv[]);
65 
67 const NamedFunc st("st", [](const Baby &b) -> NamedFunc::ScalarType{
68  float stvar = b.ht();
69  for (const auto &pt: *(b.leps_pt())) stvar += pt;
70  return stvar;
71  });
72 
73 int main(int argc, char *argv[]){
74  gErrorIgnoreLevel=6000; // Turns off ROOT errors due to missing branches
75  GetOptions(argc, argv);
76 
77  chrono::high_resolution_clock::time_point begTime;
78  begTime = chrono::high_resolution_clock::now();
79 
82  string bfolder("");
83  string hostname = execute("echo $HOSTNAME");
84  if(Contains(hostname, "cms") || Contains(hostname, "compute-"))
85  bfolder = "/net/cms2"; // In laptops, you can't create a /net folder
86 
87  string ntupletag="";
88  if(only_method!="" && !only_method.Contains("allmet") && !only_method.Contains("onemet")){
89  if(only_method.Contains("met150")) ntupletag = "_metG150";
90  else ntupletag = "_metG200";
91  }
92 
93  // //// Chinchilla
94  // ntupletag="standard";
95  // string foldermc(bfolder+"/cms2r0/babymaker/babies/2016_06_14/mc/merged_standard/");
96  // string folderdata(bfolder+"/cms2r0/babymaker/babies/2016_06_26/data/merged_standard/");
97 
99  string foldersig(bfolder+"/cms2r0/babymaker/babies/2016_08_10/T1tttt/merged_mcbase_standard/");
100  string foldermc(bfolder+"/cms2r0/babymaker/babies/2016_08_10/mc/merged_mcbase_stdnj5/");
101  string folderdata(bfolder+"/cms2r0/babymaker/babies/2016_08_10/data/merged_database_stdnj5/");
102  if(skim.Contains("met100")) {
103  foldermc = bfolder+"/cms2r0/babymaker/babies/2016_08_10/mc/merged_mcbase_met100_stdnj5/";
104  ntupletag="";
105  }
106 
107  // Old 2015 data
108  if(skim.Contains("2015")){
109  ntupletag="stdnj5";
110  foldermc = bfolder+"/cms2r0/babymaker/babies/2016_04_29/mc/merged_mcbase_stdnj5/";
111  folderdata = bfolder+"/cms2r0/babymaker/babies/2016_04_29/data/merged_stdnj5/";
112  if(only_method.Contains("old")) {
113  ntupletag="1lht500met200";
114  foldermc = bfolder+"/cms2r0/babymaker/babies/2015_11_28/mc/skim_1lht500met200/";
115  folderdata = bfolder+"/cms2r0/babymaker/babies/2016_02_04/data/singlelep/combined/skim_1lht500met200/";
116  }
117  }
118 
119  Palette colors("txt/colors.txt", "default");
120 
121  // Cuts in baseline speed up the yield finding
122  string baseline_s = "mj14>250 && nleps>=1 && met>150 && njets>=5";
123  if(skim.Contains("mj12")) ReplaceAll(baseline_s, "mj14","mj");
124  if(skim.Contains("met100")) ReplaceAll(baseline_s, "150","100");
125 
126  NamedFunc baseline=baseline_s;
127  if(do_ht) baseline = baseline && "ht>500";
128  else baseline = baseline && st>500;
129 
131  auto proc_bkg = Process::MakeShared<Baby_full>("All_bkg", Process::Type::background, colors("tt_1l"),
132  {foldermc+"*_TTJets_Tune*"+ntupletag+"*.root"},
133  baseline && "stitch && pass");
134 
135  auto proc_t1c = Process::MakeShared<Baby_full>("T1tttt(C)", Process::Type::signal, colors("t1tttt"),
136  {foldersig+"*mGluino-1300_mLSP-900_*.root"},
137  baseline && "stitch");
138  auto proc_t1nc = Process::MakeShared<Baby_full>("T1tttt(NC)", Process::Type::signal, colors("t1tttt"),
139  {foldersig+"*mGluino-1700_mLSP-100_*.root"},
140  baseline && "stitch");
141  auto proc_tt1l = Process::MakeShared<Baby_full>("tt 1lep", Process::Type::background, colors("tt_1l"),
142  {foldermc+"*_TTJets*SingleLept*"+ntupletag+"*.root", foldermc+"*_TTJets_HT*"+ntupletag+"*.root"},
143  baseline && "stitch && ntruleps==1 && pass");
144  auto proc_tt2l = Process::MakeShared<Baby_full>("tt 2lep", Process::Type::background, colors("tt_2l"),
145  {foldermc+"*_TTJets*DiLept*"+ntupletag+"*.root", foldermc+"*_TTJets_HT*"+ntupletag+"*.root"},
146  baseline && "stitch && ntruleps==2 && pass");
147 
148  // Filling all other processes
149  vector<string> vnames_other({"_WJetsToLNu", "_ST_", "_TTW", "_TTZ", "DYJetsToLL",
150  "_ZJet", "_ttHJetTobb", "_TTGJets", "_TTTT",
151  "_WH_HToBB", "_ZH_HToBB", "_WWTo", "_WZ", "_ZZ_"});
152  // QCD changed name in Capybara (2016_08_10)
153  if(skim.Contains("2015")) vnames_other.push_back("QCD_HT");
154  else{
155  vnames_other.push_back("QCD_HT*0_Tune");
156  vnames_other.push_back("QCD_HT*Inf_Tune");
157  }
158  set<string> names_other;
159  for(auto name : vnames_other)
160  names_other.insert(name = foldermc + "*" + name + "*" + ntupletag + "*.root");
161  auto proc_other = Process::MakeShared<Baby_full>("Other", Process::Type::background, colors("other"),
162  names_other, baseline && "stitch && pass");
163 
164  //string trigs = "(trig[4]||trig[8]||trig[13]||trig[33])";
165  string trigs = "trig_ra4";
166  if(skim.Contains("2015")) trigs = "(trig[4]||trig[8]||trig[28]||trig[14])";
167 
168  // Setting luminosity
169  string jsonCuts = "nonblind";
170  if(skim.Contains("2015")) lumi = 2.3;
171  else if(json=="0p869"){
172  lumi = 0.869;
173  jsonCuts = "nonblind";
174  } else if(json=="2p8"){
175  lumi = 2.8;
176  jsonCuts = "json2p6";
177  } else if(json=="1p5"){
178  lumi = 1.5;
179  jsonCuts = "json4p0&&!json2p6";
180  } else if(json=="4p3"){
181  lumi = 4.3;
182  jsonCuts = "json4p0";
183  } else if(json=="3p4"){
184  lumi = 3.4;
185  jsonCuts = "json7p65&&!json4p0";
186  } else if(json=="7p7"){
187  lumi = 7.7;
188  jsonCuts = "json7p65";
189  } else if(json=="12p9"){
190  lumi = 12.9;
191  jsonCuts = "json12p9";
192  }
193  if(mc_lumi!="") lumi = mc_lumi.Atof();
194 
195 
196  if(only_method.Contains("old")) trigs = "(trig[4]||trig[8])";
197  if(!skim.Contains("2015")) trigs += " && "+jsonCuts;
198 
199  auto proc_data = Process::MakeShared<Baby_full>("Data", Process::Type::data, kBlack,
200  {folderdata+"*"+ntupletag+"*.root"},baseline && trigs && "pass");
201 
202  vector<shared_ptr<Process> > all_procs = {proc_tt1l, proc_tt2l, proc_other};
203  //vector<shared_ptr<Process> > all_procs = {proc_bkg};
204  if (do_signal){
205  all_procs.push_back(proc_t1nc);
206  all_procs.push_back(proc_t1c);
207  }
208  if(!only_mc) all_procs.push_back(proc_data);
209 
212  // baseline defined above
213 
215  TString c_vvlowmet = "met>100 && met<=150";
216  TString c_vlowmet = "met>150 && met<=200";
217  TString c_lowmet = "met>200 && met<=350";
218  TString c_midmet = "met>350 && met<=500";
219  TString c_higmet = "met>500";
220 
222  TString c_vlownb = "nbm==0";
223  TString c_lownb = "nbm==1";
224  TString c_midnb = "nbm==2";
225  TString c_hignb = "nbm>=3";
226 
228  TString c_vlownj = "njets>=4 && njets<=5";
229  TString c_lownj = "njets>=6 && njets<=8";
230  TString c_hignj = "njets>=9";
231  TString c_nj5 = "njets==5";
232 
234  vector<TString> abcdcuts_std = {"mt<=140 && mj14<=400 && nj_all_1l",
235  "mt<=140 && mj14>400 && nj_1l",
236  "mt>140 && mj14<=400 && nj_all_1l",
237  "mt>140 && mj14>400 && nj_1l"};
238 
239  vector<TString> abcdcuts_veto = {"mt<=140 && mj14<=400 && nleps==1 && nveto==0 && nbm>=1 && nj_all_1l",
240  "mt<=140 && mj14>400 && nleps==1 && nveto==0 && nbm>=1 && nj_1l",
241  "mt>140 && mj14<=400 && nleps==1 && nveto==1 && nbm>=1 && nbm<=2 && nj_all_1l",
242  "mt>140 && mj14>400 && nleps==1 && nveto==1 && nbm>=1 && nbm<=2 && nj_1l"};
243 
244  vector<TString> abcdcuts_2l = {"mt<=140 && mj14<=400 && nleps==1 && nveto==0 && nbm>=1 && nj_all_1l",
245  "mt<=140 && mj14>400 && nleps==1 && nveto==0 && nbm>=1 && nj_1l",
246  " mj14<=400 && nleps==2 && nbm<=2 && nj_all_2l",
247  " mj14>400 && nleps==2 && nbm<=2 && nj_2l"};
248 
249  vector<TString> abcdcuts_2lveto;
250  for(size_t ind=0; ind<2; ind++) abcdcuts_2lveto.push_back(abcdcuts_2l[ind]);
251  for(size_t ind=2; ind<abcdcuts_2l.size(); ind++){
252  abcdcuts_2lveto.push_back("(("+abcdcuts_2l[ind]+") || ("+abcdcuts_veto[ind]+"))");
253  abcdcuts_2lveto.back().ReplaceAll("(( ","((");
254  }
255 
258  vector<abcd_method> abcds;
259  vector<TString> abcdcuts, metcuts, bincuts;
260  PlotMaker pm;
261 
263  vector<TString> methods_all = {"m2lveto", "m2lonly", "mvetoonly", "signal", "signal_nb1", "signal_nb2",
264  "m2lvetomet150", "m2lonlymet150", "mvetoonlymet150", "m1lmet150",
265  "m5j", "agg_himet", "agg_mixed", "agg_himult", "agg_1b"};
266 
267  vector<TString> methods_std = {"m1lmet150", "m5j", "signal", "m2lveto", "m2lvetoonemet"};
268 
269  vector<TString> methods = methods_std;
270 
271  if(only_method!="") methods = vector<TString>({only_method});
272  if(do_leptons){
273  for(auto name: methods){
274  name += "_el";
275  methods.push_back(name);
276  name.ReplaceAll("_el", "_mu");
277  methods.push_back(name);
278  if(name.Contains("2l")){
279  name.ReplaceAll("_mu", "_emu");
280  methods.push_back(name);
281  }
282  }
283  }
284 
285  for(size_t iabcd=0; iabcd<methods.size(); iabcd++) {
286  TString method = methods[iabcd];
287  TString basecuts = "", caption = "";
288 
290  if(method.Contains("2l") || method.Contains("veto")) {
291  metcuts = vector<TString>{c_vlowmet, c_lowmet, c_midmet};
292  if(only_mc) metcuts.push_back(c_higmet);
293  if(method.Contains("onemet")) metcuts = vector<TString>{"met>150 && met<=500"};
294  bincuts = vector<TString>{c_lownj, c_hignj}; // 2l nj cuts automatically lowered in abcd_method
295  caption = "Dilepton validation regions. D3 and D4 have ";
296  } else {
297  if(only_dilepton) continue;
298  abcdcuts = abcdcuts_std;
299  basecuts = "nleps==1 && nveto==0 && nbm>=1";
300  }
301 
303  if(method.Contains("2lonly")) {
304  abcdcuts = abcdcuts_2l;
305  caption += "two reconstructed leptons";
306  }
307  if(method.Contains("2lveto")) {
308  abcdcuts = abcdcuts_2lveto;
309  caption += "either two reconstructed leptons, or one lepton and one track";
310  }
311  if(method.Contains("vetoonly")) {
312  abcdcuts = abcdcuts_veto;
313  caption += "one lepton and one track";
314  }
315  if(method.Contains("2lcombined")) {
316  metcuts = vector<TString>{"met>200&&met<=500"};
317  bincuts = vector<TString>{"njets>=6"}; // 2l nj cuts automatically lowered in abcd_method
318  abcdcuts = abcdcuts_2l;
319  caption += "two reconstructed leptons";
320  }
321  if(method.Contains("2lold")) {
322  metcuts = vector<TString>{"met>200&&met<=400"};
323  abcdcuts = abcdcuts_2l;
324  abcdcuts[0].ReplaceAll("&& nveto==0 ","");
325  abcdcuts[1].ReplaceAll("&& nveto==0 ","");
326  caption += "two reconstructed leptons";
327  }
328 
329  if(method.Contains("2lvetocombined")) {
330  metcuts = vector<TString>{"met>150&&met<=500"};
331  bincuts = vector<TString>{"njets>=6"}; // 2l nj cuts automatically lowered in abcd_method
332  abcdcuts = abcdcuts_2lveto;
333  caption += "either two reconstructed leptons, or one lepton and one track";
334  }
335 
337  if(method.Contains("signal")) {
338  metcuts = vector<TString>{c_lowmet, c_midmet, c_higmet};
339  bincuts = vector<TString>{c_lownb+" && "+c_lownj, c_lownb+" && "+c_hignj,
340  c_midnb+" && "+c_lownj, c_midnb+" && "+c_hignj,
341  c_hignb+" && "+c_lownj, c_hignb+" && "+c_hignj};
342  caption = "Signal search regions";
343  if(method.Contains("nb1")) {
344  bincuts = vector<TString>{c_lownb+" && "+c_lownj, c_lownb+" && "+c_hignj};
345  caption += " for $\\nb=1$";
346  }
347  if(method.Contains("nb2")) {
348  bincuts = vector<TString>{c_midnb+" && "+c_lownj, c_midnb+" && "+c_hignj,
349  c_hignb+" && "+c_lownj, c_hignb+" && "+c_hignj};
350  caption += " for $\\nb\\geq2$";
351  }
352  if(method.Contains("allmet")) {
353  metcuts = vector<TString>{c_vlowmet, c_lowmet, c_midmet, c_higmet};
354  caption = "Signal search regions plus $150<\\met\\leq200$ GeV";
355  } // allmetsignal
356  if(method.Contains("met100")) {
357  metcuts = vector<TString>{c_vvlowmet, c_vlowmet, c_lowmet, c_midmet, c_higmet};
358  bincuts = vector<TString>{c_lownb+" && "+c_lownj, c_lownb+" && "+c_hignj,
359  c_midnb+" && "+c_lownj, c_midnb+" && "+c_hignj,
360  c_hignb+" && "+c_lownj, c_hignb+" && "+c_hignj};
361  caption = "Signal search regions plus $100<\\met\\leq200$ GeV";
362  } // allmetsignal
363  if(method.Contains("nb0")) {
364  metcuts = vector<TString>{c_vvlowmet, c_vlowmet, c_lowmet, c_midmet, c_higmet};
365  bincuts = vector<TString>{"nbm==0&&njets>=6"};
366  basecuts = "nleps==1 && nveto==0";
367  caption = "Signal search regions plus $100<\\met\\leq200$ GeV for $\\Nb==0$";
368  } // allmetsignal
369  if(method.Contains("onemet")) {
370  metcuts = vector<TString>{"met>200"};
371  caption = "Signal search regions plus $150<\\met\\leq200$ GeV";
372  } // allmetsignal
373  if(method.Contains("onebin")) bincuts = vector<TString>{"njets>=6&&nbm>=1"};
374  } // signal
375 
376 
377  if(method.Contains("m5j")) {
378  metcuts = vector<TString>{c_lowmet, c_midmet, c_higmet};
379  //if(only_mc) metcuts.push_back(c_higmet);
380  bincuts = vector<TString>{c_lownb+" && "+c_nj5, c_midnb+" && "+c_nj5, c_hignb+" && "+c_nj5};
381  caption = "Validation regions with $1\\ell, \\njets=5$";
382  if(method.Contains("met100")) {
383  metcuts = vector<TString>{c_vvlowmet, c_vlowmet, c_lowmet, c_midmet, c_higmet};
384  caption = "Validation regions with $1\\ell, \\njets=5$, $100<\\met\\leq200$ GeV";
385  } // allmetsignal
386  if(method.Contains("onebin")) bincuts = vector<TString>{"njets==5&&nbm>=1"};
387  }
388 
390  if(method.Contains("agg_himet")) {
391  metcuts = vector<TString>{"met>500"};
392  bincuts = vector<TString>{"nbm>=3&&njets>=6"};
393  caption = "High-\\met aggregate region with $1\\ell$, $\\met>500\\text{ GeV}$, $\\njets\\geq6$, $\\nb\\geq3$";
394  }
395  if(method.Contains("agg_mixed")) {
396  metcuts = vector<TString>{"met>350"};
397  bincuts = vector<TString>{"nbm>=2&&njets>=9"};
398  caption = "Mixed aggregate region with $1\\ell$, $\\met>350\\text{ GeV}$, $\\njets\\geq9$, $\\nb\\geq2$";
399  }
400  if(method.Contains("agg_himult")) {
401  metcuts = vector<TString>{"met>200"};
402  bincuts = vector<TString>{"nbm>=3&&njets>=9"};
403  caption = "High-multiplicity aggregate region with $1\\ell$, $\\met>200\\text{ GeV}$, $\\njets\\geq9$, $\\nb\\geq3$";
404  }
405  if(method.Contains("agg_1b")) {
406  metcuts = vector<TString>{"met>500"};
407  bincuts = vector<TString>{"nbm>=1&&njets>=6"};
408  caption = "Single b-tag aggregate region with $1\\ell$, $\\met>500\\text{ GeV}$, $\\njets\\geq6$, $\\nb\\geq1$";
409  }
410 
412  if(method.Contains("met150")) {
413  metcuts = vector<TString>{c_vlowmet};
414  caption.ReplaceAll("regions", "region for very low \\met");
415  }
416  if(method.Contains("m1lmet150")) {
417  bincuts = vector<TString>{c_lownb+" && "+c_lownj, c_lownb+" && "+c_hignj,
418  c_midnb+" && "+c_lownj, c_midnb+" && "+c_hignj};
419  caption = "Single lepton validation region for very low \\met";
420  }
421  if(skim.Contains("2015")) {
422  caption += ". Data taken in 2015";
423  }
424 
426  abcds.push_back(abcd_method(method, metcuts, bincuts, abcdcuts, caption, basecuts));
427  if(skim.Contains("mj12")) {
428  abcds.back().setMj12();
429  abcds.back().caption += ". Using $M_J^{1.2}$";
430  }
431  if(method.Contains("noint")) abcds.back().setIntNbNj(false);
432  if(method.Contains("_el") || method.Contains("_mu") || method.Contains("_emu")) abcds.back().setLeptons();
433  if(method.Contains("_el")) abcds.back().caption += ". Only electrons";
434  if(method.Contains("_mu")) abcds.back().caption += ". Only muons";
435  if(method.Contains("_emu")) abcds.back().caption += ". Only $e/\\mu$ pairs in D3 and D4";
436  //if(method.Contains("agg_")) abcds.back().int_nbnj = false; // Only changes caption since there is only 1 bin
437 
438  vector<TableRow> table_cuts;
439  for(size_t icut=0; icut < abcds.back().allcuts.size(); icut++)
440  table_cuts.push_back(TableRow(abcds.back().allcuts[icut].Data(), abcds.back().allcuts[icut].Data()));
441 
442  TString tname = "preds"; tname += iabcd;
443  pm.Push<Table>(tname.Data(), table_cuts, all_procs, true, false);
444  } // Loop over ABCD methods
445 
448 
449  bool single_thread = false;
450  if(single_thread) pm.multithreaded_ = false;
451  pm.min_print_ = true;
452  pm.MakePlots(lumi);
453 
456  vector<TString> tablenames;
457  for(size_t imethod=0; imethod<abcds.size(); imethod++) {
458  Table * yield_table = static_cast<Table*>(pm.Figures()[imethod].get());
459  // allyields: [0] data, [1] bkg, [2] T1tttt(NC), [3] T1tttt(C)
460  // if split_bkg [2/4] Other, [3/5] tt1l, [4/6] tt2l
461  vector<vector<GammaParams> > allyields;
462  if(!only_mc) allyields.push_back(yield_table->DataYield());
463  else allyields.push_back(yield_table->BackgroundYield(lumi));
464  allyields.push_back(yield_table->BackgroundYield(lumi));
465  if(do_signal){
466  allyields.push_back(yield_table->Yield(proc_t1nc.get(), lumi));
467  allyields.push_back(yield_table->Yield(proc_t1c.get(), lumi));
468  }
469  if(split_bkg){
470  allyields.push_back(yield_table->Yield(proc_other.get(), lumi));
471  allyields.push_back(yield_table->Yield(proc_tt1l.get(), lumi));
472  allyields.push_back(yield_table->Yield(proc_tt2l.get(), lumi));
473  }
474 
476  vector<vector<vector<float> > > kappas, preds;
477  findPreds(abcds[imethod], allyields, kappas, preds);
478 
480  if(!only_kappa) {
481  TString fullname = printTable(abcds[imethod], allyields, kappas, preds);
482  tablenames.push_back(fullname);
483  }
484 
486  plotKappa(abcds[imethod], kappas);
487 
489  if(debug) printDebug(abcds[imethod], allyields, TString(baseline.Name()), kappas, preds);
490 
491  } // Loop over ABCD methods
492 
493  if(!only_kappa){
495  cout<<endl<<"===== Tables to be moved to the AN/PAS/paper:"<<endl;
496  for(size_t ind=0; ind<tablenames.size(); ind++){
497  TString name=tablenames[ind]; name.ReplaceAll("fulltable","table");
498  cout<<" mv "<<name<<" ${tables_folder}"<<endl;
499  }
500  cout<<endl<<"===== Tables that can be compiled"<<endl;
501  for(size_t ind=0; ind<tablenames.size(); ind++)
502  cout<<" pdflatex "<<tablenames[ind]<<" > /dev/null"<<endl;
503  cout<<endl;
504  }
505 
506  double seconds = (chrono::duration<double>(chrono::high_resolution_clock::now() - begTime)).count();
507  TString hhmmss = HoursMinSec(seconds);
508  cout<<endl<<"Finding "<<abcds.size()<<" tables took "<<round(seconds)<<" seconds ("<<hhmmss<<")"<<endl<<endl;
509 } // main
510 
515 
517 // allyields: [0] data, [1] bkg, [2] T1tttt(NC), [3] T1tttt(C)
518 // if split_bkg: [2/4] Other, [3/5] tt1l, [4/6] tt2l
519 TString printTable(abcd_method &abcd, vector<vector<GammaParams> > &allyields,
520  vector<vector<vector<float> > > &kappas, vector<vector<vector<float> > > &preds){
521  cout<<endl<<"Printing table (significance estimation can take a bit)"<<endl;
523  int digits = 2;
524  TString ump = " & ";
525  bool do_zbi = true;
526  if(!unblind) do_zbi = false;
527  size_t Ncol = 6;
528  if(do_zbi) Ncol++;
529  if(do_signal) Ncol += 2;
530  if(split_bkg) Ncol += 3;
531  if(only_mc) {
532  if(do_signal) Ncol -= 1;
533  else Ncol -= 3;
534  }
535  TString blind_s = "$\\spadesuit$";
536 
538  int digits_lumi = 1;
539  if(lumi < 1) digits_lumi = 3;
540  if(lumi >= 15) digits_lumi = 0;
541  TString lumi_s = RoundNumber(lumi, digits_lumi);
542  TString outname = "tables/table_pred_lumi"+lumi_s; outname.ReplaceAll(".","p");
543  if(skim.Contains("2015")) outname += "_2015";
544  if(skim.Contains("mj12")) outname += "_mj12";
545  if(unblind) outname += "_unblind";
546  else outname += "_blind";
547  if(do_ht) outname += "_ht500";
548  outname += "_"+abcd.method+".tex";
549  ofstream out(outname);
550 
552  if(abcd.method.Contains("signal") && Ncol>7) out << "\\resizebox{\\textwidth}{!}{\n";
553  out << "\\begin{tabular}[tbp!]{ l ";
554  if(do_signal) out << "|cc";
555  if(split_bkg) out << "|ccc";
556  out << "|cc|ccc";
557  if(do_zbi) out<<"c";
558  out<<"}\\hline\\hline\n";
559  out<<"${\\cal L}="<<lumi_s<<"$ fb$^{-1}$ ";
560  if(do_signal) out << " & T1tttt(NC) & T1tttt(C) ";
561  if(split_bkg) out << " & Other & $t\\bar{t}(1\\ell)$ & $t\\bar{t}(2\\ell)$ ";
562  out << "& $\\kappa$ & MC bkg. & Pred.";
563  if(!only_mc) out << "& Obs. & Obs./MC "<<(do_zbi?"& Signi.":"");
564  else if(do_signal) out << "& Signi.(NC) & Signi.(C)";
565  out << " \\\\ \\hline\\hline\n";
566 
569  for(size_t iplane=0; iplane < abcd.planecuts.size(); iplane++) {
570  out<<endl<< "\\multicolumn{"<<Ncol<<"}{c}{$"<<CodeToLatex(abcd.planecuts[iplane].Data())<<"$} \\\\ \\hline\n";
571  for(size_t iabcd=0; iabcd < abcd.abcdcuts.size(); iabcd++){
572  for(size_t ibin=0; ibin < abcd.bincuts[iplane].size(); ibin++){
573  size_t index = abcd.indexBin(iplane, ibin, iabcd);
574  if(abcd.int_nbnj && iabcd%2==0 && ibin>0) continue;
575  if(iabcd==3 && ibin==0) out << "\\hline" << endl;
577  out << (iabcd<=1?"R":abcd.rd_letter) << iabcd+1 << ": ";
578  if(iabcd%2==0 && abcd.int_nbnj)
579  out << "All "<<(abcd.bincuts[iplane][ibin].Contains("nbm")?"\\nb, ":"")<<"\\njets" ;
580  else {
581  if(abcd.method.Contains("2lonly") && iabcd>=2) out<<"$"<<CodeToLatex(abcd.lowerNjets(abcd.bincuts[iplane][ibin]).Data())<<"$";
582  else if(abcd.method.Contains("2lveto") && iabcd>=2){
583  if(abcd.bincuts[iplane][ibin].Contains("6")) out<<"Low \\njets";
584  else out<<"High \\njets";
585  } else out<<"$"<<CodeToLatex(abcd.bincuts[iplane][ibin].Data())<<"$";
586  }
588  if(do_signal)
589  out<<ump<<RoundNumber(allyields[2][index].Yield(), digits)<< ump <<RoundNumber(allyields[3][index].Yield(), digits);
591  if(split_bkg){
592  size_t offset = (do_signal?2:0);
593  out << ump <<RoundNumber(allyields[offset+2][index].Yield(), digits)
594  << ump <<RoundNumber(allyields[offset+3][index].Yield(), digits)
595  << ump <<RoundNumber(allyields[offset+4][index].Yield(), digits);
596  }
598  out<<ump;
599  if(iabcd==3) out << "$" << RoundNumber(kappas[iplane][ibin][0], digits)
600  << "^{+" << RoundNumber(kappas[iplane][ibin][1], digits)
601  << "}_{-" << RoundNumber(kappas[iplane][ibin][2], digits) <<"}$ ";
603  out << ump << RoundNumber(allyields[1][index].Yield(), digits)<< ump;
605  if(iabcd==3) out << "$" << RoundNumber(preds[iplane][ibin][0], digits)
606  << "^{+" << RoundNumber(preds[iplane][ibin][1], digits)
607  << "}_{-" << RoundNumber(preds[iplane][ibin][2], digits) <<"}$ ";
608  if(!only_mc){
610  if(!unblind && iabcd==3) out << ump << blind_s<< ump << blind_s;
611  else {
612  out << ump << RoundNumber(allyields[0][index].Yield(), 0);
613  TString ratio_s = "-";
614  double Nobs = allyields[0][index].Yield(), Nmc = allyields[1][index].Yield();
615  double Eobs = sqrt(Nobs), Emc = allyields[1][index].Uncertainty();
616  if(Nobs==0) Eobs=1;
617  if(Emc>0){
618  double ratio = Nobs/Nmc;
619  double Eratio = sqrt(pow(Eobs/Nmc,2) + pow(Nobs*Emc/Nmc/Nmc,2));
620  ratio_s = "$"+RoundNumber(ratio, 2)+"\\pm"+RoundNumber(Eratio,2)+"$";
621  }
622  out << ump << ratio_s;
623  }
625  if(do_zbi && iabcd==3) out << ump << Zbi(allyields[0][index].Yield(), preds[iplane][ibin][0],
626  preds[iplane][ibin][1], preds[iplane][ibin][2]);
627  } else {// if not only_mc
628  if(iabcd==3 && do_signal) {
629  out<<ump<<Zbi(allyields[0][index].Yield()+allyields[2][index].Yield(),preds[iplane][ibin][0],
630  preds[iplane][ibin][1], preds[iplane][ibin][2]);
631  out<<ump<<Zbi(allyields[0][index].Yield()+allyields[3][index].Yield(),preds[iplane][ibin][0],
632  preds[iplane][ibin][1], preds[iplane][ibin][2]);
633  }
634  }
635  out << "\\\\ \n";
636  } // Loop over bin cuts
637  } // Loop over ABCD cuts
638  out << "\\hline\\hline\n";
639  } // Loop over plane cuts
641 
643  out<< "\\end{tabular}"<<endl;
644  if(abcd.method.Contains("signal") && Ncol>7) out << "}\n"; // For resizebox
645  out.close();
646 
648  TString fullname = outname; fullname.ReplaceAll("table_","fulltable_");
649  ofstream full(fullname);
650  ifstream header("txt/header.tex");
651  full<<header.rdbuf();
652  header.close();
653  if(!abcd.method.Contains("signal")) full << "\\usepackage[landscape]{geometry}\n\n";
654  full << "\\begin{document}\n\n";
655  full << "\\begin{table}\n\\centering\n";
656  full << "\\caption{" << abcd.caption <<".}\\vspace{0.1in}\n\\label{tab:"<<abcd.method<<"}\n";
657  ifstream outtab(outname);
658  full << outtab.rdbuf();
659  outtab.close();
660  full << "\\end{table}\n\n";
661  full << "\\end{document}\n";
662  full.close();
663 
664  return fullname;
665 } // printTable
667 TString Zbi(double Nobs, double Nbkg, double Eup_bkg, double Edown_bkg){
668  TString zbi_s;
669  if(false){ // Old, bad Zbi
670  double Nsig = Nobs-Nbkg;
671  double zbi = RooStats::NumberCountingUtils::BinomialExpZ(Nsig, Nbkg, Eup_bkg/Nbkg);
672  if(Nbkg==0) zbi = RooStats::NumberCountingUtils::BinomialWithTauExpZ(Nsig, Nbkg, 1/Eup_bkg);
673  if(zbi<0) zbi=0;
674  zbi_s = RoundNumber(zbi,1);
675  if(zbi_s!="-") zbi_s = "$"+zbi_s+"\\sigma$";
676  if(Nsig<=0 || Eup_bkg<=0) zbi_s = "-";
677  } else zbi_s = "$"+RoundNumber(Significance(Nobs, Nbkg, Eup_bkg, Edown_bkg),1)+"\\sigma$";
678  //cout<<"Zbi for Nobs "<<Nobs<<", Nbkg "<<Nbkg<<", Ebkg "<<Eup_bkg<<" is "<<zbi_s<<endl;
679  return zbi_s;
680 }
681 
683 void plotKappa(abcd_method &abcd, vector<vector<vector<float> > > &kappas){
684 
685  bool label_up = false;
686  double markerSize = 1.1;
687 
689  PlotOpt opts("txt/plot_styles.txt", "Kappa");
690  if(label_up) opts.BottomMargin(0.11);
691  if(kappas.size() >= 4) {
692  opts.CanvasWidth(1300);
693  markerSize = 1.5;
694  }
695  setPlotStyle(opts);
696 
697  struct kmarker{
698  TString cut;
699  int color;
700  int style;
701  vector<float> kappa;
702  };
704  vector<vector<vector<kmarker> > > k_ordered;
705  vector<kmarker> ind_bcuts; // nb cuts actually used in the plot
706  vector<float> zz; // Zero length vector for the kmarker constructor
707  vector<kmarker> bcuts({{"nbm==1",4,20,zz}, {"nbm==2",2,21,zz}, {"nbm>=3",kGreen+3,22,zz},
708  {"nbm==0",kMagenta+2,23,zz},
709  {"nbl==0",kMagenta+2,23,zz}});
710 
711  int nbins = 0; // Total number of njets bins (used in the base histo)
712  for(size_t iplane=0; iplane < kappas.size(); iplane++) {
713  k_ordered.push_back(vector<vector<kmarker> >());
714  for(size_t ibin=0; ibin < kappas[iplane].size(); ibin++){
715  TString bincut = abcd.bincuts[iplane][ibin];
716  bincut.ReplaceAll(" ","");
717  bincut.ReplaceAll("mm_","");
718  int index;
719  do{
720  index = bincut.First('[');
721  bincut.Remove(index, bincut.First(']')-index+1);
722  }while(index>=0);
723  bool found=false;
724  for(size_t ib=0; ib<bcuts.size(); ib++){
725  if(bincut.Contains(bcuts[ib].cut)){
727  bool cutfound=false;
728  for(size_t indb=0; indb<ind_bcuts.size(); indb++)
729  if(ind_bcuts[indb].color == bcuts[ib].color) cutfound = true;
730  if(!cutfound) ind_bcuts.push_back(bcuts[ib]);
731 
733  bincut.ReplaceAll(bcuts[ib].cut+"&&","");
734  for(size_t ik=0; ik<k_ordered[iplane].size(); ik++){
736  if(bincut==k_ordered[iplane][ik][0].cut){
737  k_ordered[iplane][ik].push_back({bincut, bcuts[ib].color, bcuts[ib].style, kappas[iplane][ibin]});
738  found = true;
739  break;
740  } // if same njets cut
741  } // Loop over existing ordered kappas
743  if(!found) {
744  k_ordered[iplane].push_back(vector<kmarker>({{bincut, bcuts[ib].color, bcuts[ib].style, kappas[iplane][ibin]}}));
745  found = true;
746  nbins++;
747  }
748  } // if bincut.Contains(bcuts[ib].cut)
749  } // Loop over nb cuts
750 
752  if(!found) {
753  k_ordered[iplane].push_back(vector<kmarker>({{bincut, bcuts[0].color, bcuts[0].style, kappas[iplane][ibin]}}));
754  nbins++;
755  if(ind_bcuts.size()==0) ind_bcuts.push_back(bcuts[0]);
756  }
757  } // Loop over bin cuts
758  } // Loop over plane cuts
759 
761  TCanvas can("can","");
762  can.SetFillStyle(4000);
763  TLine line; line.SetLineWidth(2); line.SetLineStyle(2);
764  TLatex label; label.SetTextSize(0.05); label.SetTextFont(42); label.SetTextAlign(23);
765  if(k_ordered.size()>3) label.SetTextSize(0.04);
766 
767 
768  float minx = 0.5, maxx = nbins+0.5, miny = 0, maxy = 2.4;
769  if(label_up) maxy = 2.6;
770  TH1D histo("histo", "", nbins, minx, maxx);
771  histo.SetMinimum(miny);
772  histo.SetMaximum(maxy);
773  histo.GetYaxis()->CenterTitle(true);
774  histo.GetXaxis()->SetLabelOffset(0.008);
775  histo.SetYTitle("#kappa");
776  histo.Draw();
777 
779  int bin = 0;
780  vector<vector<double> > vx(ind_bcuts.size()), vexh(ind_bcuts.size()), vexl(ind_bcuts.size());
781  vector<vector<double> > vy(ind_bcuts.size()), veyh(ind_bcuts.size()), veyl(ind_bcuts.size());
782  for(size_t iplane=0; iplane < k_ordered.size(); iplane++) {
783  for(size_t ibin=0; ibin < k_ordered[iplane].size(); ibin++){
784  bin++;
785  histo.GetXaxis()->SetBinLabel(bin, CodeToRootTex(k_ordered[iplane][ibin][0].cut.Data()).c_str());
786  // xval is the x position of the first marker in the group
787  double xval = bin, nbs = k_ordered[iplane][ibin].size(), minxb = 0.15, binw = 0;
788  // If there is more than one point in the group, it starts minxb to the left of the center of the bin
789  // binw is the distance between points in the njets group
790  if(nbs>1) {
791  xval -= minxb;
792  binw = 2*minxb/(nbs-1);
793  }
794  for(size_t ib=0; ib<k_ordered[iplane][ibin].size(); ib++){
796  for(size_t indb=0; indb<ind_bcuts.size(); indb++){
797  if(ind_bcuts[indb].color == k_ordered[iplane][ibin][ib].color){
798  vx[indb].push_back(xval);
799  xval += binw;
800  vexl[indb].push_back(0);
801  vexh[indb].push_back(0);
802  vy[indb].push_back(k_ordered[iplane][ibin][ib].kappa[0]);
803  veyh[indb].push_back(k_ordered[iplane][ibin][ib].kappa[1]);
804  veyl[indb].push_back(k_ordered[iplane][ibin][ib].kappa[2]);
805  }
806  } // Loop over nb cuts in ordered TGraphs
807  } // Loop over nb cuts in kappa plot
808  } // Loop over bin cuts
809 
810  // Drawing line separating MET planes
811  line.SetLineStyle(2); line.SetLineWidth(2);
812  if (iplane<k_ordered.size()-1) line.DrawLine(bin+0.5, miny, bin+0.5, maxy);
813  // Drawing MET labels
814  if(label_up) label.DrawLatex((2*bin-k_ordered[iplane].size()+1.)/2., maxy-0.1, CodeToRootTex(abcd.planecuts[iplane].Data()).c_str());
815  else label.DrawLatex((2*bin-k_ordered[iplane].size()+1.)/2., -0.26, CodeToRootTex(abcd.planecuts[iplane].Data()).c_str());
816  } // Loop over plane cuts
817 
819  double legX(opts.LeftMargin()+0.026), legY(1-opts.TopMargin()-0.04), legSingle = 0.05;
820  if(label_up) legY = 0.8;
821  double legW = 0.22, legH = legSingle*(ind_bcuts.size()+1)/2;
822  if(ind_bcuts.size()>3) legH = legSingle*((ind_bcuts.size()+1)/2);
823  TLegend leg(legX, legY-legH, legX+legW, legY);
824  leg.SetTextSize(opts.LegendEntryHeight()); leg.SetFillColor(0);
825  leg.SetFillStyle(0); leg.SetBorderSize(0);
826  leg.SetTextFont(42);
827  leg.SetNColumns(2);
828  TGraphAsymmErrors graph[20]; // There's problems with vectors of TGraphs, so using an array
829  for(size_t indb=0; indb<ind_bcuts.size(); indb++){
830  graph[indb] = TGraphAsymmErrors(vx[indb].size(), &(vx[indb][0]), &(vy[indb][0]),
831  &(vexl[indb][0]), &(vexh[indb][0]), &(veyl[indb][0]), &(veyh[indb][0]));
832  graph[indb].SetMarkerStyle(ind_bcuts[indb].style); graph[indb].SetMarkerSize(markerSize);
833  graph[indb].SetMarkerColor(ind_bcuts[indb].color);
834  graph[indb].SetLineColor(ind_bcuts[indb].color); graph[indb].SetLineWidth(2);
835  graph[indb].Draw("p0 same");
836  leg.AddEntry(&graph[indb], CodeToRootTex(ind_bcuts[indb].cut.Data()).c_str(), "p");
837  } // Loop over TGraphs
838  if(ind_bcuts.size()>1) leg.Draw();
839 
841  TLatex cmslabel;
842  cmslabel.SetTextSize(0.06);
843  cmslabel.SetNDC(kTRUE);
844  cmslabel.SetTextAlign(11);
845  cmslabel.DrawLatex(opts.LeftMargin()+0.005, 1-opts.TopMargin()+0.015,"#font[62]{CMS} #scale[0.8]{#font[52]{Simulation}}");
846  cmslabel.SetTextAlign(31);
847  cmslabel.DrawLatex(1-opts.RightMargin()-0.005, 1-opts.TopMargin()+0.015,"#font[42]{13 TeV}");
848 
849  line.SetLineStyle(3); line.SetLineWidth(1);
850  line.DrawLine(minx, 1, maxx, 1);
851 
852  TString fname="plots/kappa_" + abcd.method;
853  if(do_ht) fname += "_ht500";
854  fname += ".pdf";
855  can.SaveAs(fname);
856  cout<<endl<<" open "<<fname<<endl;
857 
858 }
859 
861 // allyields: [0] data, [1] bkg, [2] T1tttt(NC), [3] T1tttt(C)
862 void findPreds(abcd_method &abcd, vector<vector<GammaParams> > &allyields,
863  vector<vector<vector<float> > > &kappas, vector<vector<vector<float> > > &preds){
864  // Powers for kappa: ({R1, R2, D3, R4})
865  vector<float> pow_kappa({ 1, -1, -1, 1});
866  // Powers for TotBkg pred:({R1, R2, D3, R1, R2, D3, D4})
867  vector<float> pow_totpred( {-1, 1, 1, 1, -1, -1, 1});
868 
869  float val(1.), valup(1.), valdown(1.);
870 
871  for(size_t iplane=0; iplane < abcd.planecuts.size(); iplane++) {
872  kappas.push_back(vector<vector<float> >());
873  preds.push_back(vector<vector<float> >());
874  for(size_t ibin=0; ibin < abcd.bincuts[iplane].size(); ibin++){
875  vector<vector<float> > entries;
876  vector<vector<float> > weights;
878  for(size_t iabcd=0; iabcd < 3; iabcd++){
879  size_t index = abcd.indexBin(iplane, ibin, iabcd);
880  entries.push_back(vector<float>());
881  weights.push_back(vector<float>());
882  entries.back().push_back(allyields[0][index].Yield());
883  weights.back().push_back(1.);
884  } // Loop over ABCD cuts
885 
886  vector<vector<float> > kentries;
887  vector<vector<float> > kweights;
889  for(size_t iabcd=0; iabcd < 4; iabcd++){
890  size_t index = abcd.indexBin(iplane, ibin, iabcd);
891  // Yields for predictions
892  entries.push_back(vector<float>());
893  weights.push_back(vector<float>());
894  entries.back().push_back(allyields[1][index].NEffective());
895  weights.back().push_back(allyields[1][index].Weight());
896  // Yields for kappas
897  kentries.push_back(vector<float>());
898  kweights.push_back(vector<float>());
899  kentries.back().push_back(allyields[1][index].NEffective());
900  kweights.back().push_back(allyields[1][index].Weight());
901  } // Loop over ABCD cuts
902 
903  // Throwing toys to find predictions and uncertainties
904  val = calcKappa(entries, weights, pow_totpred, valdown, valup);
905  if(valdown<0) valdown = 0;
906  preds[iplane].push_back(vector<float>({val, valup, valdown}));
907  // Throwing toys to find kappas and uncertainties
908  val = calcKappa(kentries, kweights, pow_kappa, valdown, valup);
909  if(valdown<0) valdown = 0;
910  kappas[iplane].push_back(vector<float>({val, valup, valdown}));
911  } // Loop over bin cuts
912  } // Loop over plane cuts
913 
914 } // findPreds
915 
916 // allyields: [0] data, [1] bkg, [2] T1tttt(NC), [3] T1tttt(C)
917 void printDebug(abcd_method &abcd, vector<vector<GammaParams> > &allyields, TString baseline,
918  vector<vector<vector<float> > > &kappas, vector<vector<vector<float> > > &preds){
919 
920  int digits = 3;
921  cout<<endl<<endl<<"=================== Printing cuts for method "<<abcd.method<<" ==================="<<endl;
922  cout<<"-- Baseline cuts: "<<baseline<<endl;
923  for(size_t iplane=0; iplane < abcd.planecuts.size(); iplane++) {
924  cout<<endl<<" **** Plane "<<abcd.planecuts[iplane]<<" ***"<<endl;
925  for(size_t ibin=0; ibin < abcd.bincuts[iplane].size(); ibin++){
926  for(size_t iabcd=0; iabcd < abcd.abcdcuts.size(); iabcd++){
927  size_t index = abcd.indexBin(iplane, ibin, iabcd);
928  cout<<"MC: "<<setw(8)<<RoundNumber(allyields[1][index].Yield(),digits)
929  <<" Data: "<<setw(4)<<RoundNumber(allyields[0][index].Yield(), 0)
930  <<" - "<< abcd.allcuts[index]<<endl;
931  } // Loop over ABCD cuts
932  cout<<"Kappa = "<<RoundNumber(kappas[iplane][ibin][0],digits)<<"+"<<RoundNumber(kappas[iplane][ibin][1],digits)
933  <<"-"<<RoundNumber(kappas[iplane][ibin][2],digits)<<", Prediction = "
934  <<RoundNumber(preds[iplane][ibin][0],digits)<<"+"<<RoundNumber(preds[iplane][ibin][1],digits)
935  <<"-"<<RoundNumber(preds[iplane][ibin][2],digits)<<endl;
936  cout<<endl;
937  } // Loop over bin cuts
938  } // Loop over plane cuts
939 
940 } // printDebug
941 
942 void GetOptions(int argc, char *argv[]){
943  while(true){
944  static struct option long_options[] = {
945  {"method", required_argument, 0, 'm'}, // Method to run on (if you just want one)
946  {"lumi", required_argument, 0, 'l'}, // Luminosity to normalize MC with (no data)
947  {"skim", required_argument, 0, 's'}, // Which skim to use: standard, 2015 data
948  {"json", required_argument, 0, 'j'}, // Which JSON to use: 0p815, 2p6, 4p0, 7p65, 12p9
949  {"split_bkg", no_argument, 0, 'b'}, // Prints Other, tt1l, tt2l contributions
950  {"no_signal", no_argument, 0, 'n'}, // Does not print signal columns
951  {"do_leptons", no_argument, 0, 'p'}, // Does tables for e/mu/emu as well
952  {"unblind", no_argument, 0, 'u'}, // Unblinds R4/D4
953  {"only_mc", no_argument, 0, 'o'}, // Uses MC as data for the predictions
954  {"only_kappa", no_argument, 0, 'k'}, // Only plots kappa (no table)
955  {"debug", no_argument, 0, 'd'}, // Debug: prints yields and cuts used
956  {"only_dilepton", no_argument, 0, '2'}, // Makes tables only for dilepton tests
957  {"ht", no_argument, 0, 0}, // Cuts on ht>500 instead of st>500
958  {0, 0, 0, 0}
959  };
960 
961  char opt = -1;
962  int option_index;
963  opt = getopt_long(argc, argv, "m:s:j:udbnl:p2ok", long_options, &option_index);
964  if(opt == -1) break;
965 
966  string optname;
967  switch(opt){
968  case 'm':
969  only_method = optarg;
970  break;
971  case 'l':
972  mc_lumi = optarg;
973  only_mc = true;
974  break;
975  case 'k':
976  only_kappa = true;
977  only_mc = true;
978  break;
979  case 's':
980  skim = optarg;
981  break;
982  case 'j':
983  json = optarg;
984  break;
985  case 'b':
986  split_bkg = false;
987  break;
988  case 'o':
989  only_mc = true;
990  break;
991  case '2':
992  only_dilepton = true;
993  break;
994  case 'p':
995  do_leptons = true;
996  break;
997  case 'n':
998  do_signal = false;
999  break;
1000  case 'u':
1001  unblind = true;
1002  break;
1003  case 'd':
1004  debug = true;
1005  break;
1006  case 0:
1007  optname = long_options[option_index].name;
1008  if(optname == "ht"){
1009  do_ht = true;
1010  }else{
1011  printf("Bad option! Found option name %s\n", optname.c_str());
1012  exit(1);
1013  }
1014  break;
1015  default:
1016  printf("Bad option! getopt_long returned character code 0%o\n", opt);
1017  break;
1018  }
1019  }
1020 }
PlotOpt & TopMargin(double top)
Definition: plot_opt.cpp:260
void setPlotStyle(PlotOpt opts)
Definition: styles.cpp:7
PlotOpt & LeftMargin(double left)
Definition: plot_opt.cpp:233
int main(int argc, char *argv[])
Definition: table_preds.cxx:74
void findPreds(abcd_method &abcd, vector< vector< GammaParams > > &allyields, vector< vector< vector< float > > > &kappas, vector< vector< vector< float > > > &preds)
std::vector< GammaParams > Yield(const Process *process, double luminosity) const
Definition: table.cpp:158
TString HoursMinSec(float fseconds)
Definition: utilities.cpp:337
std::vector< float > *const & leps_pt() const
Get leps_pt for current event and cache it.
Definition: baby.cpp:4493
double Significance(double Nobs, double Nbkg, double Eup_bkg, double Edown_bkg=-1.)
Definition: utilities.cpp:426
PlotOpt & CanvasWidth(int width)
Definition: plot_opt.cpp:207
TString lowerNjets(TString &cut)
const std::string & Name() const
Get the string representation of this function.
Definition: named_func.cpp:376
Abstract base class for access to ntuple variables.
Definition: baby.hpp:16
const std::vector< std::unique_ptr< Figure > > & Figures() const
Definition: plot_maker.cpp:63
void ReplaceAll(std::string &str, const std::string &orig, const std::string &rep)
Definition: utilities.cpp:52
TString caption
Definition: abcd_method.hpp:18
STL namespace.
size_t indexBin(size_t iplane, size_t ibin, size_t iabcd)
Definition: abcd_method.cpp:73
Combines a callable function taking a Baby and returning a scalar or vector with its string represent...
Definition: named_func.hpp:13
bool Contains(const std::string &str, const std::string &pat)
Definition: utilities.cpp:44
TString rd_letter
Definition: abcd_method.hpp:18
TString Zbi(double Nobs, double Nbkg, double Eup_bkg, double Edown_bkg)
TString printTable(abcd_method &abcd, vector< vector< GammaParams > > &allyields, vector< vector< vector< float > > > &kappas, vector< vector< vector< float > > > &preds, vector< shared_ptr< Process > > &proc_sigs)
bool multithreaded_
Definition: plot_maker.hpp:43
std::string execute(const std::string &cmd)
Definition: utilities.cpp:65
double ScalarType
Definition: named_func.hpp:15
std::vector< std::vector< TString > > bincuts
Definition: abcd_method.hpp:17
std::vector< TString > allcuts
Definition: abcd_method.hpp:16
std::vector< TString > abcdcuts
Definition: abcd_method.hpp:16
double calcKappa(std::vector< std::vector< float > > &entries, std::vector< std::vector< float > > &weights, std::vector< float > &powers, float &mSigma, float &pSigma, bool do_data=false, bool verbose=false, double syst=-1., bool do_plot=false, int nrep=100000)
Definition: utilities.cpp:469
FigureType & Push(Args &&...args)
Definition: plot_maker.hpp:24
std::vector< GammaParams > BackgroundYield(double luminosity) const
Definition: table.cpp:175
std::string CodeToRootTex(std::string code)
Definition: utilities.cpp:116
std::string CodeToLatex(std::string code)
Definition: utilities.cpp:242
void plotKappa(abcd_method &abcd, vector< vector< vector< float > > > &kappas)
void printDebug(abcd_method &abcd, vector< vector< GammaParams > > &allyields, TString baseline, vector< vector< vector< float > > > &kappas, vector< vector< vector< float > > > &preds)
bool min_print_
Definition: plot_maker.hpp:44
TString RoundNumber(double num, int decimals, double denom=1.)
Definition: utilities.cpp:361
Organizes efficient production of plots with single loop over each process.
Definition: plot_maker.hpp:14
std::vector< TString > planecuts
Definition: abcd_method.hpp:16
TString method
Definition: abcd_method.hpp:15
PlotOpt & BottomMargin(double bottom)
Definition: plot_opt.cpp:251
std::vector< GammaParams > DataYield() const
Definition: table.cpp:188
Definition: table.hpp:15
const NamedFunc st("st", [](const Baby &b) -> NamedFunc::ScalarType{float stvar=b.ht();for(const auto &pt:*(b.leps_pt())) stvar+=pt;return stvar;})
PlotOpt & LegendEntryHeight(double height)
Definition: plot_opt.cpp:287
void MakePlots(double luminosity, const std::string &subdir="")
Prints all added plots with given luminosity.
Definition: plot_maker.cpp:54
float const & ht() const
Get ht for current event and cache it.
Definition: baby.cpp:3929
PlotOpt & RightMargin(double right)
Definition: plot_opt.cpp:242
void GetOptions(int argc, char *argv[])
Loads colors from a text configuration file.
Definition: palette.hpp:8