1317 |
|
return prob; |
1318 |
|
} |
1319 |
|
|
1320 |
– |
/*void save_with_difference(TH1F *obs, vector<TH1F*> predictions, vector<float> prediction_weights, vector<float> prediction_uncerts, TVirtualPad *canvas, string savemeas) { |
1321 |
– |
if(predictions.size()<1) { |
1322 |
– |
write_warning(__FUNCTION__,"Cannot make a pred-obs prediction plot because the prediction vector is empty. aborting!"); |
1323 |
– |
return; |
1324 |
– |
} |
1325 |
– |
TH1F *comppred = predictions[0]->Clone("comppred"); |
1326 |
– |
comppred->Scale(prediction_weights[0]); |
1327 |
– |
for(int i=1;i<predictions.size();i++) comppred->Add(predictions[i],prediction_weights[i]); |
1328 |
– |
|
1329 |
– |
TH1F *statpred = (TH1F*)comppred->Clone("statpred"); |
1330 |
– |
for(int i=1;i<=statpred->GetNbinsX();i++) statpred->SetBinContent(0); |
1331 |
– |
|
1332 |
– |
TH1F *syspred = predictions[0]; |
1333 |
– |
for(int i=1;i<=syspred->GetNbinsX();i++) syspred->SetBinContent(i,prediction_weights[0]*prediction_weights[0]*prediction_uncerts[0]*prediction_uncerts[0]*syspred->GetBinContent(i)*syspred->GetBinContent(i)); |
1334 |
– |
for(int i=1;i<predictions.size();i++) { |
1335 |
– |
for(int ibin=1;ibin<=predictions[i]->GetNbinsX();ibin++) { |
1336 |
– |
float newentry=syspred->GetBinContent(ibin); |
1337 |
– |
newentry+=(predictions[i]->GetBinContent(ibin))*(predictions[i]->GetBinContent(ibin))*prediction_weights[i]*prediction_weights[i]*prediction_uncerts[i]*prediction_uncerts[i]; |
1338 |
– |
syspred->SetBinContent(ibin,newentry); |
1339 |
– |
} |
1340 |
– |
} |
1341 |
– |
for(int ibin=1;ibin<=syspred->GetNbinsX();ibin++) { |
1342 |
– |
syspred->SetBinError(ibin,syspred->GetBinContent(i)+statpred->GetBinError()); |
1343 |
– |
syspred->SetBinContent(ibin,0); |
1344 |
– |
} |
1345 |
– |
|
1346 |
– |
|
1347 |
– |
} |
1348 |
– |
*/ |
1320 |
|
void save_with_ratio(TH1F *nominator, TH1F *denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false, bool extendrange=false, string yaxistitle="ratio",TH1F *syshisto=NULL) { |
1321 |
|
//this function saves the pad being passed as well as a new one including the ratio. |
1322 |
|
CompleteSave(canvas,savemeas); |
1393 |
|
} |
1394 |
|
|
1395 |
|
} |
1425 |
– |
eratio->SetFillColor(TColor::GetColor("#00ADE1")); |
1396 |
|
|
1397 |
+ |
if(syshisto && !do_bpred_ratio) { |
1398 |
+ |
SystDown = (TH1F*)syshisto->Clone("SystDown"); |
1399 |
+ |
SystUp = (TH1F*)syshisto->Clone("SystUp"); |
1400 |
+ |
for(int i=1;i<=syshisto->GetNbinsX();i++) { |
1401 |
+ |
SystDown->SetBinContent(i,1-syshisto->GetBinContent(i)); |
1402 |
+ |
SystUp->SetBinContent(i,1+syshisto->GetBinContent(i)); |
1403 |
+ |
} |
1404 |
+ |
SystDown->SetLineColor(TColor::GetColor("#006DE1")); |
1405 |
+ |
SystUp->SetLineColor(TColor::GetColor("#006DE1")); |
1406 |
+ |
} |
1407 |
+ |
eratio->SetFillColor(TColor::GetColor("#00ADE1")); |
1408 |
|
|
1409 |
|
ratio->SetTitle(""); |
1410 |
|
ratio->GetYaxis()->SetRangeUser(0.0,2.0); |
1483 |
|
delete main_canvas; |
1484 |
|
} |
1485 |
|
|
1486 |
< |
void save_with_ratio_and_sys_band(TH1F *nominator, TH1F *denominator, TVirtualPad *canvas, string savemeas, float systematic, string yaxistitle="SysRatio") { |
1486 |
> |
void save_with_ratio_and_sys_band(TH1F *nominator, TH1F *denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false, bool extendrange=false, string yaxistitle="ratio",TH1F *syshisto=NULL) { |
1487 |
|
//this function saves the pad being passed as well as a new one including the SysRatio. |
1488 |
|
CompleteSave(canvas,savemeas); |
1489 |
|
|
1490 |
|
float bottommargin=gStyle->GetPadBottomMargin(); |
1491 |
|
float canvas_height=gStyle->GetCanvasDefH(); |
1492 |
|
float canvas_width=gStyle->GetCanvasDefW(); |
1493 |
< |
float SysRatiospace=0.25;// space the SysRatio should take up (relative to original pad) |
1493 |
> |
float ratiospace=0.25;// space the ratio should take up (relative to original pad) |
1494 |
> |
|
1495 |
> |
float ratiobottommargin=0.3; |
1496 |
> |
float ratiotopmargin=0.1; |
1497 |
> |
|
1498 |
> |
float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace); |
1499 |
|
|
1500 |
< |
float SysRatiobottommargin=0.3; |
1501 |
< |
float SysRatiotopmargin=0.1; |
1500 |
> |
TCanvas *main_canvas = new TCanvas("main_canvas","main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace))); |
1501 |
> |
TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad |
1502 |
> |
TPad *coverpad = new TPad("coverpad","coverpad",gStyle->GetPadLeftMargin()-0.008,1-(1.0/(1+ratiospace))-0.04,1,1-(1.0/(1+ratiospace))+0.103);//pad covering up the x scale |
1503 |
> |
TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad |
1504 |
|
|
1505 |
< |
float xstretchfactor=((1-SysRatiospace)*(1-gStyle->GetPadTopMargin()))/((1)*SysRatiospace); |
1505 |
> |
main_canvas->Range(0,0,1,1); |
1506 |
> |
main_canvas->SetBorderSize(0); |
1507 |
> |
main_canvas->SetFrameFillColor(0); |
1508 |
|
|
1509 |
< |
TCanvas *MainCanvas = new TCanvas("MainCanvas","MainCanvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+SysRatiospace))); |
1510 |
< |
TPad *MainPad = new TPad("MainPad","MainPad",0,1-(1.0/(1+SysRatiospace)),1,1);//top (main) pad |
1511 |
< |
TPad *CoverPad = new TPad("CoverPad","CoverPad",gStyle->GetPadLeftMargin()-0.008,1-(1.0/(1+SysRatiospace))-0.04,1,1-(1.0/(1+SysRatiospace))+0.103);//pad covering up the x scale |
1512 |
< |
TPad *BottomPad = new TPad("BottomPad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+SysRatiospace))-0.015); //bottom pad |
1513 |
< |
|
1514 |
< |
MainCanvas->Range(0,0,1,1); |
1525 |
< |
MainCanvas->SetBorderSize(0); |
1526 |
< |
MainCanvas->SetFrameFillColor(0); |
1527 |
< |
|
1528 |
< |
MainPad->Draw(); |
1529 |
< |
MainPad->cd(); |
1530 |
< |
MainPad->Range(0,0,1,1); |
1531 |
< |
MainPad->SetFillColor(kWhite); |
1532 |
< |
MainPad->SetBorderSize(0); |
1533 |
< |
MainPad->SetFrameFillColor(0); |
1509 |
> |
mainpad->Draw(); |
1510 |
> |
mainpad->cd(); |
1511 |
> |
mainpad->Range(0,0,1,1); |
1512 |
> |
mainpad->SetFillColor(kWhite); |
1513 |
> |
mainpad->SetBorderSize(0); |
1514 |
> |
mainpad->SetFrameFillColor(0); |
1515 |
|
canvas->Range(0,0,1,1); |
1516 |
|
canvas->Draw("same"); |
1517 |
< |
MainPad->Modified(); |
1518 |
< |
MainCanvas->cd(); |
1519 |
< |
CoverPad->Draw(); |
1520 |
< |
CoverPad->cd(); |
1521 |
< |
CoverPad->Range(0,0,1,1); |
1522 |
< |
CoverPad->SetFillColor(kWhite); |
1523 |
< |
CoverPad->SetBorderSize(0); |
1524 |
< |
CoverPad->SetFrameFillColor(0); |
1525 |
< |
CoverPad->Modified(); |
1526 |
< |
MainCanvas->cd(); |
1527 |
< |
BottomPad->SetTopMargin(SysRatiotopmargin); |
1528 |
< |
BottomPad->SetBottomMargin(SysRatiobottommargin); |
1529 |
< |
BottomPad->Draw(); |
1530 |
< |
BottomPad->cd(); |
1531 |
< |
BottomPad->Range(0,0,1,1); |
1532 |
< |
BottomPad->SetFillColor(kWhite); |
1533 |
< |
TH1F *SysRatio = (TH1F*)nominator->Clone(GetNumericHistoName().c_str()); |
1534 |
< |
SysRatio->Divide(denominator); |
1517 |
> |
mainpad->Modified(); |
1518 |
> |
main_canvas->cd(); |
1519 |
> |
coverpad->Draw(); |
1520 |
> |
coverpad->cd(); |
1521 |
> |
coverpad->Range(0,0,1,1); |
1522 |
> |
coverpad->SetFillColor(kWhite); |
1523 |
> |
coverpad->SetBorderSize(0); |
1524 |
> |
coverpad->SetFrameFillColor(0); |
1525 |
> |
coverpad->Modified(); |
1526 |
> |
main_canvas->cd(); |
1527 |
> |
bottompad->SetTopMargin(ratiotopmargin); |
1528 |
> |
bottompad->SetBottomMargin(ratiobottommargin); |
1529 |
> |
bottompad->Draw(); |
1530 |
> |
bottompad->cd(); |
1531 |
> |
bottompad->Range(0,0,1,1); |
1532 |
> |
bottompad->SetFillColor(kWhite); |
1533 |
> |
TH1F *ratio = (TH1F*)nominator->Clone(GetNumericHistoName().c_str()); |
1534 |
> |
ratio->Divide(denominator); |
1535 |
|
|
1536 |
|
|
1537 |
+ |
TGraphAsymmErrors *eratio; |
1538 |
+ |
TGraphAsymmErrors *SysEnvelope = new TGraphAsymmErrors(); |
1539 |
+ |
|
1540 |
+ |
if(!do_bpred_ratio) eratio = produce_ratio_graph(ratio); |
1541 |
+ |
else { |
1542 |
+ |
bool using_data=false; |
1543 |
+ |
if((int)savemeas.find("Data")>0) using_data=true; |
1544 |
+ |
eratio = histRatio(nominator,denominator,using_data,PlottingSetup::global_ratio_binning,false); |
1545 |
+ |
if(syshisto!=0) { |
1546 |
+ |
for(int i=1;i<=syshisto->GetNbinsX();i++) { |
1547 |
+ |
SysEnvelope->SetPoint(i-1,syshisto->GetBinCenter(i),1.0); |
1548 |
+ |
SysEnvelope->SetPointError(i-1,syshisto->GetBinWidth(i),syshisto->GetBinWidth(i),syshisto->GetBinContent(i),syshisto->GetBinContent(i)); |
1549 |
+ |
} |
1550 |
+ |
SysEnvelope->SetFillColor(TColor::GetColor("#006DE1")); |
1551 |
+ |
} |
1552 |
+ |
for(int i=1;i<=ratio->GetNbinsX();i++) { |
1553 |
+ |
ratio->SetBinContent(i,0); |
1554 |
+ |
ratio->SetBinError(i,0); |
1555 |
+ |
} |
1556 |
+ |
|
1557 |
+ |
} |
1558 |
+ |
|
1559 |
+ |
if(syshisto && !do_bpred_ratio) { |
1560 |
+ |
for(int i=1;i<=syshisto->GetNbinsX();i++) { |
1561 |
+ |
SysEnvelope->SetPoint(i-1,syshisto->GetBinCenter(i),1.0); |
1562 |
+ |
SysEnvelope->SetPointError(i-1,syshisto->GetBinWidth(i),syshisto->GetBinWidth(i),syshisto->GetBinContent(i),syshisto->GetBinContent(i)); |
1563 |
+ |
} |
1564 |
+ |
SysEnvelope->SetFillColor(TColor::GetColor("#006DE1")); |
1565 |
+ |
} |
1566 |
|
|
1567 |
< |
SysRatio->SetTitle(""); |
1568 |
< |
SysRatio->GetYaxis()->SetRangeUser(0.0,2.0); |
1569 |
< |
SysRatio->GetXaxis()->SetTitle(nominator->GetXaxis()->GetTitle()); |
1570 |
< |
SysRatio->GetXaxis()->CenterTitle(); |
1571 |
< |
SysRatio->GetYaxis()->SetTitle(yaxistitle.c_str()); |
1572 |
< |
SysRatio->GetYaxis()->SetTitleOffset(0.4); |
1573 |
< |
SysRatio->GetYaxis()->CenterTitle(); |
1574 |
< |
SysRatio->SetStats(0); |
1575 |
< |
SysRatio->GetXaxis()->SetLabelSize(xstretchfactor*SysRatio->GetXaxis()->GetLabelSize()); |
1576 |
< |
SysRatio->GetYaxis()->SetLabelSize(xstretchfactor*SysRatio->GetYaxis()->GetLabelSize()); |
1577 |
< |
SysRatio->GetXaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize()); |
1578 |
< |
SysRatio->GetYaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize()); |
1579 |
< |
SysRatio->GetYaxis()->SetNdivisions(502,false); |
1580 |
< |
SysRatio->SetFillColor(TColor::GetColor("#58D3F7")); |
1581 |
< |
TBox *sysbox = new TBox(SysRatio->GetXaxis()->GetBinLowEdge(1),1-systematic,SysRatio->GetXaxis()->GetBinLowEdge(SysRatio->GetNbinsX())+SysRatio->GetXaxis()->GetBinWidth(SysRatio->GetNbinsX()),1+systematic); |
1582 |
< |
sysbox->SetFillColor(TColor::GetColor("#82FA58")); // light green |
1583 |
< |
|
1574 |
< |
SysRatio->Draw("e1"); |
1575 |
< |
sysbox->Draw(); |
1576 |
< |
SysRatio->Draw("e1,same"); |
1577 |
< |
SysRatio->Draw("e1,axis,same"); |
1567 |
> |
ratio->SetTitle(""); |
1568 |
> |
ratio->GetYaxis()->SetRangeUser(0.0,2.0); |
1569 |
> |
if(do_bpred_ratio) ratio->GetYaxis()->SetRangeUser(0.0,2.0); |
1570 |
> |
if(extendrange) ratio->GetYaxis()->SetRangeUser(0.0,4.0); |
1571 |
> |
ratio->GetXaxis()->SetTitle(nominator->GetXaxis()->GetTitle()); |
1572 |
> |
ratio->GetXaxis()->CenterTitle(); |
1573 |
> |
ratio->GetYaxis()->SetTitle(yaxistitle.c_str()); |
1574 |
> |
ratio->GetYaxis()->SetTitleOffset(0.4); |
1575 |
> |
ratio->GetYaxis()->CenterTitle(); |
1576 |
> |
ratio->SetStats(0); |
1577 |
> |
ratio->GetXaxis()->SetLabelSize(xstretchfactor*ratio->GetXaxis()->GetLabelSize()); |
1578 |
> |
ratio->GetYaxis()->SetLabelSize(xstretchfactor*ratio->GetYaxis()->GetLabelSize()); |
1579 |
> |
ratio->GetXaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize()); |
1580 |
> |
ratio->GetYaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize()); |
1581 |
> |
ratio->GetYaxis()->SetNdivisions(502,false); |
1582 |
> |
ratio->SetFillColor(TColor::GetColor("#58D3F7")); |
1583 |
> |
ratio->Draw("e1"); |
1584 |
|
|
1585 |
< |
TLine *oneline = new TLine(SysRatio->GetXaxis()->GetBinLowEdge(1),1,SysRatio->GetXaxis()->GetBinLowEdge(SysRatio->GetNbinsX())+SysRatio->GetXaxis()->GetBinWidth(SysRatio->GetNbinsX()),1); |
1585 |
> |
if(syshisto!=0) { |
1586 |
> |
ratio->Draw(""); |
1587 |
> |
SysEnvelope->SetFillColor(TColor::GetColor("#FE9A2E")); |
1588 |
> |
SysEnvelope->Draw("2,same"); |
1589 |
> |
ratio->Draw("e1,same"); |
1590 |
> |
} else { |
1591 |
> |
eratio->Draw("1"); |
1592 |
> |
} |
1593 |
> |
ratio->Draw("same,axis"); |
1594 |
> |
TLine *oneline = new TLine(ratio->GetXaxis()->GetBinLowEdge(1),1,ratio->GetXaxis()->GetBinLowEdge(ratio->GetNbinsX())+ratio->GetXaxis()->GetBinWidth(ratio->GetNbinsX()),1); |
1595 |
|
oneline->SetLineStyle(2); |
1596 |
|
oneline->SetLineColor(kBlue); |
1597 |
|
oneline->Draw("same"); |
1598 |
|
|
1599 |
< |
MainCanvas->cd(); |
1600 |
< |
MainCanvas->Modified(); |
1601 |
< |
MainCanvas->cd(); |
1602 |
< |
MainCanvas->SetSelected(MainCanvas); |
1603 |
< |
|
1604 |
< |
CompleteSave(MainCanvas,savemeas+"_withSYSSysRatio"); |
1605 |
< |
delete SysRatio; |
1606 |
< |
delete MainCanvas; |
1599 |
> |
main_canvas->cd(); |
1600 |
> |
main_canvas->Modified(); |
1601 |
> |
main_canvas->cd(); |
1602 |
> |
main_canvas->SetSelected(main_canvas); |
1603 |
> |
|
1604 |
> |
CompleteSave(main_canvas,savemeas+"_withSysRatio"); |
1605 |
> |
bottompad->cd(); |
1606 |
> |
|
1607 |
> |
Double_t chi2; |
1608 |
> |
Int_t ndf,igood; |
1609 |
> |
Double_t chi2prob = MarcosChi2TestX(nominator,denominator,chi2,ndf,igood,"UW"); |
1610 |
> |
|
1611 |
> |
stringstream Chi2text; |
1612 |
> |
Chi2text << "#chi^{2} / ndf: " << chi2 << " / " << ndf; |
1613 |
> |
stringstream Chi2probtext; |
1614 |
> |
Chi2probtext << "#chi^{2} prob: " << chi2prob; |
1615 |
> |
TText* chi2box = write_text(0.02,0.11,Chi2text.str()); |
1616 |
> |
chi2box->SetTextSize(0.08); |
1617 |
> |
chi2box->SetTextAlign(11); |
1618 |
> |
chi2box->Draw(); |
1619 |
> |
TText* chi2probbox = write_text(0.02,0.04,Chi2probtext.str()); |
1620 |
> |
chi2probbox->SetTextSize(0.08); |
1621 |
> |
chi2probbox->SetTextAlign(11); |
1622 |
> |
chi2probbox->Draw(); |
1623 |
> |
|
1624 |
> |
stringstream CompRatio; |
1625 |
> |
CompRatio << "Ratio: " << nominator->Integral() << " / " << denominator->Integral() << " \n " << nominator->Integral()/denominator->Integral(); |
1626 |
> |
TText *CompleteRatio = write_text(0.98,0.04,CompRatio.str()); |
1627 |
> |
CompleteRatio->SetTextSize(0.08); |
1628 |
> |
CompleteRatio->SetTextAlign(31); |
1629 |
> |
CompleteRatio->Draw(); |
1630 |
> |
|
1631 |
> |
CompleteSave(main_canvas,savemeas+"_withSysRatio_and_Chi2"); |
1632 |
> |
|
1633 |
> |
delete main_canvas; |
1634 |
|
} |
1635 |
|
|
1636 |
|
TH1F* CollapseStack(THStack stack,TString hname="base") { |
1849 |
|
|
1850 |
|
TPolyLine* GetFitUncertaintyShape(TF1 *fit, float low, float high,float x0,float x1) { |
1851 |
|
int nPoints=1000; |
1810 |
– |
|
1852 |
|
double x[nPoints+1]; |
1853 |
|
double y[nPoints]; |
1854 |
|
|