5 #include <TLegendEntry.h> 12 #include <RooDataSet.h> 13 #include <RooSimultaneous.h> 14 #include <RooCategory.h> 15 #include <RooRealIntegral.h> 16 #include <RooRealVar.h> 17 #include <RooAbsReal.h> 18 #include <RooAbsArg.h> 19 #include <Roo1DTable.h> 20 #include <RooRealSumPdf.h> 21 #include <RooProduct.h> 22 #include <RooProdPdf.h> 25 #include <RooStats/HistFactory/PiecewiseInterpolation.h> 26 #include <RooStats/ModelConfig.h> 33 double avogadro_number = 6.0221*10e23;
34 return (avogadro_number*argon_density/argon_molecularmass);
42 std::vector<TH1*> vec;
44 TFile*
f =
new TFile(name.c_str(),
"READ");
47 TIter next(f->GetListOfKeys());
50 while ((key = (TKey*)next())){
51 TString classname(key->GetClassName());
52 if(!classname.Contains(
"TH1"))
continue;
54 TH1*
h = (TH1*)key->ReadObj();
69 TString
name = TString(nominal->GetName()) + TString(
"_mcshapestats");
70 TH1* histo = (TH1*)nominal->Clone(name.Data());
72 for(Int_t i=1; i <= nominal->GetNbinsX(); i++){
73 Double_t mcerror = sqrt(nominal->GetBinContent(i));
76 if(nominal->GetBinContent(i) > 0.)
77 ratio = mcerror/nominal->GetBinContent(i);
79 histo->SetBinContent(i, ratio);
80 histo->SetBinError(i, 0.0);
91 TString histoname = TString(syst->GetName()) + TString(
"_") +
name;
92 TH1D* histo =
new TH1D(histoname.Data(), histoname.Data(), nominal->GetNbinsX(), nominal->GetBinLowEdge(1), nominal->GetBinLowEdge(nominal->GetNbinsX()+1));
93 if(nominal->GetNbinsX() != syst->GetNbinsX()){
94 std::cout <<
"WARNING::Nominal and systematic histograms does not have the same number of bins. No systematic is applied!" <<
std::endl;
98 for(Int_t i=0; i < nominal->GetNbinsX(); i++){
99 double nom = nominal->GetBinContent(i+1);
100 double sys = syst->GetBinContent(i+1);
103 std::cout <<
"WARNING::No events in histogram " << nominal->GetName() <<
" for bin " << i <<
". Skip systematics propagation for systematic histogram " << syst->GetName() <<
std::endl;
104 histo->SetBinContent(i+1, 0.0);
109 std::cout <<
"WARNING::Negative fractional error for histogram " << syst->GetName() <<
" and bin " << i <<
std::endl;
112 if(sys > 1.0) sys = 1.0;
115 if(name ==
"up" || name ==
"Up" || name ==
"UP" || name ==
"UP2" || name ==
"HIGH" || name ==
"High" || name ==
"high"){
118 else if(name ==
"down" || name ==
"Down" || name ==
"DOWN" || name ==
"DOWN2" || name ==
"LOW" || name ==
"Low" || name ==
"low"){
124 histo->SetBinContent(i+1, w);
135 int nbinswithevents = 0;
136 for(
int j = 0; j < histo->GetNbinsX(); j++){
137 if(histo->GetBinContent(j) > 0.0)
141 if(nbinswithevents == 1)
return true;
151 RooArgList floatParsFinal = result->floatParsFinal();
152 const TMatrixDSym& covmatrix = result->covarianceMatrix();
153 Int_t
n = covmatrix.GetNcols();
154 TH2D* CovarianceHisto =
new TH2D(
"FitCovariance",
"FitCovariance", n,0,n, n,0,n);
155 CovarianceHisto->GetXaxis()->SetLabelSize(0.01);
156 CovarianceHisto->GetYaxis()->SetLabelSize(0.01);
157 for(Int_t j = 0 ; j<
n ; j++) {
158 for(Int_t
k = 0 ;
k<
n;
k++) {
159 CovarianceHisto->Fill(j+0.5,n-
k-0.5, covmatrix(j,
k));
161 CovarianceHisto->GetXaxis()->SetBinLabel(j+1, floatParsFinal.at(j)->GetName());
162 CovarianceHisto->GetYaxis()->SetBinLabel(n-j, floatParsFinal.at(j)->GetName());
164 CovarianceHisto->SetMinimum(-1);
165 CovarianceHisto->SetMaximum(+1);
167 return CovarianceHisto;
175 TH2* corrhisto = result->correlationHist();
176 corrhisto->GetXaxis()->SetLabelSize(0.01);
177 corrhisto->GetYaxis()->SetLabelSize(0.01);
188 std::cerr <<
"ERROR::Workspace not found. Will not save snapshot." <<
std::endl;
192 RooSimultaneous* simpdf = (RooSimultaneous*)ws->pdf(
"simPdf");
194 simpdf = (RooSimultaneous*)ws->pdf(
"combPdf");
196 std::cerr <<
"ERROR::Pdf not found in workspace. Will not save snapshot." <<
std::endl;
200 RooAbsData* obsdata = (RooAbsData*)ws->data(
"obsData");
201 RooArgSet* parameters = (RooArgSet*)simpdf->getParameters(*obsdata);
202 if(!ws->loadSnapshot(snapshotname.Data())){
203 ws->saveSnapshot(snapshotname.Data(),*parameters);
206 std::cout <<
"WARNING::Snapshot " << snapshotname.Data() <<
" found in workspace. Will not overwrite it." <<
std::endl;
218 std::cerr <<
"ERROR::Workspace not found. Can't find snapshot." <<
std::endl;
222 if(!ws->loadSnapshot(snapshotname)){
223 std::cerr <<
"ERROR::Snapshot not found in workspace." <<
std::endl;
227 ws->loadSnapshot(snapshotname);
228 std::cout <<
"INFO::Workspace snapshot " << snapshotname.Data() <<
" loaded." <<
std::endl;
239 std::cerr <<
"ERROR::Workspace not found. Won't save." <<
std::endl;
243 ws->writeToFile(outFileName.Data());
244 std::cout <<
"INFO::Workspace written to file " << outFileName.Data() <<
std::endl;
255 std::cerr <<
"ERROR::NULL workspace. No interpolation code added." <<
std::endl;
259 RooArgSet fun =
ws->allFunctions();
260 TIterator* iter = fun.createIterator();
263 while( (arg=(RooAbsArg*)iter->Next()) ) {
264 if(arg->ClassName()!=TString(
"PiecewiseInterpolation") )
continue;
265 PiecewiseInterpolation*
p = (PiecewiseInterpolation*)
ws->function(arg->GetName() );
266 p->setAllInterpCodes(code);
277 const char* histname = 0;
280 RooHist* histo = (RooHist*) frame->findObject(histname, RooHist::Class());
283 for(Int_t i=0; i < histo->GetN(); i++){
285 histo->GetPoint(i,x,y);
287 if(fabs(y) < 0.00001 && histo->GetErrorYhigh(i) > 0.){
288 histo->RemovePoint(i);
289 if(i != histo->GetN()) --i;
302 std::cerr <<
"ERROR::NULL workspace. No chi2 is computed!" <<
std::endl;
311 RooSimultaneous* pdf = (RooSimultaneous*)work->pdf(
"simPdf");
313 std::cerr <<
"ERROR::No pdf found in workspace. No chi2 is computed!" <<
std::endl;
318 if(!data) data = work->data(
"obsData");
321 RooCategory* categories = work->cat(
"channelCat");
323 std::vector<TString> categoriesName;
324 TIterator* iter = categories->typeIterator();
326 while( (catType = (RooCatType*) iter->Next())) {
327 TString catname = catType->GetName();
328 categoriesName.push_back(catname);
331 double chi2 = -999.0;
332 for(UInt_t i = 0; i < categoriesName.size(); i++){
333 TString catname = categoriesName[i];
335 if(categories->setLabel(catname)){
336 std::cout <<
"WARNING::Category " << catname.Data() <<
" is not a member of channelCat. Will skip." <<
std::endl;
340 if(catname == channelname){
342 RooAbsPdf* subpdf = (RooAbsPdf*)pdf->getPdf(catname.Data());
344 std::cout <<
"WARNING::Can't find sub-pdf for region " << catname.Data() <<
". Will skip." <<
std::endl;
348 TString subdataset_str = Form(
"channelCat==channelCat::%s",catname.Data());
349 RooAbsData* subdataset = (RooAbsData*) data->reduce(subdataset_str.Data());
351 std::cout <<
"WARNING::Can't find sub-dataset for region " << catname.Data() <<
". Will skip." <<
std::endl;
355 RooRealVar*
var =(RooRealVar*) ((RooArgSet*) subpdf->getObservables(*subdataset))->find(Form(
"obs_x_%s", catname.Data()));
356 RooPlot* frame = var->frame();
357 frame->SetName(Form(
"chi2frame_%s", catname.Data()));
359 subdataset->plotOn(frame, RooFit::DataError(RooAbsData::Poisson), RooFit::MarkerColor(1), RooFit::LineColor(1));
360 subpdf->plotOn(frame,RooFit::Normalization(1,RooAbsReal::RelativeExpected),RooFit::Precision(1
e-5));
361 chi2 = frame->chiSquare();
373 std::vector<TString> binnames, std::vector<double> recobins,
374 std::vector<TString> incidentBinNames,
378 std::vector<TH1 *> xsecs;
381 std::cerr <<
"ERROR:NULL dir. Will return empty canvas" <<
std::endl;
390 RooSimultaneous* pdf = (RooSimultaneous*)work->pdf(
"simPdf");
392 std::cerr <<
"ERROR::No pdf found in workspace. Will return empty vector!" 394 std::cerr <<
"ERROR::No pdf found in workspace. Will return empty vector!" 396 std::cerr <<
"ERROR::No pdf found in workspace. Will return empty vector!" 405 RooCategory* categories = work->cat(
"channelCat");
407 std::vector<TString> categoriesName;
408 TIterator* iter = categories->typeIterator();
410 while( (catType = (RooCatType*) iter->Next())) {
411 TString catname = catType->GetName();
412 categoriesName.push_back(catname);
416 for (
size_t i = 0; i < categoriesName.size(); ++i) {
418 TString catname = categoriesName[i];
420 RooAbsPdf* subpdf = (RooAbsPdf*)pdf->getPdf(catname.Data());
422 std::cout <<
"WARNING::Can't find sub-pdf for region " << catname.Data()
427 TString RRSumPdfName = Form(
"%s_model",catname.Data());
428 RooRealSumPdf* RRSumPdf =
429 (RooRealSumPdf*)subpdf->getComponents()->find(RRSumPdfName);
430 RooArgList RRSumComponentsList = RRSumPdf->funcList();
431 RooLinkedListIter iter = RRSumComponentsList.iterator();
432 RooProduct* component;
434 std::vector<TString> compNameVec;
435 while( (component = (RooProduct*) iter.Next()) ){
436 TString componentName = component->GetName();
473 RooWorkspace *
work, TString
name, TString
error, TString plottodraw,
474 std::vector<TString> binnames, std::vector<double> recobins,
475 std::vector<TString> incidentBinNames,
476 std::vector<TString> sidebandBinNames, std::vector<double> sidebandBins,
478 bool doNegativeReco, RooAbsData*
data, RooFitResult*
result) {
481 std::vector<TCanvas*> rooplots;
484 std::cerr <<
"ERROR::NULL workspace. Will return empty vector!" <<
std::endl;
493 RooSimultaneous* pdf = (RooSimultaneous*)work->pdf(
"simPdf");
495 std::cerr <<
"ERROR::No pdf found in workspace. Will return empty vector!" <<
std::endl;
496 std::cerr <<
"ERROR::No pdf found in workspace. Will return empty vector!" <<
std::endl;
497 std::cerr <<
"ERROR::No pdf found in workspace. Will return empty vector!" <<
std::endl;
502 if(!data) data = work->data(
"obsData");
505 RooCategory* categories = work->cat(
"channelCat");
508 data->table(*((RooAbsCategory*)categories))->Print(
"v");
510 std::vector<TString> categoriesName;
511 TIterator* iter = categories->typeIterator();
513 while( (catType = (RooCatType*) iter->Next())) {
514 TString catname = catType->GetName();
515 categoriesName.push_back(catname);
518 for(UInt_t i = 0; i < categoriesName.size(); i++){
519 TString catname = categoriesName[i];
521 if(categories->setLabel(catname)){
522 std::cout <<
"WARNING::Category " << catname.Data() <<
" is not a member of channelCat. Will skip." <<
std::endl;
526 RooAbsPdf* subpdf = (RooAbsPdf*)pdf->getPdf(catname.Data());
528 std::cout <<
"WARNING::Can't find sub-pdf for region " << catname.Data() <<
". Will skip." <<
std::endl;
532 TString subdataset_str = Form(
"channelCat==channelCat::%s",catname.Data());
533 RooAbsData* subdataset = (RooAbsData*) data->reduce(subdataset_str.Data());
535 std::cout <<
"WARNING::Can't find sub-dataset for region " << catname.Data() <<
". Will skip." <<
std::endl;
539 RooRealVar*
var =(RooRealVar*) ((RooArgSet*) subpdf->getObservables(*subdataset))->find(Form(
"obs_x_%s", catname.Data()));
542 TString canName = Form(
"canvas_%s_%s_%s", catname.Data(), name.Data(), plottodraw.Data());
543 TCanvas*
c =
new TCanvas(canName, canName);
546 TLegend* legend =
new TLegend(0.10,0.70,0.90,0.90,
"");
547 legend->SetFillStyle(0);
548 legend->SetFillColor(0);
549 legend->SetBorderSize(0);
550 legend->SetTextSize(0.036);
552 legend->SetNColumns(3);
554 TLegendEntry*
entry = legend->AddEntry(
"",
"Data",
"pl") ;
555 entry->SetMarkerColor(kBlack);
556 entry->SetMarkerStyle(20);
557 entry=legend->AddEntry(
"",
"MC Total",
"lf") ;
558 entry->SetLineColor(kBlack);
559 entry->SetFillColor(kBlue);
560 entry->SetFillStyle(3444);
562 RooPlot* frame = var->frame();
563 frame->SetName(Form(
"frame_%s_%s_%s", catname.Data(), name.Data(), plottodraw.Data()));
566 if(error.Contains(
"SumW2") || error.Contains(
"sumw2") || error.Contains(
"sumW2"))
567 subdataset->plotOn(frame, RooFit::DataError(RooAbsData::SumW2), RooFit::MarkerColor(1), RooFit::LineColor(1));
569 subdataset->plotOn(frame, RooFit::DataError(RooAbsData::Poisson), RooFit::MarkerColor(1), RooFit::LineColor(1));
571 TString RRSumPdfName = Form(
"%s_model",catname.Data());
572 RooRealSumPdf* RRSumPdf = (RooRealSumPdf*) subpdf->getComponents()->
find(RRSumPdfName);
574 RooArgList RRSumComponentsList = RRSumPdf->funcList();
576 TString binWidthName = Form(
"binWidth_obs_x_%s_0",catname.Data());
577 RooRealVar* regionBinWidth = ((RooRealVar*) RRSumPdf->getVariables()->find(Form(
"binWidth_obs_x_%s_0",catname.Data()))) ;
578 if(regionBinWidth == NULL)
579 std::cout <<
"WARNING::bindWidth variable not found for region(" << catname <<
"). PLOTTING COMPONENTS WILL BE WRONG!" <<
std::endl;
582 double normCount = subpdf->expectedEvents(*var);
584 std::cout <<
"INFO::MC events after fit = " << normCount <<
" for " << subpdf->GetName() <<
std::endl;
586 RooLinkedListIter iter = RRSumComponentsList.iterator() ;
587 RooProduct* component;
589 std::vector<TString> compNameVec;
590 std::vector <double> compFracVec;
591 std::vector<TString> compStackNameVec;
592 std::vector <double> compStackFracVec;
594 compStackNameVec.clear();
596 compStackFracVec.clear();
598 while( (component = (RooProduct*) iter.Next()) ){
599 TString componentName = component->GetName();
600 TString stackComponentName = componentName;
602 if(!compStackNameVec.empty())
603 stackComponentName = Form(
"%s,%s",compStackNameVec.back().Data() ,componentName.Data());
604 compNameVec.push_back(componentName);
605 compStackNameVec.push_back(stackComponentName);
607 RooAbsReal* i_RRSumPdf = ((RooAbsPdf*)work->pdf(RRSumPdfName))->createIntegral(RooArgSet(*var));
608 Double_t Int_RRSumPdf = i_RRSumPdf->getVal();
609 RooAbsReal* i_component = ((RooProduct*)work->obj(componentName))->createIntegral(RooArgSet(*var));
610 Double_t Int_component = i_component->getVal();
612 Double_t componentFrac = 0.;
613 if(Int_RRSumPdf != 0.)
614 componentFrac = Int_component * regionBinWidth->getVal() / Int_RRSumPdf;
616 double stackComponentFrac = componentFrac;
617 if(!compStackFracVec.empty())
618 stackComponentFrac = compStackFracVec.back() + componentFrac;
620 compFracVec.push_back(componentFrac);
621 compStackFracVec.push_back(stackComponentFrac);
625 Int_t sigcolor[13] = {2,3,4,5,6,7,8,9,kMagenta, 1, kGreen+2, kTeal, kOrange+10};
626 for(
int i = (compFracVec.size()-1); i > -1; i--){
627 Int_t compPlotColor = i;
628 if(compNameVec[i].Contains(
"ChannelABS_CEX") || compNameVec[i].Contains(
"ChannelCEX_ABS")){
631 else if(compNameVec[i].Contains(
"RecoBin")){
635 compPlotColor = sigcolor[
counter];
638 std::cout <<
"INFO::Drawing " << compNameVec[i] <<
" " << counter <<
" " << compPlotColor <<
std::endl;
640 subpdf->plotOn(frame,RooFit::Components(compStackNameVec[i].
Data()),RooFit::FillColor(compPlotColor),RooFit::FillStyle(3001),RooFit::DrawOption(
"F"),RooFit::Normalization(compStackFracVec[i]*normCount,RooAbsReal::NumEvent),RooFit::Precision(1
e-5));
644 subpdf->plotOn(frame, RooFit::Normalization(1,RooAbsReal::RelativeExpected), RooFit::Precision(1
e-5), RooFit::VisualizeError(*result), RooFit::FillColor(kBlue), RooFit::FillStyle(3444));
647 subpdf->plotOn(frame, RooFit::Normalization(1,RooAbsReal::RelativeExpected), RooFit::Precision(1
e-5), RooFit::LineColor(1));
648 if(error.Contains(
"SumW2") || error.Contains(
"sumw2") || error.Contains(
"sumW2"))
649 subdataset->plotOn(frame, RooFit::DataError(RooAbsData::SumW2), RooFit::MarkerColor(1), RooFit::LineColor(1));
651 subdataset->plotOn(frame, RooFit::DataError(RooAbsData::Poisson), RooFit::MarkerColor(1), RooFit::LineColor(1));
657 bool found =
false;
bool found2 =
false;
659 for(
unsigned int i = 0; i < compFracVec.size(); i++){
660 std::cout <<
"NAME: " << compNameVec[i] <<
std::endl;
661 Int_t compPlotColor = i;
662 if(compNameVec[i].Contains(
"ChannelABS_CEX") && !
found){
664 entry=legend->AddEntry(
"",
"CEX Bkg",
"f");
665 entry->SetLineColor(46);
666 entry->SetFillColor(compPlotColor);
667 entry->SetFillStyle(3001);
671 else if(compNameVec[i].Contains(
"ChannelCEX_ABS") && !found){
673 entry=legend->AddEntry(
"",
"ABS Bkg",
"f");
674 entry->SetLineColor(46);
675 entry->SetFillColor(compPlotColor);
676 entry->SetFillStyle(3001);
680 else if(compNameVec[i].Contains(
"RecoBin") && !found2){
682 entry=legend->AddEntry(
"",
"Signal",
"f");
683 entry->SetLineColor(40);
684 entry->SetFillColor(compPlotColor);
685 entry->SetFillStyle(3001);
691 compPlotColor = sigcolor[
counter];
694 if(counter2 < (
int)binnames.size()){
695 TString legName = binnames[counter2];
696 if (compNameVec[i].Contains(
"Incident"))
697 legName = incidentBinNames[counter2];
698 if (compNameVec[i].Contains(
"Sideband"))
699 legName = sidebandBinNames[counter2];
701 entry=legend->AddEntry(
"",legName.Data(),
"f");
702 entry->SetLineColor(compPlotColor);
703 entry->SetFillColor(compPlotColor);
704 entry->SetFillStyle(3001);
711 float bottomMarginP1=0.015;
712 TPad *pad1 =
new TPad(Form(
"%s_pad1",canName.Data()),Form(
"%s_pad1",canName.Data()),0.,yMinP1,.99,1);
713 pad1->SetBottomMargin(bottomMarginP1);
714 pad1->SetFillColor(kWhite);
717 TPad *pad2 =
new TPad(Form(
"%s_pad2",canName.Data()),Form(
"%s_pad2",canName.Data()),0.,0.01,.99,0.295);
718 pad2->SetTopMargin(0.021);
719 pad2->SetBottomMargin(0.3);
720 pad2->SetFillColor(kWhite);
724 frame->GetXaxis()->SetLabelSize(0.);
727 frame->SetTitle(measurement.Data());
729 frame->GetXaxis()->SetTitle(
"Reco Bin");
730 frame->GetYaxis()->SetTitle(
"Events");
735 legend->AddEntry((TObject*)0x0, chi2_text.c_str(),
"");
740 RooPlot* frame_dummy = var->frame();
742 subdataset->plotOn(frame_dummy,RooFit::Cut(subdataset_str),RooFit::DataError(RooAbsData::Poisson));
745 const char* curvename = 0;
746 RooHist* nominal_hist = (RooHist*) frame_dummy->findObject(curvename, RooHist::Class());
748 std::cerr <<
"ERROR::Drawing the data/MC histogram. Can't find nominal histogram." <<
std::endl;
753 subpdf->plotOn(frame_dummy,RooFit::Normalization(1,RooAbsReal::RelativeExpected),RooFit::Precision(1
e-5));
756 RooCurve* nominal_curve = (RooCurve*) frame_dummy->findObject(curvename, RooCurve::Class());
758 std::cerr <<
"ERROR::Drawing the data/MC histogram. Can't find nominal curve." <<
std::endl;
764 RooHist* hratio = NULL;
765 RooCurve* ratio_curve =
new RooCurve;
767 if(plottodraw ==
"pull"){
768 hratio = (RooHist*) frame_dummy->pullHist();
769 hratio->SetTitle(
"Pull Distribution");
771 else if(plottodraw ==
"residuals"){
772 hratio = (RooHist*) frame_dummy->residHist();
773 hratio->SetTitle(
"Residual Distribution");
775 else if(plottodraw ==
"ratio"){
777 subpdf->plotOn(frame_dummy, RooFit::Normalization(1,RooAbsReal::RelativeExpected), RooFit::Precision(1
e-5), RooFit::VisualizeError(*result, 1), RooFit::FillColor(kBlue-5), RooFit::FillStyle(3004));
780 RooCurve* error_curve = (RooCurve*)frame_dummy->findObject(curvename, RooCurve::Class());
782 std::cerr <<
"ERROR::Drawing the data/MC histogram. Can't find error curve." <<
std::endl;
786 ratio_curve->SetName(Form(
"%s_ratiocurve",nominal_curve->GetName()));
787 ratio_curve->SetLineColor(kBlue-5);
788 ratio_curve->SetFillColor(kBlue-5);
789 ratio_curve->SetFillStyle(3004);
790 ratio_curve->SetLineWidth(1);
794 bool bottomCurve =
false;
795 for(Int_t i=1; i < error_curve->GetN()-1; i++){
798 error_curve->GetPoint(i,x,y) ;
800 if( i >= (nominal_curve->GetN()-1) ) bottomCurve =
true;
805 if( i == (nominal_curve->GetN() - 1) || i == nominal_curve->GetN() ){
806 ratio_curve->addPoint(x, 0.);
811 nominal_curve->GetPoint(j,xNom,yNom);
816 nominal_curve->GetPoint(j,xNom,yNom);
819 if(fabs(yNom) > 0.00001){
820 ratio_curve->addPoint(x, (y / yNom));
823 ratio_curve->addPoint(x, 0.);
828 hratio =
new RooHist(nominal_hist->getNominalBinWidth());
831 Double_t xstart, xstop,
y;
832 nominal_curve->GetPoint(2,xstart,y);
833 nominal_curve->GetPoint(nominal_curve->GetN()-1,xstop,
y);
835 for(Int_t i=0; i < nominal_hist->GetN(); i++){
837 nominal_hist->GetPoint(i,x,ypoint);
839 if(x < xstart || x > xstop)
continue;
840 if(fabs(ypoint) < 0.000001 )
continue;
843 Double_t yerrorl = nominal_hist->GetErrorYlow(i);
844 Double_t yerrorh = nominal_hist->GetErrorYhigh(i);
857 yy = ypoint / nominal_curve->interpolate(x);
858 yerrorl /= nominal_curve->interpolate(x);
859 yerrorh /= nominal_curve->interpolate(x);
861 hratio->addBinWithError(x,yy,yerrorl,yerrorh);
866 std::cerr <<
"ERROR::Drawing data and MC histogram failed. RooHist is not found." <<
std::endl;
870 hratio->SetMarkerColor(kRed);
871 hratio->SetLineColor(kRed);
874 RooPlot* frame2 = var->frame();
875 if(plottodraw ==
"ratio" && result) frame2->addPlotable(ratio_curve,
"F");
876 frame2->addPlotable(hratio,
"P");
878 if (catname.Contains(
"Sideband")) {
880 frame2->GetXaxis()->SetTitle(
"Generic Label");
881 for(
size_t i = 1; i < sidebandBins.size(); i++){
882 TString ibinstr = Form(
"%.1f-%.1f",sidebandBins[i-1],sidebandBins[i]);
883 frame2->GetXaxis()->SetBinLabel(i, ibinstr.Data());
887 if (doNegativeReco) {
888 frame2->GetXaxis()->SetBinLabel(1,
"< 0.");
889 for(
size_t i = 1; i < recobins.size(); i++){
890 TString ibinstr = Form(
"%.1f-%.1f",recobins[i-1],recobins[i]);
891 frame2->GetXaxis()->SetBinLabel(i+1, ibinstr.Data());
895 for(
size_t i = 1; i < recobins.size(); i++){
896 TString ibinstr = Form(
"%.1f-%.1f",recobins[i-1],recobins[i]);
897 frame2->GetXaxis()->SetBinLabel(i, ibinstr.Data());
900 frame2->GetXaxis()->SetTitle(
"E_{reco} [MeV]");
904 int firstbin = frame_dummy->GetXaxis()->GetFirst();
905 int lastbin = frame_dummy->GetXaxis()->GetLast();
906 double xmax = frame_dummy->GetXaxis()->GetBinUpEdge(lastbin);
907 double xmin = frame_dummy->GetXaxis()->GetBinLowEdge(firstbin);
909 if(plottodraw==
"pull"){
910 TLine* lp1 =
new TLine(xmin,1.,xmax,1.);
911 TLine* lp2 =
new TLine(xmin,2.,xmax,2.);
912 TLine* lp3 =
new TLine(xmin,3.,xmax,3.);
913 TLine* lp4 =
new TLine(xmin,4.,xmax,4.);
915 TLine* lp6 =
new TLine(xmin,-1.,xmax,-1.);
916 TLine* lp7 =
new TLine(xmin,-2.,xmax,-2.);
917 TLine* lp8 =
new TLine(xmin,-3.,xmax,-3.);
918 TLine* lp9 =
new TLine(xmin,-4.,xmax,-4.);
920 TLine* lp10 =
new TLine(xmin,0,xmax,0);
922 lp1->SetLineStyle(3);
923 lp2->SetLineStyle(3);
924 lp3->SetLineStyle(3);
925 lp4->SetLineStyle(3);
926 lp6->SetLineStyle(3);
927 lp7->SetLineStyle(3);
928 lp8->SetLineStyle(3);
929 lp9->SetLineStyle(3);
930 lp10->SetLineStyle(3);
932 frame2->addObject(lp1);
933 frame2->addObject(lp2);
934 frame2->addObject(lp3);
935 frame2->addObject(lp4);
936 frame2->addObject(lp6);
937 frame2->addObject(lp7);
938 frame2->addObject(lp8);
939 frame2->addObject(lp9);
940 frame2->addObject(lp10);
942 frame2->SetMinimum(-4.0);
943 frame2->SetMaximum(4.0);
945 frame2->GetYaxis()->SetTitle(
"Pull");
947 else if(plottodraw ==
"residuals"){
948 TLine*
l =
new TLine(xmin,0.,xmax,0.);
951 frame2->addObject(l);
952 frame2->GetYaxis()->SetTitle(
"Residual");
954 else if(plottodraw ==
"ratio"){
955 TLine* lp1 =
new TLine(xmin,1.,xmax,1.);
956 TLine* lp2 =
new TLine(xmin,0.5,xmax,0.5);
957 TLine* lp3 =
new TLine(xmin,1.5,xmax,1.5);
958 TLine* lp4 =
new TLine(xmin,2.,xmax,2.);
959 TLine* lp5 =
new TLine(xmin,2.5,xmax,2.5);
960 lp1->SetLineWidth(1);
961 lp1->SetLineStyle(3);
962 lp2->SetLineStyle(3);
963 lp3->SetLineStyle(3);
964 lp4->SetLineStyle(3);
965 lp5->SetLineStyle(3);
966 frame2->addObject(lp1);
967 frame2->addObject(lp2);
968 frame2->addObject(lp3);
969 frame2->addObject(lp4);
970 frame2->addObject(lp5);
972 frame2->SetMinimum(.0);
973 frame2->SetMaximum(3.0);
975 frame2->GetYaxis()->SetTitle(
"Data / MC");
978 frame2->GetYaxis()->SetLabelSize(0.10);
979 frame2->GetYaxis()->SetNdivisions(504);
980 frame2->GetXaxis()->SetLabelSize(0.10);
981 frame2->GetYaxis()->SetTitleSize(0.10);
982 frame2->GetXaxis()->SetTitleSize(0.10);
983 frame2->GetYaxis()->SetTitleOffset(0.35);
984 frame2->GetXaxis()->SetTitleOffset(1.);
985 frame2->GetYaxis()->SetLabelOffset(0.01);
986 frame2->GetXaxis()->SetLabelOffset(0.03);
987 frame2->GetXaxis()->SetTickLength(0.06);
989 frame2->SetTitle(
"");
990 frame2->GetYaxis()->CenterTitle();
993 rooplots.push_back(c);
1004 std::vector<TCanvas*> rooplots;
1007 std::cerr <<
"ERROR::NULL workspace. Will return empty vector!" <<
std::endl;
1012 std::cerr <<
"ERROR::NULL fit result. Will return empty vector!" <<
std::endl;
1016 RooSimultaneous* pdf = (RooSimultaneous*) work->pdf(
"simPdf");
1018 std::cout <<
"ERROR::No pdf found in workspace. Will return empty vector!" <<
std::endl;
1023 RooAbsData*
data = work->data(
"obsData");
1026 RooCategory* categories = work->cat(
"channelCat");
1028 data->table(*((RooAbsCategory*)categories))->Print(
"v");
1030 RooStats::ModelConfig *combined_config = (RooStats::ModelConfig*)work->obj(
"ModelConfig");
1031 if(!combined_config){
1032 std::cout <<
"ERROR::No model config " <<
" ModelConfig " <<
" in workspace. Will return empty vector!" <<
std::endl;
1036 const RooArgSet* obs = combined_config->GetGlobalObservables();
1038 std::cout <<
"ERROR::No observables found in ModelConfig. Will return empty vector!" <<
std::endl;
1042 RooArgList floatParsFinal = result->floatParsFinal();
1045 RooAbsReal* nll = pdf->createNLL(*data, RooFit::NumCPU(2), RooFit::GlobalObservables(*obs),
RooFit::Offset(
true));
1047 for(Int_t i = 0; i < floatParsFinal.getSize(); i++){
1048 RooAbsArg* arg = floatParsFinal.at(i);
1049 if(!arg->InheritsFrom(
"RooRealVar"))
continue;
1051 RooRealVar* par = (RooRealVar*) arg;
1052 TString parName = par->GetName();
1055 double minRange = par->getMin();
1056 double maxRange = par->getMax();
1062 par->setMin(minRange);
1066 RooPlot* frame = par->frame();
1067 nll->plotOn(frame, RooFit::ShiftToZero());
1068 frame->SetMinimum(0.);
1070 frame->SetMaximum(2.5);
1072 RooAbsReal* pll = NULL;
1074 pll = nll->createProfile(*par) ;
1075 pll->plotOn(frame, RooFit::LineColor(kRed), RooFit::LineStyle(kDashed), RooFit::NumCPU(4));
1078 TString canName=Form(
"Canvas_NLL_%s_%s", name.Data(), parName.Data());
1079 TCanvas*
c =
new TCanvas(canName,canName,600,600);
1083 TLegend* legend =
new TLegend(0.55,0.65,0.85,0.95,
"");
1084 legend->SetFillStyle(0);
1085 legend->SetFillColor(0);
1086 legend->SetBorderSize(0);
1087 legend->SetTextSize(0.036);
1088 TLegendEntry*
entry=legend->AddEntry(
"",
"NLL",
"l") ;
1089 entry->SetLineColor(kBlue);
1091 entry=legend->AddEntry(
"",
"PLL",
"l") ;
1092 entry->SetLineColor(kRed);
1093 entry->SetLineStyle(kDashed);
1098 par->setMin(minRange);
1099 par->setMax(maxRange);
1103 rooplots.push_back(c);
1114 std::vector<TCanvas*> plots;
1117 std::cerr <<
"ERROR::NULL workspace. Will return empty vector!" <<
std::endl;
1122 RooStats::ModelConfig *combined_config = (RooStats::ModelConfig*)work->obj(
"ModelConfig");
1123 if(!combined_config){
1124 std::cerr <<
"ERROR::No model config " <<
"ModelConfig " <<
" in workspace. Return empty vector!" <<
std::endl;
1129 RooAbsData *obsdata = work->data(
"obsData");
1132 std::cerr <<
"ERROR::NULL fit result. Will return empty vector!" <<
std::endl;
1142 const int nSystToConsider = SystsToConsider.size();
1143 const int nPOI = floatParList.getSize();
1145 std::vector<TH1D*> systhistovec; std::vector<TH1D*> systhistovec_prefitup; std::vector<TH1D*> systhistovec_prefitdown; std::vector<TH1D*> systhistovec_postfitup; std::vector<TH1D*> systhistovec_postfitdown;
1147 for(
int i=0; i < nPOI; i++){
1148 TH1D* systhisto =
new TH1D(Form(
"systhisto%i",i), Form(
"systhisto%i",i), nSystToConsider, 0, nSystToConsider);
1149 TH1D* systhisto_prefitup =
new TH1D(Form(
"systhisto%i_prefitup",i), Form(
"systhisto%i_prefitup",i), nSystToConsider, 0, nSystToConsider);
1150 TH1D* systhisto_prefitdown =
new TH1D(Form(
"systhisto%i_prefitdown",i), Form(
"systhisto%i_prefitdown",i), nSystToConsider, 0, nSystToConsider);
1151 TH1D* systhisto_postfitup =
new TH1D(Form(
"systhisto%i_postfitup",i), Form(
"systhisto%i_postfitup",i), nSystToConsider, 0, nSystToConsider);
1152 TH1D* systhisto_postfitdown =
new TH1D(Form(
"systhisto%i_postfitdown",i),Form(
"systhisto%i_postfitdown",i), nSystToConsider, 0, nSystToConsider);
1154 systhistovec.push_back(systhisto);
1155 systhistovec_prefitup.push_back(systhisto_prefitup);
1156 systhistovec_prefitdown.push_back(systhisto_prefitdown);
1157 systhistovec_postfitup.push_back(systhisto_postfitup);
1158 systhistovec_postfitdown.push_back(systhisto_postfitdown);
1161 for(
int i=0; i < nSystToConsider; i++){
1163 TString systname = TString(
"alpha_") + TString(SystsToConsider[i].c_str());
1164 RooRealVar*
var = work->var(systname.Data());
1166 std::cerr <<
"ERROR::Variable " << systname.Data() <<
" not found in workspace. Skip!" <<
std::endl;
1170 double originalval = var->getVal();
1171 double originalerror = var->getError();
1173 for(
int j=0; j < nPOI; j++){
1174 systhistovec[j]->SetBinContent(i+1, originalval);
1175 systhistovec[j]->SetBinError(i+1, originalerror);
1176 systhistovec[j]->GetXaxis()->SetBinLabel(i+1, SystsToConsider[i].c_str());
1177 systhistovec[j]->SetTitle( (floatParList.at(j))->GetName() );
1181 var->setVal(originalval + 1.0);
1182 RooFitResult *tempfitresult = combined_config->GetPdf()->fitTo(*obsdata, RooFit::Minimizer(
"Minuit2"), RooFit::Save(), RooFit::Strategy(1), RooFit::Minos(
false), RooFit::PrintLevel(1), RooFit::Constrain(*combined_config->GetPdf()->getParameters(*obsdata)), RooFit::Extended(),
RooFit::Offset(
true) );
1186 var->setVal(originalval - 1.0);
1187 RooFitResult *tempfitresult2 = combined_config->GetPdf()->fitTo(*obsdata, RooFit::Minimizer(
"Minuit2"), RooFit::Save(), RooFit::Strategy(1), RooFit::Minos(
false), RooFit::PrintLevel(1), RooFit::Constrain(*combined_config->GetPdf()->getParameters(*obsdata)), RooFit::Extended(),
RooFit::Offset(
true) );
1190 var->setVal(originalval + originalerror);
1191 RooFitResult *tempfitresult3 = combined_config->GetPdf()->fitTo(*obsdata, RooFit::Minimizer(
"Minuit2"), RooFit::Save(), RooFit::Strategy(1), RooFit::Minos(
false), RooFit::PrintLevel(1), RooFit::Constrain(*combined_config->GetPdf()->getParameters(*obsdata)), RooFit::Extended(),
RooFit::Offset(
true) );
1194 var->setVal(originalval - originalerror);
1195 RooFitResult *tempfitresult4 = combined_config->GetPdf()->fitTo(*obsdata, RooFit::Minimizer(
"Minuit2"), RooFit::Save(), RooFit::Strategy(1), RooFit::Minos(
false), RooFit::PrintLevel(1), RooFit::Constrain(*combined_config->GetPdf()->getParameters(*obsdata)), RooFit::Extended(),
RooFit::Offset(
true) );
1198 TIterator* Inititer = floatParList.createIterator();
1199 RooRealVar* Initvar(0);
1200 for(
int j=0; (Initvar = (RooRealVar*)Inititer->Next()); j++){
1202 TString Initvarname(Initvar->GetName());
1203 if(Initvarname.Contains(
"alpha_") || Initvarname.Contains(
"gamma_"))
continue;
1208 TIterator* iter = paramsfit.createIterator();
1209 RooRealVar* Postvar(0);
1210 for(
int k=0; (Postvar = (RooRealVar*)iter->Next());
k++){
1211 TString varname(Postvar->GetName());
1212 if(varname == Initvarname){
1213 DMu = Postvar->getVal() - Initvar->getVal();
1217 systhistovec_postfitup[j]->SetBinContent(i+1, DMu);
1220 TIterator* iter2 = paramsfit2.createIterator();
1221 RooRealVar* Postvar2(0);
1222 for(
int k=0; (Postvar2 = (RooRealVar*)iter2->Next());
k++){
1223 TString varname(Postvar2->GetName());
1224 if(varname == Initvarname){
1226 DMu = Postvar2->getVal() - Initvar->getVal();
1230 systhistovec_postfitdown[j]->SetBinContent(i+1, DMu);
1233 TIterator* iter3 = paramsfit3.createIterator();
1234 RooRealVar* Postvar3(0);
1235 for(
int k=0; (Postvar3 = (RooRealVar*)iter3->Next());
k++){
1236 TString varname(Postvar3->GetName());
1237 if(varname == Initvarname){
1238 DMu = Postvar3->getVal() - Initvar->getVal();
1242 systhistovec_prefitup[j]->SetBinContent(i+1, DMu);
1245 TIterator* iter4 = paramsfit4.createIterator();
1246 RooRealVar* Postvar4(0);
1247 for(
int k=0; (Postvar4 = (RooRealVar*)iter4->Next());
k++){
1248 TString varname(Postvar4->GetName());
1249 if(varname == Initvarname){
1250 DMu = Postvar4->getVal() - Initvar->getVal();
1254 systhistovec_prefitdown[j]->SetBinContent(i+1, DMu);
1265 var->setVal(originalval);
1266 var->setError(originalerror);
1270 TLine* lp1 =
new TLine(0,-1.,nSystToConsider,-1.);
1271 lp1->SetLineStyle(kDashed);
1272 TLine* lp2 =
new TLine(0,1.,nSystToConsider,1.);
1273 lp2->SetLineStyle(kDashed);
1274 TLine* lp3 =
new TLine(0,0,nSystToConsider,0);
1275 lp3->SetLineColor(kBlack);
1277 TLegend* legend =
new TLegend(0.20,0.80,0.85,0.90,
"");
1278 legend->SetFillStyle(0);
1279 legend->SetFillColor(0);
1280 legend->SetBorderSize(0);
1281 legend->SetTextSize(0.036);
1283 legend->SetNColumns(3);
1284 TLegendEntry*
entry = legend->AddEntry(
"",
"Pull",
"pl") ;
1285 entry->SetMarkerColor(kBlue);
1286 entry->SetMarkerStyle(20);
1287 entry=legend->AddEntry(
"",
"Pre-fit impact on #mu",
"f") ;
1288 entry->SetFillColor(kYellow);
1289 entry->SetLineColor(kYellow);
1290 entry->SetFillStyle(3001);
1291 entry=legend->AddEntry(
"",
"Post-fit impact on #mu",
"f") ;
1292 entry->SetFillColor(kBlue);
1293 entry->SetFillStyle(3005);
1295 TGaxis *Maxis =
new TGaxis(nSystToConsider,-1.4, nSystToConsider, 1.4,-1.4,1.4,510,
"+L");
1296 Maxis->SetLabelSize(0.03);
1297 Maxis->SetTextFont(72);
1298 Maxis->SetLabelOffset(0.025);
1299 Maxis->SetTitleOffset(1.1);
1300 Maxis->SetTitle(
"#Delta#mu");
1302 for(
int i=0; i < nPOI; i++){
1303 systhistovec_prefitup[i]->SetLineColor(kBlue);
1304 systhistovec_prefitup[i]->SetFillColor(kBlue);
1305 systhistovec_prefitup[i]->SetFillStyle(3005);
1306 systhistovec_prefitdown[i]->SetLineColor(kBlue);
1307 systhistovec_prefitdown[i]->SetFillColor(kBlue);
1308 systhistovec_prefitdown[i]->SetFillStyle(3005);
1309 systhistovec_postfitup[i]->SetLineColor(kYellow);
1310 systhistovec_postfitup[i]->SetFillColor(kYellow);
1311 systhistovec_postfitdown[i]->SetLineColor(kYellow);
1312 systhistovec_postfitdown[i]->SetFillColor(kYellow);
1313 systhistovec[i]->SetMarkerColor(4);
1314 systhistovec[i]->SetMarkerStyle(20);
1315 systhistovec[i]->SetLineWidth(2);
1316 systhistovec[i]->SetStats(
false);
1317 systhistovec[i]->GetYaxis()->SetRangeUser(-1.4,1.4);
1318 systhistovec[i]->GetYaxis()->SetTitle(
"(#theta - #theta_{0}) / #Delta#theta");
1319 systhistovec[i]->GetYaxis()->SetTitleOffset(1.15);
1321 TCanvas* can =
new TCanvas(Form(
"can_impact%i",i),Form(
"can_impact%i",i));
1322 systhistovec[i]->Draw();
1323 systhistovec_postfitup[i]->Draw(
"same");
1324 systhistovec_postfitdown[i]->Draw(
"same");
1325 systhistovec_prefitup[i]->Draw(
"same");
1326 systhistovec_prefitdown[i]->Draw(
"same");
1327 systhistovec[i]->Draw(
"e1same");
1333 Maxis->Draw(
"same");
1336 plots.push_back(can);
1348 std::cerr <<
"ERROR::No tree or workspace found. Pull plot failed!" <<
std::endl;
1352 if(tree->GetEntries() < 2){
1353 std::cerr <<
"ERROR::Tree has less than two entries. No pull plots! Ignore if you run on data!" <<
std::endl;
1357 RooStats::ModelConfig *combined_config = (RooStats::ModelConfig*)ws->obj(
"ModelConfig");
1358 if(!combined_config){
1359 std::cerr <<
"ERROR::No model config " <<
" ModelConfig " <<
" in workspace. No pull plots!" <<
std::endl;
1363 std::vector<Float_t> varValsPull;
1364 const RooArgSet* floatParsList = combined_config->GetParametersOfInterest();
1365 const Int_t
n = floatParsList->getSize();
1367 std::cerr <<
"ERROR::No floating parameters found. Pull plot failed!" <<
std::endl;
1370 varValsPull.resize( floatParsList->getSize(), -999. );
1372 TCanvas* cpull =
new TCanvas(
"PullMeanSigma",
"PullMeanSigma");
1374 TH1F* pullmeanhisto =
new TH1F(
"pullmeanplot",
"", n+1, 0, n+1);
1375 TH1F* pullsigmahisto =
new TH1F(
"pullsigmaplot",
"", n+1, 0, n+1);
1378 tree->SetBranchAddress(
"status", &status);
1381 TIterator* Itr = floatParsList->createIterator();
1383 for (Int_t i=0; (var = (RooRealVar*)Itr->Next()); ++i) {
1384 if(var->isConstant())
continue;
1385 TString
varName = var->GetName() + TString(
"pull");
1387 if(varName.Contains(
"Lumi") || varName.Contains(
"binWidth") || varName.Contains(
"corr"))
continue;
1388 tree->SetBranchAddress(varName.Data(), &varValsPull[i]);
1390 TH1F* pullhisto =
new TH1F(Form(
"pullhisto%i",i),Form(
"pullhisto%i",i),100,-5,5);
1391 for(Int_t j=0; j < tree->GetEntries(); j++){
1393 if(status%1000 == 0)
1394 pullhisto->Fill(varValsPull[i]);
1397 if(pullhisto->GetEntries() == 0){
1402 pullhisto->Fit(
"gaus",
"Q");
1403 TF1* fit = pullhisto->GetFunction(
"gaus");
1409 pullmeanhisto->SetBinContent(counter+1, fit->GetParameter(1));
1410 pullmeanhisto->SetBinError(counter+1, fit->GetParError(1));
1411 pullmeanhisto->GetXaxis()->SetBinLabel(counter+1, varName.Data());
1413 pullsigmahisto->SetBinContent(counter+1, fit->GetParameter(2));
1414 pullsigmahisto->SetBinError(counter+1, fit->GetParError(2));
1415 pullsigmahisto->GetXaxis()->SetBinLabel(counter+1, varName.Data());
1425 pullmeanhisto->SetLineColor(2);
1426 pullmeanhisto->SetMarkerStyle(20);
1427 pullmeanhisto->SetMarkerColor(2);
1429 pullsigmahisto->SetLineColor(1);
1430 pullsigmahisto->SetMarkerStyle(21);
1431 pullsigmahisto->SetMarkerColor(1);
1433 pullmeanhisto->GetYaxis()->SetRangeUser(-3, 3);
1434 pullsigmahisto->GetYaxis()->SetRangeUser(-3, 3);
1436 pullmeanhisto->GetXaxis()->SetLabelSize(0.015);
1437 pullsigmahisto->GetXaxis()->SetLabelSize(0.015);
1439 pullmeanhisto->SetStats(0);
1440 pullsigmahisto->SetStats(0);
1442 TLegend* legend =
new TLegend(0.55,0.65,0.85,0.95,
"");
1443 legend->SetFillStyle(0);
1444 legend->SetFillColor(0);
1445 legend->SetBorderSize(0);
1446 legend->SetTextSize(0.036);
1447 legend->AddEntry(pullmeanhisto,
"Pull Mean",
"l");
1448 legend->AddEntry(pullsigmahisto,
"Pull Sigma",
"l");
1450 TLine *mline =
new TLine(0,0.0,n,0.0);
1451 mline->SetLineColor(kBlue);
1452 TLine *sline =
new TLine(0,1.0,n,1.0);
1453 sline->SetLineColor(kBlue);
1456 pullsigmahisto->Draw(
"e");
1457 pullmeanhisto->Draw(
"esame");
1471 std::cerr <<
"ERROR::No tree or workspace found. Pull plot failed!" <<
std::endl;
1475 if(tree->GetEntries() < 2){
1476 std::cerr <<
"ERROR::Tree has less than two entries. No pull plots! Ignore if you run on data!" <<
std::endl;
1480 RooStats::ModelConfig *combined_config = (RooStats::ModelConfig*)ws->obj(
"ModelConfig");
1481 if(!combined_config){
1482 std::cerr <<
"ERROR::No model config " <<
" ModelConfig " <<
" in workspace. No pull plots!" <<
std::endl;
1486 std::vector<Float_t> varValsPull;
1487 const RooArgSet* nuisanceParsList = combined_config->GetNuisanceParameters();
1488 if(!nuisanceParsList){
1489 std::cerr <<
"ERROR::No nuisance parameters found. Nuisance parameters plot failed!" <<
std::endl;
1492 const Int_t
n = nuisanceParsList->getSize();
1493 varValsPull.resize( nuisanceParsList->getSize(), -999. );
1495 TCanvas* cpullnui =
new TCanvas(
"NuisancePullMeanSigma",
"NuisancePullMeanSigma");
1497 TH1F* nuispullmeanhisto =
new TH1F(
"nuispullmeanplot",
"", n+1, 0, n+1);
1498 TH1F* nuispullsigmahisto =
new TH1F(
"nuispullsigmaplot",
"", n+1, 0, n+1);
1501 tree->SetBranchAddress(
"status", &status);
1504 TIterator* Itr = nuisanceParsList->createIterator();
1507 for (Int_t i=0; (var = (RooRealVar*)Itr->Next()); ++i) {
1508 if(var->isConstant())
continue;
1509 TString
varName = var->GetName() + TString(
"pull");
1511 if(!varName.Contains(
"alpha") && !varName.Contains(
"gamma_stat"))
continue;
1512 if(varName.Contains(
"Lumi") || varName.Contains(
"binWidth") || varName.Contains(
"corr"))
continue;
1513 tree->SetBranchAddress(varName.Data(), &varValsPull[i]);
1515 if (varName.Contains(
"gamma_stat"))
1518 TH1F* nuispullhisto =
new TH1F(Form(
"nuispullhisto%i",i),Form(
"nuispullhisto%i",i),100,-5,5);
1519 for(Int_t j=0; j < tree->GetEntries(); j++){
1521 if(status%1000 == 0)
1522 nuispullhisto->Fill(varValsPull[i]);
1525 if(nuispullhisto->GetEntries() == 0){
1530 nuispullhisto->Fit(
"gaus",
"Q");
1531 TF1* fit = nuispullhisto->GetFunction(
"gaus");
1537 nuispullmeanhisto->SetBinContent(counter+1, fit->GetParameter(1));
1538 nuispullmeanhisto->SetBinError(counter+1, fit->GetParError(1));
1541 nuispullsigmahisto->SetBinContent(counter+1, fit->GetParameter(2));
1542 nuispullsigmahisto->SetBinError(counter+1, fit->GetParError(2));
1553 nuispullmeanhisto->SetLineColor(2);
1554 nuispullmeanhisto->SetMarkerStyle(20);
1555 nuispullmeanhisto->SetMarkerColor(2);
1557 nuispullsigmahisto->SetLineColor(1);
1558 nuispullsigmahisto->SetMarkerStyle(21);
1559 nuispullsigmahisto->SetMarkerColor(1);
1561 nuispullmeanhisto->GetYaxis()->SetRangeUser(-3, 3);
1562 nuispullsigmahisto->GetYaxis()->SetRangeUser(-3, 3);
1564 nuispullmeanhisto->SetStats(0);
1565 nuispullsigmahisto->SetStats(0);
1567 nuispullmeanhisto->GetXaxis()->SetTitle(
"Systematic ID");
1568 nuispullsigmahisto->GetXaxis()->SetTitle(
"Systematic ID");
1570 TLegend* legend =
new TLegend(0.55,0.65,0.85,0.95,
"");
1571 legend->SetFillStyle(0);
1572 legend->SetFillColor(0);
1573 legend->SetBorderSize(0);
1574 legend->SetTextSize(0.036);
1575 legend->AddEntry(nuispullmeanhisto,
"Pull Mean",
"l");
1576 legend->AddEntry(nuispullsigmahisto,
"Pull Sigma",
"l");
1578 TLine *mline =
new TLine(0,0.0,n,0.0);
1579 mline->SetLineColor(kBlue);
1580 TLine *sline =
new TLine(0,1.0,n,1.0);
1581 sline->SetLineColor(kBlue);
1582 TLine *vline =
new TLine(n-ngammas, -3., n - ngammas, 3.);
1583 vline->SetLineColor(kGreen);
1586 nuispullsigmahisto->Draw(
"e");
1587 nuispullmeanhisto->Draw(
"esame");
1602 std::cerr <<
"ERROR::No tree or workspace found. Pull plot failed!" <<
std::endl;
1606 RooStats::ModelConfig *combined_config = (RooStats::ModelConfig*)ws->obj(
"ModelConfig");
1607 if(!combined_config){
1608 std::cerr <<
"ERROR::No model config " <<
" ModelConfig " <<
" in workspace. No nuisance parameters plots!" <<
std::endl;
1613 tree->SetBranchAddress(
"status", &status);
1616 std::vector<Float_t> varValsNuisance;
1617 const RooArgSet* nuisanceParsList = combined_config->GetNuisanceParameters();
1618 if(!nuisanceParsList){
1619 std::cerr <<
"ERROR::No nuisance parameters found. Nuisance parameters plot failed!" <<
std::endl;
1622 const Int_t
n = nuisanceParsList->getSize();
1623 varValsNuisance.resize( nuisanceParsList->getSize(), -999. );
1625 TH1F* nuisancehisto =
new TH1F(
"nuisanceplot",
"", n+1, 0, n+1);
1627 TIterator* Itr = nuisanceParsList->createIterator();
1628 for (Int_t i=0; (var = (RooRealVar*)Itr->Next()); ++i) {
1629 TString
varName = var->GetName();
1630 if(!varName.Contains(
"alpha") && !varName.Contains(
"gamma_stat"))
continue;
1631 if(varName.Contains(
"Lumi") || varName.Contains(
"nom") || varName.Contains(
"binWidth") || varName.Contains(
"err") || varName.Contains(
"pull"))
continue;
1633 tree->SetBranchAddress(varName.Data(), &varValsNuisance[i]);
1636 TH1F* temphisto =
new TH1F(
"temphisto",
"temphisto", 100, -5, 5);
1638 for(Int_t j=0; j < tree->GetEntries(); j++){
1640 if(status%1000 == 0)
1641 temphisto->Fill(varValsNuisance[i]);
1644 nuisancehisto->SetBinContent(i+1, temphisto->GetMean());
1652 TIterator* Itr2 = nuisanceParsList->createIterator();
1653 for (Int_t i=0; (var = (RooRealVar*)Itr2->Next()); ++i) {
1654 TString
varName = var->GetName() + TString(
"err");
1656 if(!varName.Contains(
"alpha") && !varName.Contains(
"gamma_stat"))
continue;
1657 if(!varName.Contains(
"err"))
continue;
1658 if(varName.Contains(
"Lumi") || varName.Contains(
"nom") || varName.Contains(
"binWidth") || varName.Contains(
"pull"))
continue;
1660 tree->SetBranchAddress(varName.Data(), &varValsNuisance[i]);
1662 if(varName.Contains(
"gamma_stat"))
1665 TH1F* temphisto =
new TH1F(
"temphisto",
"temphisto", 100, -5, 5);
1667 for(Int_t j=0; j < tree->GetEntries(); j++){
1669 if(status%1000 == 0)
1670 temphisto->Fill(varValsNuisance[i]);
1674 nuisancehisto->SetBinError(i+1, temphisto->GetMean());
1675 nuisancehisto->GetXaxis()->SetBinLabel(i+1, varName);
1681 nuisancehisto->SetLineColor(1);
1682 nuisancehisto->SetMarkerStyle(21);
1683 nuisancehisto->SetMarkerColor(1);
1684 nuisancehisto->GetYaxis()->SetRangeUser(-2.0,2.0);
1685 nuisancehisto->GetXaxis()->SetTitle(
"Systematic ID");
1686 nuisancehisto->GetYaxis()->SetTitle(
"Fit Result");
1687 if(tree->GetEntries() > 1)
1688 nuisancehisto->GetYaxis()->SetTitle(
"Mean Fit Result From Toys");
1689 nuisancehisto->SetTitle(
"Nuisance Parameters");
1690 nuisancehisto->SetStats(
false);
1692 TLine *mline =
new TLine(0,0.0,n,0.0);
1693 mline->SetLineColor(kRed);
1694 TLine *sline =
new TLine(0,1.0,n,1.0);
1695 sline->SetLineColor(kRed);
1696 TLine *s1line =
new TLine(0,-1.0,n,-1.0);
1697 s1line->SetLineColor(kRed);
1698 TLine *vline =
new TLine(n-ngammas,-2,n-ngammas,2.0);
1699 vline->SetLineColor(kGreen);
1701 TCanvas* cNuisanceParameters =
new TCanvas(
"cNuisanceParameters",
"cNuisanceParamters");
1702 nuisancehisto->Draw(
"e");
1703 mline->Draw(
"same");
1704 sline->Draw(
"same");
1705 s1line->Draw(
"same");
1706 vline->Draw(
"same");
1708 return cNuisanceParameters;
1717 std::cerr <<
"ERROR::No tree or workspace found. Plot failed!" <<
std::endl;
1721 RooStats::ModelConfig *combined_config = (RooStats::ModelConfig*)ws->obj(
"ModelConfig");
1722 if(!combined_config){
1723 std::cerr <<
"ERROR::No model config " <<
" ModelConfig " <<
" in workspace. No plots!" <<
std::endl;
1727 std::vector<Float_t> varVals;
1728 std::vector<Float_t> varErrVals;
1729 const RooArgSet* floatParsList = combined_config->GetParametersOfInterest();
1730 if(floatParsList->getSize() == 0){
1731 std::cerr <<
"ERROR::No floating parameters found. Plot failed!" <<
std::endl;
1735 varVals.resize( floatParsList->getSize(), -999. );
1736 varErrVals.resize( floatParsList->getSize(), -999. );
1739 tree->SetBranchAddress(
"status", &status);
1741 Int_t NGoodToys = 0;
1742 for(Int_t j=0; j < tree->GetEntries(); j++){
1744 if(status%1000 == 0)
1749 std::cerr <<
"ERROR::Number of good fit quality is " << NGoodToys <<
". Plot failed!" <<
std::endl;
1753 RooRealVar*
var1(0);
1754 TIterator* Itr1 = floatParsList->createIterator();
1755 std::vector<TString> namevec;
1757 for(Int_t i=0; (var1 = (RooRealVar*)Itr1->Next()); ++i) {
1758 TString
varName = TString(var1->GetName());
1759 if(!varName.Contains(channelname.Data()))
continue;
1760 if(!varName.Contains(catname.Data()))
continue;
1762 if(var1->isConstant()) varName += TString(
"_constant");
1763 namevec.push_back(varName);
1767 Int_t
n = namevec.size();
1768 TString histoname = channelname +
"_MomHisto_" + catname;
1769 TH1D* histo =
new TH1D(histoname.Data(), histoname.Data(), n, 0, n);
1771 TH1D * prefit_histo = 0x0;
1773 TString prefit_name =
"PreFit_" + histoname;
1774 prefit_histo = (TH1D*)histo->Clone(prefit_name.Data());
1778 TIterator* Itr = floatParsList->createIterator();
1781 for(Int_t i=0; (var = (RooRealVar*)Itr->Next()); ++i) {
1782 TString
varName = TString(var->GetName());
1783 std::cout <<
"Ave name: " << varName <<
std::endl;
1784 if(!varName.Contains(channelname.Data()))
continue;
1785 if(!varName.Contains(catname.Data()))
continue;
1788 tree->SetBranchAddress(varName.Data(), &varVals[i]);
1789 TString varName2 = varName + TString(
"err");
1790 tree->SetBranchAddress(varName2.Data(), &varErrVals[i]);
1793 Float_t averr = 0.0;
1794 for(Int_t j=0; j < tree->GetEntries(); j++){
1796 if(status%1000 == 0){
1797 av += varVals[i]/NGoodToys;
1798 averr += varErrVals[i]/NGoodToys;
1802 histo->SetBinContent(counter, av);
1803 histo->SetBinError(counter, averr);
1806 RooRealVar *
var2(0);
1807 TIterator * prefit_itr = PreFit_POI->createIterator();
1808 while ((var2 = (RooRealVar*)prefit_itr->Next())) {
1809 std::cout <<
"Prefit:" << var2->GetName() <<
std::endl;
1810 TString var2Name(var2->GetName());
1811 if (var2Name == varName) {
1812 std::cout <<
"Found match " << var2->GetName() <<
std::endl;
1813 prefit_histo->SetBinContent(counter, var2->getVal());
1823 TLine *
line =
new TLine(0,1.0,n,1.0);
1824 line->SetLineColor(kRed);
1838 histoname = TString(
"canvas_") + histoname;
1839 histo->SetTitle(channelname.Data());
1841 histo->GetYaxis()->SetTitle(
"Fit result");
1842 if(tree->GetEntries() > 1)
1843 histo->GetYaxis()->SetTitle(
"Average Fit result");
1844 histo->GetYaxis()->SetRangeUser(-1.5,4.0);
1845 for(Int_t i=n; i > 0; i--)
1846 histo->GetXaxis()->SetBinLabel(i, namevec[n-i]);
1847 histo->SetMarkerStyle(20);
1848 histo->SetStats(
false);
1849 histo->GetXaxis()->SetLabelSize(0.02);
1851 TCanvas*
c =
new TCanvas(histoname.Data(), histoname.Data());
1852 histo->SetFillStyle(3144);
1853 histo->SetFillColor(kRed);
1861 TLegend *
leg =
new TLegend(.65, .65, .85, .85);
1862 leg->AddEntry(histo,
"Postfit",
"lpf");
1865 prefit_histo->SetMarkerColor(kBlue);
1866 prefit_histo->SetMarkerStyle(20);
1867 prefit_histo->Draw(
"p same");
1868 leg->AddEntry(prefit_histo,
"Prefit",
"lpf");
1883 std::cout <<
"INFO::Printing fractional error for each fir parameter:-" <<
std::endl;
1887 TIterator* iter = paramsfit.createIterator();
1889 for(Int_t i=0; (var = (RooRealVar*)iter->Next()); ++i){
1890 TString varname(var->GetName());
1891 if(varname.Contains(
"alpha_") || varname.Contains(
"gamma_"))
continue;
1892 if(varname.Contains(
"POI_")){
1895 std::cout << varname.Data() <<
": Fit result = " << var->getVal() <<
" +/- " << var->getError() <<
". Fractional error = " << var->getError()/var->getVal() <<
std::endl;
1909 RooStats::ModelConfig *combined_config = (RooStats::ModelConfig*)ws->obj(
"ModelConfig");
1910 if(!combined_config){
1911 std::cerr <<
"ERROR::No model config " <<
" ModelConfig " <<
" in workspace. Exit!" <<
std::endl;
1915 RooAbsPdf* pdf = combined_config->GetPdf();
1917 std::cerr <<
"ERROR::No pdf found in ModelConfig. Exit!" <<
std::endl;
1921 const RooArgSet* obs = combined_config->GetNuisanceParameters();
1923 std::cerr <<
"ERROR::No nuisance found in ModelConfig. Exit!" <<
std::endl;
1927 RooArgList floatParList;
1929 floatParList.add(*obs);
1931 TIterator* iter = floatParList.createIterator();
1933 while((arg=(RooAbsArg*)iter->Next())){
1935 if(arg->InheritsFrom(
"RooRealVar") && !arg->isConstant()){
1936 varname = TString(arg->GetName());
1942 if(varname == exceptPar)
continue;
1944 RooRealVar*
var = ws->var(varname.Data());
1946 std::cout <<
"WARNING::Can't find parameter " << varname.Data() <<
" in workspace." <<
std::endl;
1951 std::cout <<
"WARNING::Empty variable name. Skipping reset value." <<
std::endl;
1954 else if(varname.Contains(
"alpha")){
1955 var->setConstant(kTRUE);
1957 else if(varname.Contains(
"gamma_stat")){
1958 var->setConstant(kTRUE);
1973 TIterator* iter = parList.createIterator();
1975 while((arg=(RooAbsArg*)iter->Next())){
1977 if(arg->InheritsFrom(
"RooRealVar") && !arg->isConstant()){
1978 varname = TString(arg->GetName());
1984 RooRealVar*
var = ws->var(varname.Data());
1986 std::cout <<
"WARNING::Can't find parameter " << varname.Data() <<
" in workspace." <<
std::endl;
1991 std::cout <<
"WARNING::Empty variable name. Skipping reset value." <<
std::endl;
1994 else if(varname.Contains(
"alpha")){
1997 else if(varname.Contains(
"gamma_stat")){
2013 TIterator* iter = parSet.createIterator();
2015 while((arg=(RooAbsArg*)iter->Next())){
2017 if(arg->InheritsFrom(
"RooRealVar") && !arg->isConstant()){
2018 varname = TString(arg->GetName());
2024 RooRealVar*
var = ws->var(varname.Data());
2026 std::cout <<
"WARNING::Can't find parameter " << varname.Data() <<
" in workspace." <<
std::endl;
2031 std::cout <<
"WARNING::Empty variable name. Skipping reset value to nominal." <<
std::endl;
2034 else if(varname.Contains(
"nom_gamma_stat")){
2037 else if(varname.Contains(
"nom")){
2053 TIterator* iter = parList.createIterator();
2055 while((arg=(RooAbsArg*)iter->Next())){
2057 if(arg->InheritsFrom(
"RooRealVar") && !arg->isConstant()){
2058 varname = TString(arg->GetName());
2064 RooRealVar*
var = ws->var(varname.Data());
2066 std::cout <<
"WARNING::Can't find parameter " << varname.Data() <<
" in workspace." <<
std::endl;
2071 std::cout <<
"WARNING::Empty variable name. Skipping reset error." <<
std::endl;
2074 else if(varname.Contains(
"alpha")){
2076 if(var->getMin() < var->getVal() - 6.) var->setMin(var->getVal() - 6.);
2077 if(var->getMax() > var->getVal() + 6.) var->setMax(var->getVal() + 6.);
2079 else if(varname.Contains(
"gamma_stat")){
2081 RooAbsReal* constraint = (RooAbsReal*) ws->obj(Form(
"%s_constraint",varname.Data()));
2083 std::cout <<
"WARNING::Constraint for variable " << varname.Data() <<
" not found. Skip reset error." <<
std::endl;
2087 TString constraintString = TString(constraint->IsA()->GetName());
2088 if(constraintString ==
"")
continue;
2089 else if(constraintString.Contains(
"RooGaussian")){
2090 RooAbsReal* ErrorVar = (RooAbsReal*)ws->obj(Form(
"%s_sigma",varname.Data()));
2092 std::cout <<
"WARNING::Constraint type " << constraintString.Data() <<
" for variable " << varname.Data() <<
" not found. Skip reset error." <<
std::endl;
2095 Double_t
err = ErrorVar->getVal();
2097 if(var->getMin() < var->getVal() - 6.) var->setMin(var->getVal() - 6.);
2098 if(var->getMax() > var->getVal() + 6.) var->setMax(var->getVal() + 6.);
2100 else if(constraintString.Contains(
"RooPoisson")){
2101 RooAbsReal* ErrorVar = (RooAbsReal*)ws->obj(Form(
"nom_%s",varname.Data()));
2103 std::cout <<
"WARNING::Constraint type " << constraintString.Data() <<
" for variable " << varname.Data() <<
" not found. Skip reset error." <<
std::endl;
2106 Double_t
err = 1/sqrt(ErrorVar->getVal());
2108 if(var->getMin() < var->getVal() - 6.) var->setMin(var->getVal() - 6.);
2109 if(var->getMax() > var->getVal() + 6.) var->setMax(var->getVal() + 6.);
2112 std::cout <<
"WARNING::Unknown constraint type " << constraintString.Data() <<
". Set prefit uncertainty to 0.00001." <<
std::endl;
2126 RooStats::ModelConfig *combined_config = (RooStats::ModelConfig*)ws->obj(
"ModelConfig");
2127 if(!combined_config){
2128 std::cerr <<
"ERROR::No model config " <<
" ModelConfig " <<
" in workspace. Will not reset values and errors." <<
std::endl;
2132 RooAbsPdf* pdf = combined_config->GetPdf();
2134 std::cerr <<
"ERROR::No pdf found in ModelConfig. Will not reset values and errors." <<
std::endl;
2138 const RooArgSet* obs = combined_config->GetObservables();
2140 std::cerr <<
"ERROR::No observables found in ModelConfig. Will not reset values and errors." <<
std::endl;
2144 const RooArgSet* pdfpars = pdf->getParameters(obs);
2146 std::cerr <<
"ERROR::No pdf parameters found. Will not reset values and errors." <<
std::endl;
2150 const RooArgSet* globalobs = combined_config->GetGlobalObservables();
2152 std::cerr <<
"ERROR::No global observables found in ModelConfig. Will not reset values and errors." <<
std::endl;
2156 RooArgList floatParamsList;
2158 TIterator* iter = pdfpars->createIterator() ;
2160 while( (absarg=(RooAbsArg*)iter->Next()) ) {
2161 if(absarg->InheritsFrom(
"RooRealVar") && !absarg->isConstant()){
2162 floatParamsList.add(*absarg);
bool IsSingleBinHisto(TH1 *histo)
std::vector< TCanvas * > PlotDatasetsAndPdfs(RooWorkspace *work, TString name, TString error, TString plottodraw, std::vector< TString > binnames, std::vector< double > recobins, std::vector< TString > incidentBinNames, std::vector< TString > sidebandBinNames, std::vector< double > sidebandBins, TString measurement="PDFit", bool doNegativeReco=false, RooAbsData *data=NULL, RooFitResult *result=NULL)
double GetArgonNumberDensity(double argon_density, double argon_molecularmass)
RooArgList GetPostfitPOIList(RooArgList paramsfit, bool print=false)
void ResetValues(RooWorkspace *ws, const RooArgList &parList)
void SetInterpolationCode(RooWorkspace *ws, int code)
void SaveWorkspace(RooWorkspace *ws, TString outFileName)
TH1 * GetStatsSystHistogram(TH1 *nominal)
const std::string instance
int find(const type *d) const
bool LoadSnapshot(RooWorkspace *ws, TString snapshotname)
void MakeNuisanceParamsConstant(RooWorkspace *ws, TString exceptPar)
std::vector< TH1 * > PlotXSecs(RooWorkspace *work, std::string name, std::vector< TString > binnames, std::vector< double > recobins, std::vector< TString > incidentBinNames, RooAbsData *data=0x0, RooFitResult *result=0x0)
TH1 * GetSystematicHistoFromNominal(TH1 *nominal, TH1 *syst, TString name)
void RemoveEmptyBins(RooPlot *frame)
std::vector< TCanvas * > PlotNuisanceParametersImpact(RooWorkspace *work, RooFitResult *result, TString snapshotload, std::vector< std::string > SystsToConsider)
TH2 * GetFitCovariance(RooFitResult *result)
TCanvas * PlotParametersPull(TTree *tree, RooWorkspace *ws)
double GetDataMCChi2(RooWorkspace *work, TString channelname, RooAbsData *data=NULL)
CodeOutputInterface * code
void err(const char *fmt,...)
void ResetValuesToNominal(RooWorkspace *ws, const RooArgSet &parSet)
TCanvas * PlotNuisanceParameters(TTree *tree, RooWorkspace *ws)
std::vector< TCanvas * > PlotNLL(RooWorkspace *work, TString name, RooFitResult *result, bool plotPLL=false)
TH2 * GetFitCorrelationMatrix(RooFitResult *result)
void line(double t, double *p, double &x, double &y, double &z)
void SaveSnapshot(RooWorkspace *ws, TString snapshotname)
void ResetError(RooWorkspace *ws, const RooArgList &parList)
TCanvas * PlotAverageResultsFromToys(TTree *tree, RooWorkspace *ws, TString channelname, TString catname, RooArgList *PreFit_POI=0x0)
std::string to_string(ModuleType const mt)
TCanvas * PlotNuisanceParametersPull(TTree *tree, RooWorkspace *ws)
QTextStream & endl(QTextStream &s)
std::vector< TH1 * > GetSystHistograms(std::string name)
void ResetAllValuesAndErrors(RooWorkspace *ws)