11 #include "core/histo_stack.hpp" 29 gErrorIgnoreLevel = 6000;
31 chrono::high_resolution_clock::time_point begTime;
32 begTime = chrono::high_resolution_clock::now();
36 string hostname(
execute(
"echo $HOSTNAME"));
38 bfolder =
"/net/cms2";
40 Palette colors(
"txt/colors.txt",
"default");
43 string folder_mc(bfolder+
"/cms2r0/babymaker/babies/reclustered/2016_06_14/mc/merged_nl1st500met150nj5/");
45 if (!
do_met150) folder_mc = bfolder+
"/cms2r0/babymaker/babies/reclustered/2016_06_14/mc/merged_nleps1met200nj5/";
47 set<string> files_tt({folder_mc+
"*_TTJets*Lept*.root", folder_mc+
"*_TTJets_HT*.root"});
48 set<string> files_wjets({folder_mc+
"*_WJetsToLNu*.root"});
49 set<string> files_st({folder_mc+
"*_ST_*.root"});
50 set<string> files_other({
51 folder_mc+
"*DYJetsToLL*.root", folder_mc+
"*_QCD_HT*.root",
52 folder_mc+
"*_ZJet*.root", folder_mc+
"*_WWTo*.root",
53 folder_mc+
"*ggZH_HToBB*.root", folder_mc+
"*ttHJetTobb*.root",
54 folder_mc+
"*_TTGJets*.root", folder_mc+
"*_TTTT_*.root",
55 folder_mc+
"*_TTWJets*.root", folder_mc+
"*_TTZTo*.root",
56 folder_mc+
"*_WH_HToBB*.root", folder_mc+
"*_WZTo*.root",
57 folder_mc+
"*_ZH_HToBB*.root", folder_mc+
"_ZZ_*.root"});
59 set<string> files_nontt(files_other);
60 files_nontt.insert(files_wjets.begin(), files_wjets.end());
61 files_nontt.insert(files_st.begin(), files_st.end());
63 set<string> files_all(files_nontt);
64 files_all.insert(files_tt.begin(), files_tt.end());
66 PlotOpt log_shapes(
"txt/plot_styles.txt",
"CMSPaper");
67 log_shapes.
Title(TitleType::info)
69 .
YAxis(YAxisType::log)
70 .
Stack(StackType::shapes)
72 PlotOpt lin_shapes = log_shapes().
YAxis(YAxisType::linear);
73 vector<PlotOpt> plot_types = {lin_shapes};
75 NamedFunc baseline_1l =
"stitch && nleps==1 && nveto==0 && nbm>=1 && weight<1";
76 NamedFunc baseline_2l =
"stitch && nleps==2";
77 NamedFunc baseline_lveto =
"stitch && nleps==1 && nveto==1 && nbm>=1 && mt>140";
79 auto tt1l_lowmt = Process::MakeShared<Baby_full>(
"t#bar{t}(1l), m_{T} #leq 140",
81 tt1l_lowmt->SetLineStyle(2);
82 auto tt1l_highmt = Process::MakeShared<Baby_full>(
"t#bar{t}(1l), m_{T} > 140",
84 auto tt2l = Process::MakeShared<Baby_full>(
"t#bar{t}(2l)",
86 auto ttlveto = Process::MakeShared<Baby_full>(
"t#bar{t}(lv), m_{T} > 140",
89 auto tt1l_highmt_2trul = Process::MakeShared<Baby_full>(
"t#bar{t}(1l), m_{T} > 140, tru: 2l",
91 baseline_1l &&
"ntruleps>=1 && ntruels+ntrumus+ntrutausl==2 && mt>140");
92 auto tt1l_highmt_1trul_1trutauh = Process::MakeShared<Baby_full>(
"t#bar{t}(1l), m_{T} > 140, tru: l#tau_{h}",
94 baseline_1l &&
"ntruleps>=1 && ntruels+ntrumus+ntrutausl==1 && ntrutaush==1 && mt>140");
95 auto tt1l_highmt_1trul = Process::MakeShared<Baby_full>(
"t#bar{t}(1l), m_{T} > 140, tru: 1l",
97 baseline_1l &&
"ntruleps>=1 && ntruels+ntrumus+ntrutausl==1 && ntrutaush==0 && mt>140");
99 auto bkg1l_lowmt = Process::MakeShared<Baby_full>(
"Tot. bkgd (1l), m_{T}#leq140",
101 bkg1l_lowmt->SetLineStyle(2);
102 auto bkg1l_highmt = Process::MakeShared<Baby_full>(
"Tot. bkgd (1l), m_{T}>140",
104 auto bkg2l = Process::MakeShared<Baby_full>(
"Tot. bkgd (2l)",
106 auto bkglveto = Process::MakeShared<Baby_full>(
"Tot. bkgd (lv), m_{T} > 140",
109 auto wjets1l_lowmt = Process::MakeShared<Baby_full>(
"W+jets (1l), m_{T}#leq140",
112 auto st1l_lowmt = Process::MakeShared<Baby_full>(
"Single t (1l), m_{T}#leq140",
115 auto other1l_lowmt = Process::MakeShared<Baby_full>(
"Other (1l), m_{T}#leq140",
118 auto nontt2l = Process::MakeShared<Baby_full>(
"Non-t#bar{t} (2l)",
120 auto nontt1l_highmt = Process::MakeShared<Baby_full>(
"Non-t#bar{t} (1l), m_{T}>140",
123 map<string, vector<shared_ptr<Process> > > procs, procs_pie, procs_isr;
125 procs[
"lowmt"] = vector<shared_ptr<Process> >({tt1l_lowmt, other1l_lowmt, st1l_lowmt, wjets1l_lowmt});
126 procs_pie[
"lowmt"] = vector<shared_ptr<Process> >({tt1l_lowmt, other1l_lowmt, st1l_lowmt, wjets1l_lowmt});
128 procs[
"highmt"] = vector<shared_ptr<Process> >({tt1l_lowmt, tt1l_highmt_2trul,
129 tt1l_highmt_1trul_1trutauh, tt1l_highmt_1trul, nontt1l_highmt});
130 procs_isr[
"highmt"] = vector<shared_ptr<Process> >({tt1l_lowmt, tt1l_highmt_2trul,
131 tt1l_highmt_1trul_1trutauh, tt1l_highmt_1trul});
132 procs_pie[
"highmt"] = vector<shared_ptr<Process> >({tt1l_highmt_2trul,
133 tt1l_highmt_1trul_1trutauh, tt1l_highmt_1trul, nontt1l_highmt});
135 procs[
"dilep"] = vector<shared_ptr<Process> >({tt1l_lowmt, nontt2l, ttlveto, tt2l});
136 procs_isr[
"dilep"] = vector<shared_ptr<Process> >({tt1l_lowmt, ttlveto, tt2l});
137 procs_pie[
"dilep"] = vector<shared_ptr<Process> >({nontt2l, ttlveto, tt2l});
139 procs[
"totbkg"] = vector<shared_ptr<Process> >({bkg1l_lowmt, bkg2l, bkglveto, bkg1l_highmt});
140 procs_pie[
"totbkg"] = vector<shared_ptr<Process> >({bkg2l, bkglveto, bkg1l_highmt});
142 vector<NamedFunc> htopt;
147 for (
const auto &pt: *(b.
leps_pt())) st += pt;
151 float ht_proxy = b.
ht();
156 float ht_proxy = b.
ht();
162 float ht_proxy = b.
ht();
167 vector<NamedFunc> metbins;
170 metbins.push_back(
NamedFunc(
"met>200&&met<=350"));
171 metbins.push_back(
NamedFunc(
"met>350&&met<=500"));
179 for (
size_t imc(0); imc<b.
mc_pt()->size(); imc++){
180 if (fabs(b.
mc_id()->at(imc))==6 && b.
mc_status()->at(imc)==62) toppt += b.
mc_pt()->at(imc);
185 map<bool, vector<string> > nobjbins;
187 nobjbins[
true] = vector<string>();
188 nobjbins[
true].push_back(
"njets+nleps==6");
189 nobjbins[
true].push_back(
"njets+nleps>=7 && njets+nleps<=9");
190 nobjbins[
true].push_back(
"njets+nleps>=10");
192 nobjbins[
false] = vector<string>();
193 nobjbins[
false].push_back(
"njets==5");
194 nobjbins[
false].push_back(
"njets>=6 && njets<=8");
195 nobjbins[
false].push_back(
"njets>=9");
197 set<string> pie_names, plot_names;
200 vector<bool> rcopts = {
true,
false};
202 for (
auto mj_lep: {
true,
false}){
203 string xtitle = mj_lep ?
"M_{J} [GeV]" :
"M_{J} (no lep) [GeV]";
204 string var = (
Contains(folder_mc,
"reclustered") && mj_lep) ?
"mj14_original" :
"mj14";
205 for (
auto &iproc:procs){
206 vector<TableRow> table_cuts;
207 for (
auto &imet: metbins) {
208 for (
auto &inobj: nobjbins[mj_lep]) {
209 for (
auto &iht: htopt){
211 if(iproc.first ==
"dilep" &&
Contains(inobj,
"==6"))
continue;
212 vector<shared_ptr<Process> > procs_tmp = iproc.second;
214 if (iproc.first ==
"totbkg" &&
Contains(inobj,
"==6"))
215 procs_tmp = vector<shared_ptr<Process> >({bkg1l_lowmt, bkglveto, bkg1l_highmt});
217 NamedFunc icut = imet && inobj && iht>500;
218 pm.
Push<HistoStack>(HistoDef(iproc.first+
"_"+iht.PlainName(),
219 10, 100., 850., var, xtitle, icut,
"weight", {250.,400.}), procs_tmp, plot_types);
220 plot_names.insert(pm.
GetLast<HistoStack>()->definition_.Name()+
"_OPT_"+plot_types[0].TypeString()+
".pdf");
222 if (procs_isr.find(iproc.first)!=procs_isr.end()) {
223 pm.
Push<HistoStack>(HistoDef(iproc.first+
"_"+iht.PlainName(),
224 10, 0., 800., ave_toppt,
"Ave. top p_{T} [GeV]", icut && var+
">250",
"weight"), procs_isr[iproc.first], plot_types);
225 plot_names.insert(pm.
GetLast<HistoStack>()->definition_.Name()+
"_OPT_"+plot_types[0].TypeString()+
".pdf");
226 pm.
Push<HistoStack>(HistoDef(iproc.first+
"_"+iht.PlainName(),
227 10, 0., 800.,
"isr_tru_pt",
"True ISR p_{T} [GeV]", icut && var+
">250",
"weight"), procs_isr[iproc.first], plot_types);
228 plot_names.insert(pm.
GetLast<HistoStack>()->definition_.Name()+
"_OPT_"+plot_types[0].TypeString()+
".pdf");
231 table_cuts.push_back(
TableRow(
"",icut));
232 pie_names.insert(
"pie_"+iproc.first+
"_"+icut.PlainName()+
"_perc_lumi"+
RoundNumber(lumi,0).Data()+
".pdf");
237 pm.
Push<
Table>(iproc.first, table_cuts, procs_pie[iproc.first],
false,
true,
true);
245 SlideMaker sm_mjnolep(
"mjlep_vs_nolep.tex",
"1610");
246 for (
auto &iht: htopt){
247 for (
auto &imet: metbins) {
248 for (
size_t inobj(0); inobj<nobjbins[
true].size(); inobj++) {
249 vector<string> pnames;
250 for (
auto mj_lep: {
true,
false}) {
251 for (
auto &iproc: procs){
252 string proc = iproc.first;
253 if(proc ==
"dilep" && (
Contains(nobjbins[mj_lep][inobj],
"==6") ||
Contains(nobjbins[mj_lep][inobj],
"==5")))
continue;
254 NamedFunc icut = imet && nobjbins[mj_lep][inobj] && iht>500;
255 string var = mj_lep ?
"mj14_original" :
"mj14";
257 +
"_WGT_weight_OPT_"+plot_types[0].TypeString()+
".pdf";
258 if (plot_names.find(iname)!=plot_names.end()) pnames.push_back(iname);
270 for (
auto mj_lep: {
true,
false}){
271 string sname = mj_lep ?
"plots_mj.tex" :
"plots_mj_nolep.tex";
273 string var = (
Contains(folder_mc,
"reclustered") && mj_lep) ?
"mj14_original" :
"mj14";
274 for (
auto &iproc: procs){
275 string proc = iproc.first;
276 for (
auto &imet: metbins) {
277 for (
auto &inobj: nobjbins[mj_lep]) {
278 vector<string> pnames(15,
"");
279 for (
size_t iht(0); iht<htopt.size(); iht++){
280 NamedFunc icut = imet && inobj && htopt[iht]>500;
281 string iname = proc+
"_"+htopt[iht].PlainName()+
"_VAR_"+var +
"_CUT_" + icut.
PlainName()
282 +
"_WGT_weight_OPT_"+plot_types[0].TypeString()+
".pdf";
283 if (plot_names.find(iname)!=plot_names.end()){
285 pnames[htopt.size()+iht] = iname;
287 icut = icut && var+
">250";
289 +
"_WGT_weight_OPT_"+plot_types[0].TypeString()+
".pdf";
290 if (plot_names.find(iname)!=plot_names.end()) pnames[2*htopt.size()+iht] = iname;
300 double seconds = (chrono::duration<double>(chrono::high_resolution_clock::now() - begTime)).count();
302 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.
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)
std::string PlainName() const
PlotOpt & RatioMaximum(double ratio_maximum)
std::vector< int > *const & mc_id() const
Get mc_id for current event and cache it.
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.
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.