28 const vector<double> xbins,
NamedFunc xvar,
string xlabel,
30 const vector<shared_ptr<Process> > &proc,
31 const vector<PlotOpt> &plot_types,
int tag_digits=0);
49 gErrorIgnoreLevel = 6000;
52 string hostname =
execute(
"echo $HOSTNAME");
54 bfolder =
"/net/cms2";
56 Palette colors(
"txt/colors.txt",
"default");
59 string dir_mc_isr = bfolder+
"/cms2r0/babymaker/babies/2016_06_14/mc/merged_"+
isrtype+
"/";
61 {dir_mc_isr+
"*_TTJets*SingleLept*.root"},
"ntruleps<=1");
63 {dir_mc_isr+
"*_TTJets*DiLept*.root"},
"ntruleps>=2");
65 {dir_mc_isr+
"*_ST_*.root"});
68 {dir_mc_isr+
"*DYJetsToLL_M-50_*.root"},
"stitch");
70 {dir_mc_isr+
"*_TTWJets*.root", dir_mc_isr+
"*_TTZTo*.root", dir_mc_isr+
"*_TTGJets*.root"});
72 {dir_mc_isr+
"*_WJetsToLNu*.root",
74 dir_mc_isr+
"*_ZJet*.root", dir_mc_isr+
"*_WWTo*.root",
75 dir_mc_isr+
"*ggZH_HToBB*.root", dir_mc_isr+
"*ttHJetTobb*.root",
76 dir_mc_isr+
"*_TTTT_*.root",
77 dir_mc_isr+
"*_WH_HToBB*.root", dir_mc_isr+
"*_WZTo*.root",
78 dir_mc_isr+
"*_ZH_HToBB*.root", dir_mc_isr+
"_ZZ_*.root"});
81 string dir_mc_isr_alg = bfolder+
"/cms2r0/babymaker/babies/2016_07_18/mc/merged_"+isrtype+
"/";
83 {dir_mc_isr_alg+
"*_TTJets*SingleLept*.root"},
"ntruleps<=1");
85 {dir_mc_isr_alg+
"*_TTJets*DiLept*.root"},
"ntruleps>=2");
89 {dir_mc_isr+
"*_WJetsToLNu*.root"},
92 {dir_mc_isr+
"*DYJetsToLL_M-50_Tu*.root",dir_mc_isr+
"*QCD_HT*.root",
93 dir_mc_isr+
"*_ZJet*.root", dir_mc_isr+
"*_WWTo*.root",
94 dir_mc_isr+
"*ggZH_HToBB*.root", dir_mc_isr+
"*ttHJetTobb*.root",
95 dir_mc_isr+
"*_TTTT_*.root",
96 dir_mc_isr+
"*_WH_HToBB*.root", dir_mc_isr+
"*_WZTo*.root",
97 dir_mc_isr+
"*_ZH_HToBB*.root", dir_mc_isr+
"_ZZ_*.root"});
99 string dir_data_isr = bfolder+
"/cms2r0/babymaker/babies/2016_06_26/data/skim_"+isrtype+
"/";
102 {dir_data_isr+
"*.root"},
103 "pass && (trig[19]||trig[23])");
105 vector<shared_ptr<Process> > procs;
106 if (isrtype==
"zisr") procs = {
data, dyjets,
tt2l,
tt1l, single_t, ttv, other};
107 else if (isrtype==
"ttisr") procs = {
data,
tt2l,
tt1l, dyjets, single_t, ttv, other};
108 else if (isrtype==
"wisr") procs = {
data, wjets,
tt1l,
tt2l, single_t, ttv, other_w};
109 else {cout<<isrtype<<
" not supported, exiting"<<endl<<endl;
return 0;}
111 vector<shared_ptr<Process> > procs_alg = {
data, tt2l_alg, tt1l_alg, dyjets, single_t, ttv, other};
114 string dir_mc_std(bfolder+
"/cms2r0/babymaker/babies/2016_06_14/mc/merged_standard/");
115 string dir_data_std(bfolder+
"/cms2r0/babymaker/babies/2016_06_26/data/merged_standard/");
118 {dir_data_std+
"/*.root"},
119 "(trig[4]||trig[8]||trig[13]||trig[33])");
122 {dir_mc_std+
"*_TTJets*SingleLept*.root"},
125 {dir_mc_std+
"*_TTJets*DiLept*.root"},
128 {dir_mc_std+
"*_WJetsToLNu*.root"},
131 {dir_mc_std+
"*_ST_*.root"});
133 {dir_mc_std+
"*_TTWJets*.root", dir_mc_std+
"*_TTZTo*.root"});
135 {dir_mc_std+
"*DYJetsToLL*.root",dir_mc_std+
"*QCD_HT*.root",
136 dir_mc_std+
"*_ZJet*.root",dir_mc_std+
"*_ttHJetTobb*.root",
137 dir_mc_std+
"*_TTGJets*.root",dir_mc_std+
"*_TTTT*.root",
138 dir_mc_std+
"*_WH_HToBB*.root",dir_mc_std+
"*_ZH_HToBB*.root",
139 dir_mc_std+
"*_WWTo*.root",dir_mc_std+
"*_WZ*.root",dir_mc_std+
"*_ZZ_*.root"},
142 string dir_mc_std_alg = bfolder+
"/cms2r0/babymaker/babies/2016_07_18/mc/merged_standard/";
144 {dir_mc_std_alg+
"*_TTJets*SingleLept*.root"},
147 {dir_mc_std_alg+
"*_TTJets*DiLept*.root"},
150 vector<shared_ptr<Process> > procs_1l = {std_data, std_tt1l, std_tt2l, std_wjets, std_singlet, std_ttv, std_other};
151 vector<shared_ptr<Process> > procs_1l_alg = {std_data, std_tt1l_alg, std_tt2l_alg, std_wjets, std_singlet, std_ttv, std_other};
153 PlotOpt log_lumi(
"txt/plot_styles.txt",
"CMSPaper");
154 log_lumi.
Title(TitleType::info)
155 .
Bottom(BottomType::ratio)
156 .
YAxis(YAxisType::log)
157 .
Stack(StackType::data_norm);
159 PlotOpt log_shapes = log_lumi().
Stack(StackType::shapes)
162 PlotOpt lin_shapes = log_shapes().
YAxis(YAxisType::linear);
163 vector<PlotOpt> plot_types = {log_lumi, lin_lumi};
164 vector<PlotOpt> plot_vals = {lin_lumi().
PrintVals(
true)};
172 NamedFunc baseline =
"nleps==2" && nreliso_els+nreliso_mus>=1;
173 NamedFunc baseline_w = nreliso_els+nreliso_mus==1 &&
"ht>200&&met>100&&nbl==0";
174 NamedFunc baseline_1l =
"nleps==1 && ht>500 && met>200 && nbm>=1 && pass";
175 if(isrtype==
"wisr") baseline = baseline_w;
186 vector<double> jets_pt =
isrJetsPt(b, 30.);
188 for (
auto &jpt: jets_pt) ht += jpt;
206 const vector<double> isr_syspt_slices = {0, 100, 200, 300};
207 const vector<double> nisrjet_bins = {-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5};
208 vector<double> nisrjet_bins_vals = {-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5};
209 if(isrtype!=
"ttisr") nisrjet_bins_vals = nisrjet_bins;
212 vector<double> nisrjet_slices = {0,1,2,3,4,5};
213 const vector<double> isr_syspt_bins = {0, 50, 100, 150, 200, 300, 400, 600, 800};
215 const vector<double> isr_ht_slices = {0,100, 200, 300, 400, 500, 2000};
216 const vector<double> isr_ht_bins = {0,100, 200, 300};
218 vector<double> ptbins = {30,40,50,75,100,150,200,300,400,600};
219 vector<double> ptbins_zoom = {20,25,30,35,40,50,75,100,150,200};
221 vector<NamedFunc> weight_opts;
223 if (isrtype==
"ttisr"){
228 }
else if (isrtype==
"zisr"){
231 for (
const auto &iweight: weight_opts){
232 vector<shared_ptr<Process> > *iprocs = &procs;
233 if(
CodeToPlainText(iweight.Name())==
"w_ttisr_alg") iprocs = &procs_alg;
236 pm.
Push<
Hist1D>(
Axis(13, -0.5, 12.5,
"njets",
"Number of jets"), baseline_1l, procs_1l_alg, plot_types).Weight(iweight).
Tag(
"tt1l");
238 pm.
Push<
Hist1D>(
Axis(13, -0.5, 12.5,
"njets",
"Number of jets"), baseline_1l, procs_1l, plot_types).Weight(iweight).
Tag(
"tt1l");
240 addSlices(pm, isr_syspt_slices, isr_syspt, nisrjet_bins, nisrjets,
"ISR jet multiplicity", baseline, iweight, *iprocs, plot_types);
241 addSlices(pm, nisrjet_slices, nisrjets, isr_syspt_bins, isr_syspt,
"ISR p_{T} [GeV]", baseline, iweight, *iprocs, {log_lumi});
242 addSlices(pm, isr_ht_slices, isr_ht, isr_syspt_bins, isr_syspt,
"ISR p_{T} [GeV]", baseline, iweight, *iprocs, {log_lumi});
243 addSlices(pm, isr_ht_slices, isr_ht, nisrjet_bins, nisrjets,
"ISR jet multiplicity", baseline, iweight, *iprocs, {log_lumi});
244 addSlices(pm, nisrjet_slices, nisrjets, isr_syspt_bins, isr_ht,
"ISR H_{T} [GeV]", baseline, iweight, *iprocs, {log_lumi});
246 pm.
Push<
Hist1D>(
Axis(isr_syspt_bins, isr_syspt,
"ISR p_{T} [GeV]"), baseline &&
"ht>300", *iprocs, vector<PlotOpt>{log_lumi}).Weight(iweight).
Tag(isrtype);
247 pm.
Push<
Hist1D>(
Axis(ptbins, isr_jetspt[0.],
"Leading ISR jet p_{T} [GeV]"), baseline && nisrjets>0., *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
248 pm.
Push<
Hist1D>(
Axis(ptbins, isr_jetspt[1],
"2^{nd} ISR jet p_{T} [GeV]"), baseline && nisrjets>1, *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
249 pm.
Push<
Hist1D>(
Axis(ptbins, isr_jetspt[2],
"3^{rd} ISR jet p_{T} [GeV]"), baseline && nisrjets>2, *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
250 pm.
Push<
Hist1D>(
Axis(ptbins, isr_jetspt[3],
"4^{th} ISR jet p_{T} [GeV]"), baseline && nisrjets>3, *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
252 pm.
Push<
Hist1D>(
Axis(ptbins_zoom, isr_jetspt20[0.],
"Leading ISR jet p_{T} [GeV]"), baseline && nisrjets20>0., *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
253 pm.
Push<
Hist1D>(
Axis(ptbins_zoom, isr_jetspt20[1],
"2^{nd} ISR jet p_{T} [GeV]"), baseline && nisrjets20>1, *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
254 pm.
Push<
Hist1D>(
Axis(ptbins_zoom, isr_jetspt20[2],
"3^{rd} ISR jet p_{T} [GeV]"), baseline && nisrjets20>2, *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
255 pm.
Push<
Hist1D>(
Axis(ptbins_zoom, isr_jetspt20[3],
"4^{th} ISR jet p_{T} [GeV]"), baseline && nisrjets20>3, *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
257 pm.
Push<
Hist1D>(
Axis(ptbins, max_reliso_elspt,
"Leading electron p_{T} [GeV]"), baseline && nreliso_els>0., *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
258 pm.
Push<
Hist1D>(
Axis(ptbins, max_reliso_muspt,
"Leading muon p_{T} [GeV]"), baseline && nreliso_mus>0., *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
260 pm.
Push<
Hist1D>(
Axis(20,0.,500.,
"met",
"MET [GeV]"), baseline, *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
261 pm.
Push<
Hist1D>(
Axis(15,0.,1500.,
"ht",
"H_{T} [GeV]"), baseline, *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
262 pm.
Push<
Hist1D>(
Axis(15,0.,1500.,
"mj14",
"M_{J} [GeV]"), baseline, *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
263 pm.
Push<
Hist1D>(
Axis(nisrjet_bins_vals, nisrjets,
"ISR jet multiplicity"), baseline, *iprocs, plot_vals).Weight(iweight).
Tag(isrtype+
"_vals");
264 pm.
Push<
Hist1D>(
Axis(nisrjet_bins, nisrjets50,
"Number of 50 GeV ISR jets"), baseline, *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
265 pm.
Push<
Hist1D>(
Axis(nisrjet_bins, nisrjets75,
"Number of 75 GeV ISR jets"), baseline, *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
267 pm.
Push<
Hist1D>(
Axis(nisrjet_bins, nisrjets,
"ISR jet multiplicity"), baseline &&
"ht>200", *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
268 pm.
Push<
Hist1D>(
Axis(isr_syspt_bins, isr_syspt,
"ISR p_{T} [GeV]"), baseline &&
"ht>200", *iprocs, plot_types).Weight(iweight).
Tag(isrtype);
278 const vector<double> xbins,
NamedFunc xvar,
string xlabel,
280 const vector<shared_ptr<Process> > &proc,
281 const vector<PlotOpt> &plot_types,
int tag_digits){
285 for(
unsigned i(0); i<slices.size(); i++){
286 NamedFunc cut = baseline && svar>=slices[i];
287 if (i<(slices.size()-1)) cut = cut && svar<slices[i+1];
290 pm.
Push<
Hist1D>(
Axis(xbins, xvar, xlabel), cut, proc, plot_types).Weight(weight).
Tag(tag);
295 return iel<b.
els_pt()->size()
296 && b.
els_pt()->at(iel)>30.
304 for (
size_t iel(0); iel<b.
els_pt()->size(); iel++){
312 for (
size_t iel(0); iel<b.
els_pt()->size(); iel++){
319 return imu<b.
mus_pt()->size()
320 && b.
mus_pt()->at(imu)>30.
321 && fabs(b.
mus_eta()->at(imu))<2.
328 for (
size_t imu(0); imu<b.
mus_pt()->size(); imu++){
336 for (
size_t imu(0); imu<b.
mus_pt()->size(); imu++){
343 return ijet<b.
jets_pt()->size()
349 vector<double> isr_jetspt;
350 for (
size_t ijet(0); ijet<b.
jets_pt()->size(); ijet++){
353 isr_jetspt.push_back(b.
jets_pt()->at(ijet));
355 std::sort(isr_jetspt.begin(), isr_jetspt.end(), std::greater<double>());
365 if (b.
ntrupv()<0)
return 1.;
369 int nisrjets = b.
njets();
371 if (use_baby_nisr) nisrjets = b.
nisr();
372 else nisrjets = b.
njets() - 2;
375 if (nisrjets==0)
return 1.099*wgt;
376 else if (nisrjets==1)
return 0.969*wgt;
377 else if (nisrjets==2)
return 0.870*wgt;
378 else if (nisrjets==3)
return 0.772*wgt;
379 else if (nisrjets==4)
return 0.712*wgt;
380 else if (nisrjets==5)
return 0.661*wgt;
381 else if (nisrjets>=6)
return 0.566*wgt;
386 if (b.
ntrupv()<0)
return 1.;
391 int nisrjets(b.
njets());
393 if (nisrjets==0)
return 0.981*wgt;
394 else if (nisrjets==1)
return 1.071*wgt;
395 else if (nisrjets==2)
return 1.169*wgt;
396 else if (nisrjets==3)
return 1.157*wgt;
397 else if (nisrjets==4)
return 1.014*wgt;
398 else if (nisrjets==5)
return 0.920*wgt;
399 else if (nisrjets==6)
return 0.867*wgt;
400 else if (nisrjets>=7)
return 0.935*wgt;
NamedFunc::ScalarType nJetsWeights_ttisr(const Baby &b, bool use_baby_nisr)
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.
NamedFunc::VectorType isrJetsPt(const Baby &b, float ptThresh=30.)
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
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.
std::string CodeToPlainText(std::string code)
Abstract base class for access to ntuple variables.
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)
float const & w_toppt() const
Get w_toppt for current event and cache it.
NamedFunc::ScalarType maxRelIsoElsPt(const Baby &b)
float const & jetsys_nob_pt() const
Get jetsys_nob_pt for current event and cache it.
NamedFunc::ScalarType nRelIsoMus(const Baby &b)
std::string execute(const std::string &cmd)
NamedFunc::ScalarType nJetsWeights_visr(const Baby &b)
float const & jetsys_pt() const
Get jetsys_pt for current event and cache it.
FigureType & Push(Args &&...args)
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)
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)
NamedFunc::ScalarType isrSystemPt(const Baby &b)
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.
A full 1D plot with stacked/overlayed histograms.
std::vector< float > *const & jets_pt() const
Get jets_pt for current event and cache it.
PlotOpt & PrintVals(bool print_vals)
NamedFunc::ScalarType maxRelIsoMusPt(const Baby &b)
int const & ntrupv() const
Get ntrupv for current event and cache it.
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.
Hist1D & Tag(const std::string &tag)
PlotOpt & Title(PlotOptTypes::TitleType title_type)
bool isRelIsoEl(const Baby &b, size_t iel)
bool isGoodJet(const Baby &b, size_t ijet)
NamedFunc::ScalarType nRelIsoEls(const Baby &b)
std::vector< bool > *const & mus_tight() const
Get mus_tight for current event and cache it.
bool isRelIsoMu(const Baby &b, size_t imu)
Loads colors from a text configuration file.