ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
plot_2016-09-09_mjshapes_stVSht.cxx
Go to the documentation of this file.
1 #include <cmath>
2 #include <stdio.h>
3 #include <chrono>
4 
5 #include "TError.h"
6 #include "TVector2.h"
7 
8 #include "core/plot_maker.hpp"
9 #include "core/plot_opt.hpp"
10 #include "core/palette.hpp"
11 #include "core/histo_stack.hpp"
12 #include "core/event_scan.hpp"
13 #include "core/utilities.hpp"
14 #include "core/table.hpp"
15 #include "core/slide_maker.hpp"
16 
17 using namespace std;
18 using namespace PlotOptTypes;
19 
20 namespace{
21  bool do_metbins = false;
22  bool do_met150 = true;
23  bool do_njbins = false;
24 }
25 
26 int main(){
27  gErrorIgnoreLevel = 6000;
28 
29  chrono::high_resolution_clock::time_point begTime;
30  begTime = chrono::high_resolution_clock::now();
31 
32  double lumi = 2.6;
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  Palette colors("txt/colors.txt", "default");
39 
40  //if folder name contains "reclustered", plots will also be made for MJ_nolep
41  string folder_mc(bfolder+"/cms2r0/babymaker/babies/2016_08_10/mc/merged_mcbase_stdnj5/");
42  string ntupletag = "*.root";
43  if (!do_met150) ntupletag = "*metG200*.root";
44 
45  set<string> files_tt({folder_mc+"*_TTJets*Lept"+ntupletag, folder_mc+"*_TTJets_HT"+ntupletag});
46  set<string> files_wjets({folder_mc+"*_WJetsToLNu"+ntupletag});
47  set<string> files_st({folder_mc+"*_ST_"+ntupletag});
48  set<string> files_other({
49  folder_mc+"*DYJetsToLL"+ntupletag,
50  folder_mc+"*_QCD_HT*00_Tune"+ntupletag, folder_mc+"*_QCD_HT*Inf_Tune"+ntupletag,
51  folder_mc+"*_ZJet"+ntupletag, folder_mc+"*_WWTo"+ntupletag,
52  folder_mc+"*ggZH_HToBB"+ntupletag, folder_mc+"*ttHJetTobb"+ntupletag,
53  folder_mc+"*_TTGJets"+ntupletag, folder_mc+"*_TTTT_"+ntupletag,
54  folder_mc+"*_TTWJets"+ntupletag, folder_mc+"*_TTZTo"+ntupletag,
55  folder_mc+"*_WH_HToBB"+ntupletag, folder_mc+"*_WZTo"+ntupletag,
56  folder_mc+"*_ZH_HToBB"+ntupletag, folder_mc+"_ZZ_"+ntupletag});
57 
58  set<string> files_nontt(files_other);
59  files_nontt.insert(files_wjets.begin(), files_wjets.end());
60  files_nontt.insert(files_st.begin(), files_st.end());
61 
62  set<string> files_all(files_nontt);
63  files_all.insert(files_tt.begin(), files_tt.end());
64 
65  PlotOpt log_shapes("txt/plot_styles.txt", "CMSPaper");
66  log_shapes.Title(TitleType::info)
67  .Bottom(BottomType::ratio)
68  .YAxis(YAxisType::log)
69  .Stack(StackType::shapes)
70  .RatioMaximum(2.4);
71  PlotOpt lin_shapes = log_shapes().YAxis(YAxisType::linear);
72  vector<PlotOpt> plot_types = {lin_shapes};
73 
74  NamedFunc baseline_1l = "stitch && nleps==1 && nveto==0 && nbm>=1 && weight<1";
75  NamedFunc baseline_2l = "stitch && nleps==2";
76  NamedFunc baseline_lveto = "stitch && nleps==1 && nveto==1 && nbm>=1 && mt>140";
77 
78  auto tt1l_lowmt = Process::MakeShared<Baby_full>("t#bar{t}(1l), m_{T} #leq 140",
79  Process::Type::background, colors("tt_1l"), files_tt, baseline_1l && "ntruleps>=1 && mt<=140");
80  tt1l_lowmt->SetLineStyle(2);
81  auto tt1l_highmt = Process::MakeShared<Baby_full>("t#bar{t}(1l), m_{T} > 140",
82  Process::Type::background, colors("tt_1l"), files_tt, baseline_1l && "ntruleps>=1 && mt>140");
83  auto tt2l = Process::MakeShared<Baby_full>("t#bar{t}(2l)",
84  Process::Type::background, kGreen+2, files_tt, baseline_2l && "ntruleps>=1");
85  auto ttlveto = Process::MakeShared<Baby_full>("t#bar{t}(lv), m_{T} > 140",
86  Process::Type::background, kOrange+1, files_tt, baseline_lveto && "ntruleps>=1");
87  auto tt2lveto = Process::MakeShared<Baby_full>("t#bar{t}(2l or 1l+trk)",
88  Process::Type::background, kPink+2, files_tt, (baseline_lveto || baseline_2l) && "ntruleps>=1");
89 
90  auto tt1l_highmt_2trul = Process::MakeShared<Baby_full>("t#bar{t}(1l), m_{T} > 140, tru: 2l",
91  Process::Type::background, colors("tt_2l"), files_tt,
92  baseline_1l && "ntruleps>=1 && ntruels+ntrumus+ntrutausl==2 && mt>140");
93  auto tt1l_highmt_1trul_1trutauh = Process::MakeShared<Baby_full>("t#bar{t}(1l), m_{T} > 140, tru: l#tau_{h}",
94  Process::Type::background, kBlue-6, files_tt,
95  baseline_1l && "ntruleps>=1 && ntruels+ntrumus+ntrutausl==1 && ntrutaush==1 && mt>140");
96  auto tt1l_highmt_1trul = Process::MakeShared<Baby_full>("t#bar{t}(1l), m_{T} > 140, tru: 1l",
97  Process::Type::background, kTeal-6, files_tt,
98  baseline_1l && "ntruleps>=1 && ntruels+ntrumus+ntrutausl==1 && ntrutaush==0 && mt>140");
99 
100  auto bkg1l_lowmt = Process::MakeShared<Baby_full>("Tot. bkgd (1l), m_{T}#leq140",
101  Process::Type::background, kGray+3, files_all, baseline_1l && "mt<=140");
102  bkg1l_lowmt->SetLineStyle(2);
103  auto bkg1l_highmt = Process::MakeShared<Baby_full>("Tot. bkgd (1l), m_{T}>140",
104  Process::Type::background, kGray+3, files_all, baseline_1l && "mt>140");
105  auto bkg2l = Process::MakeShared<Baby_full>("Tot. bkgd (2l)",
106  Process::Type::background, kGreen-5, files_all, baseline_2l);
107  auto bkglveto = Process::MakeShared<Baby_full>("Tot. bkgd (lv), m_{T} > 140",
108  Process::Type::background, kOrange+1, files_all, baseline_lveto);
109 
110  auto wjets1l_lowmt = Process::MakeShared<Baby_full>("W+jets (1l), m_{T}#leq140",
111  Process::Type::background, colors("wjets"), files_wjets, baseline_1l && "mt<=140");
112  // wjets1l_lowmt->SetLineStyle(2);
113  auto st1l_lowmt = Process::MakeShared<Baby_full>("Single t (1l), m_{T}#leq140",
114  Process::Type::background, colors("single_t"), files_st, baseline_1l && "mt<=140");
115  // st1l_lowmt->SetLineStyle(2);
116  auto other1l_lowmt = Process::MakeShared<Baby_full>("Other (1l), m_{T}#leq140",
117  Process::Type::background, colors("other"), files_other, baseline_1l && "mt<=140");
118  // other1l_lowmt->SetLineStyle(2);
119  auto nontt2l = Process::MakeShared<Baby_full>("Non-t#bar{t} (2l)",
120  Process::Type::background, colors("other"), files_nontt, baseline_2l);
121  auto nontt1l_highmt = Process::MakeShared<Baby_full>("Non-t#bar{t} (1l), m_{T}>140",
122  Process::Type::background, colors("other"), files_nontt, baseline_1l && "mt>140");
123 
124  map<string, vector<shared_ptr<Process> > > procs, procs_pie, procs_isr;
125  // compare the shapes of the low-mT components: tt, st, w, other
126  procs["lowmt"] = vector<shared_ptr<Process> >({tt1l_lowmt, other1l_lowmt, st1l_lowmt, wjets1l_lowmt});
127  procs_pie["lowmt"] = vector<shared_ptr<Process> >({tt1l_lowmt, other1l_lowmt, st1l_lowmt, wjets1l_lowmt});
128  // compare the tt@low-mT shape to the high-mT components: tru 2l, tru 1l+tauh, non-tt
129  procs["highmt"] = vector<shared_ptr<Process> >({tt1l_lowmt, tt1l_highmt_2trul,
130  tt1l_highmt_1trul_1trutauh, tt1l_highmt_1trul, nontt1l_highmt});
131  procs_pie["highmt"] = vector<shared_ptr<Process> >({tt1l_highmt_2trul,
132  tt1l_highmt_1trul_1trutauh, tt1l_highmt_1trul, nontt1l_highmt});
133  // compare the tt@low-mT shape to the dilepton test pieces: tt 2l, non-tt 2l and lveto
134  procs["dilep"] = vector<shared_ptr<Process> >({tt1l_lowmt, nontt2l, ttlveto, tt2l});
135  procs_pie["dilep"] = vector<shared_ptr<Process> >({nontt2l, ttlveto, tt2l});
136  // compare full background: low-mT, high-mT, 2l and lveto
137  procs["totbkg"] = vector<shared_ptr<Process> >({bkg1l_lowmt, bkg2l, bkglveto, bkg1l_highmt});
138  procs_pie["totbkg"] = vector<shared_ptr<Process> >({bkg2l, bkglveto, bkg1l_highmt});
139 
140  procs["2lonly"] = vector<shared_ptr<Process> >({tt1l_lowmt, tt1l_highmt, tt2l, tt2lveto});
141 
142  vector<NamedFunc> metbins;
143  if (do_met150) metbins.push_back(NamedFunc("met>150&&met<=200"));
144  if (do_metbins) {
145  metbins.push_back(NamedFunc("met>200&&met<=350"));
146  metbins.push_back(NamedFunc("met>350&&met<=500"));
147  metbins.push_back(NamedFunc("met>500"));
148  } else {
149  metbins.push_back(NamedFunc("met>150"));
150  metbins.push_back(NamedFunc("met>200"));
151  }
152 
153  vector<string> nobjbins;
154  if (do_njbins) {
155  nobjbins.push_back("njets+nleps==6");
156  nobjbins.push_back("njets+nleps>=7 && njets+nleps<=9");
157  nobjbins.push_back("njets+nleps>=10");
158  } else {
159  nobjbins.push_back("njets+nleps>=7");
160  }
161 
162  PlotMaker pm;
163  for (auto &iht: {"ht>500","st>500"}){
164  for (auto &iproc:procs){
165  vector<TableRow> table_cuts;
166  for (auto &imet: metbins) {
167  for (auto &inobj: nobjbins) {
168  // no dilepton test for njets==5
169  if(iproc.first == "dilep" && Contains(inobj,"==6")) continue;
170  vector<shared_ptr<Process> > procs_tmp = iproc.second;
171  //similarly, remove 2l for njets==5 category
172  if (iproc.first == "totbkg" && Contains(inobj,"==6"))
173  procs_tmp = vector<shared_ptr<Process> >({bkg1l_lowmt, bkglveto, bkg1l_highmt});
174  // histograms
175  NamedFunc icut = imet && inobj && iht;
176  pm.Push<HistoStack>(HistoDef(iproc.first,
177  15, 100., 700., "mj14", "M_{J} [GeV]", icut, "weight", {250.,400.}), procs_tmp, plot_types);
178  } // loop over nobj bins
179  } // loop over met bins
180  } // loop over proc sets
181  }
182  pm.min_print_ = true;
183  pm.MakePlots(lumi, "mjshapes");
184 
185  double seconds = (chrono::duration<double>(chrono::high_resolution_clock::now() - begTime)).count();
186  TString hhmmss = HoursMinSec(seconds);
187  cout<<endl<<"Making plots took "<<round(seconds)<<" seconds ("<<hhmmss<<")"<<endl<<endl;
188 }
189 
PlotOpt & Stack(PlotOptTypes::StackType stack_type)
Definition: plot_opt.cpp:120
PlotOpt & YAxis(PlotOptTypes::YAxisType y_axis_type)
Definition: plot_opt.cpp:102
TString HoursMinSec(float fseconds)
Definition: utilities.cpp:337
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
FigureType & Push(Args &&...args)
Definition: plot_maker.hpp:24
bool min_print_
Definition: plot_maker.hpp:44
Organizes efficient production of plots with single loop over each process.
Definition: plot_maker.hpp:14
PlotOpt & Bottom(PlotOptTypes::BottomType bottom_type)
Definition: plot_opt.cpp:93
PlotOpt & RatioMaximum(double ratio_maximum)
Definition: plot_opt.cpp:368
void MakePlots(double luminosity, const std::string &subdir="")
Prints all added plots with given luminosity.
Definition: plot_maker.cpp:54
PlotOpt & Title(PlotOptTypes::TitleType title_type)
Definition: plot_opt.cpp:111
Loads colors from a text configuration file.
Definition: palette.hpp:8