ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
plot_2016-10-05_mjshapes_systematics_richstu.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/hist1d.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 = true;
22  bool do_met150 = true;
23  bool do_met100 = true;
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  string ntupletag="metG200";
39  if(do_met150 && do_met100) ntupletag="";
40  string foldermc(bfolder+"/cms2r0/babymaker/babies/2016_08_10/mc/merged_mcbase_met100_stdnj5/");
41 
42  Palette colors("txt/colors.txt", "default");
43 
44 
45  NamedFunc baseline = "stitch && nleps==1 && nveto==0 && st>500 && met>100 && njets>=5 && nbm>=1 && weight<1";
46 
47  set<string> allfiles = {foldermc+"*_TTJets*Lept*"+ntupletag+"*.root", foldermc+"*_TTJets_HT*"+ntupletag+"*.root",
48  foldermc+"*_WJetsToLNu*"+ntupletag+"*.root",foldermc+"*_ST_*"+ntupletag+"*.root",
49  foldermc+"*_TTW*"+ntupletag+"*.root",foldermc+"*_TTZ*"+ntupletag+"*.root",
50  foldermc+"*_TTGJets*"+ntupletag+"*.root",foldermc+"*_TTTT*"+ntupletag+"*.root",
51  foldermc+"*QCD_HT*Inf_Tune*"+ntupletag+"*.root",
52  foldermc+"*QCD_HT*0_Tune*"+ntupletag+"*.root",foldermc+"*DYJetsToLL*"+ntupletag+"*.root",
53  foldermc+"*_ZJet*"+ntupletag+"*.root",foldermc+"*_ttHJetTobb*"+ntupletag+"*.root",
54  foldermc+"*_WH_HToBB*"+ntupletag+"*.root",foldermc+"*_ZH_HToBB*"+ntupletag+"*.root",
55  foldermc+"*_WWTo*"+ntupletag+"*.root",foldermc+"*_WZ*"+ntupletag+"*.root",
56  foldermc+"*_ZZ_*"+ntupletag+"*.root"
57  };
58 
59  set<string> ttfiles = {foldermc+"*_TTJets*Lept*"+ntupletag+"*.root", foldermc+"*_TTJets_HT*"+ntupletag+"*.root"};
60  set<string> wfiles = {foldermc+"*_WJetsToLNu*"+ntupletag+"*.root"};
61  // set<string> stfiles = {foldermc+"*_ST_*"+ntupletag+"*.root"};
62  set<string> otherfiles = {foldermc+"*_ST_*"+ntupletag+"*.root", foldermc+"*_TTW*"+ntupletag+"*.root",foldermc+"*_TTZ*"+ntupletag+"*.root",
63  foldermc+"*_TTGJets*"+ntupletag+"*.root",foldermc+"*_TTTT*"+ntupletag+"*.root",
64  foldermc+"*QCD_HT*Inf_Tune*"+ntupletag+"*.root",
65  foldermc+"*QCD_HT*0_Tune*"+ntupletag+"*.root",foldermc+"*DYJetsToLL*"+ntupletag+"*.root",
66  foldermc+"*_ZJet*"+ntupletag+"*.root",foldermc+"*_ttHJetTobb*"+ntupletag+"*.root",
67  foldermc+"*_WH_HToBB*"+ntupletag+"*.root",foldermc+"*_ZH_HToBB*"+ntupletag+"*.root",
68  foldermc+"*_WWTo*"+ntupletag+"*.root",foldermc+"*_WZ*"+ntupletag+"*.root",
69  foldermc+"*_ZZ_*"+ntupletag+"*.root"};
70 
71  auto proc_2l = Process::MakeShared<Baby_full>("tru 2l", Process::Type::background, kPink-2,
72  allfiles, baseline && "stitch && ntruleps>=2");
73  auto proc_1lgood = Process::MakeShared<Baby_full>("tru 1l m_{T}-m_{T}^{tru}#leq60", Process::Type::background, kPink-6,
74  allfiles, baseline && "stitch && ntruleps==1 && mt-mt_tru<=60");
75  auto proc_1lbad = Process::MakeShared<Baby_full>("tru 1l m_{T}-m_{T}^{tru}>60", Process::Type::background, kBlue+1,
76  allfiles, baseline && "stitch && ntruleps==1 && mt-mt_tru>60");
77 
78  auto proc_2l_himt = Process::MakeShared<Baby_full>("True 2l, m_{T}>140", Process::Type::background,kCyan-3, //kGreen+1,
79  allfiles, baseline && "stitch && ntruleps>=2 && mt>140");
80  auto proc_1lgood_himt = Process::MakeShared<Baby_full>("tru 1l well meas. m_{T}>140", Process::Type::background, kGreen-3,
81  allfiles, baseline && "stitch && ntruleps==1 && mt_tru>=140 && mt>140");
82  auto proc_1lbad_himt = Process::MakeShared<Baby_full>("tru 1l mismeas. m_{T}>140", Process::Type::background, kRed,
83  allfiles, baseline && "stitch && ntruleps==1 && mt_tru<=140 && mt>140");
84  auto proc_0l_himt = Process::MakeShared<Baby_full>("True 0l, m_{T}>140", Process::Type::background,colors("other"),
85  allfiles, baseline && "stitch && ntruleps==0 && mt>140");
86 
88  auto proc_lomt = Process::MakeShared<Baby_full>("All bkg. m_{T}#leq140", Process::Type::background, 1,
89  allfiles, baseline && "stitch && mt<=140");
90  auto proc_tt_lomt = Process::MakeShared<Baby_full>("t#bar{t} m_{T}#leq140", Process::Type::background, 1,
91  ttfiles, baseline && "stitch && mt<=140 && ntruleps==1");
92 
94  auto proc_1l_himt = Process::MakeShared<Baby_full>("True 1l, m_{T}>140", Process::Type::background,colors("tt_1l"),
95  allfiles, baseline && "stitch && ntruleps==1 && mt>140");
96  auto proc_01l_himt = Process::MakeShared<Baby_full>("True 0-1l, m_{T}>140", Process::Type::background,kRed+1,
97  allfiles, baseline && "stitch && ntruleps<=1 && mt>140");
98 
100  auto proc_tt2l_himt = Process::MakeShared<Baby_full>("t#bar{t} 2l, m_{T}>140", Process::Type::background,
101  colors("tt_2l"), ttfiles,
102  baseline && "stitch && ntruleps>=2 && mt>140");
103  auto proc_tt1l_himt = Process::MakeShared<Baby_full>("t#bar{t} 1l, m_{T}>140", Process::Type::background,
104  colors("tt_1l"), ttfiles,
105  baseline && "stitch && ntruleps==1 && mt>140");
106  auto proc_w_himt = Process::MakeShared<Baby_full>("W+jets, m_{T}>140", Process::Type::background,
107  colors("wjets"), wfiles,
108  baseline && "stitch && mt>140");
109  // auto proc_st_himt = Process::MakeShared<Baby_full>("Single t, m_{T}>140", Process::Type::background,
110  // colors("single_t"), stfiles,
111  // baseline && "stitch && mt>140");
112  auto proc_other_himt = Process::MakeShared<Baby_full>("Other, m_{T}>140", Process::Type::background,
113  colors("other"), otherfiles,
114  baseline && "stitch && mt>140");
115 
116 
117  //vector<shared_ptr<Process> > all_procs = {proc_1lgood, proc_2l, proc_1lbad, proc_0l};
118  vector<shared_ptr<Process> > goodbad_procs = {proc_lomt, proc_1lbad_himt, proc_1lgood_himt, proc_2l_himt};
119  vector<shared_ptr<Process> > goodbad0_procs = {proc_lomt, proc_0l_himt, proc_1lbad_himt, proc_1lgood_himt, proc_2l_himt};
120  vector<shared_ptr<Process> > proc_procs = {proc_lomt, proc_other_himt,
121  proc_w_himt, proc_tt1l_himt, proc_tt2l_himt};
122  vector<shared_ptr<Process> > lep_procs = {proc_lomt, proc_01l_himt, proc_2l_himt};
123 
124  PlotOpt log_shapes("txt/plot_styles.txt", "CMSPaper");
125  log_shapes.Title(TitleType::info)
126  .Bottom(BottomType::ratio)
127  .YAxis(YAxisType::log)
128  .Stack(StackType::shapes)
129  .RatioMaximum(2.8);
130  PlotOpt lin_shapes = log_shapes().YAxis(YAxisType::linear);
131  vector<PlotOpt> plot_types = {lin_shapes};
132 
133 
134  vector<NamedFunc> metbins;
135  if (do_met100) metbins.push_back(NamedFunc("met>100&&met<=150"));
136  if (do_met150) metbins.push_back(NamedFunc("met>150&&met<=200"));
137  if (do_metbins) {
138  metbins.push_back(NamedFunc("met>200&&met<=350"));
139  metbins.push_back(NamedFunc("met>350&&met<=500"));
140  metbins.push_back(NamedFunc("met>500"));
141  } else {
142  metbins.push_back(NamedFunc("met>200"));
143  }
144  vector<string> nobjbins;
145  nobjbins = vector<string>();
146  // nobjbins.push_back("njets==5");
147  // nobjbins.push_back("njets>=6 && njets<=8");
148  // nobjbins.push_back("njets>=9");
149  nobjbins.push_back("njets>=6");
150  nobjbins.push_back("njets>=9");
151 
152  int Nplots=0;
153  PlotMaker pm;
154  for (auto &imet: metbins) {
155  for (auto &inobj: nobjbins) {
156  NamedFunc icut = imet && inobj;
157  pm.Push<Hist1D>(Axis(10, 100., 850., "mj14", "M_{J} [GeV]", {250., 400.}),
158  icut, goodbad_procs, plot_types).Tag("thin_goodbad");
159  pm.Push<Hist1D>(Axis(10, 100., 850., "mj14", "M_{J} [GeV]", {250., 400.}),
160  icut, goodbad0_procs, plot_types).Tag("thin_goodbad0");
161  pm.Push<Hist1D>(Axis(10, 100., 850., "mj14", "M_{J} [GeV]", {250., 400.}),
162  icut, proc_procs, plot_types).Tag("thin_proc");
163  pm.Push<Hist1D>(Axis(10, 100., 850., "mj14", "M_{J} [GeV]", {250., 400.}),
164  icut, lep_procs, plot_types).Tag("thin_lep");
165 
166  pm.Push<Hist1D>(Axis(5, 100., 850., "mj14", "M_{J} [GeV]", {250., 400.}),
167  icut, goodbad_procs, plot_types).Tag("fat_goodbad");
168  pm.Push<Hist1D>(Axis(5, 100., 850., "mj14", "M_{J} [GeV]", {250., 400.}),
169  icut, goodbad0_procs, plot_types).Tag("fat_goodbad0");
170  pm.Push<Hist1D>(Axis(5, 100., 850., "mj14", "M_{J} [GeV]", {250., 400.}),
171  icut, proc_procs, plot_types).Tag("fat_proc");
172  pm.Push<Hist1D>(Axis(5, 100., 850., "mj14", "M_{J} [GeV]", {250., 400.}),
173  icut, lep_procs, plot_types).Tag("fat_lep");
174 
175  // pm.Push<Hist1D>(Axis(10, 100., 850., "mj14", "M_{J} [GeV]", {250., 400.}),
176  // icut, lep_procs, plot_types).Tag("lep");
177  // pm.Push<Hist1D>(Axis(12, 0., 420., "mt", "m_{T} [GeV]", {140.}),
178  // icut, all_procs, plot_types).Tag("mt");
179  Nplots += 1;
180  } // Loop over nobj bins
181  } // Loop over met bins
182  pm.min_print_ = true;
183  pm.MakePlots(lumi);
184 
185 
186 
187  double seconds = (chrono::duration<double>(chrono::high_resolution_clock::now() - begTime)).count();
188  TString hhmmss = HoursMinSec(seconds);
189  cout<<endl<<"Making "<<Nplots<<" plots took "<<round(seconds)<<" seconds ("<<hhmmss<<")"<<endl<<endl;
190 }
191 
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
Definition: axis.hpp:12
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
A full 1D plot with stacked/overlayed histograms.
Definition: hist1d.hpp:23
void MakePlots(double luminosity, const std::string &subdir="")
Prints all added plots with given luminosity.
Definition: plot_maker.cpp:54
Hist1D & Tag(const std::string &tag)
Definition: hist1d.cpp:512
PlotOpt & Title(PlotOptTypes::TitleType title_type)
Definition: plot_opt.cpp:111
Loads colors from a text configuration file.
Definition: palette.hpp:8