10 #include <initializer_list> 25 #include "RooArgList.h" 26 #include "RooArgSet.h" 27 #include "RooRealVar.h" 28 #include "RooAbsData.h" 29 #include "RooDataSet.h" 30 #include "RooProdPdf.h" 31 #include "RooNLLVar.h" 32 #include "RooMinuit.h" 47 int main(
int argc,
char *argv[]){
50 if(
file_wspace ==
"")
ERROR(
"You need to specify the file containing the workspace with option -f");
58 RooWorkspace *w =
static_cast<RooWorkspace*
>(in_file.Get(
"w"));
59 RooFitResult *fit_b =
static_cast<RooFitResult*
>(in_file.Get(
"fit_b"));
60 RooFitResult *fit_s =
static_cast<RooFitResult*
>(in_file.Get(
"fit_s"));
81 TFile in_file(path.c_str(),
"read");
82 RooFitResult *fit_b =
static_cast<RooFitResult*
>(in_file.Get(
"fit_b"));
83 RooFitResult *fit_s =
static_cast<RooFitResult*
>(in_file.Get(
"fit_s"));
84 if(fit_b ==
nullptr || fit_s ==
nullptr){
85 execute(
"python/run_combine.py --full_fit --overwrite "+path);
90 RooArgSet funcs = w.allFunctions();
91 TIter iter(funcs.createIterator());
92 int size = funcs.getSize();
93 RooAbsArg *arg =
nullptr;
95 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
97 if(arg ==
nullptr)
continue;
98 string name = arg->GetName();
99 if(name.substr(0,9) !=
"nsig_BLK_")
continue;
100 TIter iter2(arg->getVariables()->createIterator());
101 int size2 = arg->getVariables()->getSize();
102 RooAbsArg *arg2 =
nullptr;
104 while((arg2 = static_cast<RooAbsArg*>(iter2())) && i2 < size2){
106 if(arg2 ==
nullptr)
continue;
107 string name2 = arg2->GetName();
108 auto pos2 = name2.find(
"_PRC_");
109 if(pos2 != string::npos){
112 return name2.substr(pos2+5);
123 for(
size_t i = 0; i < s.size(); ++i){
134 const RooFitResult &
f,
141 ofstream out(file_name);
142 out <<
"\\documentclass{article}\n";
143 out <<
"\\usepackage{amsmath,graphicx,rotating,longtable}\n";
144 out <<
"\\thispagestyle{empty}\n";
145 out <<
"\\begin{document}\n";
146 out <<
"\\begin{longtable}{rr}\n";
147 out <<
"\\hline\\hline\n";
148 out <<
"Variable & Fit Value\\\\\n";
150 out << fixed << setprecision(6);
151 for(
const auto &var: var_names){
152 RooRealVar *varo = w.var(var.c_str());
153 if(varo ==
nullptr)
continue;
154 if(!varo->isConstant()){
155 out <<
TexFriendly(var) <<
" & $" << varo->getVal() <<
"\\pm" <<
GetError(*varo, f) <<
"$\\\\\n";
157 out <<
TexFriendly(var) <<
" & $" << varo->getVal() <<
"$\\\\\n";
160 for(
const auto &func: func_names){
161 RooAbsReal *funco = w.function(func.c_str());
162 if(funco ==
nullptr)
continue;
163 if(!funco->isConstant()){
164 out <<
TexFriendly(func) <<
" & $" << funco->getVal() <<
"\\pm" <<
GetError(*funco, f) <<
"$\\\\\n";
166 out <<
TexFriendly(func) <<
" & $" << funco->getVal() <<
"$\\\\\n";
170 out <<
"\\hline\\hline\n";
171 out <<
"\\end{longtable}\n";
172 out <<
"\\end{document}\n";
175 cout<<
"Saved "<<file_name.c_str()<<endl;
179 const RooFitResult &
f,
187 bool dosig(
Contains(file_name,
"sig_table")), blind_all(
Contains(file_name,
"r4blinded"));
188 bool blind_2b(
Contains(file_name,
"1bunblinded"));
189 size_t digits(2), ncols(11);
190 if(!dosig) ncols = 9;
196 ofstream out(file_name);
197 out << fixed << setprecision(digits);
198 out <<
"\\documentclass{article}\n";
199 out <<
"\\usepackage{amsmath,graphicx,rotating,longtable}\n";
200 out <<
"\\thispagestyle{empty}\n";
201 out <<
"\\begin{document}\n";
202 out <<
"\\begin{longtable}{rr}\n";
203 out <<
"\\centering\n";
204 out <<
"\\resizebox{\\textwidth}{!}{\n";
205 out <<
"\\begin{tabular}{l ";
206 for(
size_t i = 0; i < ncols-1; ++i) out <<
"r";
208 out <<
"\\hline\\hline\n";
210 for(
const auto &prc_name: prc_names){
211 out << prc_name <<
" & ";
213 out <<
"MC Bkg. "<<(dosig?
"& Bkgnd. Pred. ":
"")<<
"& Signal "<<(dosig?
"& Sig. Pred. ":
"")
214 <<
"& $\\kappa$ & Pred. & Obs.";
219 for(
const auto &bin_name: bin_names){
221 out <<
"\\hline\\hline"<<endl;
222 if(
Contains(bin_name,
"lowmet")) out<<
"\\multicolumn{"<<ncols<<
"}{c}{$200<E_{T}^{miss}\\leq 350$} \\\\ \\hline"<<endl;
223 if(
Contains(bin_name,
"medmet")) out<<
"\\multicolumn{"<<ncols<<
"}{c}{$350<E_{T}^{miss}\\leq 500$} \\\\ \\hline"<<endl;
224 if(
Contains(bin_name,
"highmet")) out<<
"\\multicolumn{"<<ncols<<
"}{c}{$E_{T}^{miss}>500$} \\\\ \\hline"<<endl;
230 ReplaceAll(bin_tex,
"lownj\\_",
"$6 \\leq N_{jets}\\leq8$, ");
231 ReplaceAll(bin_tex,
"highnj\\_",
"$N_{jets}\\geq9$, ");
232 ReplaceAll(bin_tex,
"allnb",
"all $N_{jets}, N_b$");
236 for(
int ind(1); ind<=4; ind++){
237 ReplaceAll(bin_tex,
"r"+to_string(ind)+
"\\_",
"R"+to_string(ind)+
": ");
238 ReplaceAll(bin_tex,
"r"+to_string(ind)+
"c\\_",
"R"+to_string(ind)+
": ");
239 ReplaceAll(bin_tex,
"d"+to_string(ind)+
"\\_",
"D"+to_string(ind)+
": ");
241 out << bin_tex <<
" & ";
242 for(
const auto &prc_name: prc_names){
243 out <<
GetMCYield(w, bin_name, prc_name) <<
" & ";
250 out <<
GetMCYield(w, bin_name, sig_name) <<
" & ";
258 if(full_err >= stat_err){
259 double ratio = stat_err/full_err;
260 sys_err = full_err*sqrt(1.-ratio*ratio);
261 if(
false)
DBG(sys_err);
263 DBG(
"(systematic error)^2<0 for " << bin_name);
265 out <<
"$" << kappa <<
"\\pm" << full_err <<
"$ & ";
274 if(
Contains(bin_name,
"4") && (blind_all || (!
Contains(bin_name,
"1b") && blind_2b))) out <<
"-- & ";
275 else out << setprecision(0) <<
GetObserved(w, bin_name);
276 out << setprecision(digits);
279 if(
Contains(bin_name,
"r3") ||
Contains(bin_name,
"d3")) out <<
"\\hline"<<endl;
281 out <<
"\\hline\\hline\n";
282 out <<
"\\end{tabular}\n";
284 out <<
"\\end{longtable}\n";
285 out <<
"\\end{document}\n";
288 cout<<
"Saved "<<file_name.c_str()<<endl;
292 const string &bin_name,
293 const string &prc_name){
294 RooArgSet funcs = w.allFunctions();
295 TIter iter(funcs.createIterator());
296 int size = funcs.getSize();
297 RooAbsArg *arg =
nullptr;
299 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
301 if(arg ==
nullptr)
continue;
302 string name = arg->GetName();
303 if(name.substr(0,8) !=
"ymc_BLK_")
continue;
304 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
305 if(!(
Contains(name,
"_PRC_"+prc_name)))
continue;
306 return static_cast<RooRealVar*
>(arg)->getVal();
313 const string &bin_name){
314 RooArgSet funcs = w.allFunctions();
315 TIter iter(funcs.createIterator());
316 int size = funcs.getSize();
317 RooAbsArg *arg =
nullptr;
319 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
321 if(arg ==
nullptr)
continue;
322 string name = arg->GetName();
323 if(name.substr(0,8) !=
"ymc_BLK_")
continue;
324 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
325 if(
Contains(name,
"_PRC_"))
continue;
326 return static_cast<RooRealVar*
>(arg)->getVal();
333 const RooFitResult &
f,
334 const string &bin_name){
335 RooArgSet funcs = w.allFunctions();
336 TIter iter(funcs.createIterator());
337 int size = funcs.getSize();
338 RooAbsArg *arg =
nullptr;
340 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
342 if(arg ==
nullptr)
continue;
343 string name = arg->GetName();
344 if(name.substr(0,8) !=
"ymc_BLK_")
continue;
345 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
346 if(
Contains(name,
"_PRC_"))
continue;
347 return GetError(*static_cast<RooAbsReal*>(arg), f);
354 const string &bin_name){
355 RooArgSet funcs = w.allFunctions();
356 TIter iter(funcs.createIterator());
357 int size = funcs.getSize();
358 RooAbsArg *arg =
nullptr;
360 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
362 if(arg ==
nullptr)
continue;
363 string name = arg->GetName();
364 if(name.substr(0,9) !=
"nbkg_BLK_")
continue;
365 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
366 if(
Contains(name,
"_PRC_"))
continue;
367 return static_cast<RooRealVar*
>(arg)->getVal();
374 const RooFitResult &
f,
375 const string &bin_name){
376 RooArgSet funcs = w.allFunctions();
377 TIter iter(funcs.createIterator());
378 int size = funcs.getSize();
379 RooAbsArg *arg =
nullptr;
381 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
383 if(arg ==
nullptr)
continue;
384 string name = arg->GetName();
385 if(name.substr(0,9) !=
"nbkg_BLK_")
continue;
386 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
387 if(
Contains(name,
"_PRC_"))
continue;
388 return GetError(*static_cast<RooAbsReal*>(arg), f);
395 const string &bin_name){
396 RooArgSet funcs = w.allFunctions();
397 TIter iter(funcs.createIterator());
398 int size = funcs.getSize();
399 RooAbsArg *arg =
nullptr;
401 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
403 if(arg ==
nullptr)
continue;
404 string name = arg->GetName();
405 if(name.substr(0,9) !=
"nsig_BLK_")
continue;
406 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
407 if(
Contains(name,
"_PRC_"))
continue;
408 return static_cast<RooRealVar*
>(arg)->getVal();
415 const RooFitResult &
f,
416 const string &bin_name){
417 RooArgSet funcs = w.allFunctions();
418 TIter iter(funcs.createIterator());
419 int size = funcs.getSize();
420 RooAbsArg *arg =
nullptr;
422 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
424 if(arg ==
nullptr)
continue;
425 string name = arg->GetName();
426 if(name.substr(0,9) !=
"nsig_BLK_")
continue;
427 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
428 if(
Contains(name,
"_PRC_"))
continue;
429 return GetError(*static_cast<RooAbsReal*>(arg), f);
436 const string &bin_name){
437 RooArgSet funcs = w.allFunctions();
438 TIter iter(funcs.createIterator());
439 int size = funcs.getSize();
440 RooAbsArg *arg =
nullptr;
442 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
444 if(arg ==
nullptr)
continue;
445 string name = arg->GetName();
446 if(name.substr(0,9) !=
"nexp_BLK_")
continue;
447 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
448 if(
Contains(name,
"_PRC_"))
continue;
449 return static_cast<RooRealVar*
>(arg)->getVal();
456 const RooFitResult &
f,
457 const string &bin_name){
458 RooArgSet funcs = w.allFunctions();
459 TIter iter(funcs.createIterator());
460 int size = funcs.getSize();
461 RooAbsArg *arg =
nullptr;
463 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
465 if(arg ==
nullptr)
continue;
466 string name = arg->GetName();
467 if(name.substr(0,9) !=
"nexp_BLK_")
continue;
468 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
469 if(
Contains(name,
"_PRC_"))
continue;
470 return GetError(*static_cast<RooAbsReal*>(arg), f);
477 const string &bin_name){
478 RooAbsArg *arg =
nullptr;
479 const RooArgSet &vars = w.allVars();
480 TIterator *iter_ptr = vars.createIterator();
481 while(iter_ptr !=
nullptr && *(*iter_ptr) !=
nullptr){
482 arg =
static_cast<RooAbsArg*
>((*iter_ptr)());
483 if(arg ==
nullptr)
continue;
484 string name = arg->GetName();
485 if(name.substr(0,9) !=
"nobs_BLK_")
continue;
486 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
487 if(
Contains(name,
"_PRC_"))
continue;
488 return static_cast<RooRealVar*
>(arg)->getVal();
494 const string &bin_name){
495 RooArgSet funcs = w.allFunctions();
496 TIter iter(funcs.createIterator());
497 int size = funcs.getSize();
498 RooAbsArg *arg =
nullptr;
500 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
502 if(arg ==
nullptr)
continue;
503 string name = arg->GetName();
504 if(name.substr(0,15) !=
"nosyskappa_BLK_")
continue;
505 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
506 if(
Contains(name,
"_PRC_"))
continue;
507 return static_cast<RooRealVar*
>(arg)->getVal();
514 const RooFitResult &
f,
515 const string &bin_name){
516 RooArgSet funcs = w.allFunctions();
517 TIter iter(funcs.createIterator());
518 int size = funcs.getSize();
519 RooAbsArg *arg =
nullptr;
521 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
523 if(arg ==
nullptr)
continue;
524 string name = arg->GetName();
525 if(name.substr(0,15) !=
"nosyskappa_BLK_")
continue;
526 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
527 if(
Contains(name,
"_PRC_"))
continue;
528 return GetError(*static_cast<RooAbsReal*>(arg), f);
535 const string &bin_name){
536 RooArgSet funcs = w.allFunctions();
537 TIter iter(funcs.createIterator());
538 int size = funcs.getSize();
539 RooAbsArg *arg =
nullptr;
541 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
543 if(arg ==
nullptr)
continue;
544 string name = arg->GetName();
545 if(name.substr(0,13) !=
"syskappa_BLK_")
continue;
546 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
547 if(
Contains(name,
"_PRC_"))
continue;
548 return static_cast<RooRealVar*
>(arg)->getVal();
555 const RooFitResult &
f,
556 const string &bin_name){
557 RooArgSet funcs = w.allFunctions();
558 TIter iter(funcs.createIterator());
559 int size = funcs.getSize();
560 RooAbsArg *arg =
nullptr;
562 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
564 if(arg ==
nullptr)
continue;
565 string name = arg->GetName();
566 if(name.substr(0,13) !=
"syskappa_BLK_")
continue;
567 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
568 if(
Contains(name,
"_PRC_"))
continue;
569 return GetError(*static_cast<RooAbsReal*>(arg), f);
576 const string &bin_name){
577 RooArgSet funcs = w.allFunctions();
578 TIter iter(funcs.createIterator());
579 int size = funcs.getSize();
580 RooAbsArg *arg =
nullptr;
582 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
584 if(arg ==
nullptr)
continue;
585 string name = arg->GetName();
586 if(name.substr(0,12) !=
"kappamc_BLK_")
continue;
587 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
588 if(
Contains(name,
"_PRC_"))
continue;
589 return static_cast<RooRealVar*
>(arg)->getVal();
596 const RooFitResult &
f,
597 const string &bin_name){
598 RooArgSet funcs = w.allFunctions();
599 TIter iter(funcs.createIterator());
600 int size = funcs.getSize();
601 RooAbsArg *arg =
nullptr;
603 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
605 if(arg ==
nullptr)
continue;
606 string name = arg->GetName();
607 if(name.substr(0,12) !=
"kappamc_BLK_")
continue;
608 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
609 if(
Contains(name,
"_PRC_"))
continue;
610 return GetError(*static_cast<RooAbsReal*>(arg), f);
617 const RooFitResult &
f){
619 RooArgList pars = f.floatParsFinal();
620 for(
int ipar = 0; ipar < pars.getSize(); ++ipar){
621 RooRealVar *fit_var =
static_cast<RooRealVar*
>(pars.at(ipar));
622 if(fit_var ==
nullptr)
continue;
623 RooRealVar *w_var = w.var(fit_var->GetName());
624 if(w_var ==
nullptr)
continue;
625 w_var->removeRange();
626 w_var->setVal(fit_var->getVal());
627 w_var->setError(fit_var->getError());
628 if(fit_var->GetName() == string(
"r")) set_r =
true;
632 for(
const auto &var: var_names){
633 RooRealVar *varo = w.var(var.c_str());
634 if(varo ==
nullptr)
continue;
635 if(!varo->isConstant()){
640 RooRealVar *r_var =
static_cast<RooRealVar*
>(w.var(
"r"));
641 if(r_var !=
nullptr){
644 r_var->setConstant(
true);
646 r_var->setConstant(
false);
653 const RooFitResult &
f,
661 vector<vector<double> > component_yields =
GetComponentYields(w, bin_names, prc_names);
666 exp_signal.SetLineColor(kRed+1);
667 exp_signal.SetFillColor(0);
668 exp_signal.SetFillStyle(0);
676 TPad bot_pad(
"bot_pad",
"bot_pad", 0., 0., 1., 0.4);
677 bot_pad.SetFillColor(0); bot_pad.SetFillStyle(4000);
678 bot_pad.SetMargin(0.1, 0., 0.5, 0.);
681 TPad mid_pad(
"mid_pad",
"mid_pad", 0., 0.4, 1., 0.85);
682 mid_pad.SetFillColor(0); mid_pad.SetFillStyle(4000);
683 mid_pad.SetMargin(0.1, 0., 0.0, 0.);
684 if(!linear) mid_pad.SetLogy();
687 TPad top_pad(
"top_pad",
"top_pad", 0., 0.85, 1., 1.0);
688 top_pad.SetFillColor(0); top_pad.SetFillStyle(4000);
689 top_pad.SetMargin(0.1, 0., 0.0, 0.);
692 double font_size = 0.1;
696 signal.SetTitleSize(font_size,
"Y");
697 signal.SetTitleOffset(offset,
"Y");
698 signal.SetFillColor(kRed+1);
699 signal.SetFillStyle(1001);
700 signal.SetLineColor(2);
701 signal.SetLineStyle(1);
702 signal.SetLineWidth(0);
703 if(linear) signal.SetMinimum(0.);
704 else signal.SetMinimum(0.03);
706 for(
auto h = histos.rbegin(); h!= histos.rend(); ++h){
707 if(linear) h->SetMinimum(0.);
708 else h->SetMinimum(0.03);
712 double marker_size(1.4);
713 obs.SetMarkerStyle(20); obs.SetMarkerSize(marker_size);
714 band.Draw(
"02 same");
715 if(linear) obs.SetMinimum(0.);
716 else obs.SetMinimum(0.03);
717 obs.Draw(
"e0 x0 p0 same");
718 if(linear) signal.SetMinimum(0.);
719 else signal.SetMinimum(0.03);
720 signal.Draw(
"same axis");
721 if(linear) exp_signal.SetMinimum(0.);
722 else exp_signal.SetMinimum(0.03);
723 if(
Contains(file_name,
"bkg")) exp_signal.Draw(
"hist same");
726 TLegend l(0.1, 0., 1., 1.);
728 l.SetFillColor(0); l.SetFillStyle(4000);
730 l.AddEntry(&obs,
"Observed",
"lep");
731 if(r_var->isConstant()){
732 l.AddEntry(&exp_signal,
"Expected Signal",
"l");
734 l.AddEntry(&signal,
"Fitted Signal",
"f");
737 oss << setprecision(6) << fixed;
739 if(r_var ==
nullptr){
741 }
else if(r_var->isConstant()){
742 oss << r_var->getVal() <<
" (fixed)";
744 oss << r_var->getVal() <<
"#pm" <<
GetError(*r_var, f);
747 l.AddEntry(&obs, oss.str().c_str(),
"");
748 for(
auto h = histos.crbegin(); h != histos.crend(); ++h){
749 l.AddEntry(&(*h), h->GetName(),
"f");
754 TLine line; line.SetLineStyle(2);
755 TGraphErrors obs_rat =
MakeRatio(obs, signal);
756 TGraphErrors pred_rat =
MakeRatio(signal, signal);
758 obs_rat.SetMarkerStyle(20); obs_rat.SetMarkerSize(marker_size);
759 obs_rat.SetMarkerColor(1);
760 dumb.SetLineColor(0);
761 dumb.SetLineWidth(0);
762 dumb.SetFillColor(0);
763 dumb.SetFillStyle(4000);
765 dumb.SetMaximum(2.8);
766 dumb.SetTitle(
";;Obs/Pred ");
767 dumb.GetXaxis()->LabelsOption(
"V");
768 dumb.SetTitleSize(font_size,
"Y");
769 dumb.SetTitleOffset(offset,
"Y");
771 pred_rat.SetFillColor(kGray);
772 pred_rat.SetFillStyle(3001);
773 pred_rat.Draw(
"02 same");
774 obs_rat.Draw(
"ep0 same");
775 line.DrawLine(0.5, 1, 0.5+dumb.GetNbinsX(), 1);
776 c.Print(file_name.c_str());
780 vector<string> names;
781 TIter iter(w.allVars().createIterator());
782 int size = w.allVars().getSize();
783 TObject *obj =
nullptr;
785 while((obj = iter()) && i < size){
787 if(obj ==
nullptr)
continue;
788 string name = obj->GetName();
792 sort(names.begin(), names.end());
797 vector<string> names;
798 RooArgSet funcs = w.allFunctions();
799 TIter iter(funcs.createIterator());
800 int size = funcs.getSize();
801 TObject *obj =
nullptr;
803 while((obj = iter()) && i < size){
805 if(obj ==
nullptr)
continue;
806 string name = obj->GetName();
815 RooArgSet funcs = w.allFunctions();
816 vector<string> blocks = {
"lowmet",
"medmet",
"highmet"};
817 vector<string> regions = {
"r1",
"r2",
"r3",
"r4"};
818 vector<string> njets = {
"",
"lownj",
"highnj"};
819 vector<string> nbs = {
"allnb",
"1b",
"2b",
"3b"};
820 for(
const auto &block: blocks){
821 for(
const auto ®ion: regions){
822 for(
const auto &nj: njets){
823 for(
const auto &nb: nbs){
824 string name =
"nexp_BLK_"+block+
"_BIN_"+region+
"_"+block+
"_"+(nj==
""?string(
""):nj+
"_")+nb;
825 if(funcs.find(name.c_str())) names.push_back(name);
832 vector<string>
GetBinNames(
const RooWorkspace &w,
bool r4_only_local){
834 vector<string> names;
835 for(
const auto &
name: func_names){
836 if(
name.substr(0,9) !=
"nexp_BLK_")
continue;
838 string bin_name =
name.substr(5);
847 vector<string> names;
848 for(
const auto &
name: func_names){
849 if(
name.substr(0,9) !=
"nexp_BLK_")
continue;
850 auto bpos =
name.find(
"_BIN_");
851 auto ppos =
name.find(
"_PRC_");
852 if(bpos == string::npos)
continue;
853 string bin_name =
name.substr(bpos+5, ppos-bpos-5);
861 vector<string> names;
862 RooArgSet funcs = w.allFunctions();
863 TIter iter(funcs.createIterator());
864 int size = funcs.getSize();
865 RooAbsArg *arg =
nullptr;
867 while((arg = static_cast<RooAbsArg*>(iter())) && i < size){
869 if(arg ==
nullptr)
continue;
870 string name = arg->GetName();
871 if(name.substr(0,9) !=
"frac_BIN_")
continue;
872 auto prc_pos = name.find(
"_PRC_");
873 if(prc_pos == string::npos)
continue;
874 string bin_name = name.substr(prc_pos+5);
875 if(find(names.cbegin(), names.cend(), bin_name) != names.cend())
continue;
883 const vector<string> &bin_names,
884 const vector<string> &prc_names){
885 vector<vector<double> > yields(bin_names.size());
886 for(
auto &bin: yields){
887 bin = vector<double>(prc_names.size(), 0.);
889 for(
size_t ibin = 0; ibin < yields.size(); ++ibin){
890 const string &bin_name = bin_names.at(ibin);
891 auto blk_pos = bin_name.find(
"_BIN_");
892 if(blk_pos == string::npos)
continue;
893 string plain_name = bin_name.substr(blk_pos+5);
894 for(
size_t iprc = 0; iprc < yields.at(ibin).size(); ++iprc){
895 const string &prc_name = prc_names.at(iprc);
896 RooRealVar *nbkg_arg =
static_cast<RooRealVar*
>(w.function((
"nbkg_"+bin_name).c_str()));
897 if(nbkg_arg ==
nullptr)
continue;
898 RooRealVar *frac_arg =
static_cast<RooRealVar*
>(w.function((
"frac_BIN_"+plain_name+
"_PRC_"+prc_name).c_str()));
899 if(frac_arg ==
nullptr)
continue;
900 yields.at(ibin).at(iprc) = nbkg_arg->getVal() * frac_arg->getVal();
907 const vector<string> &bin_names,
908 const vector<string> &prc_names){
909 if(yields.size() == 0){
910 return vector<TH1D>();
912 vector<TH1D> histos(yields.at(0).size(),
913 TH1D(
"",
";;Yield ", yields.size(), 0.5, yields.size()+0.5));
914 for(
size_t ibin = 0; ibin < yields.size(); ++ibin){
915 for(
size_t iprc = 0; iprc < yields.at(ibin).size(); ++iprc){
916 histos.at(iprc).SetBinContent(ibin+1, yields.at(ibin).at(iprc));
919 for(
auto &h: histos) h.SetMinimum(0.03);
921 for(
size_t iprc = 0; iprc < histos.size(); ++iprc){
922 TH1D &h = histos.at(iprc);
923 h.SetName(prc_names.at(iprc).c_str());
926 h.SetFillColor(color);
927 h.SetLineColor(color);
929 for(
size_t ibin = 0; ibin < bin_names.size(); ++ibin){
930 const string &
name = bin_names.at(ibin);
931 auto pos = name.find(
"_BIN_");
932 if(pos == string::npos)
continue;
933 pos = name.find(
"4");
935 string label = name.substr(pos+5);
936 h.GetXaxis()->SetBinLabel(ibin+1, label.c_str());
939 sort(histos.begin(), histos.end(),
940 [](
const TH1D &
a,
const TH1D &
b) ->
bool{
return a.Integral() <
b.Integral();});
942 for(
size_t iprc = histos.size()-1; iprc < histos.size(); --iprc){
943 TH1D &h = histos.at(iprc);
944 for(
size_t isum = iprc-1; isum < histos.size(); --isum){
945 h.Add(&histos.at(isum));
953 const vector<string> &bin_names){
954 TH1D h(
"",
";;Yield ", bin_names.size(), 0.5, bin_names.size()+0.5);
957 h.SetLineColor(kRed+1);
961 for(
size_t ibin = 0; ibin < bin_names.size(); ++ibin){
962 h.SetBinError(ibin+1, 0.);
963 string name = bin_names.at(ibin);
964 auto pos = name.find(
"_BIN_");
965 name = name.substr(pos+5);
966 h.GetXaxis()->SetBinLabel(ibin+1, name.c_str());
967 if(pos != string::npos){
968 h.SetBinContent(ibin+1,
GetMCYield(w, name,
"signal"));
970 h.SetBinContent(ibin+1, -1.);
978 const RooFitResult &
f,
979 const vector<string> &bin_names){
980 TH1D h(
"signal",
";;Yield ", bin_names.size(), 0.5, bin_names.size()+0.5);
981 h.SetFillColor(kRed+1);
982 h.SetLineColor(kRed+1);
986 for(
size_t ibin = 0; ibin < bin_names.size(); ++ibin){
987 const string &
name = bin_names.at(ibin);
988 auto pos = name.find(
"_BIN_");
989 if(pos == string::npos)
continue;
990 string label = name.substr(pos+5);
991 h.GetXaxis()->SetBinLabel(ibin+1, label.c_str());
992 RooRealVar *var =
static_cast<RooRealVar*
>(w.function((
"nexp_"+name).c_str()));
993 if(var ==
nullptr)
continue;
994 h.SetBinContent(ibin+1, var->getVal());
995 h.SetBinError(ibin+1,
GetError(*var, f));
1002 const vector<string> &bin_names){
1003 TH1D h(
"observed",
";;Yield ", bin_names.size(), 0.5, bin_names.size()+0.5);
1004 h.SetBinErrorOption(TH1::kPoisson);
1007 h.SetFillStyle(4000);
1010 for(
size_t ibin = 0; ibin < bin_names.size(); ++ibin){
1011 const string &
name = bin_names.at(ibin);
1012 auto pos = name.find(
"_BIN_");
1013 if(pos == string::npos)
continue;
1014 string label = name.substr(pos+5);
1015 h.GetXaxis()->SetBinLabel(ibin+1, label.c_str());
1016 RooRealVar *var =
static_cast<RooRealVar*
>(w.var((
"nobs_"+name).c_str()));
1017 if(var ==
nullptr)
continue;
1018 h.SetBinContent(ibin+1, var->getVal());
1026 std::vector<TH1D> &cs){
1027 double factor = 0.02;
1031 double lmax = log(hmax);
1032 double lmin = log(hmin);
1033 double log_diff = lmax-lmin;
1034 lmin -= factor*log_diff;
1035 lmax += factor*log_diff;
1048 a.SetMaximum(hmax+1.1*sqrt(hmax));
1049 b.SetMaximum(hmax+1.1*sqrt(hmax));
1057 const vector<TH1D> &cs){
1060 if(this_max > the_max) the_max = this_max;
1061 for(
const auto &
c: cs){
1063 if(this_max > the_max) the_max = this_max;
1070 const vector<TH1D> &cs){
1073 if(this_min < the_min) the_min = this_min;
1074 for(
const auto &
c: cs){
1076 if(this_min < the_min) the_min = this_min;
1082 double the_max = -numeric_limits<double>::max();
1083 for(
int bin = 1; bin <= h.GetNbinsX(); ++bin){
1084 double content = h.GetBinContent(bin);
1085 if(content > the_max){
1097 double the_min = numeric_limits<double>::max();
1098 for(
int bin = 1; bin <= h.GetNbinsX(); ++bin){
1099 double content = h.GetBinContent(bin);
1100 if(content < the_min){
1112 TGraphErrors g(h.GetNbinsX());
1113 for(
int bin = 1; bin <= h.GetNbinsX(); ++bin){
1114 g.SetPoint(bin, h.GetBinCenter(bin), h.GetBinContent(bin));
1115 g.SetPointError(bin, 0.5, h.GetBinError(bin));
1117 g.SetFillColor(kGray);
1118 g.SetFillStyle(3001);
1123 TGraphErrors g(num.GetNbinsX());
1125 if(&num != &den) xerror = 0;
1126 for(
int bin = 1; bin <= num.GetNbinsX(); ++bin){
1127 double x = num.GetBinCenter(bin);
1128 double nc = num.GetBinContent(bin);
1129 double dc = den.GetBinContent(bin);
1130 double ne = num.GetBinError(bin);
1131 double big_num = 0.5*numeric_limits<float>::max();
1133 g.SetPoint(bin, x, nc/dc);
1134 g.SetPointError(bin, xerror, ne/dc);
1136 g.SetPoint(bin, x, 1.);
1137 g.SetPointError(bin, xerror, big_num);
1139 g.SetPoint(bin, x, nc > 0. ? big_num : -big_num);
1140 g.SetPointError(bin, xerror, big_num);
1147 auto pos = full_path.rfind(
"/");
1148 if(pos != string::npos){
1149 return full_path.substr(pos+1);
1156 const RooFitResult &
f,
1163 TCanvas
c(
"can",
"");
1166 TH1D h(
"",
";;#lambda", bin_names.size(), 0.5, bin_names.size()+0.5);
1167 for(
size_t ibin = 0; ibin < bin_names.size(); ++ibin){
1168 string bin = bin_names.at(ibin);
1169 auto pos = bin.find(
"_BIN_");
1170 string plain_bin = bin.substr(pos+5);
1171 h.GetXaxis()->SetBinLabel(ibin+1, plain_bin.c_str());
1172 h.SetBinContent(ibin+1, static_cast<RooRealVar*>(w.function((
"kappamc_"+bin).c_str()))->getVal());
1173 h.SetBinError(ibin+1,
GetError(*w.function((
"kappamc_"+bin).c_str()), f));
1175 h.GetXaxis()->LabelsOption(
"V");
1177 c.SetMargin(0.1, 0.05, 1./3., 0.05);
1178 c.Print(file_name.c_str());
1182 const RooFitResult &
f,
1183 string covar_file_name){
1185 const RooArgList &fpf = f.floatParsFinal();
1187 vector<RooAbsReal*> yields;
1188 RooArgSet funcs = w.allFunctions();
1189 TIter iter(funcs.createIterator());
1190 int size = funcs.getSize();
1191 RooAbsReal *arg =
nullptr;
1193 while((arg = static_cast<RooAbsReal*>(iter())) && i < size){
1195 if(arg ==
nullptr)
continue;
1196 string name = arg->GetName();
1197 if(name.substr(0,9) !=
"nbkg_BLK_")
continue;
1198 if(!
Contains(name,
"_BIN_"))
continue;
1199 if(
Contains(name,
"_PRC_"))
continue;
1201 yields.push_back(arg);
1204 vector<vector<double> > errors(fpf.getSize(), vector<double>(yields.size(), 0.));
1205 for(Int_t iparam = 0; iparam<fpf.getSize(); ++iparam){
1206 RooRealVar &rrv =
static_cast<RooRealVar&
>(*w.var(fpf.at(iparam)->GetName()));
1208 double cenVal = rrv.getVal();
1209 double minVal = rrv.getMin();
1210 double maxVal = rrv.getMax();
1211 double downVal = cenVal-fabs(rrv.getErrorLo());
1212 double upVal = cenVal+fabs(rrv.getErrorHi());
1213 if(upVal-downVal >= maxVal-minVal){
1217 }
else if(downVal < minVal){
1218 upVal += minVal - downVal;
1220 }
else if(upVal > maxVal){
1221 downVal -= upVal - maxVal;
1226 for(
size_t iyield = 0; iyield<yields.size(); ++iyield){
1227 errors.at(iparam).at(iyield) = 0.5*yields.at(iyield)->getVal();
1229 rrv.setVal(downVal);
1230 for(
size_t iyield = 0; iyield<yields.size(); ++iyield){
1231 errors.at(iparam).at(iyield) -= 0.5*yields.at(iyield)->getVal();
1236 vector<vector<double> > right(fpf.getSize(), vector<double>(yields.size(), 0.));
1237 for(Int_t iparam = 0; iparam<fpf.getSize(); ++iparam){
1238 for(
size_t iyield = 0; iyield<yields.size(); ++iyield){
1239 right.at(iparam).at(iyield) = 0.;
1240 for(Int_t entry = 0; entry<fpf.getSize(); ++entry){
1241 right.at(iparam).at(iyield) += f.correlation(fpf.at(iparam)->GetName(),fpf.at(entry)->GetName())
1242 * errors.at(entry).at(iyield);
1247 vector<vector<double> > covar(yields.size(), vector<double>(yields.size(), 0.));
1248 for(
size_t irow = 0; irow < yields.size(); ++irow){
1249 for(
size_t icol = 0.; icol < yields.size(); ++icol){
1250 covar.at(irow).at(icol) = 0.;
1251 for(Int_t ientry = 0.; ientry < fpf.getSize(); ++ientry){
1252 covar.at(irow).at(icol) += errors.at(ientry).at(irow) * right.at(ientry).at(icol);
1257 TH2D h_covar(
"",
"",
1258 covar.size(), -0.5, covar.size()-0.5,
1259 covar.size(), -0.5, covar.size()-0.5);
1261 covar.size(), -0.5, covar.size()-0.5,
1262 covar.size(), -0.5, covar.size()-0.5);
1263 h_covar.SetLabelSize(0.015,
"xy");
1264 h_covar.SetMarkerSize(12.5/covar.size());
1265 h_covar.SetTickLength(0.,
"xy");
1266 h_corr.SetLabelSize(0.015,
"xy");
1267 h_corr.SetMarkerSize(12.5/covar.size());
1268 h_corr.SetTickLength(0.,
"xy");
1269 for(
size_t x = 0;
x < yields.size(); ++
x){
1270 string name = yields.at(
x)->GetName();
1271 auto pos = name.find(
"_BIN_");
1272 name = name.substr(pos+5);
1274 h_covar.GetXaxis()->SetBinLabel(
x+1, name.c_str());
1275 h_covar.GetYaxis()->SetBinLabel(
x+1, name.c_str());
1276 h_corr.GetXaxis()->SetBinLabel(
x+1, name.c_str());
1277 h_corr.GetYaxis()->SetBinLabel(
x+1, name.c_str());
1278 for(
size_t y = 0;
y < yields.size(); ++
y){
1279 h_covar.SetBinContent(
x+1,
y+1,covar.at(
x).at(
y));
1280 h_corr.SetBinContent(
x+1,
y+1,covar.at(
x).at(
y)/sqrt(covar.at(
x).at(
x)*covar.at(
y).at(
y)));
1283 h_corr.SetMinimum(-1.);
1284 h_corr.SetMaximum(1.);
1286 const unsigned num = 3;
1287 const int bands = 255;
1289 double stops[num] = {0.0, 0.5, 1.0};
1290 double red[num] = {0.0, 1.0, 1.0};
1291 double green[num] = {0.0, 1.0, 0.0};
1292 double blue[num] = {1.0, 1.0, 0.0};
1293 int fi = TColor::CreateGradientColorTable(num, stops, red, green, blue, bands);
1294 for(
int ib = 0; ib < bands; ++ib){
1297 gStyle->SetNumberContours(bands);
1298 gStyle->SetPalette(bands, colors);
1300 TCanvas
c(
"can",
"", 1024, 1024);
1301 c.SetMargin(0.2, 0.05, 0.2, 0.05);
1302 gStyle->SetPaintTextFormat(
"6.1f");
1303 h_covar.LabelsOption(
"v",
"x");
1304 h_corr.LabelsOption(
"v",
"x");
1305 h_covar.Draw(
"axis");
1306 h_corr.Draw(
"col same");
1307 h_covar.Draw(
"text same");
1310 TLatex ltitle(c.GetLeftMargin(), 1.-0.5*c.GetTopMargin(),
1311 "#font[62]{CMS}#scale[0.76]{#font[52]{ Preliminary}}");
1312 TLatex rtitle(1.-c.GetRightMargin(), 1.-0.5*c.GetTopMargin(),
1313 "#scale[0.8]{35.9 fb^{-1} (13 TeV)}");
1316 ltitle.SetTextAlign(12);
1317 rtitle.SetTextAlign(32);
1319 ltitle.Draw(
"same");
1320 rtitle.Draw(
"same");
1321 c.Print(covar_file_name.c_str());
1323 TString fitname =
"Global";
1324 if(
Contains(covar_file_name,
"nor4")) {
1325 fitname =
"Predictive";
1327 TString pname = covar_file_name; pname.ReplaceAll(
".pdf",
".root");
1328 TFile file(pname,
"recreate");
1330 h_covar.Write(
"CovarianceMatrix_"+fitname+
"Fit");
1332 cout<<
"Saved correlation matrix in "<<pname<<endl<<endl;
1334 gStyle->SetPaintTextFormat(
"6.2f");
1337 h_corr.Draw(
"text same");
1338 ReplaceAll(covar_file_name,
"_covar.pdf",
"_corr.pdf");
1339 ltitle.Draw(
"same");
1340 rtitle.Draw(
"same");
1341 c.Print(covar_file_name.c_str());
1343 pname = covar_file_name; pname.ReplaceAll(
".pdf",
".root");
1344 TFile fileCorr(pname,
"recreate");
1346 h_corr.Write(
"CorrelationMatrix_"+fitname+
"Fit");
1348 cout<<
"Saved correlation matrix in "<<pname<<endl<<endl;
1352 const RooFitResult &
f){
1354 RooAbsReal* cloneFunc =
static_cast<RooAbsReal*
>(var.cloneTree());
1355 RooArgSet* errorParams = cloneFunc->getObservables(f.floatParsFinal());
1356 RooArgSet* nset = cloneFunc->getParameters(*errorParams);
1359 RooArgList paramList;
1360 const RooArgList& fpf = f.floatParsFinal();
1361 vector<int> fpf_idx;
1362 for (
int i=0; i<fpf.getSize(); i++) {
1363 RooAbsArg* par = errorParams->find(fpf[i].
GetName());
1365 paramList.add(*par);
1366 fpf_idx.push_back(i);
1370 vector<double> errors(paramList.getSize());
1371 for (Int_t ivar=0; ivar<paramList.getSize(); ivar++) {
1372 RooRealVar& rrv =
static_cast<RooRealVar&
>(fpf[fpf_idx[ivar]]);
1374 double cenVal = rrv.getVal();
1375 double minVal = rrv.getMin();
1376 double maxVal = rrv.getMax();
1377 double downVal = cenVal-fabs(rrv.getErrorLo());
1378 double upVal = cenVal+fabs(rrv.getErrorHi());
1379 if(upVal-downVal >= maxVal-minVal){
1383 }
else if(downVal < minVal){
1384 upVal += minVal - downVal;
1386 }
else if(upVal > maxVal){
1387 downVal -= upVal - maxVal;
1392 static_cast<RooRealVar*
>(paramList.at(ivar))->setVal(upVal);
1393 double up = cloneFunc->getVal(nset);
1396 static_cast<RooRealVar*
>(paramList.at(ivar))->setVal(downVal);
1397 double down = cloneFunc->getVal(nset);
1399 errors.at(ivar) = 0.5*(up-down);
1401 static_cast<RooRealVar*
>(paramList.at(ivar))->setVal(cenVal);
1404 vector<double> right(errors.size());
1405 for(
size_t i = 0; i < right.size(); ++i){
1407 for(
size_t j = 0; j < errors.size(); ++j){
1408 right.at(i) += f.correlation(paramList.at(i)->GetName(),paramList.at(j)->GetName())*errors.at(j);
1412 for(
size_t i = 0; i < right.size(); ++i){
1413 sum += errors.at(i)*right.at(i);
1416 if(cloneFunc !=
nullptr){
1418 cloneFunc =
nullptr;
1420 if(errorParams !=
nullptr){
1422 errorParams =
nullptr;
1424 if(nset !=
nullptr){
1437 ReplaceAll(name,
"lowmet",
"200<p_{T}^{miss}#leq 350");
1438 ReplaceAll(name,
"medmet",
"350<p_{T}^{miss}#leq 500");
1439 ReplaceAll(name,
"highmet",
"p_{T}^{miss}>500");
1440 ReplaceAll(name,
"_lownj",
", 6#leq N_{jets}#leq 8");
1441 ReplaceAll(name,
"_highnj",
", N_{jets}#geq 9");
1451 static struct option long_options[] = {
1452 {
"file_wspace", required_argument, 0,
'f'},
1453 {
"table_clean", no_argument, 0,
'c'},
1454 {
"r4_only", no_argument, 0,
'4'},
1455 {
"exp_sig", no_argument, 0,
's'},
1456 {
"global", no_argument, 0,
'g'},
1462 opt = getopt_long(argc, argv,
"f:c4sg", long_options, &option_index);
1463 if( opt == -1)
break;
1483 optname = long_options[option_index].name;
1486 printf(
"Bad option! Found option name %s\n", optname.c_str());
1490 printf(
"Bad option! getopt_long returned character code 0%o\n", opt);
void Append(T &collection, const typename T::value_type &value)
void ReplaceAll(std::string &str, const std::string &orig, const std::string &rep)
bool Contains(const std::string &str, const std::string &pat)
std::string execute(const std::string &cmd)
std::string ChangeExtension(std::string path, const std::string &new_ext)
def style(h, width, style, color)