16 #include "TGraphAsymmErrors.h" 23 #include "core/baby.hpp" 51 for (
unsigned i(0); i<b.
mc_pt()->size(); i++){
52 if (abs(b.
mc_id()->at(i))!=24)
continue;
53 if (b.
mc_mass()->at(i) > 140.) {
60 void plotRatio(vector<vector<vector<GammaParams> > > &allyields, oneplot &plotdef,
61 vector<vector<vector<int> > > &indices, vector<TString> &leglabels){
63 size_t ngraphs = indices.size();
64 size_t nbins = allyields[0][0].size();
67 float val(1.), valup(1.), valdown(1.);
68 vector<vector<vector<float> > > ratios(ngraphs);
69 float maxr=-1., minr=1e6;
70 for(
size_t igraph=0; igraph<ngraphs; igraph++){
73 for(
size_t ipow=0; ipow<indices[igraph].size(); ipow++) powers.push_back(indices[igraph][ipow][2]);
76 for(
size_t ibin=0; ibin<nbins; ibin++){
77 vector<vector<float> > entries;
78 vector<vector<float> > weights;
79 for(
size_t ind=0; ind<indices[igraph].size(); ind++) {
80 size_t ibkg = indices[igraph][ind][0];
81 size_t iabcd = indices[igraph][ind][1];
82 entries.push_back(vector<float>());
83 weights.push_back(vector<float>());
84 entries.back().push_back(allyields[ibkg][iabcd][ibin].NEffective());
85 weights.back().push_back(allyields[ibkg][iabcd][ibin].Weight());
89 val =
calcKappa(entries, weights, powers, valdown, valup);
90 if(valdown<0) valdown = 0;
91 ratios[igraph].push_back(vector<float>({val, valdown, valup}));
92 if(maxr < val+valup) maxr = val+valup;
93 if(minr > val-valdown) minr = val-valdown;
98 TString ytitle=
"Ratio";
99 if(indices[0].size()==2){
100 size_t ind0=indices[0][0][1], ind1=indices[0][1][1];
101 if((ind0==
r3&&ind1==
r1) || (ind0==
r4&&ind1==
r2)) ytitle =
"R(m_{T})";
102 if((ind0==
r4&&ind1==
r3) || (ind0==
r2&&ind1==
r1)) ytitle =
"R(M_{J})";
104 if(indices[0].size()==4){
105 size_t ind0=indices[0][0][1], ind1=indices[0][1][1];
106 size_t ind2=indices[0][2][1], ind3=indices[0][3][1];
107 if((ind0==
r4&&ind1==
r3&&ind2==
r2&&ind3==
r1)) ytitle =
"R(M_{J}^{high}) / R[M_{J}^{low}(bkg)]";
110 PlotOpt opts(
"txt/plot_styles.txt",
"Ratio");
114 TCanvas can(
"can",
"");
115 TLine line; line.SetLineWidth(2); line.SetLineStyle(2);
116 TLatex label; label.SetTextSize(0.05); label.SetTextFont(42); label.SetTextAlign(23);
118 float minx = 0.5, maxx = nbins+0.5, miny = 0, maxy = maxr*1.2;
120 TH1D histo(
"histo",
"", nbins, minx, maxx);
121 histo.SetMinimum(miny);
122 histo.SetMaximum(maxy);
123 histo.GetYaxis()->CenterTitle(
true);
124 histo.GetXaxis()->SetLabelOffset(0.008);
125 histo.SetYTitle(ytitle);
129 vector<vector<double> > vx(ngraphs), vexh(ngraphs), vexl(ngraphs);
130 vector<vector<double> > vy(ngraphs), veyh(ngraphs), veyl(ngraphs);
131 for(
size_t ibin=0; ibin<nbins; ibin++){
132 histo.GetXaxis()->SetBinLabel(ibin+1,
CodeToRootTex(plotdef.bincuts[ibin].Data()).c_str());
134 double xval = ibin+1, minxb = 0.15, binw = 0;
139 binw = 2*minxb/(ngraphs-1);
141 for(
size_t igraph=0; igraph<ngraphs; igraph++){
142 vx[igraph].push_back(xval);
144 vexl[igraph].push_back(0);
145 vexh[igraph].push_back(0);
146 vy[igraph] .push_back(ratios[igraph][ibin][0]);
147 veyl[igraph].push_back(ratios[igraph][ibin][1]);
148 veyh[igraph].push_back(ratios[igraph][ibin][2]);
154 double legW = 0.19*ngraphs, legH = legSingle*(ngraphs+1)/2;
155 TLegend leg(legX, legY-legH, legX+legW, legY);
157 leg.SetFillStyle(0); leg.SetBorderSize(0);
159 leg.SetNColumns(ngraphs);
161 Palette colors(
"txt/colors.txt",
"default");
163 vector<int> mcolors({kRed, kGreen-3, kCyan-3, 1});
164 vector<int> styles({20, 21, 22, 23});
165 TGraphAsymmErrors graph[20];
166 for(
size_t igraph=0; igraph<ngraphs; igraph++){
167 graph[igraph] = TGraphAsymmErrors(vx[igraph].size(), &(vx[igraph][0]), &(vy[igraph][0]),
168 &(vexl[igraph][0]), &(vexh[igraph][0]), &(veyl[igraph][0]), &(veyh[igraph][0]));
169 graph[igraph].SetMarkerStyle(styles[igraph]); graph[igraph].SetMarkerSize(1.4);
170 if(leglabels[igraph]==
"All bkg.") mcolors[igraph] = 1;
171 if(leglabels[igraph]==
"t#bar{t} (2l)") mcolors[igraph] = colors(
"tt_2l");
172 if(leglabels[igraph]==
"t#bar{t} (1l)") mcolors[igraph] = colors(
"tt_1l");
173 if(leglabels[igraph]==
"Other") mcolors[igraph] = colors(
"wjets");
174 graph[igraph].SetMarkerColor(mcolors[igraph]);
175 graph[igraph].SetLineColor(mcolors[igraph]); graph[igraph].SetLineWidth(2);
176 graph[igraph].Draw(
"p0 same");
177 leg.AddEntry(&graph[igraph], leglabels[igraph],
"p");
183 cmslabel.SetTextSize(0.06);
184 cmslabel.SetNDC(kTRUE);
185 cmslabel.SetTextAlign(11);
186 cmslabel.DrawLatex(opts.
LeftMargin()+0.005, 1-opts.
TopMargin()+0.015,
"#font[62]{CMS} #scale[0.8]{#font[52]{Simulation}}");
187 cmslabel.SetTextAlign(31);
190 line.SetLineStyle(3); line.SetLineWidth(1);
191 line.DrawLine(minx, 1, maxx, 1);
194 can.SaveAs(fname.c_str());
195 cout<<endl<<
" open "<<fname<<endl;
200 void printDebug(vector<vector<TString> > &allcuts, vector<vector<vector<GammaParams> > > &allyields,
205 int main(
int argc,
char *argv[]){
206 gErrorIgnoreLevel=6000;
209 chrono::high_resolution_clock::time_point begTime;
210 begTime = chrono::high_resolution_clock::now();
215 string hostname =
execute(
"echo $HOSTNAME");
217 bfolder =
"/net/cms2";
220 string foldermc(bfolder+
"/cms2r0/babymaker/babies/2016_08_10/mc/merged_mcbase_met100_stdnj5/");
221 if(
skim.Contains(
"met150")) ntupletag=
"_met150";
222 if(
skim.Contains(
"both")) ntupletag=
"";
224 Palette colors(
"txt/colors.txt",
"default");
228 NamedFunc baselinef =
"pass && stitch && mj14>250 && nleps==1 && nveto==0 && st>500 && met>100 && njets>=5 && nbm>=1";
238 set<string> allfiles = {foldermc+
"*_TTJets*Lept*"+ntupletag+
"*.root", foldermc+
"*_TTJets_HT*"+ntupletag+
"*.root",
239 foldermc+
"*_WJetsToLNu*"+ntupletag+
"*.root",
240 foldermc+
"*_ST_*"+ntupletag+
"*.root",
241 foldermc+
"*_TTW*"+ntupletag+
"*.root", foldermc+
"*_TTZ*"+ntupletag+
"*.root",
242 foldermc+
"*_TTGJets*"+ntupletag+
"*.root",foldermc+
"*_TTTT*"+ntupletag+
"*.root",
243 foldermc+
"*QCD_HT*Inf_Tune*"+ntupletag+
"*.root",
244 foldermc+
"*QCD_HT*0_Tune*"+ntupletag+
"*.root",foldermc+
"*DYJetsToLL*"+ntupletag+
"*.root",
245 foldermc+
"*_ZJet*"+ntupletag+
"*.root",foldermc+
"*_ttHJetTobb*"+ntupletag+
"*.root",
246 foldermc+
"*_WH_HToBB*"+ntupletag+
"*.root",foldermc+
"*_ZH_HToBB*"+ntupletag+
"*.root",
247 foldermc+
"*_WWTo*"+ntupletag+
"*.root",foldermc+
"*_WZ*"+ntupletag+
"*.root",
248 foldermc+
"*_ZZ_*"+ntupletag+
"*.root" 251 set<string> nottfiles = {foldermc+
"*_WJetsToLNu*"+ntupletag+
"*.root",
252 foldermc+
"*_ST_*"+ntupletag+
"*.root",
253 foldermc+
"*_TTW*"+ntupletag+
"*.root", foldermc+
"*_TTZ*"+ntupletag+
"*.root",
254 foldermc+
"*_TTGJets*"+ntupletag+
"*.root",foldermc+
"*_TTTT*"+ntupletag+
"*.root",
255 foldermc+
"*QCD_HT*Inf_Tune*"+ntupletag+
"*.root",
256 foldermc+
"*QCD_HT*0_Tune*"+ntupletag+
"*.root",foldermc+
"*DYJetsToLL*"+ntupletag+
"*.root",
257 foldermc+
"*_ZJet*"+ntupletag+
"*.root",foldermc+
"*_ttHJetTobb*"+ntupletag+
"*.root",
258 foldermc+
"*_WH_HToBB*"+ntupletag+
"*.root",foldermc+
"*_ZH_HToBB*"+ntupletag+
"*.root",
259 foldermc+
"*_WWTo*"+ntupletag+
"*.root",foldermc+
"*_WZ*"+ntupletag+
"*.root",
260 foldermc+
"*_ZZ_*"+ntupletag+
"*.root" 263 set<string> nowfiles = {foldermc+
"*_TTJets*Lept*"+ntupletag+
"*.root", foldermc+
"*_TTJets_HT*"+ntupletag+
"*.root",
264 foldermc+
"*_ST_*"+ntupletag+
"*.root",
265 foldermc+
"*_TTW*"+ntupletag+
"*.root", foldermc+
"*_TTZ*"+ntupletag+
"*.root",
266 foldermc+
"*_TTGJets*"+ntupletag+
"*.root",foldermc+
"*_TTTT*"+ntupletag+
"*.root",
267 foldermc+
"*QCD_HT*Inf_Tune*"+ntupletag+
"*.root",
268 foldermc+
"*QCD_HT*0_Tune*"+ntupletag+
"*.root",foldermc+
"*DYJetsToLL*"+ntupletag+
"*.root",
269 foldermc+
"*_ZJet*"+ntupletag+
"*.root",foldermc+
"*_ttHJetTobb*"+ntupletag+
"*.root",
270 foldermc+
"*_WH_HToBB*"+ntupletag+
"*.root",foldermc+
"*_ZH_HToBB*"+ntupletag+
"*.root",
271 foldermc+
"*_WWTo*"+ntupletag+
"*.root",foldermc+
"*_WZ*"+ntupletag+
"*.root",
272 foldermc+
"*_ZZ_*"+ntupletag+
"*.root" 275 set<string> ttfiles = {foldermc+
"*_TTJets*Lept*"+ntupletag+
"*.root", foldermc+
"*_TTJets_HT*"+ntupletag+
"*.root"};
276 set<string> wfiles = {foldermc+
"*_WJetsToLNu*"+ntupletag+
"*.root"};
281 allfiles, baselinef &&
"stitch && ntruleps<=1");
283 allfiles, baselinef &&
"stitch && ntruleps<=1 && mt_tru>140 && 0");
285 allfiles, baselinef &&
"stitch && ntruleps>=2");
327 vector<shared_ptr<Process> > all_procs = {proc_tt1l, proc_tt2l, proc_other};
334 vector<oneplot> plotcuts({{
"njets",
"met>200", {
"njets==5",
"njets==6",
"njets==7",
"njets==8",
"njets>=9"}},
335 {
"met",
"njets==5", {
"met>100 && met<=150",
"met>150 && met<=200",
"met>200 && met<=350",
"met>350&&met<=500",
"met>500"}}});
336 vector<TString> abcdcuts = {
"mt<=140 && mj14<=400",
"mt<=140 && mj14>400",
337 "mt>140 && mj14<=400",
"mt>140 && mj14>400"};
338 size_t Nabcd = abcdcuts.size();
341 vector<vector<vector<TString> > > allcuts(plotcuts.size(), vector<vector<TString> > (Nabcd));
342 for(
size_t iplot=0; iplot<plotcuts.size(); iplot++){
343 for(
size_t iabcd=0; iabcd<abcdcuts.size(); iabcd++){
344 vector<TableRow> table_cuts;
345 for(
size_t ibin=0; ibin<plotcuts[iplot].bincuts.size(); ibin++){
346 TString totcut=plotcuts[iplot].baseline+
" && "+plotcuts[iplot].bincuts[ibin]+
" && "+abcdcuts[iabcd];
347 table_cuts.push_back(
TableRow(
"", totcut.Data()));
348 allcuts[iplot][iabcd].push_back(totcut);
350 TString tname =
"rmj"; tname += iplot; tname += iabcd;
351 pm.
Push<
Table>(tname.Data(), table_cuts, all_procs,
false,
false);
364 for(
size_t iplot=0; iplot<plotcuts.size(); iplot++){
366 vector<vector<vector<GammaParams> > > allyields(4,vector<vector<GammaParams> >(Nabcd));
367 for(
size_t iabcd=0; iabcd<abcdcuts.size(); iabcd++){
368 Table * yield_table =
static_cast<Table*
>(pm.
Figures()[iplot*Nabcd+iabcd].get());
370 allyields[
tt1l] [iabcd] = yield_table->
Yield(proc_tt1l.get(),
lumi);
371 allyields[
tt2l] [iabcd] = yield_table->
Yield(proc_tt2l.get(),
lumi);
372 allyields[
other][iabcd] = yield_table->
Yield(proc_other.get(),
lumi);
379 vector<vector<vector<int> > > indices({
385 vector<TString> leglabels({
"tt: M_{J}<400",
"tt: M_{J}>400",
"bkg: M_{J}<400",
"bkg: M_{J}>400"});
386 plotRatio(allyields, plotcuts[iplot], indices, leglabels);
389 indices = vector<vector<vector<int> > >({
390 {{
tt1l,
r4, 1}, {
tt1l,
r3, -1}, {
bkg,
r2, -1}, {
bkg,
r1, 1}},
392 {{
tt2l,
r4, 1}, {
tt2l,
r3, -1}, {
bkg,
r2, -1}, {
bkg,
r1, 1}},
393 {{
bkg,
r4, 1}, {
bkg,
r3, -1}, {
bkg,
r2, -1}, {
bkg,
r1, 1}}
401 leglabels = vector<TString>({
"0-1l",
"2l",
"All bkg."});
402 plotRatio(allyields, plotcuts[iplot], indices, leglabels);
408 double seconds = (chrono::duration<double>(chrono::high_resolution_clock::now() - begTime)).count();
410 cout<<endl<<
"Finding "<<plotcuts.size()<<
" plots took "<<round(seconds)<<
" seconds ("<<hhmmss<<
")"<<endl<<endl;
420 void printDebug(vector<vector<TString> > &allcuts, vector<vector<vector<GammaParams> > > &allyields,
423 cout<<endl<<endl<<
"============================ Printing cuts ============================"<<endl;
424 cout<<
"-- Baseline cuts: "<<baseline<<endl<<endl;
425 for(
size_t ibin=0; ibin<allcuts[0].size(); ibin++){
426 for(
size_t iabcd=0; iabcd<allcuts.size(); iabcd++){
427 cout<<
"MC: " <<setw(9)<<
RoundNumber(allyields[
bkg] [iabcd][ibin].Yield(), digits)
428 <<
" tt1l: "<<setw(9)<<
RoundNumber(allyields[
tt1l] [iabcd][ibin].Yield(), digits)
429 <<
" tt2l: "<<setw(9)<<
RoundNumber(allyields[
tt2l] [iabcd][ibin].Yield(), digits)
430 <<
" other: "<<setw(9)<<
RoundNumber(allyields[
other][iabcd][ibin].Yield(), digits)
431 <<
" - "<< allcuts[iabcd][ibin]<<endl;
441 static struct option long_options[] = {
442 {
"lumi", required_argument, 0,
'l'},
443 {
"skim", required_argument, 0,
's'},
444 {
"debug", no_argument, 0,
'd'},
450 opt = getopt_long(argc, argv,
"s:l:d", long_options, &option_index);
467 printf(
"Bad option! getopt_long returned character code 0%o\n", opt);
PlotOpt & TopMargin(double top)
void setPlotStyle(PlotOpt opts)
PlotOpt & LeftMargin(double left)
std::vector< GammaParams > Yield(const Process *process, double luminosity) const
TString HoursMinSec(float fseconds)
std::string CodeToPlainText(std::string code)
Abstract base class for access to ntuple variables.
const std::vector< std::unique_ptr< Figure > > & Figures() const
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)
vector< TString > bincuts
std::string execute(const std::string &cmd)
NamedFunc offshellw("offshellw",[](const Baby &b) -> NamedFunc::ScalarType{for(unsigned i(0);i< b.mc_pt() ->size();i++){if(abs(b.mc_id() ->at(i))!=24) continue;if(b.mc_mass() ->at(i) > 140.){return 1;}}return 0;})
double calcKappa(std::vector< std::vector< float > > &entries, std::vector< std::vector< float > > &weights, std::vector< float > &powers, float &mSigma, float &pSigma, bool do_data=false, bool verbose=false, double syst=-1., bool do_plot=false, int nrep=100000)
std::vector< float > *const & mc_pt() const
Get mc_pt for current event and cache it.
FigureType & Push(Args &&...args)
std::vector< GammaParams > BackgroundYield(double luminosity) const
std::string CodeToRootTex(std::string code)
int main(int argc, char *argv[])
TString RoundNumber(double num, int decimals, double denom=1.)
Organizes efficient production of plots with single loop over each process.
void plotRatio(vector< vector< vector< GammaParams > > > &allyields, oneplot &plotdef, vector< vector< vector< int > > > &indices, vector< TString > &leglabels)
std::vector< int > *const & mc_id() const
Get mc_id for current event and cache it.
void printDebug(vector< vector< TString > > &allcuts, vector< vector< vector< GammaParams > > > &allyields, TString baseline)
void GetOptions(int argc, char *argv[])
PlotOpt & LegendEntryHeight(double height)
void MakePlots(double luminosity, const std::string &subdir="")
Prints all added plots with given luminosity.
std::vector< float > *const & mc_mass() const
Get mc_mass for current event and cache it.
PlotOpt & RightMargin(double right)
Loads colors from a text configuration file.