ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
plot_2016-08-31_mjshapes_stchecks.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 
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 ntupletag="_metG200";
33  string ntupletag="";
34  //string folder_mc(bfolder+"/cms2r0/babymaker/babies/2016_08_10/mc/merged_mcbase_stdnj5/");
35  string folder_mc(bfolder+"/cms2r0/babymaker/babies/2016_06_14/mc/merged_nl1st500met150nj5/");
36 
37  //speed up if met 150-200 not needed
38  //if (!do_met150) ntupletag = "_metG150";
39 
40  set<string> files_tt({folder_mc+"*_TTJets*Lept*"+ntupletag+"*.root",
41  folder_mc+"*_TTJets_HT*"+ntupletag+"*.root"});
42  set<string> files_wjets({folder_mc+"*_WJetsToLNu*"+ntupletag+"*.root"});
43  set<string> files_st({folder_mc+"*_ST_*"+ntupletag+"*.root"});
44  set<string> files_other({
45  folder_mc+"*DYJetsToLL*"+ntupletag+"*.root", folder_mc+"*_QCD_HT*"+ntupletag+"*.root",
46  folder_mc+"*_ZJet*"+ntupletag+"*.root", folder_mc+"*_WWTo*"+ntupletag+"*.root",
47  folder_mc+"*ggZH_HToBB*"+ntupletag+"*.root", folder_mc+"*ttHJetTobb*"+ntupletag+"*.root",
48  folder_mc+"*_TTGJets*"+ntupletag+"*.root", folder_mc+"*_TTTT_*"+ntupletag+"*.root",
49  folder_mc+"*_TTWJets*"+ntupletag+"*.root", folder_mc+"*_TTZTo*"+ntupletag+"*.root",
50  folder_mc+"*_WH_HToBB*"+ntupletag+"*.root", folder_mc+"*_WZTo*"+ntupletag+"*.root",
51  folder_mc+"*_ZH_HToBB*"+ntupletag+"*.root", folder_mc+"_ZZ_*"+ntupletag+"*.root"});
52 
53  set<string> files_nontt(files_other);
54  files_nontt.insert(files_wjets.begin(), files_wjets.end());
55  files_nontt.insert(files_st.begin(), files_st.end());
56 
57  set<string> files_all(files_nontt);
58  files_all.insert(files_tt.begin(), files_tt.end());
59 
60  PlotOpt log_shapes("txt/plot_styles.txt", "CMSPaper");
61  log_shapes.Title(TitleType::info)
62  .Bottom(BottomType::ratio)
63  .YAxis(YAxisType::log)
64  .Stack(StackType::shapes)
65  .RatioMaximum(2.4);
66  PlotOpt lin_shapes = log_shapes().YAxis(YAxisType::linear);
67  vector<PlotOpt> plot_types = {lin_shapes};
68 
69  NamedFunc baseline_1l = "stitch && nleps==1 && nveto==0 && nbm>=1 && weight<1";
70  NamedFunc baseline_2l = "stitch && nleps==2";
71  NamedFunc baseline_lveto = "stitch && nleps==1 && nveto==1 && nbm>=1 && mt>140";
72 
73  auto tt1l_lowmt = Process::MakeShared<Baby_full>("t#bar{t}(1l), m_{T} #leq 140",
74  Process::Type::background, colors("tt_1l"), files_tt, baseline_1l && "ntruleps>=1 && mt<=140");
75  auto tt1l_highmt = Process::MakeShared<Baby_full>("t#bar{t}(1l), m_{T} > 140",
76  Process::Type::background, colors("tt_1l"), files_tt, baseline_1l && "ntruleps>=1 && mt>140");
77  auto tt2l = Process::MakeShared<Baby_full>("t#bar{t}(2l)",
78  Process::Type::background, kGreen+2, files_tt, baseline_2l && "ntruleps>=1");
79  auto ttlveto = Process::MakeShared<Baby_full>("t#bar{t}(lv), m_{T} > 140",
80  Process::Type::background, kOrange+1, files_tt, baseline_lveto && "ntruleps>=1");
81 
82  auto tt1l_highmt_2trul = Process::MakeShared<Baby_full>("t#bar{t}(1l), m_{T} > 140, tru: 2l",
83  Process::Type::background, colors("tt_2l"), files_tt,
84  baseline_1l && "ntruleps>=1 && ntruels+ntrumus+ntrutausl==2 && mt>140");
85  auto tt1l_highmt_1trul_1trutauh = Process::MakeShared<Baby_full>("t#bar{t}(1l), m_{T} > 140, tru: l#tau_{h}",
86  Process::Type::background, kBlue-6, files_tt,
87  baseline_1l && "ntruleps>=1 && ntruels+ntrumus+ntrutausl==1 && ntrutaush==1 && mt>140");
88  auto tt1l_highmt_1trul = Process::MakeShared<Baby_full>("t#bar{t}(1l), m_{T} > 140, tru: 1l",
89  Process::Type::background, kTeal-6, files_tt,
90  baseline_1l && "ntruleps>=1 && ntruels+ntrumus+ntrutausl==1 && ntrutaush==0 && mt>140");
91 
92  auto bkg1l_lowmt = Process::MakeShared<Baby_full>("Tot. bkgd (1l), m_{T}#leq140",
93  Process::Type::background, kGray+3, files_all, baseline_1l && "mt<=140");
94  bkg1l_lowmt->SetLineStyle(2);
95  auto bkg1l_highmt = Process::MakeShared<Baby_full>("Tot. bkgd (1l), m_{T}>140",
96  Process::Type::background, kGray+3, files_all, baseline_1l && "mt>140");
97  auto bkg2l = Process::MakeShared<Baby_full>("Tot. bkgd (2l)",
98  Process::Type::background, kGreen-5, files_all, baseline_2l);
99  auto bkglveto = Process::MakeShared<Baby_full>("Tot. bkgd (lv), m_{T} > 140",
100  Process::Type::background, kOrange+1, files_all, baseline_lveto);
101 
102  auto wjets1l_lowmt = Process::MakeShared<Baby_full>("W+jets (1l), m_{T}#leq140",
103  Process::Type::background, colors("wjets"), files_wjets, baseline_1l && "mt<=140");
104  //wjets1l_lowmt->SetLineStyle(2);
105  auto st1l_lowmt = Process::MakeShared<Baby_full>("Single t (1l), m_{T}#leq140",
106  Process::Type::background, colors("single_t"), files_st, baseline_1l && "mt<=140");
107  //st1l_lowmt->SetLineStyle(2);
108  auto other1l_lowmt = Process::MakeShared<Baby_full>("Other (1l), m_{T}#leq140",
109  Process::Type::background, colors("other"), files_other, baseline_1l && "mt<=140");
110  //other1l_lowmt->SetLineStyle(2);
111  auto nontt2l = Process::MakeShared<Baby_full>("Non-t#bar{t} (2l)",
112  Process::Type::background, colors("other"), files_nontt, baseline_2l);
113  auto nontt1l_highmt = Process::MakeShared<Baby_full>("Non-t#bar{t} (1l), m_{T}>140",
114  Process::Type::background, colors("other"), files_nontt, baseline_1l && "mt>140");
115 
116  map<string, vector<shared_ptr<Process> > > procs;
117  procs["totbkg"] = vector<shared_ptr<Process> >({bkg1l_lowmt, bkglveto, bkg2l, bkg1l_highmt});
118  procs["dilep"] = vector<shared_ptr<Process> >({tt1l_lowmt, nontt2l, ttlveto, tt2l});
119  procs["lowmt"] = vector<shared_ptr<Process> >({tt1l_lowmt, other1l_lowmt, st1l_lowmt, wjets1l_lowmt});
120  procs["highmt"] = vector<shared_ptr<Process> >({tt1l_lowmt, tt1l_highmt_2trul,
121  tt1l_highmt_1trul_1trutauh, tt1l_highmt_1trul, nontt1l_highmt});
122 
123  vector<NamedFunc> htopt;
124  htopt.push_back(NamedFunc("ht"));
125  //htopt.push_back(NamedFunc("st"));
126  htopt.push_back(NamedFunc("st", [](const Baby &b) -> NamedFunc::ScalarType{
127  float st = b.ht();
128  for (const auto &pt: *(b.leps_pt())) st += pt;
129  return st;
130  }));
131  // htopt.push_back(NamedFunc("ht1l_stmin2l", [](const Baby &b) -> NamedFunc::ScalarType{
132  // float ht_proxy = b.ht();
133  // if (b.nleps()==2) ht_proxy = b.ht()+b.leps_pt()->at(1);
134  // return ht_proxy;
135  // }));
136  // htopt.push_back(NamedFunc("ht1l_stmax2l", [](const Baby &b) -> NamedFunc::ScalarType{
137  // float ht_proxy = b.ht();
138  // if (b.nleps()==2) ht_proxy = b.ht()+b.leps_pt()->at(0);
139  // return ht_proxy;
140  // }));
141  // htopt.push_back(NamedFunc("ht1l_stave2l", [](const Baby &b) -> NamedFunc::ScalarType{
142  // float ht_proxy = b.ht();
143  // if (b.nleps()==2) ht_proxy = b.ht()+(b.leps_pt()->at(0)+b.leps_pt()->at(1))/2.;
144  // return ht_proxy;
145  // }));
146 
147  int Nplots=0;
148  PlotMaker pm;
149  for (auto mj_lep: {true}){
150  vector<string> nobj_cuts;
151  if (mj_lep){
152  nobj_cuts.push_back("met>200&&njets+nleps==6");
153  nobj_cuts.push_back("met>200&&njets+nleps>=7 && njets+nleps<=9");
154  nobj_cuts.push_back("met>200&&njets+nleps>=10");
155  nobj_cuts.push_back("met>150&&met<=200&&njets+nleps==6");
156  nobj_cuts.push_back("met>150&&met<=200&&njets+nleps>=7 && njets+nleps<=9");
157  nobj_cuts.push_back("met>150&&met<=200&&njets+nleps>=10");
158  } else {
159  nobj_cuts.push_back("njets>=6 && njets<=8");
160  nobj_cuts.push_back("njets>=9");
161  }
162 
163  string var("mj14"), xtitle("M_{J} [GeV]");
164  //if (!mj_lep) {var = "mj14"; xtitle = "M_{J} (no lep) [GeV]";}
165  for (auto &iht: htopt){
166  for (auto &iproc:procs){
167  for (auto inobj: nobj_cuts) {
168  if(iproc.first == "dilep" && Contains(inobj,"==6")) continue;
169  pm.Push<HistoStack>(HistoDef(iproc.first+"_"+iht.PlainName(),
170  10, 100., 850., var, xtitle, inobj && iht>500, "weight", {250.,400.}), iproc.second, plot_types);
171  Nplots++;
172  }
173  }
174  }
175  }
176  pm.min_print_ = true;
177  pm.MakePlots(lumi);
178 
179  double seconds = (chrono::duration<double>(chrono::high_resolution_clock::now() - begTime)).count();
180  TString hhmmss = HoursMinSec(seconds);
181  cout<<endl<<"Making "<<Nplots<<" plots took "<<round(seconds)<<" seconds ("<<hhmmss<<")"<<endl<<endl;
182 }
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
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