ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
plot_2016-08-01_mjshapes_systematics_talk.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 "plot_maker.hpp"
9 #include "plot_opt.hpp"
10 #include "palette.hpp"
11 #include "histo_stack.hpp"
12 #include "event_scan.hpp"
13 #include "utilities.hpp"
14 
15 using namespace std;
16 using namespace PlotOptTypes;
17 
18 int main(){
19  gErrorIgnoreLevel = 6000;
20 
21  chrono::high_resolution_clock::time_point begTime;
22  begTime = chrono::high_resolution_clock::now();
23 
24  double lumi = 2.6;
25  string bfolder("");
26  string hostname(execute("echo $HOSTNAME"));
27  if(Contains(hostname, "cms") || Contains(hostname, "compute-"))
28  bfolder = "/net/cms2"; // In laptops, you can't create a /net folder
29 
30  Palette colors("txt/colors.txt", "default");
31 
32  string folder_mc(bfolder+"/cms2r0/babymaker/babies/2016_06_14/mc/merged_nl1st500met150nj5/");
33 
34  set<string> files_tt({folder_mc+"*_TTJets*Lept*.root", folder_mc+"*_TTJets_HT*.root"});
35  set<string> files_wjets({folder_mc+"*_WJetsToLNu*.root"});
36  set<string> files_st({folder_mc+"*_ST_*.root"});
37  set<string> files_other({
38  folder_mc+"*DYJetsToLL*.root", folder_mc+"*_QCD_HT*.root",
39  folder_mc+"*_ZJet*.root", folder_mc+"*_WWTo*.root",
40  folder_mc+"*ggZH_HToBB*.root", folder_mc+"*ttHJetTobb*.root",
41  folder_mc+"*_TTGJets*.root", folder_mc+"*_TTTT_*.root",
42  folder_mc+"*_TTWJets*.root", folder_mc+"*_TTZTo*.root",
43  folder_mc+"*_WH_HToBB*.root", folder_mc+"*_WZTo*.root",
44  folder_mc+"*_ZH_HToBB*.root", folder_mc+"_ZZ_*.root"});
45 
46  set<string> files_nontt(files_other);
47  files_nontt.insert(files_wjets.begin(), files_wjets.end());
48  files_nontt.insert(files_st.begin(), files_st.end());
49 
50  set<string> files_all(files_nontt);
51  files_all.insert(files_tt.begin(), files_tt.end());
52 
53  PlotOpt log_shapes("txt/plot_styles.txt", "CMSPaper");
54  log_shapes.Title(TitleType::info)
55  .Bottom(BottomType::ratio)
56  .YAxis(YAxisType::log)
57  .Stack(StackType::shapes)
58  .RatioMaximum(2.4);
59  PlotOpt lin_shapes = log_shapes().YAxis(YAxisType::linear);
60  vector<PlotOpt> plot_types = {lin_shapes};
61 
62  NamedFunc baseline_1l = "stitch && nleps==1 && nveto==0 && nbm>=1 && weight<1";
63  NamedFunc baseline_2l = "stitch && nleps==2";
64  NamedFunc baseline_lveto = "stitch && nleps==1 && nveto==1 && nbm>=1 && mt>140";
65 
66  auto tt1l_lowmt = Process::MakeShared<Baby_full>("t#bar{t}(1l), m_{T} #leq 140",
67  Process::Type::background, colors("tt_1l"), files_tt, baseline_1l && "ntruleps>=1 && mt<=140");
68  auto tt1l_highmt = Process::MakeShared<Baby_full>("t#bar{t}(1l), m_{T} > 140",
69  Process::Type::background, colors("tt_1l"), files_tt, baseline_1l && "ntruleps>=1 && mt>140");
70  auto tt2l = Process::MakeShared<Baby_full>("t#bar{t}(2l)",
71  Process::Type::background, kGreen+2, files_tt, baseline_2l && "ntruleps>=1");
72  auto ttlveto = Process::MakeShared<Baby_full>("t#bar{t}(lv), m_{T} > 140",
73  Process::Type::background, kOrange+1, files_tt, baseline_lveto && "ntruleps>=1");
74 
75  auto tt1l_highmt_2trul = Process::MakeShared<Baby_full>("t#bar{t}(1l), m_{T} > 140, tru: 2l",
76  Process::Type::background, colors("tt_2l"), files_tt,
77  baseline_1l && "ntruleps>=1 && ntruels+ntrumus+ntrutausl==2 && mt>140");
78  auto tt1l_highmt_1trul_1trutauh = Process::MakeShared<Baby_full>("t#bar{t}(1l), m_{T} > 140, tru: l#tau_{h}",
79  Process::Type::background, kBlue-6, files_tt,
80  baseline_1l && "ntruleps>=1 && ntruels+ntrumus+ntrutausl==1 && ntrutaush==1 && mt>140");
81  auto tt1l_highmt_1trul = Process::MakeShared<Baby_full>("t#bar{t}(1l), m_{T} > 140, tru: 1l",
82  Process::Type::background, kTeal-6, files_tt,
83  baseline_1l && "ntruleps>=1 && ntruels+ntrumus+ntrutausl==1 && ntrutaush==0 && mt>140");
84 
85  auto bkg1l_lowmt = Process::MakeShared<Baby_full>("Tot. bkgd (1l), m_{T}#leq140",
86  Process::Type::background, kGray+3, files_all, baseline_1l && "mt<=140");
87  bkg1l_lowmt->SetLineStyle(2);
88  auto bkg1l_highmt = Process::MakeShared<Baby_full>("Tot. bkgd (1l), m_{T}>140",
89  Process::Type::background, kGray+3, files_all, baseline_1l && "mt>140");
90  auto bkg2l = Process::MakeShared<Baby_full>("Tot. bkgd (2l)",
91  Process::Type::background, kGreen-5, files_all, baseline_2l);
92  auto bkglveto = Process::MakeShared<Baby_full>("Tot. bkgd (lv), m_{T} > 140",
93  Process::Type::background, kOrange+1, files_all, baseline_lveto);
94 
95  auto wjets1l_lowmt = Process::MakeShared<Baby_full>("W+jets (1l), m_{T}#leq140",
96  Process::Type::background, colors("wjets"), files_wjets, baseline_1l && "mt<=140");
97  //wjets1l_lowmt->SetLineStyle(2);
98  auto st1l_lowmt = Process::MakeShared<Baby_full>("Single t (1l), m_{T}#leq140",
99  Process::Type::background, colors("single_t"), files_st, baseline_1l && "mt<=140");
100  //st1l_lowmt->SetLineStyle(2);
101  auto other1l_lowmt = Process::MakeShared<Baby_full>("Other (1l), m_{T}#leq140",
102  Process::Type::background, colors("other"), files_other, baseline_1l && "mt<=140");
103  //other1l_lowmt->SetLineStyle(2);
104  auto nontt2l = Process::MakeShared<Baby_full>("Non-t#bar{t} (2l)",
105  Process::Type::background, colors("other"), files_nontt, baseline_2l);
106  auto nontt1l_highmt = Process::MakeShared<Baby_full>("Non-t#bar{t} (1l), m_{T}>140",
107  Process::Type::background, colors("other"), files_nontt, baseline_1l && "mt>140");
108 
109  map<string, vector<shared_ptr<Process> > > procs;
110  procs["totbkg"] = vector<shared_ptr<Process> >({bkg1l_lowmt, bkglveto, bkg2l, bkg1l_highmt});
111  procs["dilep"] = vector<shared_ptr<Process> >({tt1l_lowmt, nontt2l, ttlveto, tt2l});
112  procs["lowmt"] = vector<shared_ptr<Process> >({tt1l_lowmt, other1l_lowmt, st1l_lowmt, wjets1l_lowmt});
113  procs["highmt"] = vector<shared_ptr<Process> >({tt1l_lowmt, tt1l_highmt_2trul,
114  tt1l_highmt_1trul_1trutauh, tt1l_highmt_1trul, nontt1l_highmt});
115 
116  vector<NamedFunc> htopt;
117  htopt.push_back(NamedFunc("ht"));
118  htopt.push_back(NamedFunc("st", [](const Baby &b) -> NamedFunc::ScalarType{
119  float st = b.ht();
120  for (const auto &pt: *(b.leps_pt())) st += pt;
121  return st;
122  }));
123  htopt.push_back(NamedFunc("ht1l_stmin2l", [](const Baby &b) -> NamedFunc::ScalarType{
124  float ht_proxy = b.ht();
125  if (b.nleps()==2) ht_proxy = b.ht()+b.leps_pt()->at(1);
126  return ht_proxy;
127  }));
128  htopt.push_back(NamedFunc("ht1l_stmax2l", [](const Baby &b) -> NamedFunc::ScalarType{
129  float ht_proxy = b.ht();
130  if (b.nleps()==2) ht_proxy = b.ht()+b.leps_pt()->at(0);
131  return ht_proxy;
132  }));
133  htopt.push_back(NamedFunc("ht1l_stave2l", [](const Baby &b) -> NamedFunc::ScalarType{
134  float ht_proxy = b.ht();
135  if (b.nleps()==2) ht_proxy = b.ht()+(b.leps_pt()->at(0)+b.leps_pt()->at(1))/2.;
136  return ht_proxy;
137  }));
138 
139  int Nplots=0;
140  PlotMaker pm;
141  for (auto mj_lep: {true}){
142  vector<string> nobj_cuts;
143  if (mj_lep){
144  nobj_cuts.push_back("met>200&&njets+nleps==6");
145  nobj_cuts.push_back("met>200&&njets+nleps>=7 && njets+nleps<=9");
146  nobj_cuts.push_back("met>200&&njets+nleps>=10");
147  nobj_cuts.push_back("met>150&&met<=200&&njets+nleps==6");
148  nobj_cuts.push_back("met>150&&met<=200&&njets+nleps>=7 && njets+nleps<=9");
149  nobj_cuts.push_back("met>150&&met<=200&&njets+nleps>=10");
150  } else {
151  nobj_cuts.push_back("njets>=6 && njets<=8");
152  nobj_cuts.push_back("njets>=9");
153  }
154 
155  string var("mj14"), xtitle("M_{J} [GeV]");
156  //if (!mj_lep) {var = "mj14"; xtitle = "M_{J} (no lep) [GeV]";}
157  for (auto &iht: htopt){
158  for (auto &iproc:procs){
159  for (auto inobj: nobj_cuts) {
160  if(iproc.first == "dilep" && Contains(inobj,"==6")) continue;
161  pm.Push<HistoStack>(HistoDef(iproc.first+"_"+iht.PlainName(),
162  10, 100., 850., var, xtitle, inobj && iht>500, "weight", {250.,400.}), iproc.second, plot_types);
163  Nplots++;
164  }
165  }
166  }
167  }
168  pm.min_print_ = true;
169  pm.MakePlots(lumi);
170 
171  double seconds = (chrono::duration<double>(chrono::high_resolution_clock::now() - begTime)).count();
172  TString hhmmss = HoursMinSec(seconds);
173  cout<<endl<<"Making "<<Nplots<<" plots took "<<round(seconds)<<" seconds ("<<hhmmss<<")"<<endl<<endl;
174 }
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
std::vector< float > *const & leps_pt() const
Get leps_pt for current event and cache it.
Definition: baby.cpp:4493
int const & nleps() const
Get nleps for current event and cache it.
Definition: baby.cpp:6053
Abstract base class for access to ntuple variables.
Definition: baby.hpp:16
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
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
const NamedFunc st("st", [](const Baby &b) -> NamedFunc::ScalarType{float stvar=b.ht();for(const auto &pt:*(b.leps_pt())) stvar+=pt;return stvar;})
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
float const & ht() const
Get ht for current event and cache it.
Definition: baby.cpp:3929
Loads colors from a text configuration file.
Definition: palette.hpp:8