ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
plot_pie.cxx
Go to the documentation of this file.
1 
3 #include <fstream>
4 #include <iostream>
5 #include <vector>
6 #include <ctime>
7 
8 #include "TError.h" // Controls error level reporting
9 
10 #include "core/utilities.hpp"
11 #include "core/baby.hpp"
12 #include "core/process.hpp"
13 #include "core/named_func.hpp"
14 #include "core/plot_maker.hpp"
15 #include "core/palette.hpp"
16 #include "core/table.hpp"
17 #include "core/plot_opt.hpp"
18 
19 namespace{
20  //bool do_met150 = true;
21 }
22 
23 using namespace std;
24 
25 int main(){
26  gErrorIgnoreLevel=6000; // Turns off ROOT errors due to missing branches
27 
28  time_t begtime, endtime;
29  time(&begtime);
30 
33  string bfolder("");
34  string hostname = execute("echo $HOSTNAME");
35  if(Contains(hostname, "cms") || Contains(hostname, "compute-"))
36  bfolder = "/net/cms2"; // In laptops, you can't create a /net folder
37 
38  string foldermc(bfolder+"/cms2r0/babymaker/babies/2016_08_10/mc/merged_mcbase_stdnj5/");
39  //if(do_met150) foldermc = (bfolder+"/cms2r0/babymaker/babies/2016_06_14/mc/merged_met150/");
40  Palette colors("txt/colors.txt", "default");
41 
42  // Cuts in baseline speed up the yield finding
43  string baseline = "mj14>250 && nleps>=1 && ht>500 && met>150 && pass && njets>=5 && weight<1"; // Excluding one QCD event
44  //if(do_met150) baseline = "mj14>250 && nleps>=1 && ht>500 && met>150 && pass && njets>=5";
45 
46  auto proc_tt1l = Process::MakeShared<Baby_full>("t#bar{t} (l)", Process::Type::background, colors("tt_1l"),
47  {foldermc+"*_TTJets*SingleLept*.root", foldermc+"*_TTJets_HT*.root"},
48  baseline+" && stitch && ntruleps==1");
49  auto proc_tt2l = Process::MakeShared<Baby_full>("t#bar{t} (ll)", Process::Type::background, colors("tt_2l"),
50  {foldermc+"*_TTJets*DiLept*.root", foldermc+"*_TTJets_HT*.root"},
51  baseline+" && stitch && ntruleps==2 && ntrutaush==0");
52  auto proc_ttltau = Process::MakeShared<Baby_full>("t#bar{t} (#tau_{h}l)", Process::Type::background, colors("tt_ltau"),
53  {foldermc+"*_TTJets*DiLept*.root", foldermc+"*_TTJets_HT*.root"},
54  baseline+" && stitch && ntruleps==2 && ntrutaush>=1");
55  auto proc_wjets = Process::MakeShared<Baby_full>("W+jets", Process::Type::background, colors("wjets"),
56  {foldermc+"*_WJetsToLNu*.root"}, baseline+" && stitch");
57  auto proc_single_t = Process::MakeShared<Baby_full>("Single t", Process::Type::background, colors("single_t"),
58  {foldermc+"*_ST_*.root"}, baseline);
59  auto proc_ttv = Process::MakeShared<Baby_full>("t#bar{t}V", Process::Type::background, colors("ttv"),
60  {foldermc+"*_TTWJets*.root", foldermc+"*_TTZ*.root"}, baseline);
61  auto proc_other = Process::MakeShared<Baby_full>("Other", Process::Type::background, colors("other"),
62  {foldermc+"*DYJetsToLL*.root",foldermc+"*QCD_HT*0_Tune*.root",foldermc+"*QCD_HT*Inf_Tune*.root",
63  foldermc+"*_ZJet*.root",foldermc+"*_ttHJetTobb*.root",
64  foldermc+"*_TTGJets*.root",foldermc+"*_TTTT*.root",
65  foldermc+"*_WH_HToBB*.root",foldermc+"*_ZH_HToBB*.root",
66  foldermc+"*_WWTo*.root",foldermc+"*_WZ*.root",foldermc+"*_ZZ_*.root"},
67  baseline+" && stitch");
68 
69  // auto proc_tt1l = Process::MakeShared<Baby_full>("t#bar{t} (1l", Process::Type::background, colors("tt_1l"),
70  // {foldermc+"*_TTJets_Tune*.root"},
71  // baseline+" && ntruleps==1");
72  // auto proc_tt2l = Process::MakeShared<Baby_full>("t#bar{t} 2l", Process::Type::background, colors("tt_2l"),
73  // {foldermc+"*_TTJets_Tune**.root"},
74  // baseline+" && ntruleps==2");
75 
76 
77 
78  vector<shared_ptr<Process> > all_procs = {proc_tt1l, proc_tt2l, proc_ttltau, proc_wjets, proc_single_t, proc_ttv, proc_other};
79  //vector<shared_ptr<Process> > all_procs = {proc_tt1l, proc_tt2l};
80 
82  TString c_vlowmet = "met>150 && met<=200";
83  TString c_lowmet = "met>200 && met<=350";
84  TString c_midmet = "met>350 && met<=500";
85  TString c_higmet = "met>500";
86  vector<TString> metcuts({c_vlowmet, c_lowmet, c_midmet, c_higmet});
87  // if(do_met150) metcuts = vector<TString>({c_vlowmet});
88 
90  TString c_lownb = "nbm==1";
91  TString c_midnb = "nbm==2";
92  TString c_hignb = "nbm>=3";
93  vector<TString> nbcuts({c_lownb, c_midnb, c_hignb});
94  //vector<TString> nbcuts({"nbm>=2"});
95 
97  TString c_lownj = "njets>=6 && njets<=8";
98  TString c_hignj = "njets>=9";
99  TString c_nj5 = "njets==5";
100  vector<TString> njcuts({c_nj5, c_lownj, c_hignj});
101  //vector<TString> njcuts({"njets>=6"});
102 
104  TString c_lowmt = "mt<=140";
105  TString c_higmt = "mt>140";
106  vector<TString> mtcuts({c_lowmt, c_higmt});
107 
108  // Adding nleps==1 cuts
109  vector<TString> cuts;
110  for(size_t imet=0; imet<metcuts.size(); imet++)
111  for(size_t inb=0; inb<nbcuts.size(); inb++)
112  for(size_t inj=0; inj<njcuts.size(); inj++)
113  for(size_t imt=0; imt<mtcuts.size(); imt++){
114  cuts.push_back("nleps==1 && nveto==0 && "+metcuts[imet]+"&&"+nbcuts[inb]+"&&"+njcuts[inj]+"&&"+mtcuts[imt]);
115  cuts.push_back("nleps==1 && nveto==1 && "+metcuts[imet]+"&&"+nbcuts[inb]+"&&"+njcuts[inj]+"&&"+mtcuts[imt]);
116  }
117 
118  // Adding nleps==2 cuts
119  njcuts = vector<TString>({"njets>=5 && njets<=7", "njets>=8"});
120  for(size_t imet=0; imet<metcuts.size(); imet++)
121  for(size_t inj=0; inj<njcuts.size(); inj++)
122  cuts.push_back("nleps==2 && "+metcuts[imet]+"&&"+njcuts[inj]);
123 
124  vector<TableRow> table_cuts;
125  for(size_t icut=0; icut<cuts.size(); icut++){
126  table_cuts.push_back(TableRow("$"+CodeToLatex(cuts[icut].Data())+"$", cuts[icut].Data()));
127  }
128 
129  PlotMaker pm;
130  pm.Push<Table>("chart", table_cuts, all_procs, true, true, true);
131  pm.min_print_ = true;
132  pm.MakePlots(40.);
133 
134  time(&endtime);
135  cout<<endl<<"Making "<<table_cuts.size()<<" piecharts took "<<difftime(endtime, begtime)<<" seconds"<<endl<<endl;
136 }
STL namespace.
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
FigureType & Push(Args &&...args)
Definition: plot_maker.hpp:24
std::string CodeToLatex(std::string code)
Definition: utilities.cpp:242
bool min_print_
Definition: plot_maker.hpp:44
Organizes efficient production of plots with single loop over each process.
Definition: plot_maker.hpp:14
int main()
Definition: plot_pie.cxx:25
Definition: table.hpp:15
void MakePlots(double luminosity, const std::string &subdir="")
Prints all added plots with given luminosity.
Definition: plot_maker.cpp:54
Loads colors from a text configuration file.
Definition: palette.hpp:8