27 gErrorIgnoreLevel = 6000;
29 chrono::high_resolution_clock::time_point begTime;
30 begTime = chrono::high_resolution_clock::now();
34 string hostname(
execute(
"echo $HOSTNAME"));
36 bfolder =
"/net/cms2";
38 string ntupletag=
"metG200";
40 string foldermc(bfolder+
"/cms2r0/babymaker/babies/2016_08_10/mc/merged_mcbase_met100_stdnj5/");
42 Palette colors(
"txt/colors.txt",
"default");
46 set<string> files_tt({folder_mc+
"*_TTJets*Lept*.root", folder_mc+
"*_TTJets_HT*.root"});
47 set<string> files_wjets({folder_mc+
"*_WJetsToLNu*.root"});
48 set<string> files_st({folder_mc+
"*_ST_*.root"});
49 set<string> files_other({
50 folder_mc+
"*DYJetsToLL*.root", folder_mc+
"*_QCD_HT*.root",
51 folder_mc+
"*_ZJet*.root", folder_mc+
"*_WWTo*.root",
52 folder_mc+
"*ggZH_HToBB*.root", folder_mc+
"*ttHJetTobb*.root",
53 folder_mc+
"*_TTGJets*.root", folder_mc+
"*_TTTT_*.root",
54 folder_mc+
"*_TTWJets*.root", folder_mc+
"*_TTZTo*.root",
55 folder_mc+
"*_WH_HToBB*.root", folder_mc+
"*_WZTo*.root",
56 folder_mc+
"*_ZH_HToBB*.root", folder_mc+
"_ZZ_*.root"});
58 NamedFunc baseline =
"stitch && nleps==1 && nveto==0 && st>500 && met>100 && njets>=5 && nbm>=1 && weight<1";
60 set<string> allfiles = {foldermc+
"*_TTJets*Lept*"+ntupletag+
"*.root", foldermc+
"*_TTJets_HT*"+ntupletag+
"*.root",
61 foldermc+
"*_WJetsToLNu*"+ntupletag+
"*.root",foldermc+
"*_ST_*"+ntupletag+
"*.root",
62 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" 72 set<string> ttfiles = {foldermc+
"*_TTJets*Lept*"+ntupletag+
"*.root", foldermc+
"*_TTJets_HT*"+ntupletag+
"*.root"};
73 set<string> wfiles = {foldermc+
"*_WJetsToLNu*"+ntupletag+
"*.root"};
75 set<string> otherfiles = {foldermc+
"*_ST_*"+ntupletag+
"*.root", foldermc+
"*_TTW*"+ntupletag+
"*.root",foldermc+
"*_TTZ*"+ntupletag+
"*.root",
76 foldermc+
"*_TTGJets*"+ntupletag+
"*.root",foldermc+
"*_TTTT*"+ntupletag+
"*.root",
77 foldermc+
"*QCD_HT*Inf_Tune*"+ntupletag+
"*.root",
78 foldermc+
"*QCD_HT*0_Tune*"+ntupletag+
"*.root",foldermc+
"*DYJetsToLL*"+ntupletag+
"*.root",
79 foldermc+
"*_ZJet*"+ntupletag+
"*.root",foldermc+
"*_ttHJetTobb*"+ntupletag+
"*.root",
80 foldermc+
"*_WH_HToBB*"+ntupletag+
"*.root",foldermc+
"*_ZH_HToBB*"+ntupletag+
"*.root",
81 foldermc+
"*_WWTo*"+ntupletag+
"*.root",foldermc+
"*_WZ*"+ntupletag+
"*.root",
82 foldermc+
"*_ZZ_*"+ntupletag+
"*.root"};
85 allfiles, baseline &&
"stitch && ntruleps>=2");
87 allfiles, baseline &&
"stitch && ntruleps==1 && mt-mt_tru<=60");
89 allfiles, baseline &&
"stitch && ntruleps==1 && mt-mt_tru>60");
92 allfiles, baseline &&
"stitch && ntruleps>=2 && mt>140");
93 auto proc_1lgood_himt = Process::MakeShared<Baby_full>(
"tru 1l well meas. m_{T}>140",
Process::Type::background, kGreen-3,
94 allfiles, baseline &&
"stitch && ntruleps==1 && mt_tru>=140 && mt>140");
96 allfiles, baseline &&
"stitch && ntruleps==1 && mt_tru<=140 && mt>140");
98 allfiles, baseline &&
"stitch && ntruleps==0 && mt>140");
102 allfiles, baseline &&
"stitch && mt<=140");
104 ttfiles, baseline &&
"stitch && mt<=140 && ntruleps==1");
108 allfiles, baseline &&
"stitch && ntruleps==1 && mt>140");
110 allfiles, baseline &&
"stitch && ntruleps<=1 && mt>140");
114 colors(
"tt_2l"), ttfiles,
115 baseline &&
"stitch && ntruleps>=2 && mt>140");
117 colors(
"tt_1l"), ttfiles,
118 baseline &&
"stitch && ntruleps==1 && mt>140");
120 colors(
"wjets"), wfiles,
121 baseline &&
"stitch && mt>140");
126 colors(
"other"), otherfiles,
127 baseline &&
"stitch && mt>140");
128 >>>>>>> b1f888b55e7125d5a772cc4a7067bd650781e35f
132 vector<shared_ptr<Process> > goodbad_procs = {proc_lomt, proc_1lbad_himt, proc_1lgood_himt, proc_2l_himt};
133 vector<shared_ptr<Process> > goodbad0_procs = {proc_lomt, proc_0l_himt, proc_1lbad_himt, proc_1lgood_himt, proc_2l_himt};
134 vector<shared_ptr<Process> > proc_procs = {proc_lomt, proc_other_himt,
135 proc_w_himt, proc_tt1l_himt, proc_tt2l_himt};
136 vector<shared_ptr<Process> > lep_procs = {proc_lomt, proc_01l_himt, proc_2l_himt};
138 PlotOpt log_shapes(
"txt/plot_styles.txt",
"CMSPaper");
139 log_shapes.
Title(TitleType::info)
141 .
Bottom(BottomType::ratio)
142 .
YAxis(YAxisType::log)
143 .
Stack(StackType::shapes)
145 PlotOpt lin_shapes = log_shapes().
YAxis(YAxisType::linear);
146 vector<PlotOpt> plot_types = {lin_shapes};
148 NamedFunc baseline_1l =
"stitch && nleps==1 && nveto==0 && nbm>=1 && weight<1";
149 NamedFunc baseline_2l =
"stitch && nleps==2";
150 NamedFunc baseline_lveto =
"stitch && nleps==1 && nveto==1 && nbm>=1 && mt>140";
152 auto tt1l_lowmt = Process::MakeShared<Baby_full>(
"t#bar{t}(1l), m_{T} #leq 140",
154 tt1l_lowmt->SetLineStyle(2);
155 auto tt1l_highmt = Process::MakeShared<Baby_full>(
"t#bar{t}(1l), m_{T} > 140",
157 auto tt2l = Process::MakeShared<Baby_full>(
"t#bar{t}(2l)",
159 auto ttlveto = Process::MakeShared<Baby_full>(
"t#bar{t}(lv), m_{T} > 140",
162 auto tt1l_highmt_2trul = Process::MakeShared<Baby_full>(
"t#bar{t}(1l), m_{T} > 140, tru: 2l",
164 baseline_1l &&
"ntruleps>=1 && ntruels+ntrumus+ntrutausl==2 && mt>140");
165 auto tt1l_highmt_1trul_1trutauh = Process::MakeShared<Baby_full>(
"t#bar{t}(1l), m_{T} > 140, tru: l#tau_{h}",
167 baseline_1l &&
"ntruleps>=1 && ntruels+ntrumus+ntrutausl==1 && ntrutaush==1 && mt>140");
168 auto tt1l_highmt_1trul = Process::MakeShared<Baby_full>(
"t#bar{t}(1l), m_{T} > 140, tru: 1l",
170 baseline_1l &&
"ntruleps>=1 && ntruels+ntrumus+ntrutausl==1 && ntrutaush==0 && mt>140");
172 auto bkg1l_lowmt = Process::MakeShared<Baby_full>(
"Tot. bkgd (1l), m_{T}#leq140",
174 bkg1l_lowmt->SetLineStyle(2);
175 auto bkg1l_highmt = Process::MakeShared<Baby_full>(
"Tot. bkgd (1l), m_{T}>140",
177 auto bkg2l = Process::MakeShared<Baby_full>(
"Tot. bkgd (2l)",
179 auto bkglveto = Process::MakeShared<Baby_full>(
"Tot. bkgd (lv), m_{T} > 140",
182 auto wjets1l_lowmt = Process::MakeShared<Baby_full>(
"W+jets (1l), m_{T}#leq140",
185 auto st1l_lowmt = Process::MakeShared<Baby_full>(
"Single t (1l), m_{T}#leq140",
188 auto other1l_lowmt = Process::MakeShared<Baby_full>(
"Other (1l), m_{T}#leq140",
191 auto nontt2l = Process::MakeShared<Baby_full>(
"Non-t#bar{t} (2l)",
193 auto nontt1l_highmt = Process::MakeShared<Baby_full>(
"Non-t#bar{t} (1l), m_{T}>140",
196 map<string, vector<shared_ptr<Process> > > procs, procs_pie, procs_isr;
198 procs[
"lowmt"] = vector<shared_ptr<Process> >({tt1l_lowmt, other1l_lowmt, st1l_lowmt, wjets1l_lowmt});
199 procs_pie[
"lowmt"] = vector<shared_ptr<Process> >({tt1l_lowmt, other1l_lowmt, st1l_lowmt, wjets1l_lowmt});
201 procs[
"highmt"] = vector<shared_ptr<Process> >({tt1l_lowmt, tt1l_highmt_2trul,
202 tt1l_highmt_1trul_1trutauh, tt1l_highmt_1trul, nontt1l_highmt});
203 procs_isr[
"highmt"] = vector<shared_ptr<Process> >({tt1l_lowmt, tt1l_highmt_2trul,
204 tt1l_highmt_1trul_1trutauh, tt1l_highmt_1trul});
205 procs_pie[
"highmt"] = vector<shared_ptr<Process> >({tt1l_highmt_2trul,
206 tt1l_highmt_1trul_1trutauh, tt1l_highmt_1trul, nontt1l_highmt});
208 procs[
"dilep"] = vector<shared_ptr<Process> >({tt1l_lowmt, nontt2l, ttlveto, tt2l});
209 procs_isr[
"dilep"] = vector<shared_ptr<Process> >({tt1l_lowmt, ttlveto, tt2l});
210 procs_pie[
"dilep"] = vector<shared_ptr<Process> >({nontt2l, ttlveto, tt2l});
212 procs[
"totbkg"] = vector<shared_ptr<Process> >({bkg1l_lowmt, bkg2l, bkglveto, bkg1l_highmt});
213 procs_pie[
"totbkg"] = vector<shared_ptr<Process> >({bkg2l, bkglveto, bkg1l_highmt});
215 vector<NamedFunc> htopt;
220 for (
const auto &pt: *(b.
leps_pt())) st += pt;
224 float ht_proxy = b.
ht();
229 float ht_proxy = b.
ht();
235 float ht_proxy = b.
ht();
240 .Bottom(BottomType::ratio)
241 .YAxis(YAxisType::log)
242 .Stack(StackType::shapes)
244 PlotOpt lin_shapes = log_shapes().
YAxis(YAxisType::linear);
245 vector<PlotOpt> plot_types = {lin_shapes};
247 >>>>>>> b1f888b55e7125d5a772cc4a7067bd650781e35f
249 vector<NamedFunc> metbins;
253 metbins.push_back(
NamedFunc(
"met>200&&met<=350"));
254 metbins.push_back(
NamedFunc(
"met>350&&met<=500"));
263 for (
size_t imc(0); imc<b.
mc_pt()->size(); imc++){
264 if (fabs(b.
mc_id()->at(imc))==6 && b.
mc_status()->at(imc)==62) toppt += b.
mc_pt()->at(imc);
269 map<bool, vector<string> > nobjbins;
271 nobjbins[
true] = vector<string>();
272 nobjbins[
true].push_back(
"njets+nleps==6");
273 nobjbins[
true].push_back(
"njets+nleps>=7 && njets+nleps<=9");
274 nobjbins[
true].push_back(
"njets+nleps>=10");
276 nobjbins[
false] = vector<string>();
277 nobjbins[
false].push_back(
"njets==5");
278 nobjbins[
false].push_back(
"njets>=6 && njets<=8");
279 nobjbins[
false].push_back(
"njets>=9");
281 vector<string> nobjbins;
282 nobjbins = vector<string>();
286 nobjbins.push_back(
"njets>=6");
287 nobjbins.push_back(
"njets>=9");
288 >>>>>>> b1f888b55e7125d5a772cc4a7067bd650781e35f
293 vector<bool> rcopts = {
true,
false};
295 for (
auto mj_lep: {
true,
false}){
296 string xtitle = mj_lep ?
"M_{J} [GeV]" :
"M_{J} (no lep) [GeV]";
297 string var = (
Contains(folder_mc,
"reclustered") && mj_lep) ?
"mj14_original" :
"mj14";
298 for (
auto &iproc:procs){
299 vector<TableRow> table_cuts;
300 for (
auto &imet: metbins) {
301 for (
auto &inobj: nobjbins[mj_lep]) {
302 for (
auto &iht: htopt){
304 if(iproc.first ==
"dilep" &&
Contains(inobj,
"==6"))
continue;
305 vector<shared_ptr<Process> > procs_tmp = iproc.second;
307 if (iproc.first ==
"totbkg" &&
Contains(inobj,
"==6"))
308 procs_tmp = vector<shared_ptr<Process> >({bkg1l_lowmt, bkglveto, bkg1l_highmt});
310 NamedFunc icut = imet && inobj && iht>500;
313 plot_names.insert(pm.
GetLast<
Hist1D>()->
Name()+
"_OPT_"+plot_types[0].TypeString()+
".pdf");
315 if (procs_isr.find(iproc.first)!=procs_isr.end()) {
316 pm.
Push<
Hist1D>(
Axis(10, 0., 800., ave_toppt,
"Ave. top p_{T} [GeV]"),
317 icut && var+
">250", procs_isr[iproc.first], plot_types).Tag(
CodeToPlainText(iproc.first+
"_"+iht.Name()));
318 plot_names.insert(pm.
GetLast<
Hist1D>()->
Name()+
"_OPT_"+plot_types[0].TypeString()+
".pdf");
319 pm.
Push<
Hist1D>(
Axis(10, 0., 800.,
"isr_tru_pt",
"True ISR p_{T} [GeV]"),
320 icut && var+
">250", procs_isr[iproc.first], plot_types).Tag(
CodeToPlainText(iproc.first+
"_"+iht.Name()));
321 plot_names.insert(pm.
GetLast<
Hist1D>()->
Name()+
"_OPT_"+plot_types[0].TypeString()+
".pdf");
324 table_cuts.push_back(
TableRow(
"",icut));
330 pm.
Push<
Table>(iproc.first, table_cuts, procs_pie[iproc.first],
false,
true,
true);
338 SlideMaker sm_mjnolep(
"mjlep_vs_nolep.tex",
"1610");
339 for (
auto &iht: htopt){
340 for (
auto &imet: metbins) {
341 for (
size_t inobj(0); inobj<nobjbins[
true].size(); inobj++) {
342 vector<string> pnames;
343 for (
auto mj_lep: {
true,
false}) {
344 for (
auto &iproc: procs){
345 string proc = iproc.first;
346 if(proc ==
"dilep" && (
Contains(nobjbins[mj_lep][inobj],
"==6") ||
Contains(nobjbins[mj_lep][inobj],
"==5")))
continue;
347 NamedFunc icut = imet && nobjbins[mj_lep][inobj] && iht>500;
348 string var = mj_lep ?
"mj14_original" :
"mj14";
350 +
"_WGT_weight_OPT_"+plot_types[0].TypeString()+
".pdf");
351 if (plot_names.find(iname)!=plot_names.end()) pnames.push_back(iname);
363 for (
auto mj_lep: {
true,
false}){
364 string sname = mj_lep ?
"plots_mj.tex" :
"plots_mj_nolep.tex";
366 string var = (
Contains(folder_mc,
"reclustered") && mj_lep) ?
"mj14_original" :
"mj14";
367 for (
auto &iproc: procs){
368 string proc = iproc.first;
369 for (
auto &imet: metbins) {
370 for (
auto &inobj: nobjbins[mj_lep]) {
371 vector<string> pnames(15,
"");
372 for (
size_t iht(0); iht<htopt.size(); iht++){
373 NamedFunc icut = imet && inobj && htopt[iht]>500;
374 string iname =
CodeToPlainText(proc+
"_"+htopt[iht].Name()+
"_VAR_"+var +
"_CUT_" + icut.
Name()
375 +
"_WGT_weight_OPT_"+plot_types[0].TypeString()+
".pdf");
376 if (plot_names.find(iname)!=plot_names.end()){
378 pnames[htopt.size()+iht] = iname;
380 icut = icut && var+
">250";
382 +
"_WGT_weight_OPT_"+plot_types[0].TypeString()+
".pdf");
383 if (plot_names.find(iname)!=plot_names.end()) pnames[2*htopt.size()+iht] = iname;
393 for (
auto &imet: metbins) {
394 for (
auto &inobj: nobjbins) {
396 pm.
Push<
Hist1D>(
Axis(10, 100., 850.,
"mj14",
"M_{J} [GeV]", {250., 400.}),
397 icut, goodbad_procs, plot_types).
Tag(
"thin_goodbad");
398 pm.
Push<
Hist1D>(
Axis(10, 100., 850.,
"mj14",
"M_{J} [GeV]", {250., 400.}),
399 icut, goodbad0_procs, plot_types).
Tag(
"thin_goodbad0");
400 pm.
Push<
Hist1D>(
Axis(10, 100., 850.,
"mj14",
"M_{J} [GeV]", {250., 400.}),
401 icut, proc_procs, plot_types).
Tag(
"thin_proc");
402 pm.
Push<
Hist1D>(
Axis(10, 100., 850.,
"mj14",
"M_{J} [GeV]", {250., 400.}),
403 icut, lep_procs, plot_types).
Tag(
"thin_lep");
405 pm.
Push<
Hist1D>(
Axis(5, 100., 850.,
"mj14",
"M_{J} [GeV]", {250., 400.}),
406 icut, goodbad_procs, plot_types).
Tag(
"fat_goodbad");
407 pm.
Push<
Hist1D>(
Axis(5, 100., 850.,
"mj14",
"M_{J} [GeV]", {250., 400.}),
408 icut, goodbad0_procs, plot_types).
Tag(
"fat_goodbad0");
409 pm.
Push<
Hist1D>(
Axis(5, 100., 850.,
"mj14",
"M_{J} [GeV]", {250., 400.}),
410 icut, proc_procs, plot_types).
Tag(
"fat_proc");
411 pm.
Push<
Hist1D>(
Axis(5, 100., 850.,
"mj14",
"M_{J} [GeV]", {250., 400.}),
412 icut, lep_procs, plot_types).
Tag(
"fat_lep");
425 >>>>>>> b1f888b55e7125d5a772cc4a7067bd650781e35f
427 double seconds = (chrono::duration<double>(chrono::high_resolution_clock::now() - begTime)).count();
429 cout<<endl<<
"Making "<<Nplots<<
" plots took "<<round(seconds)<<
" seconds ("<<hhmmss<<
")"<<endl<<endl;
std::vector< int > *const & mc_status() const
Get mc_status for current event and cache it.
PlotOpt & Stack(PlotOptTypes::StackType stack_type)
PlotOpt & YAxis(PlotOptTypes::YAxisType y_axis_type)
TString HoursMinSec(float fseconds)
std::vector< float > *const & leps_pt() const
Get leps_pt for current event and cache it.
int const & nleps() const
Get nleps for current event and cache it.
std::string CodeToPlainText(std::string code)
const std::string & Name() const
Get the string representation of this function.
Abstract base class for access to ntuple variables.
Combines a callable function taking a Baby and returning a scalar or vector with its string represent...
bool Contains(const std::string &str, const std::string &pat)
std::string execute(const std::string &cmd)
std::vector< float > *const & mc_pt() const
Get mc_pt for current event and cache it.
FigureType & Push(Args &&...args)
TString RoundNumber(double num, int decimals, double denom=1.)
Organizes efficient production of plots with single loop over each process.
PlotOpt & Bottom(PlotOptTypes::BottomType bottom_type)
PlotOpt & RatioMaximum(double ratio_maximum)
std::vector< int > *const & mc_id() const
Get mc_id for current event and cache it.
A full 1D plot with stacked/overlayed histograms.
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 AddSlide(std::vector< std::string > pnames, int ncols=-1, std::string title="")
void MakePlots(double luminosity, const std::string &subdir="")
Prints all added plots with given luminosity.
Hist1D & Tag(const std::string &tag)
PlotOpt & Title(PlotOptTypes::TitleType title_type)
float const & ht() const
Get ht for current event and cache it.
Loads colors from a text configuration file.