17 #include "RooStats/NumberCountingUtils.h" 19 #include "TGraphAsymmErrors.h" 26 #include "core/baby.hpp" 48 TString
skim =
"standard";
56 vector<vector<vector<float> > > &kappas, vector<vector<vector<float> > > &preds);
59 vector<vector<vector<float> > > &kappas, vector<vector<vector<float> > > &preds);
61 vector<vector<vector<float> > > &kappas, vector<vector<vector<float> > > &preds);
62 TString
Zbi(
double Nobs,
double Nbkg,
double Eup_bkg,
double Edown_bkg);
69 for (
const auto &pt: *(b.
leps_pt())) stvar += pt;
73 int main(
int argc,
char *argv[]){
74 gErrorIgnoreLevel=6000;
77 chrono::high_resolution_clock::time_point begTime;
78 begTime = chrono::high_resolution_clock::now();
83 string hostname =
execute(
"echo $HOSTNAME");
85 bfolder =
"/net/cms2";
89 if(
only_method.Contains(
"met150")) ntupletag =
"_metG150";
90 else ntupletag =
"_metG200";
99 string foldersig(bfolder+
"/cms2r0/babymaker/babies/2016_08_10/T1tttt/merged_mcbase_standard/");
100 string foldermc(bfolder+
"/cms2r0/babymaker/babies/2016_08_10/mc/merged_mcbase_stdnj5/");
101 string folderdata(bfolder+
"/cms2r0/babymaker/babies/2016_08_10/data/merged_database_stdnj5/");
102 if(
skim.Contains(
"met100")) {
103 foldermc = bfolder+
"/cms2r0/babymaker/babies/2016_08_10/mc/merged_mcbase_met100_stdnj5/";
108 if(
skim.Contains(
"2015")){
110 foldermc = bfolder+
"/cms2r0/babymaker/babies/2016_04_29/mc/merged_mcbase_stdnj5/";
111 folderdata = bfolder+
"/cms2r0/babymaker/babies/2016_04_29/data/merged_stdnj5/";
113 ntupletag=
"1lht500met200";
114 foldermc = bfolder+
"/cms2r0/babymaker/babies/2015_11_28/mc/skim_1lht500met200/";
115 folderdata = bfolder+
"/cms2r0/babymaker/babies/2016_02_04/data/singlelep/combined/skim_1lht500met200/";
119 Palette colors(
"txt/colors.txt",
"default");
122 string baseline_s =
"mj14>250 && nleps>=1 && met>150 && njets>=5";
127 if(
do_ht) baseline = baseline &&
"ht>500";
128 else baseline = baseline &&
st>500;
132 {foldermc+
"*_TTJets_Tune*"+ntupletag+
"*.root"},
133 baseline &&
"stitch && pass");
136 {foldersig+
"*mGluino-1300_mLSP-900_*.root"},
137 baseline &&
"stitch");
138 auto proc_t1nc = Process::MakeShared<Baby_full>(
"T1tttt(NC)",
Process::Type::signal, colors(
"t1tttt"),
139 {foldersig+
"*mGluino-1700_mLSP-100_*.root"},
140 baseline &&
"stitch");
142 {foldermc+
"*_TTJets*SingleLept*"+ntupletag+
"*.root", foldermc+
"*_TTJets_HT*"+ntupletag+
"*.root"},
143 baseline &&
"stitch && ntruleps==1 && pass");
145 {foldermc+
"*_TTJets*DiLept*"+ntupletag+
"*.root", foldermc+
"*_TTJets_HT*"+ntupletag+
"*.root"},
146 baseline &&
"stitch && ntruleps==2 && pass");
149 vector<string> vnames_other({
"_WJetsToLNu",
"_ST_",
"_TTW",
"_TTZ",
"DYJetsToLL",
150 "_ZJet",
"_ttHJetTobb",
"_TTGJets",
"_TTTT",
151 "_WH_HToBB",
"_ZH_HToBB",
"_WWTo",
"_WZ",
"_ZZ_"});
153 if(
skim.Contains(
"2015")) vnames_other.push_back(
"QCD_HT");
155 vnames_other.push_back(
"QCD_HT*0_Tune");
156 vnames_other.push_back(
"QCD_HT*Inf_Tune");
158 set<string> names_other;
159 for(
auto name : vnames_other)
160 names_other.insert(name = foldermc +
"*" + name +
"*" + ntupletag +
"*.root");
162 names_other, baseline &&
"stitch && pass");
165 string trigs =
"trig_ra4";
166 if(
skim.Contains(
"2015")) trigs =
"(trig[4]||trig[8]||trig[28]||trig[14])";
169 string jsonCuts =
"nonblind";
170 if(
skim.Contains(
"2015"))
lumi = 2.3;
171 else if(
json==
"0p869"){
173 jsonCuts =
"nonblind";
174 }
else if(
json==
"2p8"){
176 jsonCuts =
"json2p6";
177 }
else if(
json==
"1p5"){
179 jsonCuts =
"json4p0&&!json2p6";
180 }
else if(
json==
"4p3"){
182 jsonCuts =
"json4p0";
183 }
else if(
json==
"3p4"){
185 jsonCuts =
"json7p65&&!json4p0";
186 }
else if(
json==
"7p7"){
188 jsonCuts =
"json7p65";
189 }
else if(
json==
"12p9"){
191 jsonCuts =
"json12p9";
196 if(
only_method.Contains(
"old")) trigs =
"(trig[4]||trig[8])";
197 if(!
skim.Contains(
"2015")) trigs +=
" && "+jsonCuts;
200 {folderdata+
"*"+ntupletag+
"*.root"},baseline && trigs &&
"pass");
202 vector<shared_ptr<Process> > all_procs = {proc_tt1l, proc_tt2l, proc_other};
205 all_procs.push_back(proc_t1nc);
206 all_procs.push_back(proc_t1c);
208 if(!
only_mc) all_procs.push_back(proc_data);
215 TString c_vvlowmet =
"met>100 && met<=150";
216 TString c_vlowmet =
"met>150 && met<=200";
217 TString c_lowmet =
"met>200 && met<=350";
218 TString c_midmet =
"met>350 && met<=500";
219 TString c_higmet =
"met>500";
222 TString c_vlownb =
"nbm==0";
223 TString c_lownb =
"nbm==1";
224 TString c_midnb =
"nbm==2";
225 TString c_hignb =
"nbm>=3";
228 TString c_vlownj =
"njets>=4 && njets<=5";
229 TString c_lownj =
"njets>=6 && njets<=8";
230 TString c_hignj =
"njets>=9";
231 TString c_nj5 =
"njets==5";
234 vector<TString> abcdcuts_std = {
"mt<=140 && mj14<=400 && nj_all_1l",
235 "mt<=140 && mj14>400 && nj_1l",
236 "mt>140 && mj14<=400 && nj_all_1l",
237 "mt>140 && mj14>400 && nj_1l"};
239 vector<TString> abcdcuts_veto = {
"mt<=140 && mj14<=400 && nleps==1 && nveto==0 && nbm>=1 && nj_all_1l",
240 "mt<=140 && mj14>400 && nleps==1 && nveto==0 && nbm>=1 && nj_1l",
241 "mt>140 && mj14<=400 && nleps==1 && nveto==1 && nbm>=1 && nbm<=2 && nj_all_1l",
242 "mt>140 && mj14>400 && nleps==1 && nveto==1 && nbm>=1 && nbm<=2 && nj_1l"};
244 vector<TString> abcdcuts_2l = {
"mt<=140 && mj14<=400 && nleps==1 && nveto==0 && nbm>=1 && nj_all_1l",
245 "mt<=140 && mj14>400 && nleps==1 && nveto==0 && nbm>=1 && nj_1l",
246 " mj14<=400 && nleps==2 && nbm<=2 && nj_all_2l",
247 " mj14>400 && nleps==2 && nbm<=2 && nj_2l"};
249 vector<TString> abcdcuts_2lveto;
250 for(
size_t ind=0; ind<2; ind++) abcdcuts_2lveto.push_back(abcdcuts_2l[ind]);
251 for(
size_t ind=2; ind<abcdcuts_2l.size(); ind++){
252 abcdcuts_2lveto.push_back(
"(("+abcdcuts_2l[ind]+
") || ("+abcdcuts_veto[ind]+
"))");
253 abcdcuts_2lveto.back().ReplaceAll(
"(( ",
"((");
258 vector<abcd_method> abcds;
259 vector<TString> abcdcuts, metcuts, bincuts;
263 vector<TString> methods_all = {
"m2lveto",
"m2lonly",
"mvetoonly",
"signal",
"signal_nb1",
"signal_nb2",
264 "m2lvetomet150",
"m2lonlymet150",
"mvetoonlymet150",
"m1lmet150",
265 "m5j",
"agg_himet",
"agg_mixed",
"agg_himult",
"agg_1b"};
267 vector<TString> methods_std = {
"m1lmet150",
"m5j",
"signal",
"m2lveto",
"m2lvetoonemet"};
269 vector<TString>
methods = methods_std;
273 for(
auto name: methods){
275 methods.push_back(name);
276 name.ReplaceAll(
"_el",
"_mu");
277 methods.push_back(name);
278 if(name.Contains(
"2l")){
279 name.ReplaceAll(
"_mu",
"_emu");
280 methods.push_back(name);
285 for(
size_t iabcd=0; iabcd<methods.size(); iabcd++) {
286 TString
method = methods[iabcd];
287 TString basecuts =
"", caption =
"";
290 if(method.Contains(
"2l") || method.Contains(
"veto")) {
291 metcuts = vector<TString>{c_vlowmet, c_lowmet, c_midmet};
292 if(
only_mc) metcuts.push_back(c_higmet);
293 if(method.Contains(
"onemet")) metcuts = vector<TString>{
"met>150 && met<=500"};
294 bincuts = vector<TString>{c_lownj, c_hignj};
295 caption =
"Dilepton validation regions. D3 and D4 have ";
298 abcdcuts = abcdcuts_std;
299 basecuts =
"nleps==1 && nveto==0 && nbm>=1";
303 if(method.Contains(
"2lonly")) {
304 abcdcuts = abcdcuts_2l;
305 caption +=
"two reconstructed leptons";
307 if(method.Contains(
"2lveto")) {
308 abcdcuts = abcdcuts_2lveto;
309 caption +=
"either two reconstructed leptons, or one lepton and one track";
311 if(method.Contains(
"vetoonly")) {
312 abcdcuts = abcdcuts_veto;
313 caption +=
"one lepton and one track";
315 if(method.Contains(
"2lcombined")) {
316 metcuts = vector<TString>{
"met>200&&met<=500"};
317 bincuts = vector<TString>{
"njets>=6"};
318 abcdcuts = abcdcuts_2l;
319 caption +=
"two reconstructed leptons";
321 if(method.Contains(
"2lold")) {
322 metcuts = vector<TString>{
"met>200&&met<=400"};
323 abcdcuts = abcdcuts_2l;
324 abcdcuts[0].ReplaceAll(
"&& nveto==0 ",
"");
325 abcdcuts[1].ReplaceAll(
"&& nveto==0 ",
"");
326 caption +=
"two reconstructed leptons";
329 if(method.Contains(
"2lvetocombined")) {
330 metcuts = vector<TString>{
"met>150&&met<=500"};
331 bincuts = vector<TString>{
"njets>=6"};
332 abcdcuts = abcdcuts_2lveto;
333 caption +=
"either two reconstructed leptons, or one lepton and one track";
337 if(method.Contains(
"signal")) {
338 metcuts = vector<TString>{c_lowmet, c_midmet, c_higmet};
339 bincuts = vector<TString>{c_lownb+
" && "+c_lownj, c_lownb+
" && "+c_hignj,
340 c_midnb+
" && "+c_lownj, c_midnb+
" && "+c_hignj,
341 c_hignb+
" && "+c_lownj, c_hignb+
" && "+c_hignj};
342 caption =
"Signal search regions";
343 if(method.Contains(
"nb1")) {
344 bincuts = vector<TString>{c_lownb+
" && "+c_lownj, c_lownb+
" && "+c_hignj};
345 caption +=
" for $\\nb=1$";
347 if(method.Contains(
"nb2")) {
348 bincuts = vector<TString>{c_midnb+
" && "+c_lownj, c_midnb+
" && "+c_hignj,
349 c_hignb+
" && "+c_lownj, c_hignb+
" && "+c_hignj};
350 caption +=
" for $\\nb\\geq2$";
352 if(method.Contains(
"allmet")) {
353 metcuts = vector<TString>{c_vlowmet, c_lowmet, c_midmet, c_higmet};
354 caption =
"Signal search regions plus $150<\\met\\leq200$ GeV";
356 if(method.Contains(
"met100")) {
357 metcuts = vector<TString>{c_vvlowmet, c_vlowmet, c_lowmet, c_midmet, c_higmet};
358 bincuts = vector<TString>{c_lownb+
" && "+c_lownj, c_lownb+
" && "+c_hignj,
359 c_midnb+
" && "+c_lownj, c_midnb+
" && "+c_hignj,
360 c_hignb+
" && "+c_lownj, c_hignb+
" && "+c_hignj};
361 caption =
"Signal search regions plus $100<\\met\\leq200$ GeV";
363 if(method.Contains(
"nb0")) {
364 metcuts = vector<TString>{c_vvlowmet, c_vlowmet, c_lowmet, c_midmet, c_higmet};
365 bincuts = vector<TString>{
"nbm==0&&njets>=6"};
366 basecuts =
"nleps==1 && nveto==0";
367 caption =
"Signal search regions plus $100<\\met\\leq200$ GeV for $\\Nb==0$";
369 if(method.Contains(
"onemet")) {
370 metcuts = vector<TString>{
"met>200"};
371 caption =
"Signal search regions plus $150<\\met\\leq200$ GeV";
373 if(method.Contains(
"onebin")) bincuts = vector<TString>{
"njets>=6&&nbm>=1"};
377 if(method.Contains(
"m5j")) {
378 metcuts = vector<TString>{c_lowmet, c_midmet, c_higmet};
380 bincuts = vector<TString>{c_lownb+
" && "+c_nj5, c_midnb+
" && "+c_nj5, c_hignb+
" && "+c_nj5};
381 caption =
"Validation regions with $1\\ell, \\njets=5$";
382 if(method.Contains(
"met100")) {
383 metcuts = vector<TString>{c_vvlowmet, c_vlowmet, c_lowmet, c_midmet, c_higmet};
384 caption =
"Validation regions with $1\\ell, \\njets=5$, $100<\\met\\leq200$ GeV";
386 if(method.Contains(
"onebin")) bincuts = vector<TString>{
"njets==5&&nbm>=1"};
390 if(method.Contains(
"agg_himet")) {
391 metcuts = vector<TString>{
"met>500"};
392 bincuts = vector<TString>{
"nbm>=3&&njets>=6"};
393 caption =
"High-\\met aggregate region with $1\\ell$, $\\met>500\\text{ GeV}$, $\\njets\\geq6$, $\\nb\\geq3$";
395 if(method.Contains(
"agg_mixed")) {
396 metcuts = vector<TString>{
"met>350"};
397 bincuts = vector<TString>{
"nbm>=2&&njets>=9"};
398 caption =
"Mixed aggregate region with $1\\ell$, $\\met>350\\text{ GeV}$, $\\njets\\geq9$, $\\nb\\geq2$";
400 if(method.Contains(
"agg_himult")) {
401 metcuts = vector<TString>{
"met>200"};
402 bincuts = vector<TString>{
"nbm>=3&&njets>=9"};
403 caption =
"High-multiplicity aggregate region with $1\\ell$, $\\met>200\\text{ GeV}$, $\\njets\\geq9$, $\\nb\\geq3$";
405 if(method.Contains(
"agg_1b")) {
406 metcuts = vector<TString>{
"met>500"};
407 bincuts = vector<TString>{
"nbm>=1&&njets>=6"};
408 caption =
"Single b-tag aggregate region with $1\\ell$, $\\met>500\\text{ GeV}$, $\\njets\\geq6$, $\\nb\\geq1$";
412 if(method.Contains(
"met150")) {
413 metcuts = vector<TString>{c_vlowmet};
414 caption.ReplaceAll(
"regions",
"region for very low \\met");
416 if(method.Contains(
"m1lmet150")) {
417 bincuts = vector<TString>{c_lownb+
" && "+c_lownj, c_lownb+
" && "+c_hignj,
418 c_midnb+
" && "+c_lownj, c_midnb+
" && "+c_hignj};
419 caption =
"Single lepton validation region for very low \\met";
421 if(
skim.Contains(
"2015")) {
422 caption +=
". Data taken in 2015";
426 abcds.push_back(
abcd_method(method, metcuts, bincuts, abcdcuts, caption, basecuts));
427 if(
skim.Contains(
"mj12")) {
428 abcds.back().setMj12();
429 abcds.back().caption +=
". Using $M_J^{1.2}$";
431 if(method.Contains(
"noint")) abcds.back().setIntNbNj(
false);
432 if(method.Contains(
"_el") || method.Contains(
"_mu") || method.Contains(
"_emu")) abcds.back().setLeptons();
433 if(method.Contains(
"_el")) abcds.back().caption +=
". Only electrons";
434 if(method.Contains(
"_mu")) abcds.back().caption +=
". Only muons";
435 if(method.Contains(
"_emu")) abcds.back().caption +=
". Only $e/\\mu$ pairs in D3 and D4";
438 vector<TableRow> table_cuts;
439 for(
size_t icut=0; icut < abcds.back().allcuts.size(); icut++)
440 table_cuts.push_back(
TableRow(abcds.back().allcuts[icut].Data(), abcds.back().allcuts[icut].Data()));
442 TString tname =
"preds"; tname += iabcd;
443 pm.
Push<
Table>(tname.Data(), table_cuts, all_procs,
true,
false);
456 vector<TString> tablenames;
457 for(
size_t imethod=0; imethod<abcds.size(); imethod++) {
461 vector<vector<GammaParams> > allyields;
466 allyields.push_back(yield_table->
Yield(proc_t1nc.get(),
lumi));
467 allyields.push_back(yield_table->
Yield(proc_t1c.get(),
lumi));
470 allyields.push_back(yield_table->
Yield(proc_other.get(),
lumi));
471 allyields.push_back(yield_table->
Yield(proc_tt1l.get(),
lumi));
472 allyields.push_back(yield_table->
Yield(proc_tt2l.get(),
lumi));
476 vector<vector<vector<float> > > kappas, preds;
477 findPreds(abcds[imethod], allyields, kappas, preds);
481 TString fullname =
printTable(abcds[imethod], allyields, kappas, preds);
482 tablenames.push_back(fullname);
495 cout<<endl<<
"===== Tables to be moved to the AN/PAS/paper:"<<endl;
496 for(
size_t ind=0; ind<tablenames.size(); ind++){
497 TString name=tablenames[ind]; name.ReplaceAll(
"fulltable",
"table");
498 cout<<
" mv "<<name<<
" ${tables_folder}"<<endl;
500 cout<<endl<<
"===== Tables that can be compiled"<<endl;
501 for(
size_t ind=0; ind<tablenames.size(); ind++)
502 cout<<
" pdflatex "<<tablenames[ind]<<
" > /dev/null"<<endl;
506 double seconds = (chrono::duration<double>(chrono::high_resolution_clock::now() - begTime)).count();
508 cout<<endl<<
"Finding "<<abcds.size()<<
" tables took "<<round(seconds)<<
" seconds ("<<hhmmss<<
")"<<endl<<endl;
520 vector<vector<vector<float> > > &kappas, vector<vector<vector<float> > > &preds){
521 cout<<endl<<
"Printing table (significance estimation can take a bit)"<<endl;
535 TString
blind_s =
"$\\spadesuit$";
539 if(
lumi < 1) digits_lumi = 3;
540 if(
lumi >= 15) digits_lumi = 0;
542 TString outname =
"tables/table_pred_lumi"+lumi_s; outname.ReplaceAll(
".",
"p");
543 if(
skim.Contains(
"2015")) outname +=
"_2015";
544 if(
skim.Contains(
"mj12")) outname +=
"_mj12";
545 if(
unblind) outname +=
"_unblind";
546 else outname +=
"_blind";
547 if(
do_ht) outname +=
"_ht500";
548 outname +=
"_"+abcd.
method+
".tex";
549 ofstream out(outname);
552 if(abcd.
method.Contains(
"signal") && Ncol>7) out <<
"\\resizebox{\\textwidth}{!}{\n";
553 out <<
"\\begin{tabular}[tbp!]{ l ";
558 out<<
"}\\hline\\hline\n";
559 out<<
"${\\cal L}="<<lumi_s<<
"$ fb$^{-1}$ ";
560 if(
do_signal) out <<
" & T1tttt(NC) & T1tttt(C) ";
561 if(
split_bkg) out <<
" & Other & $t\\bar{t}(1\\ell)$ & $t\\bar{t}(2\\ell)$ ";
562 out <<
"& $\\kappa$ & MC bkg. & Pred.";
563 if(!
only_mc) out <<
"& Obs. & Obs./MC "<<(do_zbi?
"& Signi.":
"");
564 else if(
do_signal) out <<
"& Signi.(NC) & Signi.(C)";
565 out <<
" \\\\ \\hline\\hline\n";
569 for(
size_t iplane=0; iplane < abcd.
planecuts.size(); iplane++) {
570 out<<endl<<
"\\multicolumn{"<<Ncol<<
"}{c}{$"<<
CodeToLatex(abcd.
planecuts[iplane].Data())<<
"$} \\\\ \\hline\n";
571 for(
size_t iabcd=0; iabcd < abcd.
abcdcuts.size(); iabcd++){
572 for(
size_t ibin=0; ibin < abcd.
bincuts[iplane].size(); ibin++){
573 size_t index = abcd.
indexBin(iplane, ibin, iabcd);
574 if(abcd.
int_nbnj && iabcd%2==0 && ibin>0)
continue;
575 if(iabcd==3 && ibin==0) out <<
"\\hline" << endl;
577 out << (iabcd<=1?
"R":abcd.
rd_letter) << iabcd+1 <<
": ";
579 out <<
"All "<<(abcd.
bincuts[iplane][ibin].Contains(
"nbm")?
"\\nb, ":
"")<<
"\\njets" ;
582 else if(abcd.
method.Contains(
"2lveto") && iabcd>=2){
583 if(abcd.
bincuts[iplane][ibin].Contains(
"6")) out<<
"Low \\njets";
584 else out<<
"High \\njets";
589 out<<ump<<
RoundNumber(allyields[2][index].Yield(), digits)<< ump <<
RoundNumber(allyields[3][index].Yield(), digits);
593 out << ump <<
RoundNumber(allyields[offset+2][index].Yield(), digits)
594 << ump <<
RoundNumber(allyields[offset+3][index].Yield(), digits)
595 << ump <<
RoundNumber(allyields[offset+4][index].Yield(), digits);
599 if(iabcd==3) out <<
"$" <<
RoundNumber(kappas[iplane][ibin][0], digits)
600 <<
"^{+" <<
RoundNumber(kappas[iplane][ibin][1], digits)
601 <<
"}_{-" <<
RoundNumber(kappas[iplane][ibin][2], digits) <<
"}$ ";
603 out << ump <<
RoundNumber(allyields[1][index].Yield(), digits)<< ump;
605 if(iabcd==3) out <<
"$" <<
RoundNumber(preds[iplane][ibin][0], digits)
606 <<
"^{+" <<
RoundNumber(preds[iplane][ibin][1], digits)
607 <<
"}_{-" <<
RoundNumber(preds[iplane][ibin][2], digits) <<
"}$ ";
612 out << ump <<
RoundNumber(allyields[0][index].Yield(), 0);
613 TString ratio_s =
"-";
614 double Nobs = allyields[0][index].Yield(), Nmc = allyields[1][index].Yield();
615 double Eobs = sqrt(Nobs), Emc = allyields[1][index].Uncertainty();
618 double ratio = Nobs/Nmc;
619 double Eratio = sqrt(pow(Eobs/Nmc,2) + pow(Nobs*Emc/Nmc/Nmc,2));
622 out << ump << ratio_s;
625 if(do_zbi && iabcd==3) out << ump <<
Zbi(allyields[0][index].Yield(), preds[iplane][ibin][0],
626 preds[iplane][ibin][1], preds[iplane][ibin][2]);
629 out<<ump<<
Zbi(allyields[0][index].Yield()+allyields[2][index].Yield(),preds[iplane][ibin][0],
630 preds[iplane][ibin][1], preds[iplane][ibin][2]);
631 out<<ump<<
Zbi(allyields[0][index].Yield()+allyields[3][index].Yield(),preds[iplane][ibin][0],
632 preds[iplane][ibin][1], preds[iplane][ibin][2]);
638 out <<
"\\hline\\hline\n";
643 out<<
"\\end{tabular}"<<endl;
644 if(abcd.
method.Contains(
"signal") && Ncol>7) out <<
"}\n";
648 TString fullname = outname; fullname.ReplaceAll(
"table_",
"fulltable_");
649 ofstream full(fullname);
650 ifstream header(
"txt/header.tex");
651 full<<header.rdbuf();
653 if(!abcd.
method.Contains(
"signal")) full <<
"\\usepackage[landscape]{geometry}\n\n";
654 full <<
"\\begin{document}\n\n";
655 full <<
"\\begin{table}\n\\centering\n";
656 full <<
"\\caption{" << abcd.
caption <<
".}\\vspace{0.1in}\n\\label{tab:"<<abcd.
method<<
"}\n";
657 ifstream outtab(outname);
658 full << outtab.rdbuf();
660 full <<
"\\end{table}\n\n";
661 full <<
"\\end{document}\n";
667 TString
Zbi(
double Nobs,
double Nbkg,
double Eup_bkg,
double Edown_bkg){
670 double Nsig = Nobs-Nbkg;
671 double zbi = RooStats::NumberCountingUtils::BinomialExpZ(Nsig, Nbkg, Eup_bkg/Nbkg);
672 if(Nbkg==0) zbi = RooStats::NumberCountingUtils::BinomialWithTauExpZ(Nsig, Nbkg, 1/Eup_bkg);
675 if(zbi_s!=
"-") zbi_s =
"$"+zbi_s+
"\\sigma$";
676 if(Nsig<=0 || Eup_bkg<=0) zbi_s =
"-";
685 bool label_up =
false;
686 double markerSize = 1.1;
689 PlotOpt opts(
"txt/plot_styles.txt",
"Kappa");
691 if(kappas.size() >= 4) {
704 vector<vector<vector<kmarker> > > k_ordered;
705 vector<kmarker> ind_bcuts;
707 vector<kmarker> bcuts({{
"nbm==1",4,20,zz}, {
"nbm==2",2,21,zz}, {
"nbm>=3",kGreen+3,22,zz},
708 {
"nbm==0",kMagenta+2,23,zz},
709 {
"nbl==0",kMagenta+2,23,zz}});
712 for(
size_t iplane=0; iplane < kappas.size(); iplane++) {
713 k_ordered.push_back(vector<vector<kmarker> >());
714 for(
size_t ibin=0; ibin < kappas[iplane].size(); ibin++){
715 TString bincut = abcd.
bincuts[iplane][ibin];
716 bincut.ReplaceAll(
" ",
"");
717 bincut.ReplaceAll(
"mm_",
"");
720 index = bincut.First(
'[');
721 bincut.Remove(index, bincut.First(
']')-index+1);
724 for(
size_t ib=0; ib<bcuts.size(); ib++){
725 if(bincut.Contains(bcuts[ib].cut)){
728 for(
size_t indb=0; indb<ind_bcuts.size(); indb++)
729 if(ind_bcuts[indb].color == bcuts[ib].color) cutfound =
true;
730 if(!cutfound) ind_bcuts.push_back(bcuts[ib]);
733 bincut.ReplaceAll(bcuts[ib].cut+
"&&",
"");
734 for(
size_t ik=0; ik<k_ordered[iplane].size(); ik++){
736 if(bincut==k_ordered[iplane][ik][0].cut){
737 k_ordered[iplane][ik].push_back({bincut, bcuts[ib].color, bcuts[ib].style, kappas[iplane][ibin]});
744 k_ordered[iplane].push_back(vector<kmarker>({{bincut, bcuts[ib].color, bcuts[ib].style, kappas[iplane][ibin]}}));
753 k_ordered[iplane].push_back(vector<kmarker>({{bincut, bcuts[0].color, bcuts[0].style, kappas[iplane][ibin]}}));
755 if(ind_bcuts.size()==0) ind_bcuts.push_back(bcuts[0]);
761 TCanvas can(
"can",
"");
762 can.SetFillStyle(4000);
763 TLine line; line.SetLineWidth(2); line.SetLineStyle(2);
764 TLatex label; label.SetTextSize(0.05); label.SetTextFont(42); label.SetTextAlign(23);
765 if(k_ordered.size()>3) label.SetTextSize(0.04);
768 float minx = 0.5, maxx = nbins+0.5, miny = 0, maxy = 2.4;
769 if(label_up) maxy = 2.6;
770 TH1D histo(
"histo",
"", nbins, minx, maxx);
771 histo.SetMinimum(miny);
772 histo.SetMaximum(maxy);
773 histo.GetYaxis()->CenterTitle(
true);
774 histo.GetXaxis()->SetLabelOffset(0.008);
775 histo.SetYTitle(
"#kappa");
780 vector<vector<double> > vx(ind_bcuts.size()), vexh(ind_bcuts.size()), vexl(ind_bcuts.size());
781 vector<vector<double> > vy(ind_bcuts.size()), veyh(ind_bcuts.size()), veyl(ind_bcuts.size());
782 for(
size_t iplane=0; iplane < k_ordered.size(); iplane++) {
783 for(
size_t ibin=0; ibin < k_ordered[iplane].size(); ibin++){
785 histo.GetXaxis()->SetBinLabel(bin,
CodeToRootTex(k_ordered[iplane][ibin][0].cut.Data()).c_str());
787 double xval = bin, nbs = k_ordered[iplane][ibin].size(), minxb = 0.15, binw = 0;
792 binw = 2*minxb/(nbs-1);
794 for(
size_t ib=0; ib<k_ordered[iplane][ibin].size(); ib++){
796 for(
size_t indb=0; indb<ind_bcuts.size(); indb++){
797 if(ind_bcuts[indb].color == k_ordered[iplane][ibin][ib].color){
798 vx[indb].push_back(xval);
800 vexl[indb].push_back(0);
801 vexh[indb].push_back(0);
802 vy[indb].push_back(k_ordered[iplane][ibin][ib].kappa[0]);
803 veyh[indb].push_back(k_ordered[iplane][ibin][ib].kappa[1]);
804 veyl[indb].push_back(k_ordered[iplane][ibin][ib].kappa[2]);
811 line.SetLineStyle(2); line.SetLineWidth(2);
812 if (iplane<k_ordered.size()-1) line.DrawLine(bin+0.5, miny, bin+0.5, maxy);
814 if(label_up) label.DrawLatex((2*bin-k_ordered[iplane].size()+1.)/2., maxy-0.1,
CodeToRootTex(abcd.
planecuts[iplane].Data()).c_str());
815 else label.DrawLatex((2*bin-k_ordered[iplane].size()+1.)/2., -0.26,
CodeToRootTex(abcd.
planecuts[iplane].Data()).c_str());
820 if(label_up) legY = 0.8;
821 double legW = 0.22, legH = legSingle*(ind_bcuts.size()+1)/2;
822 if(ind_bcuts.size()>3) legH = legSingle*((ind_bcuts.size()+1)/2);
823 TLegend leg(legX, legY-legH, legX+legW, legY);
825 leg.SetFillStyle(0); leg.SetBorderSize(0);
828 TGraphAsymmErrors graph[20];
829 for(
size_t indb=0; indb<ind_bcuts.size(); indb++){
830 graph[indb] = TGraphAsymmErrors(vx[indb].size(), &(vx[indb][0]), &(vy[indb][0]),
831 &(vexl[indb][0]), &(vexh[indb][0]), &(veyl[indb][0]), &(veyh[indb][0]));
832 graph[indb].SetMarkerStyle(ind_bcuts[indb].style); graph[indb].SetMarkerSize(markerSize);
833 graph[indb].SetMarkerColor(ind_bcuts[indb].color);
834 graph[indb].SetLineColor(ind_bcuts[indb].color); graph[indb].SetLineWidth(2);
835 graph[indb].Draw(
"p0 same");
836 leg.AddEntry(&graph[indb],
CodeToRootTex(ind_bcuts[indb].cut.Data()).c_str(),
"p");
838 if(ind_bcuts.size()>1) leg.Draw();
842 cmslabel.SetTextSize(0.06);
843 cmslabel.SetNDC(kTRUE);
844 cmslabel.SetTextAlign(11);
845 cmslabel.DrawLatex(opts.
LeftMargin()+0.005, 1-opts.
TopMargin()+0.015,
"#font[62]{CMS} #scale[0.8]{#font[52]{Simulation}}");
846 cmslabel.SetTextAlign(31);
849 line.SetLineStyle(3); line.SetLineWidth(1);
850 line.DrawLine(minx, 1, maxx, 1);
852 TString fname=
"plots/kappa_" + abcd.
method;
853 if(
do_ht) fname +=
"_ht500";
856 cout<<endl<<
" open "<<fname<<endl;
863 vector<vector<vector<float> > > &kappas, vector<vector<vector<float> > > &preds){
865 vector<float> pow_kappa({ 1, -1, -1, 1});
867 vector<float> pow_totpred( {-1, 1, 1, 1, -1, -1, 1});
869 float val(1.), valup(1.), valdown(1.);
871 for(
size_t iplane=0; iplane < abcd.
planecuts.size(); iplane++) {
872 kappas.push_back(vector<vector<float> >());
873 preds.push_back(vector<vector<float> >());
874 for(
size_t ibin=0; ibin < abcd.
bincuts[iplane].size(); ibin++){
875 vector<vector<float> > entries;
876 vector<vector<float> > weights;
878 for(
size_t iabcd=0; iabcd < 3; iabcd++){
879 size_t index = abcd.
indexBin(iplane, ibin, iabcd);
880 entries.push_back(vector<float>());
881 weights.push_back(vector<float>());
882 entries.back().push_back(allyields[0][index].Yield());
883 weights.back().push_back(1.);
886 vector<vector<float> > kentries;
887 vector<vector<float> > kweights;
889 for(
size_t iabcd=0; iabcd < 4; iabcd++){
890 size_t index = abcd.
indexBin(iplane, ibin, iabcd);
892 entries.push_back(vector<float>());
893 weights.push_back(vector<float>());
894 entries.back().push_back(allyields[1][index].NEffective());
895 weights.back().push_back(allyields[1][index].Weight());
897 kentries.push_back(vector<float>());
898 kweights.push_back(vector<float>());
899 kentries.back().push_back(allyields[1][index].NEffective());
900 kweights.back().push_back(allyields[1][index].Weight());
904 val =
calcKappa(entries, weights, pow_totpred, valdown, valup);
905 if(valdown<0) valdown = 0;
906 preds[iplane].push_back(vector<float>({val, valup, valdown}));
908 val =
calcKappa(kentries, kweights, pow_kappa, valdown, valup);
909 if(valdown<0) valdown = 0;
910 kappas[iplane].push_back(vector<float>({val, valup, valdown}));
918 vector<vector<vector<float> > > &kappas, vector<vector<vector<float> > > &preds){
921 cout<<endl<<endl<<
"=================== Printing cuts for method "<<abcd.
method<<
" ==================="<<endl;
922 cout<<
"-- Baseline cuts: "<<baseline<<endl;
923 for(
size_t iplane=0; iplane < abcd.
planecuts.size(); iplane++) {
924 cout<<endl<<
" **** Plane "<<abcd.
planecuts[iplane]<<
" ***"<<endl;
925 for(
size_t ibin=0; ibin < abcd.
bincuts[iplane].size(); ibin++){
926 for(
size_t iabcd=0; iabcd < abcd.
abcdcuts.size(); iabcd++){
927 size_t index = abcd.
indexBin(iplane, ibin, iabcd);
928 cout<<
"MC: "<<setw(8)<<
RoundNumber(allyields[1][index].Yield(),digits)
929 <<
" Data: "<<setw(4)<<
RoundNumber(allyields[0][index].Yield(), 0)
930 <<
" - "<< abcd.
allcuts[index]<<endl;
932 cout<<
"Kappa = "<<
RoundNumber(kappas[iplane][ibin][0],digits)<<
"+"<<
RoundNumber(kappas[iplane][ibin][1],digits)
933 <<
"-"<<
RoundNumber(kappas[iplane][ibin][2],digits)<<
", Prediction = " 935 <<
"-"<<
RoundNumber(preds[iplane][ibin][2],digits)<<endl;
944 static struct option long_options[] = {
945 {
"method", required_argument, 0,
'm'},
946 {
"lumi", required_argument, 0,
'l'},
947 {
"skim", required_argument, 0,
's'},
948 {
"json", required_argument, 0,
'j'},
949 {
"split_bkg", no_argument, 0,
'b'},
950 {
"no_signal", no_argument, 0,
'n'},
951 {
"do_leptons", no_argument, 0,
'p'},
952 {
"unblind", no_argument, 0,
'u'},
953 {
"only_mc", no_argument, 0,
'o'},
954 {
"only_kappa", no_argument, 0,
'k'},
955 {
"debug", no_argument, 0,
'd'},
956 {
"only_dilepton", no_argument, 0,
'2'},
957 {
"ht", no_argument, 0, 0},
963 opt = getopt_long(argc, argv,
"m:s:j:udbnl:p2ok", long_options, &option_index);
1007 optname = long_options[option_index].name;
1008 if(optname ==
"ht"){
1011 printf(
"Bad option! Found option name %s\n", optname.c_str());
1016 printf(
"Bad option! getopt_long returned character code 0%o\n", opt);
PlotOpt & TopMargin(double top)
void setPlotStyle(PlotOpt opts)
PlotOpt & LeftMargin(double left)
int main(int argc, char *argv[])
void findPreds(abcd_method &abcd, vector< vector< GammaParams > > &allyields, vector< vector< vector< float > > > &kappas, vector< vector< vector< float > > > &preds)
std::vector< GammaParams > Yield(const Process *process, double luminosity) const
TString HoursMinSec(float fseconds)
std::vector< float > *const & leps_pt() const
Get leps_pt for current event and cache it.
double Significance(double Nobs, double Nbkg, double Eup_bkg, double Edown_bkg=-1.)
PlotOpt & CanvasWidth(int width)
TString lowerNjets(TString &cut)
const std::string & Name() const
Get the string representation of this function.
Abstract base class for access to ntuple variables.
const std::vector< std::unique_ptr< Figure > > & Figures() const
void ReplaceAll(std::string &str, const std::string &orig, const std::string &rep)
size_t indexBin(size_t iplane, size_t ibin, size_t iabcd)
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)
TString Zbi(double Nobs, double Nbkg, double Eup_bkg, double Edown_bkg)
TString printTable(abcd_method &abcd, vector< vector< GammaParams > > &allyields, vector< vector< vector< float > > > &kappas, vector< vector< vector< float > > > &preds, vector< shared_ptr< Process > > &proc_sigs)
std::string execute(const std::string &cmd)
list methods
Aggregate bins.
std::vector< std::vector< TString > > bincuts
std::vector< TString > allcuts
std::vector< TString > abcdcuts
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)
FigureType & Push(Args &&...args)
std::vector< GammaParams > BackgroundYield(double luminosity) const
std::string CodeToRootTex(std::string code)
std::string CodeToLatex(std::string code)
void plotKappa(abcd_method &abcd, vector< vector< vector< float > > > &kappas)
void printDebug(abcd_method &abcd, vector< vector< GammaParams > > &allyields, TString baseline, vector< vector< vector< float > > > &kappas, vector< vector< vector< float > > > &preds)
TString RoundNumber(double num, int decimals, double denom=1.)
Organizes efficient production of plots with single loop over each process.
std::vector< TString > planecuts
PlotOpt & BottomMargin(double bottom)
std::vector< GammaParams > DataYield() const
const NamedFunc st("st", [](const Baby &b) -> NamedFunc::ScalarType{float stvar=b.ht();for(const auto &pt:*(b.leps_pt())) stvar+=pt;return stvar;})
PlotOpt & LegendEntryHeight(double height)
void MakePlots(double luminosity, const std::string &subdir="")
Prints all added plots with given luminosity.
float const & ht() const
Get ht for current event and cache it.
PlotOpt & RightMargin(double right)
void GetOptions(int argc, char *argv[])
Loads colors from a text configuration file.