13 #include "histo_stack.hpp" 30 const vector<double> xbins,
NamedFunc xvar,
string xlabel,
32 const vector<shared_ptr<Process> > &proc,
33 const vector<PlotOpt> &plot_types,
int tag_digits=0);
52 gErrorIgnoreLevel = 6000;
56 string hostname =
execute(
"echo $HOSTNAME");
58 bfolder =
"/net/cms2";
60 Palette colors(
"txt/colors.txt",
"default");
63 string dir_mc_isr = bfolder+
"/cms2r0/babymaker/babies/2016_06_14/mc/merged_"+
isrtype+
"/";
65 {dir_mc_isr+
"*_TTJets*SingleLept*.root"},
"ntruleps<=1");
67 {dir_mc_isr+
"*_TTJets*DiLept*.root"},
"ntruleps>=2");
69 {dir_mc_isr+
"*_ST_*.root"});
72 {dir_mc_isr+
"*DYJetsToLL_M-50_*.root"},
"stitch");
74 {dir_mc_isr+
"*_TTWJets*.root", dir_mc_isr+
"*_TTZTo*.root", dir_mc_isr+
"*_TTGJets*.root"});
76 {dir_mc_isr+
"*_WJetsToLNu*.root",
78 dir_mc_isr+
"*_ZJet*.root", dir_mc_isr+
"*_WWTo*.root",
79 dir_mc_isr+
"*ggZH_HToBB*.root", dir_mc_isr+
"*ttHJetTobb*.root",
80 dir_mc_isr+
"*_TTTT_*.root",
81 dir_mc_isr+
"*_WH_HToBB*.root", dir_mc_isr+
"*_WZTo*.root",
82 dir_mc_isr+
"*_ZH_HToBB*.root", dir_mc_isr+
"_ZZ_*.root"});
85 string dir_mc_isr_alg = bfolder+
"/cms2r0/babymaker/babies/2016_07_18/mc/merged_"+isrtype+
"/";
87 {dir_mc_isr_alg+
"*_TTJets*SingleLept*.root"},
"ntruleps<=1");
89 {dir_mc_isr_alg+
"*_TTJets*DiLept*.root"},
"ntruleps>=2");
93 {dir_mc_isr+
"*_WJetsToLNu*.root"},
96 {dir_mc_isr+
"*DYJetsToLL_M-50_Tu*.root",dir_mc_isr+
"*QCD_HT*.root",
97 dir_mc_isr+
"*_ZJet*.root", dir_mc_isr+
"*_WWTo*.root",
98 dir_mc_isr+
"*ggZH_HToBB*.root", dir_mc_isr+
"*ttHJetTobb*.root",
99 dir_mc_isr+
"*_TTTT_*.root",
100 dir_mc_isr+
"*_WH_HToBB*.root", dir_mc_isr+
"*_WZTo*.root",
101 dir_mc_isr+
"*_ZH_HToBB*.root", dir_mc_isr+
"_ZZ_*.root"});
103 string dir_data_isr = bfolder+
"/cms2r0/babymaker/babies/2016_06_26/data/skim_"+isrtype+
"/";
106 {dir_data_isr+
"*.root"},
107 "pass && (trig[19]||trig[23])");
109 vector<shared_ptr<Process> > procs;
110 if (isrtype==
"zisr") procs = {
data, dyjets,
tt2l,
tt1l, single_t, ttv, other};
111 else if (isrtype==
"ttisr") procs = {
data,
tt2l,
tt1l, dyjets, single_t, ttv, other};
112 else if (isrtype==
"wisr") procs = {
data, wjets,
tt1l,
tt2l, single_t, ttv, other_w};
113 else {cout<<isrtype<<
" not supported, exiting"<<endl<<endl;
return 0;}
115 vector<shared_ptr<Process> > procs_alg = {
data, tt2l_alg, tt1l_alg, dyjets, single_t, ttv, other};
119 string dir_mc_std(bfolder+
"/cms2r0/babymaker/babies/2016_06_14/mc/merged_standard/");
120 string dir_data_std(bfolder+
"/cms2r0/babymaker/babies/2016_06_26/data/merged_standard/");
123 {dir_data_std+
"/*.root"},
124 "(trig[4]||trig[8]||trig[13]||trig[33])");
127 {dir_mc_std+
"*_TTJets*SingleLept*.root"},
130 {dir_mc_std+
"*_TTJets*DiLept*.root"},
133 {dir_mc_std+
"*_WJetsToLNu*.root"},
136 {dir_mc_std+
"*_ST_*.root"});
138 {dir_mc_std+
"*_TTWJets*.root", dir_mc_std+
"*_TTZTo*.root"});
140 {dir_mc_std+
"*DYJetsToLL*.root",dir_mc_std+
"*QCD_HT*.root",
141 dir_mc_std+
"*_ZJet*.root",dir_mc_std+
"*_ttHJetTobb*.root",
142 dir_mc_std+
"*_TTGJets*.root",dir_mc_std+
"*_TTTT*.root",
143 dir_mc_std+
"*_WH_HToBB*.root",dir_mc_std+
"*_ZH_HToBB*.root",
144 dir_mc_std+
"*_WWTo*.root",dir_mc_std+
"*_WZ*.root",dir_mc_std+
"*_ZZ_*.root"},
147 string dir_mc_std_alg = bfolder+
"/cms2r0/babymaker/babies/2016_07_18/mc/merged_standard/";
149 {dir_mc_std_alg+
"*_TTJets*SingleLept*.root"},
152 {dir_mc_std_alg+
"*_TTJets*DiLept*.root"},
155 vector<shared_ptr<Process> > procs_1l = {std_data, std_tt1l, std_tt2l, std_wjets, std_singlet, std_ttv, std_other};
156 vector<shared_ptr<Process> > procs_1l_alg = {std_data, std_tt1l_alg, std_tt2l_alg, std_wjets, std_singlet, std_ttv, std_other};
158 PlotOpt log_lumi(
"txt/plot_styles.txt",
"CMSPaper");
159 log_lumi.
Title(TitleType::info)
160 .
Bottom(BottomType::ratio)
161 .
YAxis(YAxisType::log)
162 .
Stack(StackType::data_norm);
164 PlotOpt log_shapes = log_lumi().
Stack(StackType::shapes)
167 PlotOpt lin_shapes = log_shapes().
YAxis(YAxisType::linear);
168 vector<PlotOpt> plot_types = {log_lumi, lin_lumi};
169 vector<PlotOpt> plot_vals = {lin_lumi().
PrintVals(
true)};
177 NamedFunc baseline =
"nleps==2" && nreliso_els+nreliso_mus>=1;
178 NamedFunc baseline_w = nreliso_els+nreliso_mus==1 &&
"ht>200&&met>100&&nbl==0";
179 NamedFunc baseline_1l =
"nleps==1 && ht>500 && met>200 && nbm>=1 && pass";
180 if(isrtype==
"wisr") baseline = baseline_w;
191 vector<double> jets_pt =
isrJetsPt(b, 30.);
193 for (
auto &jpt: jets_pt) ht += jpt;
211 const vector<double> isr_syspt_slices = {0, 100, 200, 300};
212 const vector<double> nisrjet_bins = {-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5};
213 vector<double> nisrjet_bins_vals = {-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5};
214 if(isrtype!=
"ttisr") nisrjet_bins_vals = nisrjet_bins;
217 vector<double> nisrjet_slices = {0,1,2,3,4,5};
218 const vector<double> isr_syspt_bins = {0, 50, 100, 150, 200, 300, 400, 600, 800};
220 const vector<double> isr_ht_slices = {0,100, 200, 300, 400, 500, 2000};
221 const vector<double> isr_ht_bins = {0,100, 200, 300};
223 vector<double> ptbins = {30,40,50,75,100,150,200,300,400,600};
224 vector<double> ptbins_zoom = {20,25,30,35,40,50,75,100,150,200};
226 vector<NamedFunc> weight_opts;
228 if (isrtype==
"ttisr"){
233 }
else if (isrtype==
"zisr"){
236 for (
const auto &iweight: weight_opts){
237 vector<shared_ptr<Process> > *iprocs = &procs;
238 if(iweight.PlainName()==
"w_ttisr_alg") iprocs = &procs_alg;
240 if(iweight.PlainName()==
"w_ttisr_alg")
241 pm.
Push<HistoStack>(HistoDef(
"tt1l", 13, -0.5, 12.5,
"njets",
"Number of jets", baseline_1l, iweight), procs_1l_alg, plot_types);
243 pm.
Push<HistoStack>(HistoDef(
"tt1l", 13, -0.5, 12.5,
"njets",
"Number of jets", baseline_1l, iweight), procs_1l, plot_types);
245 addSlices(pm, isr_syspt_slices, isr_syspt, nisrjet_bins, nisrjets,
"ISR jet multiplicity", baseline, iweight, *iprocs, plot_types);
246 addSlices(pm, nisrjet_slices, nisrjets, isr_syspt_bins, isr_syspt,
"ISR p_{T} [GeV]", baseline, iweight, *iprocs, {log_lumi});
247 addSlices(pm, isr_ht_slices, isr_ht, isr_syspt_bins, isr_syspt,
"ISR p_{T} [GeV]", baseline, iweight, *iprocs, {log_lumi});
248 addSlices(pm, isr_ht_slices, isr_ht, nisrjet_bins, nisrjets,
"ISR jet multiplicity", baseline, iweight, *iprocs, {log_lumi});
249 addSlices(pm, nisrjet_slices, nisrjets, isr_syspt_bins, isr_ht,
"ISR H_{T} [GeV]", baseline, iweight, *iprocs, {log_lumi});
251 pm.
Push<HistoStack>(HistoDef(isrtype, isr_syspt_bins, isr_syspt,
"ISR p_{T} [GeV]", baseline &&
"ht>300", iweight), *iprocs, vector<PlotOpt>({log_lumi}));
252 pm.
Push<HistoStack>(HistoDef(isrtype, ptbins, isr_jetspt[0.],
"Leading ISR jet p_{T} [GeV]", baseline && nisrjets>0., iweight), *iprocs, plot_types);
253 pm.
Push<HistoStack>(HistoDef(isrtype, ptbins, isr_jetspt[1],
"2^{nd} ISR jet p_{T} [GeV]", baseline && nisrjets>1, iweight), *iprocs, plot_types);
254 pm.
Push<HistoStack>(HistoDef(isrtype, ptbins, isr_jetspt[2],
"3^{rd} ISR jet p_{T} [GeV]", baseline && nisrjets>2, iweight), *iprocs, plot_types);
255 pm.
Push<HistoStack>(HistoDef(isrtype, ptbins, isr_jetspt[3],
"4^{th} ISR jet p_{T} [GeV]", baseline && nisrjets>3, iweight), *iprocs, plot_types);
257 pm.
Push<HistoStack>(HistoDef(isrtype, ptbins_zoom, isr_jetspt20[0.],
"Leading ISR jet p_{T} [GeV]", baseline && nisrjets20>0., iweight), *iprocs, plot_types);
258 pm.
Push<HistoStack>(HistoDef(isrtype, ptbins_zoom, isr_jetspt20[1],
"2^{nd} ISR jet p_{T} [GeV]", baseline && nisrjets20>1, iweight), *iprocs, plot_types);
259 pm.
Push<HistoStack>(HistoDef(isrtype, ptbins_zoom, isr_jetspt20[2],
"3^{rd} ISR jet p_{T} [GeV]", baseline && nisrjets20>2, iweight), *iprocs, plot_types);
260 pm.
Push<HistoStack>(HistoDef(isrtype, ptbins_zoom, isr_jetspt20[3],
"4^{th} ISR jet p_{T} [GeV]", baseline && nisrjets20>3, iweight), *iprocs, plot_types);
262 pm.
Push<HistoStack>(HistoDef(isrtype, ptbins, max_reliso_elspt,
"Leading electron p_{T} [GeV]", baseline && nreliso_els>0., iweight), *iprocs, plot_types);
263 pm.
Push<HistoStack>(HistoDef(isrtype, ptbins, max_reliso_muspt,
"Leading muon p_{T} [GeV]", baseline && nreliso_mus>0., iweight), *iprocs, plot_types);
265 pm.
Push<HistoStack>(HistoDef(isrtype,20,0.,500.,
"met",
"MET [GeV]", baseline, iweight), *iprocs, plot_types);
266 pm.
Push<HistoStack>(HistoDef(isrtype,15,0.,1500.,
"ht",
"H_{T} [GeV]", baseline, iweight), *iprocs, plot_types);
267 pm.
Push<HistoStack>(HistoDef(isrtype,15,0.,1500.,
"mj14",
"M_{J} [GeV]", baseline, iweight), *iprocs, plot_types);
268 pm.
Push<HistoStack>(HistoDef(isrtype+
"_vals",nisrjet_bins_vals, nisrjets,
"ISR jet multiplicity", baseline, iweight), *iprocs, plot_vals);
269 pm.
Push<HistoStack>(HistoDef(isrtype,nisrjet_bins, nisrjets50,
"Number of 50 GeV ISR jets", baseline, iweight), *iprocs, plot_types);
270 pm.
Push<HistoStack>(HistoDef(isrtype,nisrjet_bins, nisrjets75,
"Number of 75 GeV ISR jets", baseline, iweight), *iprocs, plot_types);
272 pm.
Push<HistoStack>(HistoDef(isrtype,nisrjet_bins, nisrjets,
"ISR jet multiplicity", baseline &&
"ht>200", iweight), *iprocs, plot_types);
273 pm.
Push<HistoStack>(HistoDef(isrtype,isr_syspt_bins, isr_syspt,
"ISR p_{T} [GeV]", baseline &&
"ht>200", iweight), *iprocs, plot_types);
285 const vector<double> xbins,
NamedFunc xvar,
string xlabel,
287 const vector<shared_ptr<Process> > &proc,
288 const vector<PlotOpt> &plot_types,
int tag_digits){
291 pm.
Push<HistoStack>(HistoDef(
isrtype+
"_incl", xbins, xvar, xlabel, baseline, weight), proc, plot_types);
292 for(
unsigned i(0); i<slices.size(); i++){
293 NamedFunc cut = baseline && svar>=slices[i];
294 if (i<(slices.size()-1)) cut = cut && svar<slices[i+1];
297 pm.
Push<HistoStack>(HistoDef(tag, xbins, xvar, xlabel, cut, weight), proc, plot_types);
302 return iel<b.
els_pt()->size()
303 && b.
els_pt()->at(iel)>30.
311 for (
size_t iel(0); iel<b.
els_pt()->size(); iel++){
319 for (
size_t iel(0); iel<b.
els_pt()->size(); iel++){
326 return imu<b.
mus_pt()->size()
327 && b.
mus_pt()->at(imu)>30.
328 && fabs(b.
mus_eta()->at(imu))<2.
335 for (
size_t imu(0); imu<b.
mus_pt()->size(); imu++){
343 for (
size_t imu(0); imu<b.
mus_pt()->size(); imu++){
350 return ijet<b.
jets_pt()->size()
356 vector<double> isr_jetspt;
357 for (
size_t ijet(0); ijet<b.
jets_pt()->size(); ijet++){
360 isr_jetspt.push_back(b.
jets_pt()->at(ijet));
362 std::sort(isr_jetspt.begin(), isr_jetspt.end(), std::greater<double>());
372 if (b.
ntrupv()<0)
return 1.;
376 int nisrjets = b.
njets();
378 if (use_baby_nisr) nisrjets = b.
nisr();
379 else nisrjets = b.
njets() - 2;
382 if (nisrjets==0)
return 1.099*wgt;
383 else if (nisrjets==1)
return 0.969*wgt;
384 else if (nisrjets==2)
return 0.870*wgt;
385 else if (nisrjets==3)
return 0.772*wgt;
386 else if (nisrjets==4)
return 0.712*wgt;
387 else if (nisrjets==5)
return 0.661*wgt;
388 else if (nisrjets>=6)
return 0.566*wgt;
393 if (b.
ntrupv()<0)
return 1.;
398 int nisrjets(b.
njets());
400 if (nisrjets==0)
return 0.981*wgt;
401 else if (nisrjets==1)
return 1.071*wgt;
402 else if (nisrjets==2)
return 1.169*wgt;
403 else if (nisrjets==3)
return 1.157*wgt;
404 else if (nisrjets==4)
return 1.014*wgt;
405 else if (nisrjets==5)
return 0.920*wgt;
406 else if (nisrjets==6)
return 0.867*wgt;
407 else if (nisrjets>=7)
return 0.935*wgt;
std::vector< float > *const & els_reliso() const
Get els_reliso for current event and cache it.
std::vector< float > *const & mus_eta() const
Get mus_eta for current event and cache it.
PlotOpt & Stack(PlotOptTypes::StackType stack_type)
std::vector< float > *const & jets_csv() const
Get jets_csv for current event and cache it.
PlotOpt & YAxis(PlotOptTypes::YAxisType y_axis_type)
std::vector< ScalarType > VectorType
void addSlices(PlotMaker &pm, const vector< double > slices, NamedFunc svar, const vector< double > xbins, NamedFunc xvar, string xlabel, const NamedFunc &baseline, const NamedFunc &weight, const vector< shared_ptr< Process > > &proc, const vector< PlotOpt > &plot_types, int tag_digits=0)
float const & eff_trig() const
Get eff_trig for current event and cache it.
int const & njets() const
Get njets for current event and cache it.
std::vector< float > *const & els_pt() const
Get els_pt for current event and cache it.
NamedFunc::ScalarType nJetsWeights_ttisr(const Baby &b, bool use_baby_nisr)
Abstract base class for access to ntuple variables.
NamedFunc::ScalarType maxRelIsoMusPt(const Baby &b)
std::vector< float > *const & mus_pt() const
Get mus_pt for current event and cache it.
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)
NamedFunc::ScalarType nRelIsoEls(const Baby &b)
float const & w_toppt() const
Get w_toppt for current event and cache it.
float const & jetsys_nob_pt() const
Get jetsys_nob_pt for current event and cache it.
std::string execute(const std::string &cmd)
float const & jetsys_pt() const
Get jetsys_pt for current event and cache it.
NamedFunc::ScalarType isrSystemPt(const Baby &b)
FigureType & Push(Args &&...args)
bool isRelIsoEl(const Baby &b, size_t iel)
NamedFunc::ScalarType nRelIsoMus(const Baby &b)
std::vector< float > *const & jets_eta() const
Get jets_eta for current event and cache it.
std::vector< bool > *const & els_tight() const
Get els_tight for current event and cache it.
std::vector< float > *const & mus_reliso() const
Get mus_reliso for current event and cache it.
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)
NamedFunc::VectorType isrJetsPt(const Baby &b, float ptThresh=30.)
bool isRelIsoMu(const Baby &b, size_t imu)
float const & weight() const
Get weight for current event and cache it.
std::vector< float > *const & els_sceta() const
Get els_sceta for current event and cache it.
PlotOpt & ShowBackgroundError(bool show_background_error)
float const & nisr() const
Get nisr for current event and cache it.
std::vector< float > *const & jets_pt() const
Get jets_pt for current event and cache it.
NamedFunc::ScalarType nJetsWeights_visr(const Baby &b)
PlotOpt & PrintVals(bool print_vals)
int const & ntrupv() const
Get ntrupv for current event and cache it.
bool isGoodJet(const Baby &b, size_t ijet)
std::vector< bool > *const & jets_islep() const
Get jets_islep for current event and cache it.
void MakePlots(double luminosity, const std::string &subdir="")
Prints all added plots with given luminosity.
PlotOpt & Title(PlotOptTypes::TitleType title_type)
NamedFunc::ScalarType maxRelIsoElsPt(const Baby &b)
std::vector< bool > *const & mus_tight() const
Get mus_tight for current event and cache it.
Loads colors from a text configuration file.