ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
plot_ratios.cxx
Go to the documentation of this file.
1 
3 #include <fstream>
4 #include <iostream>
5 #include <vector>
6 #include <ctime>
7 #include <iomanip> // setw
8 #include <chrono>
9 
10 #include <unistd.h>
11 #include <stdlib.h>
12 #include <getopt.h>
13 
14 #include "TError.h" // Controls error level reporting
15 #include "TCanvas.h"
16 #include "TGraphAsymmErrors.h"
17 #include "TH1D.h"
18 #include "TLine.h"
19 #include "TLatex.h"
20 #include "TLegend.h"
21 
22 #include "core/utilities.hpp"
23 #include "core/baby.hpp"
24 #include "core/process.hpp"
25 #include "core/named_func.hpp"
26 #include "core/plot_maker.hpp"
27 #include "core/palette.hpp"
28 #include "core/table.hpp"
29 #include "core/styles.hpp"
30 #include "core/plot_opt.hpp"
31 #include "core/functions.hpp"
32 
33 using namespace std;
34 
35 namespace{
36  bool debug = false;
37  TString skim = "both";
38  float lumi=40.;
39 
40  enum Regions {r1, r2, r3, r4};
41  enum Bkgs {bkg, tt1l, tt2l, other};
42 
43  struct oneplot{
44  TString name;
45  TString baseline;
46  vector<TString> bincuts;
47  };
48 }
49 
50 NamedFunc offshellw("offshellw",[](const Baby &b) -> NamedFunc::ScalarType{
51  for (unsigned i(0); i<b.mc_pt()->size(); i++){
52  if (abs(b.mc_id()->at(i))!=24) continue;
53  if (b.mc_mass()->at(i) > 140.) {
54  return 1;
55  }
56  }
57  return 0;
58  });
59 
60 void plotRatio(vector<vector<vector<GammaParams> > > &allyields, oneplot &plotdef,
61  vector<vector<vector<int> > > &indices, vector<TString> &leglabels){
62 
63  size_t ngraphs = indices.size();
64  size_t nbins = allyields[0][0].size();
65 
67  float val(1.), valup(1.), valdown(1.);
68  vector<vector<vector<float> > > ratios(ngraphs);
69  float maxr=-1., minr=1e6;
70  for(size_t igraph=0; igraph<ngraphs; igraph++){
71  // Finding powers to calculate ratio
72  vector<float> powers;
73  for(size_t ipow=0; ipow<indices[igraph].size(); ipow++) powers.push_back(indices[igraph][ipow][2]);
74 
75  // Finding ratios for each bin
76  for(size_t ibin=0; ibin<nbins; ibin++){
77  vector<vector<float> > entries;
78  vector<vector<float> > weights;
79  for(size_t ind=0; ind<indices[igraph].size(); ind++) {
80  size_t ibkg = indices[igraph][ind][0];
81  size_t iabcd = indices[igraph][ind][1];
82  entries.push_back(vector<float>());
83  weights.push_back(vector<float>());
84  entries.back().push_back(allyields[ibkg][iabcd][ibin].NEffective());
85  weights.back().push_back(allyields[ibkg][iabcd][ibin].Weight());
86  } // Loop over indices
87 
88  // Throwing toys to find ratios and uncertainties
89  val = calcKappa(entries, weights, powers, valdown, valup);
90  if(valdown<0) valdown = 0;
91  ratios[igraph].push_back(vector<float>({val, valdown, valup}));
92  if(maxr < val+valup) maxr = val+valup;
93  if(minr > val-valdown) minr = val-valdown;
94  } // Loop over bins
95  } // Loop over graphs
96 
98  TString ytitle="Ratio";
99  if(indices[0].size()==2){
100  size_t ind0=indices[0][0][1], ind1=indices[0][1][1];
101  if((ind0==r3&&ind1==r1) || (ind0==r4&&ind1==r2)) ytitle = "R(m_{T})";
102  if((ind0==r4&&ind1==r3) || (ind0==r2&&ind1==r1)) ytitle = "R(M_{J})";
103  }
104  if(indices[0].size()==4){
105  size_t ind0=indices[0][0][1], ind1=indices[0][1][1];
106  size_t ind2=indices[0][2][1], ind3=indices[0][3][1];
107  if((ind0==r4&&ind1==r3&&ind2==r2&&ind3==r1)) ytitle = "R(M_{J}^{high}) / R[M_{J}^{low}(bkg)]";
108  }
110  PlotOpt opts("txt/plot_styles.txt", "Ratio");
111  setPlotStyle(opts);
112 
114  TCanvas can("can","");
115  TLine line; line.SetLineWidth(2); line.SetLineStyle(2);
116  TLatex label; label.SetTextSize(0.05); label.SetTextFont(42); label.SetTextAlign(23);
117 
118  float minx = 0.5, maxx = nbins+0.5, miny = 0, maxy = maxr*1.2;
119  if(maxy>5) maxy = 5;
120  TH1D histo("histo", "", nbins, minx, maxx);
121  histo.SetMinimum(miny);
122  histo.SetMaximum(maxy);
123  histo.GetYaxis()->CenterTitle(true);
124  histo.GetXaxis()->SetLabelOffset(0.008);
125  histo.SetYTitle(ytitle);
126  histo.Draw();
127 
129  vector<vector<double> > vx(ngraphs), vexh(ngraphs), vexl(ngraphs);
130  vector<vector<double> > vy(ngraphs), veyh(ngraphs), veyl(ngraphs);
131  for(size_t ibin=0; ibin<nbins; ibin++){
132  histo.GetXaxis()->SetBinLabel(ibin+1, CodeToRootTex(plotdef.bincuts[ibin].Data()).c_str());
133  // xval is the x position of the first marker in the group
134  double xval = ibin+1, minxb = 0.15, binw = 0;
135  // If there is more than one point in the group, it starts minxb to the left of the center of the bin
136  // binw is the distance between points in the njets group
137  if(ngraphs>1) {
138  xval -= minxb;
139  binw = 2*minxb/(ngraphs-1);
140  }
141  for(size_t igraph=0; igraph<ngraphs; igraph++){
142  vx[igraph].push_back(xval);
143  xval += binw;
144  vexl[igraph].push_back(0);
145  vexh[igraph].push_back(0);
146  vy[igraph] .push_back(ratios[igraph][ibin][0]);
147  veyl[igraph].push_back(ratios[igraph][ibin][1]);
148  veyh[igraph].push_back(ratios[igraph][ibin][2]);
149  } // Loop over TGraphs
150  } // Loop over bin cuts
151 
153  double legX(opts.LeftMargin()+0.023), legY(1-opts.TopMargin()-0.03), legSingle = 0.05;
154  double legW = 0.19*ngraphs, legH = legSingle*(ngraphs+1)/2;
155  TLegend leg(legX, legY-legH, legX+legW, legY);
156  leg.SetTextSize(opts.LegendEntryHeight()); leg.SetFillColor(0);
157  leg.SetFillStyle(0); leg.SetBorderSize(0);
158  leg.SetTextFont(42);
159  leg.SetNColumns(ngraphs);
160 
161  Palette colors("txt/colors.txt", "default");
162  //vector<int> mcolors({kRed, kGreen+1, 4, kMagenta+2});
163  vector<int> mcolors({kRed, kGreen-3, kCyan-3, 1});
164  vector<int> styles({20, 21, 22, 23});
165  TGraphAsymmErrors graph[20]; // There's problems with vectors of TGraphs, so using an array
166  for(size_t igraph=0; igraph<ngraphs; igraph++){
167  graph[igraph] = TGraphAsymmErrors(vx[igraph].size(), &(vx[igraph][0]), &(vy[igraph][0]),
168  &(vexl[igraph][0]), &(vexh[igraph][0]), &(veyl[igraph][0]), &(veyh[igraph][0]));
169  graph[igraph].SetMarkerStyle(styles[igraph]); graph[igraph].SetMarkerSize(1.4);
170  if(leglabels[igraph]=="All bkg.") mcolors[igraph] = 1;
171  if(leglabels[igraph]=="t#bar{t} (2l)") mcolors[igraph] = colors("tt_2l");
172  if(leglabels[igraph]=="t#bar{t} (1l)") mcolors[igraph] = colors("tt_1l");
173  if(leglabels[igraph]=="Other") mcolors[igraph] = colors("wjets");
174  graph[igraph].SetMarkerColor(mcolors[igraph]);
175  graph[igraph].SetLineColor(mcolors[igraph]); graph[igraph].SetLineWidth(2);
176  graph[igraph].Draw("p0 same");
177  leg.AddEntry(&graph[igraph], leglabels[igraph], "p");
178  } // Loop over TGraphs
179  leg.Draw();
180 
182  TLatex cmslabel;
183  cmslabel.SetTextSize(0.06);
184  cmslabel.SetNDC(kTRUE);
185  cmslabel.SetTextAlign(11);
186  cmslabel.DrawLatex(opts.LeftMargin()+0.005, 1-opts.TopMargin()+0.015,"#font[62]{CMS} #scale[0.8]{#font[52]{Simulation}}");
187  cmslabel.SetTextAlign(31);
188  cmslabel.DrawLatex(1-opts.RightMargin()-0.005, 1-opts.TopMargin()+0.015,"#font[42]{13 TeV}");
189 
190  line.SetLineStyle(3); line.SetLineWidth(1);
191  line.DrawLine(minx, 1, maxx, 1);
192 
193  string fname="plots/ratio_"+CodeToPlainText(ytitle.Data())+"_"+plotdef.name.Data()+"_"+CodeToPlainText(plotdef.baseline.Data())+".pdf";
194  can.SaveAs(fname.c_str());
195  cout<<endl<<" open "<<fname<<endl;
196 
197 } // plotRatio
198 
199 
200 void printDebug(vector<vector<TString> > &allcuts, vector<vector<vector<GammaParams> > > &allyields,
201  TString baseline);
202 
203 void GetOptions(int argc, char *argv[]);
204 
205 int main(int argc, char *argv[]){
206  gErrorIgnoreLevel=6000; // Turns off ROOT errors due to missing branches
207  GetOptions(argc, argv);
208 
209  chrono::high_resolution_clock::time_point begTime;
210  begTime = chrono::high_resolution_clock::now();
211 
214  string bfolder("");
215  string hostname = execute("echo $HOSTNAME");
216  if(Contains(hostname, "cms") || Contains(hostname, "compute-"))
217  bfolder = "/net/cms2"; // In laptops, you can't create a /net folder
218 
219  string ntupletag="";
220  string foldermc(bfolder+"/cms2r0/babymaker/babies/2016_08_10/mc/merged_mcbase_met100_stdnj5/");
221  if(skim.Contains("met150")) ntupletag="_met150";
222  if(skim.Contains("both")) ntupletag="";
223 
224  Palette colors("txt/colors.txt", "default");
225 
226  // Cuts in baseline speed up the yield finding
227  string baseline="";
228  NamedFunc baselinef = "pass && stitch && mj14>250 && nleps==1 && nveto==0 && st>500 && met>100 && njets>=5 && nbm>=1";
229 
230  // // For syncing
231  // auto proc_tt1l = Process::MakeShared<Baby_full>("tt 1lep", Process::Type::background, colors("tt_1l"),
232  // {foldermc+"*_TTJets*SingleLept*"+ntupletag+"*.root"},
233  // baseline);
234  // auto proc_tt2l = Process::MakeShared<Baby_full>("tt 2lep", Process::Type::background, colors("tt_2l"),
235  // {foldermc+"*_TTJets*DiLept*"+ntupletag+"*.root", foldermc+"*_TTJets_HT*"+ntupletag+"*.root"},
236  // baseline);
237 
238  set<string> allfiles = {foldermc+"*_TTJets*Lept*"+ntupletag+"*.root", foldermc+"*_TTJets_HT*"+ntupletag+"*.root",
239  foldermc+"*_WJetsToLNu*"+ntupletag+"*.root",
240  foldermc+"*_ST_*"+ntupletag+"*.root",
241  foldermc+"*_TTW*"+ntupletag+"*.root", foldermc+"*_TTZ*"+ntupletag+"*.root",
242  foldermc+"*_TTGJets*"+ntupletag+"*.root",foldermc+"*_TTTT*"+ntupletag+"*.root",
243  foldermc+"*QCD_HT*Inf_Tune*"+ntupletag+"*.root",
244  foldermc+"*QCD_HT*0_Tune*"+ntupletag+"*.root",foldermc+"*DYJetsToLL*"+ntupletag+"*.root",
245  foldermc+"*_ZJet*"+ntupletag+"*.root",foldermc+"*_ttHJetTobb*"+ntupletag+"*.root",
246  foldermc+"*_WH_HToBB*"+ntupletag+"*.root",foldermc+"*_ZH_HToBB*"+ntupletag+"*.root",
247  foldermc+"*_WWTo*"+ntupletag+"*.root",foldermc+"*_WZ*"+ntupletag+"*.root",
248  foldermc+"*_ZZ_*"+ntupletag+"*.root"
249  };
250 
251  set<string> nottfiles = {foldermc+"*_WJetsToLNu*"+ntupletag+"*.root",
252  foldermc+"*_ST_*"+ntupletag+"*.root",
253  foldermc+"*_TTW*"+ntupletag+"*.root", foldermc+"*_TTZ*"+ntupletag+"*.root",
254  foldermc+"*_TTGJets*"+ntupletag+"*.root",foldermc+"*_TTTT*"+ntupletag+"*.root",
255  foldermc+"*QCD_HT*Inf_Tune*"+ntupletag+"*.root",
256  foldermc+"*QCD_HT*0_Tune*"+ntupletag+"*.root",foldermc+"*DYJetsToLL*"+ntupletag+"*.root",
257  foldermc+"*_ZJet*"+ntupletag+"*.root",foldermc+"*_ttHJetTobb*"+ntupletag+"*.root",
258  foldermc+"*_WH_HToBB*"+ntupletag+"*.root",foldermc+"*_ZH_HToBB*"+ntupletag+"*.root",
259  foldermc+"*_WWTo*"+ntupletag+"*.root",foldermc+"*_WZ*"+ntupletag+"*.root",
260  foldermc+"*_ZZ_*"+ntupletag+"*.root"
261  };
262 
263  set<string> nowfiles = {foldermc+"*_TTJets*Lept*"+ntupletag+"*.root", foldermc+"*_TTJets_HT*"+ntupletag+"*.root",
264  foldermc+"*_ST_*"+ntupletag+"*.root",
265  foldermc+"*_TTW*"+ntupletag+"*.root", foldermc+"*_TTZ*"+ntupletag+"*.root",
266  foldermc+"*_TTGJets*"+ntupletag+"*.root",foldermc+"*_TTTT*"+ntupletag+"*.root",
267  foldermc+"*QCD_HT*Inf_Tune*"+ntupletag+"*.root",
268  foldermc+"*QCD_HT*0_Tune*"+ntupletag+"*.root",foldermc+"*DYJetsToLL*"+ntupletag+"*.root",
269  foldermc+"*_ZJet*"+ntupletag+"*.root",foldermc+"*_ttHJetTobb*"+ntupletag+"*.root",
270  foldermc+"*_WH_HToBB*"+ntupletag+"*.root",foldermc+"*_ZH_HToBB*"+ntupletag+"*.root",
271  foldermc+"*_WWTo*"+ntupletag+"*.root",foldermc+"*_WZ*"+ntupletag+"*.root",
272  foldermc+"*_ZZ_*"+ntupletag+"*.root"
273  };
274 
275  set<string> ttfiles = {foldermc+"*_TTJets*Lept*"+ntupletag+"*.root", foldermc+"*_TTJets_HT*"+ntupletag+"*.root"};
276  set<string> wfiles = {foldermc+"*_WJetsToLNu*"+ntupletag+"*.root"};
277  //allfiles = ttfiles;
278 
280  auto proc_tt1l = Process::MakeShared<Baby_full>("1lbad", Process::Type::background, kRed,
281  allfiles, baselinef && "stitch && ntruleps<=1");
282  auto proc_other = Process::MakeShared<Baby_full>("1lgood", Process::Type::background, kGreen-3,
283  allfiles, baselinef && "stitch && ntruleps<=1 && mt_tru>140 && 0");
284  auto proc_tt2l = Process::MakeShared<Baby_full>("2l", Process::Type::background, kCyan-3,
285  allfiles, baselinef && "stitch && ntruleps>=2");
286 
287  // //// Contributions
288  // auto proc_tt1l = Process::MakeShared<Baby_full>("1lbad", Process::Type::background, kRed,
289  // allfiles, baselinef && "stitch && ntruleps<=1 && mt_tru<=140");
290  // auto proc_other = Process::MakeShared<Baby_full>("1lgood", Process::Type::background, kGreen-3,
291  // allfiles, baselinef && "stitch && ntruleps<=1 && mt_tru>140");
292  // auto proc_tt2l = Process::MakeShared<Baby_full>("2l", Process::Type::background, kCyan-3,
293  // allfiles, baselinef && "stitch && ntruleps>=2");
294 
295 
296  // //// Contributions
297  // auto proc_tt1l = Process::MakeShared<Baby_full>("tt 1lep", Process::Type::background, colors("tt_1l"),
298  // {foldermc+"*_TTJets*SingleLept*"+ntupletag+"*.root", foldermc+"*_TTJets_HT*"+ntupletag+"*.root"},
299  // baselinef && "stitch && ntruleps==1");
300  // auto proc_tt2l = Process::MakeShared<Baby_full>("tt 2lep", Process::Type::background, colors("tt_2l"),
301  // {foldermc+"*_TTJets*DiLept*"+ntupletag+"*.root", foldermc+"*_TTJets_HT*"+ntupletag+"*.root"},
302  // baselinef && "stitch && ntruleps==2");
303 
304  // auto proc_other = Process::MakeShared<Baby_full>("Other", Process::Type::background, colors("other"),
305  // {foldermc+"*_WJetsToLNu*"+ntupletag+"*.root",foldermc+"*_ST_*"+ntupletag+"*.root",
306  // foldermc+"*_TTW*"+ntupletag+"*.root",foldermc+"*_TTZ*"+ntupletag+"*.root",
307  // foldermc+"*DYJetsToLL*"+ntupletag+"*.root",foldermc+"*QCD_HT*Inf_Tune*"+ntupletag+"*.root",
308  // foldermc+"*QCD_HT*0_Tune*"+ntupletag+"*.root",
309  // foldermc+"*_ZJet*"+ntupletag+"*.root",foldermc+"*_ttHJetTobb*"+ntupletag+"*.root",
310  // foldermc+"*_TTGJets*"+ntupletag+"*.root",foldermc+"*_TTTT*"+ntupletag+"*.root",
311  // foldermc+"*_WH_HToBB*"+ntupletag+"*.root",foldermc+"*_ZH_HToBB*"+ntupletag+"*.root",
312  // foldermc+"*_WWTo*"+ntupletag+"*.root",foldermc+"*_WZ*"+ntupletag+"*.root",foldermc+"*_ZZ_*"+ntupletag+"*.root"},
313  // baselinef && "stitch");
314 
315  // //// Use these processes to make quick plots
316  // auto proc_tt1l = Process::MakeShared<Baby_full>("tt 1lep", Process::Type::background, colors("tt_1l"),
317  // {foldermc+"*_TTJets_Tune*.root"},
318  // baselinef && "ntruleps==1");
319  // auto proc_tt2l = Process::MakeShared<Baby_full>("tt 2lep", Process::Type::background, colors("tt_2l"),
320  // {foldermc+"*_TTJets_Tune*.root"},
321  // baselinef && "ntruleps==2");
322 
323  // auto proc_other = Process::MakeShared<Baby_full>("Other", Process::Type::background, colors("other"),
324  // {foldermc+"*_WWTo*"+ntupletag+"*.root",foldermc+"*_WZ*"+ntupletag+"*.root"},
325  // baselinef && "stitch");
326 
327  vector<shared_ptr<Process> > all_procs = {proc_tt1l, proc_tt2l, proc_other};
328 
331  // baseline defined above
332 
333  // Makes a plot for each vector in plotcuts
334  vector<oneplot> plotcuts({{"njets", "met>200", {"njets==5", "njets==6", "njets==7", "njets==8", "njets>=9"}},
335  {"met", "njets==5", {"met>100 && met<=150","met>150 && met<=200","met>200 && met<=350","met>350&&met<=500","met>500"}}});
336  vector<TString> abcdcuts = {"mt<=140 && mj14<=400", "mt<=140 && mj14>400",
337  "mt>140 && mj14<=400", "mt>140 && mj14>400"};
338  size_t Nabcd = abcdcuts.size();
339 
340  PlotMaker pm;
341  vector<vector<vector<TString> > > allcuts(plotcuts.size(), vector<vector<TString> > (Nabcd));
342  for(size_t iplot=0; iplot<plotcuts.size(); iplot++){
343  for(size_t iabcd=0; iabcd<abcdcuts.size(); iabcd++){
344  vector<TableRow> table_cuts;
345  for(size_t ibin=0; ibin<plotcuts[iplot].bincuts.size(); ibin++){
346  TString totcut=plotcuts[iplot].baseline+" && "+plotcuts[iplot].bincuts[ibin]+" && "+abcdcuts[iabcd];
347  table_cuts.push_back(TableRow("", totcut.Data()));
348  allcuts[iplot][iabcd].push_back(totcut);
349  } // Loop over bins
350  TString tname = "rmj"; tname += iplot; tname += iabcd;
351  pm.Push<Table>(tname.Data(), table_cuts, all_procs, false, false);
352  } // Loop over abcdcuts
353  } // Loop over plots
354 
357 
358  pm.min_print_ = true;
359  pm.MakePlots(lumi);
360 
363 
364  for(size_t iplot=0; iplot<plotcuts.size(); iplot++){
365  // allyields: [0] All bkg, [1] tt1l, [2] tt2l, [3] other
366  vector<vector<vector<GammaParams> > > allyields(4,vector<vector<GammaParams> >(Nabcd));
367  for(size_t iabcd=0; iabcd<abcdcuts.size(); iabcd++){
368  Table * yield_table = static_cast<Table*>(pm.Figures()[iplot*Nabcd+iabcd].get());
369  allyields[bkg] [iabcd] = yield_table->BackgroundYield(lumi);
370  allyields[tt1l] [iabcd] = yield_table->Yield(proc_tt1l.get(), lumi);
371  allyields[tt2l] [iabcd] = yield_table->Yield(proc_tt2l.get(), lumi);
372  allyields[other][iabcd] = yield_table->Yield(proc_other.get(), lumi);
373  } // Loop over ABCD cuts
374 
376  if(debug) printDebug(allcuts[iplot], allyields, baseline);
377 
379  vector<vector<vector<int> > > indices({
380  {{tt2l, r3, 1}, {tt1l, r1, -1}},
381  {{tt2l, r4, 1}, {tt1l, r2, -1}},
382  {{bkg, r3, 1}, {bkg, r1, -1}},
383  {{bkg, r4, 1}, {bkg, r2, -1}}
384 });
385  vector<TString> leglabels({"tt: M_{J}<400", "tt: M_{J}>400", "bkg: M_{J}<400", "bkg: M_{J}>400"});
386  plotRatio(allyields, plotcuts[iplot], indices, leglabels);
387 
389  indices = vector<vector<vector<int> > >({
390  {{tt1l, r4, 1}, {tt1l, r3, -1}, {bkg, r2, -1}, {bkg, r1, 1}},
391  // {{other, r4, 1}, {other, r3, -1}, {bkg, r2, -1}, {bkg, r1, 1}},
392  {{tt2l, r4, 1}, {tt2l, r3, -1}, {bkg, r2, -1}, {bkg, r1, 1}},
393  {{bkg, r4, 1}, {bkg, r3, -1}, {bkg, r2, -1}, {bkg, r1, 1}}
394  // {{tt1l, r4, 1}, {tt1l, r3, -1}, {tt1l, r2, -1}, {tt1l, r1, 1}},
395 // {{other, r4, 1}, {other, r3, -1}, {tt1l, r2, -1}, {tt1l, r1, 1}},
396 // {{tt2l, r4, 1}, {tt2l, r3, -1}, {tt1l, r2, -1}, {tt1l, r1, 1}},
397 // {{bkg, r4, 1}, {bkg, r3, -1}, {tt1l, r2, -1}, {tt1l, r1, 1}}
398  });
399  //leglabels = vector<TString>({"1l m^{true}_{T}#leq140", "1l m^{true}_{T}>140", "2l", "All bkg."});
400  // leglabels = vector<TString>({"t#bar{t} 1l", "Other", "t#bar{t} 2l", "All bkg."});
401  leglabels = vector<TString>({"0-1l", "2l", "All bkg."});
402  plotRatio(allyields, plotcuts[iplot], indices, leglabels);
403 
404 
405  } // Loop over plots
406 
407 
408  double seconds = (chrono::duration<double>(chrono::high_resolution_clock::now() - begTime)).count();
409  TString hhmmss = HoursMinSec(seconds);
410  cout<<endl<<"Finding "<<plotcuts.size()<<" plots took "<<round(seconds)<<" seconds ("<<hhmmss<<")"<<endl<<endl;
411 } // main
412 
417 
418 
419 // allyields: [0] All bkg, [1] tt1l, [2] tt2l, [3] other
420 void printDebug(vector<vector<TString> > &allcuts, vector<vector<vector<GammaParams> > > &allyields,
421  TString baseline){
422  int digits = 3;
423  cout<<endl<<endl<<"============================ Printing cuts ============================"<<endl;
424  cout<<"-- Baseline cuts: "<<baseline<<endl<<endl;
425  for(size_t ibin=0; ibin<allcuts[0].size(); ibin++){
426  for(size_t iabcd=0; iabcd<allcuts.size(); iabcd++){
427  cout<<"MC: " <<setw(9)<<RoundNumber(allyields[bkg] [iabcd][ibin].Yield(), digits)
428  <<" tt1l: "<<setw(9)<<RoundNumber(allyields[tt1l] [iabcd][ibin].Yield(), digits)
429  <<" tt2l: "<<setw(9)<<RoundNumber(allyields[tt2l] [iabcd][ibin].Yield(), digits)
430  <<" other: "<<setw(9)<<RoundNumber(allyields[other][iabcd][ibin].Yield(), digits)
431  <<" - "<< allcuts[iabcd][ibin]<<endl;
432  } // Loop over ABCD cuts
433  cout<<endl;
434  } // Loop over bin cuts
435 
436 } // printDebug
437 
438 
439 void GetOptions(int argc, char *argv[]){
440  while(true){
441  static struct option long_options[] = {
442  {"lumi", required_argument, 0, 'l'}, // Luminosity to normalize MC with (no data)
443  {"skim", required_argument, 0, 's'}, // Which skim to use: standard, met150, 2015 data
444  {"debug", no_argument, 0, 'd'}, // Debug: prints yields and cuts used
445  {0, 0, 0, 0}
446  };
447 
448  char opt = -1;
449  int option_index;
450  opt = getopt_long(argc, argv, "s:l:d", long_options, &option_index);
451  if(opt == -1) break;
452 
453  string optname;
454  switch(opt){
455  case 'l':
456  lumi = atof(optarg);
457  break;
458  case 's':
459  skim = optarg;
460  break;
461  case 'd':
462  debug = true;
463  break;
464  case 0:
465  break;
466  default:
467  printf("Bad option! getopt_long returned character code 0%o\n", opt);
468  break;
469  }
470  }
471 }
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
std::vector< GammaParams > Yield(const Process *process, double luminosity) const
Definition: table.cpp:158
TString HoursMinSec(float fseconds)
Definition: utilities.cpp:337
std::string CodeToPlainText(std::string code)
Definition: utilities.cpp:79
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
STL namespace.
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
std::string execute(const std::string &cmd)
Definition: utilities.cpp:65
double ScalarType
Definition: named_func.hpp:15
NamedFunc offshellw("offshellw",[](const Baby &b) -> NamedFunc::ScalarType{for(unsigned i(0);i< b.mc_pt() ->size();i++){if(abs(b.mc_id() ->at(i))!=24) continue;if(b.mc_mass() ->at(i) > 140.){return 1;}}return 0;})
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
std::vector< float > *const & mc_pt() const
Get mc_pt for current event and cache it.
Definition: baby.cpp:4613
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
int main(int argc, char *argv[])
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
void plotRatio(vector< vector< vector< GammaParams > > > &allyields, oneplot &plotdef, vector< vector< vector< int > > > &indices, vector< TString > &leglabels)
Definition: plot_ratios.cxx:60
std::vector< int > *const & mc_id() const
Get mc_id for current event and cache it.
Definition: baby.cpp:4553
void printDebug(vector< vector< TString > > &allcuts, vector< vector< vector< GammaParams > > > &allyields, TString baseline)
void GetOptions(int argc, char *argv[])
Definition: table.hpp:15
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
std::vector< float > *const & mc_mass() const
Get mc_mass for current event and cache it.
Definition: baby.cpp:4565
PlotOpt & RightMargin(double right)
Definition: plot_opt.cpp:242
Loads colors from a text configuration file.
Definition: palette.hpp:8