39 |
|
#include <TPaveText.h> |
40 |
|
#include <TRandom.h> |
41 |
|
#include <TGraphErrors.h> |
42 |
+ |
#include <TROOT.h> |
43 |
|
#ifndef Verbosity |
44 |
|
#define Verbosity 0 |
45 |
|
#endif |
62 |
|
int PaperMode=0; // PaperMode=true will suppress "Preliminary" in DrawPrelim() |
63 |
|
int Approved=0; // Approved=true will only plot approved plots |
64 |
|
bool is2012=true; |
65 |
+ |
bool is53reco=false; |
66 |
|
} |
67 |
|
|
68 |
|
bool dopng=false; |
256 |
|
} |
257 |
|
} |
258 |
|
|
259 |
+ |
void DeadEnd(string message) { |
260 |
+ |
dout << endl; |
261 |
+ |
dout << "\033[1;31m _ _ _ " << endl; |
262 |
+ |
dout << "\033[1;31m __| | ___ __ _ __| | ___ _ __ __| | " << endl; |
263 |
+ |
dout << "\033[1;31m / _` |/ _ \\/ _` |/ _` | / _ \\ '_ \\ / _` | " << endl; |
264 |
+ |
dout << "\033[1;31m| (_| | __/ (_| | (_| | | __/ | | | (_| | " << endl; |
265 |
+ |
dout << "\033[1;31m \\__,_|\\___|\\__,_|\\__,_| \\___|_| |_|\\__,_| " << endl; |
266 |
+ |
dout << "\033[1;31m " << endl; |
267 |
+ |
dout << "" << endl; |
268 |
+ |
dout << " A totally fatal error has occurred: " << endl; |
269 |
+ |
dout << " " << message << endl; |
270 |
+ |
dout << endl; |
271 |
+ |
dout << "If you do not know how to deal with this error message please call Customer Support Mumbai (or Zurich...) \033[0m" << endl; |
272 |
+ |
dout << " ... aborting now ... " << endl; |
273 |
+ |
assert(0); |
274 |
+ |
} |
275 |
+ |
|
276 |
+ |
|
277 |
+ |
void SanityChecks() { |
278 |
+ |
//this function gets called whenever samples are initialized (see ActiveSamples.C) |
279 |
+ |
//whatever is necessary for the code to run should be put here. |
280 |
+ |
|
281 |
+ |
if(gROOT->GetVersionInt()<53200) { |
282 |
+ |
DeadEnd("ROOT version outdated, you are using "+any2string(gROOT->GetVersionInt())+" but the earliest recommended version is 5.32.00"); |
283 |
+ |
} |
284 |
+ |
|
285 |
+ |
|
286 |
+ |
} |
287 |
+ |
|
288 |
|
void initialize_log() { |
289 |
|
if(!PlottingSetup::publicmode) { |
290 |
|
dout << "____________________________________________________________" << endl; |
667 |
|
return val; |
668 |
|
} |
669 |
|
|
670 |
+ |
TGraphAsymmErrors *SysAndStatRatio(TH1F *h1,TH1F *h2, TH1F *sys, int id, vector<float>binning, bool precise=false) { |
671 |
+ |
int absJZBbinsNumber = binning.size()-1; |
672 |
+ |
TGraphAsymmErrors* graph = new TGraphAsymmErrors(absJZBbinsNumber); |
673 |
+ |
for(int i=0;i<absJZBbinsNumber;i++) |
674 |
+ |
{ |
675 |
+ |
float xCenter=h1->GetBinCenter(i+1); |
676 |
+ |
float xWidth=(h1->GetBinWidth(i+1))*0.5; |
677 |
+ |
float nominatorError = h1->GetBinError(i+1); |
678 |
+ |
float nominator=h1->GetBinContent(i+1); |
679 |
+ |
float denominatorError=h2->GetBinError(i+1); |
680 |
+ |
float denominator=h2->GetBinContent(i+1); |
681 |
+ |
float errorN = 0; |
682 |
+ |
float errorP = computeRatioError(nominator,nominatorError,denominator,denominatorError); |
683 |
+ |
float syserr=sys->GetBinContent(i+1); |
684 |
+ |
float errorsys=0; |
685 |
+ |
if(id==1) // (is data) |
686 |
+ |
{ |
687 |
+ |
if(!precise) errorP = computeRatioError(nominator,statErrorP(nominator),denominator,statErrorP(denominator)); |
688 |
+ |
else errorP = computeRatioError(nominator,nominatorError,denominator,denominatorError); |
689 |
+ |
errorsys=computeRatioError(nominator,syserr,denominator,0); |
690 |
+ |
errorP = TMath::Sqrt(errorsys*errorsys+errorP*errorP); |
691 |
+ |
errorN = errorP; // symmetrize using statErrorP |
692 |
+ |
} else { |
693 |
+ |
errorN = computeRatioError(nominator,nominatorError,denominator,denominatorError); |
694 |
+ |
errorsys=computeRatioError(nominator,syserr,denominator,0); |
695 |
+ |
errorN = TMath::Sqrt(errorsys*errorsys+errorP*errorP); |
696 |
+ |
errorP = errorN; // symmetrize using statErrorP |
697 |
+ |
} |
698 |
+ |
if(denominator!=0) { |
699 |
+ |
graph->SetPoint(i, xCenter, nominator/denominator); |
700 |
+ |
graph->SetPointError(i,xWidth,xWidth,errorN,errorP); |
701 |
+ |
} |
702 |
+ |
else { |
703 |
+ |
graph->SetPoint(i, xCenter, -999); |
704 |
+ |
graph->SetPointError(i,xWidth,xWidth,errorN,errorP); |
705 |
+ |
} |
706 |
+ |
} |
707 |
+ |
return graph; |
708 |
+ |
} |
709 |
+ |
|
710 |
+ |
|
711 |
|
TGraphAsymmErrors *histRatio(TH1F *h1,TH1F *h2, int id, vector<float>binning, bool precise=false) |
712 |
|
{ |
713 |
|
int absJZBbinsNumber = binning.size()-1; |
1313 |
|
return prob; |
1314 |
|
} |
1315 |
|
|
1316 |
< |
void save_with_ratio(TH1F *nominator, TH1F *denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false, bool extendrange=false, string yaxistitle="ratio") { |
1316 |
> |
/*void save_with_difference(TH1F *obs, vector<TH1F*> predictions, vector<float> prediction_weights, vector<float> prediction_uncerts, TVirtualPad *canvas, string savemeas) { |
1317 |
> |
if(predictions.size()<1) { |
1318 |
> |
write_warning(__FUNCTION__,"Cannot make a pred-obs prediction plot because the prediction vector is empty. aborting!"); |
1319 |
> |
return; |
1320 |
> |
} |
1321 |
> |
TH1F *comppred = predictions[0]->Clone("comppred"); |
1322 |
> |
comppred->Scale(prediction_weights[0]); |
1323 |
> |
for(int i=1;i<predictions.size();i++) comppred->Add(predictions[i],prediction_weights[i]); |
1324 |
> |
|
1325 |
> |
TH1F *statpred = (TH1F*)comppred->Clone("statpred"); |
1326 |
> |
for(int i=1;i<=statpred->GetNbinsX();i++) statpred->SetBinContent(0); |
1327 |
> |
|
1328 |
> |
TH1F *syspred = predictions[0]; |
1329 |
> |
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)); |
1330 |
> |
for(int i=1;i<predictions.size();i++) { |
1331 |
> |
for(int ibin=1;ibin<=predictions[i]->GetNbinsX();ibin++) { |
1332 |
> |
float newentry=syspred->GetBinContent(ibin); |
1333 |
> |
newentry+=(predictions[i]->GetBinContent(ibin))*(predictions[i]->GetBinContent(ibin))*prediction_weights[i]*prediction_weights[i]*prediction_uncerts[i]*prediction_uncerts[i]; |
1334 |
> |
syspred->SetBinContent(ibin,newentry); |
1335 |
> |
} |
1336 |
> |
} |
1337 |
> |
for(int ibin=1;ibin<=syspred->GetNbinsX();ibin++) { |
1338 |
> |
syspred->SetBinError(ibin,syspred->GetBinContent(i)+statpred->GetBinError()); |
1339 |
> |
syspred->SetBinContent(ibin,0); |
1340 |
> |
} |
1341 |
> |
|
1342 |
> |
|
1343 |
> |
} |
1344 |
> |
*/ |
1345 |
> |
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) { |
1346 |
|
//this function saves the pad being passed as well as a new one including the ratio. |
1347 |
|
CompleteSave(canvas,savemeas); |
1348 |
|
|
1394 |
|
|
1395 |
|
|
1396 |
|
TGraphAsymmErrors *eratio; |
1397 |
+ |
TH1F *SystDown; |
1398 |
+ |
TH1F *SystUp; |
1399 |
+ |
|
1400 |
|
if(!do_bpred_ratio) eratio = produce_ratio_graph(ratio); |
1401 |
|
else { |
1402 |
|
bool using_data=false; |
1403 |
|
if((int)savemeas.find("Data")>0) using_data=true; |
1404 |
|
eratio = histRatio(nominator,denominator,using_data,PlottingSetup::global_ratio_binning,false); |
1405 |
+ |
if(syshisto!=0) { |
1406 |
+ |
SystDown = (TH1F*)syshisto->Clone("SystDown"); |
1407 |
+ |
SystUp = (TH1F*)syshisto->Clone("SystUp"); |
1408 |
+ |
for(int i=1;i<=syshisto->GetNbinsX();i++) { |
1409 |
+ |
SystDown->SetBinContent(i,1-syshisto->GetBinContent(i)); |
1410 |
+ |
SystUp->SetBinContent(i,1+syshisto->GetBinContent(i)); |
1411 |
+ |
} |
1412 |
+ |
SystDown->SetLineColor(TColor::GetColor("#006DE1")); |
1413 |
+ |
SystUp->SetLineColor(TColor::GetColor("#006DE1")); |
1414 |
+ |
} |
1415 |
|
for(int i=1;i<=ratio->GetNbinsX();i++) { |
1416 |
|
ratio->SetBinContent(i,0); |
1417 |
|
ratio->SetBinError(i,0); |
1418 |
|
} |
1419 |
+ |
|
1420 |
|
} |
1421 |
|
eratio->SetFillColor(TColor::GetColor("#00ADE1")); |
1422 |
+ |
|
1423 |
|
|
1424 |
|
ratio->SetTitle(""); |
1425 |
|
ratio->GetYaxis()->SetRangeUser(0.5,1.5); |
1439 |
|
ratio->SetFillColor(TColor::GetColor("#58D3F7")); |
1440 |
|
ratio->SetMarkerSize(0); |
1441 |
|
ratio->Draw("e2"); |
1442 |
< |
eratio->Draw("2"); |
1442 |
> |
if(syshisto!=0) { |
1443 |
> |
// sysratio->Draw("2"); |
1444 |
> |
// eratio->Draw("2,same"); |
1445 |
> |
eratio->Draw("2"); |
1446 |
> |
SystDown->Draw("histo,same"); |
1447 |
> |
SystUp->Draw("histo,same"); |
1448 |
> |
} else { |
1449 |
> |
eratio->Draw("2"); |
1450 |
> |
} |
1451 |
|
ratio->Draw("same,axis"); |
1452 |
|
TLine *oneline = new TLine(ratio->GetXaxis()->GetBinLowEdge(1),1,ratio->GetXaxis()->GetBinLowEdge(ratio->GetNbinsX())+ratio->GetXaxis()->GetBinWidth(ratio->GetNbinsX()),1); |
1453 |
|
oneline->SetLineStyle(2); |
1630 |
|
perror ("Couldn't open the directory"); |
1631 |
|
} |
1632 |
|
|
1633 |
< |
void ClearHisto(TH1F *histo) { |
1633 |
> |
void ClearHisto(TH1* histo) { |
1634 |
|
for(int ix=0;ix<=histo->GetNbinsX()+1;ix++) {//also reset over- and underflow |
1635 |
|
histo->SetBinContent(ix,0); |
1636 |
|
histo->SetBinContent(ix,0); |
1638 |
|
} |
1639 |
|
|
1640 |
|
void AddSquared(TH1F *histo, TH1F *addthis, float weight) { |
1641 |
< |
weight=1.0; |
1642 |
< |
for(int ix=0;ix<=histo->GetNbinsX()+1;ix++) {//also include over- and underflow |
1643 |
< |
histo->SetBinContent(ix,histo->GetBinContent(ix)+(addthis->GetBinContent(ix))*(addthis->GetBinContent(ix))*weight); |
1641 |
> |
for(int ix=1;ix<=addthis->GetNbinsX()+1;ix++) {//also include over- and underflow |
1642 |
> |
float bincenter=addthis->GetBinCenter(ix); |
1643 |
> |
int nBinHisto= histo->FindBin(bincenter); |
1644 |
> |
float old_content=histo->GetBinContent(nBinHisto); |
1645 |
> |
histo->SetBinContent(nBinHisto,old_content+((addthis->GetBinContent(ix))*(addthis->GetBinContent(ix))*weight)); |
1646 |
|
} |
1647 |
|
} |
1648 |
|
|
1649 |
< |
void SQRT(TH1F *histo) { |
1649 |
> |
void SQRT(TH1* histo) { |
1650 |
|
for(int ix=0;ix<=histo->GetNbinsX()+1;ix++) {//also include over- and underflow |
1651 |
|
histo->SetBinContent(ix,TMath::Sqrt(histo->GetBinContent(ix))); |
1652 |
|
} |