39 |
|
#include <TPaveText.h> |
40 |
|
#include <TRandom.h> |
41 |
|
#include <TGraphErrors.h> |
42 |
+ |
#include <TROOT.h> |
43 |
+ |
#include <TPolyLine.h> |
44 |
+ |
|
45 |
|
#ifndef Verbosity |
46 |
|
#define Verbosity 0 |
47 |
|
#endif |
64 |
|
int PaperMode=0; // PaperMode=true will suppress "Preliminary" in DrawPrelim() |
65 |
|
int Approved=0; // Approved=true will only plot approved plots |
66 |
|
bool is2012=true; |
67 |
+ |
bool is53reco=true; |
68 |
+ |
bool openBox = true; |
69 |
+ |
vector<TH1F*> FakeHistoHeap; |
70 |
+ |
|
71 |
|
} |
72 |
|
|
73 |
|
bool dopng=false; |
261 |
|
} |
262 |
|
} |
263 |
|
|
264 |
+ |
void DeleteStack(THStack mcstack) { |
265 |
+ |
TH1F* h; |
266 |
+ |
TIter nextHist(mcstack.GetHists()); |
267 |
+ |
while ( h = (TH1F*)nextHist() ) { |
268 |
+ |
h->Delete(); |
269 |
+ |
} |
270 |
+ |
delete h; |
271 |
+ |
} |
272 |
+ |
|
273 |
+ |
|
274 |
+ |
void DeadEnd(string message) { |
275 |
+ |
dout << endl; |
276 |
+ |
dout << "\033[1;31m _ _ _ " << endl; |
277 |
+ |
dout << "\033[1;31m __| | ___ __ _ __| | ___ _ __ __| | " << endl; |
278 |
+ |
dout << "\033[1;31m / _` |/ _ \\/ _` |/ _` | / _ \\ '_ \\ / _` | " << endl; |
279 |
+ |
dout << "\033[1;31m| (_| | __/ (_| | (_| | | __/ | | | (_| | " << endl; |
280 |
+ |
dout << "\033[1;31m \\__,_|\\___|\\__,_|\\__,_| \\___|_| |_|\\__,_| " << endl; |
281 |
+ |
dout << "\033[1;31m " << endl; |
282 |
+ |
dout << "" << endl; |
283 |
+ |
dout << " A totally fatal error has occurred: " << endl; |
284 |
+ |
dout << " " << message << endl; |
285 |
+ |
dout << endl; |
286 |
+ |
dout << "If you do not know how to deal with this error message please call Customer Support Mumbai (or Zurich...) \033[0m" << endl; |
287 |
+ |
dout << " ... aborting now ... " << endl; |
288 |
+ |
assert(0); |
289 |
+ |
} |
290 |
+ |
|
291 |
+ |
|
292 |
+ |
void SanityChecks() { |
293 |
+ |
//this function gets called whenever samples are initialized (see ActiveSamples.C) |
294 |
+ |
//whatever is necessary for the code to run should be put here. |
295 |
+ |
|
296 |
+ |
if(gROOT->GetVersionInt()<53200) { |
297 |
+ |
DeadEnd("ROOT version outdated, you are using "+any2string(gROOT->GetVersionInt())+" but the earliest recommended version is 5.32.00"); |
298 |
+ |
} |
299 |
+ |
|
300 |
+ |
|
301 |
+ |
} |
302 |
+ |
|
303 |
|
void initialize_log() { |
304 |
|
if(!PlottingSetup::publicmode) { |
305 |
|
dout << "____________________________________________________________" << endl; |
439 |
|
|
440 |
|
|
441 |
|
void setlumi(float l) { |
442 |
< |
generaltoolboxlumi=l; |
442 |
> |
generaltoolboxlumi=l; |
443 |
|
} |
444 |
|
|
445 |
|
int write_first_line(vector<vector<string> > &entries) { |
597 |
|
string prel=" Preliminary"; |
598 |
|
if(PlottingSetup::PaperMode) prel=""; |
599 |
|
//prelimtext << "CMS Preliminary 2011 , #sqrt{s}= 7 TeV, L= O(1) fb^{-1}"; //temporary replacement |
600 |
+ |
if(PlottingSetup::is53reco) prel += " 53X"; |
601 |
|
string energy="7 TeV"; |
602 |
|
if(PlottingSetup::is2012) energy="8 TeV"; |
603 |
|
if(writelumi == 0) { |
683 |
|
return val; |
684 |
|
} |
685 |
|
|
686 |
+ |
TGraphAsymmErrors *SysAndStatRatio(TH1F *h1,TH1F *h2, TH1F *sys, int id, vector<float>binning, bool precise=false) { |
687 |
+ |
int absJZBbinsNumber = binning.size()-1; |
688 |
+ |
TGraphAsymmErrors* graph = new TGraphAsymmErrors(absJZBbinsNumber); |
689 |
+ |
for(int i=0;i<absJZBbinsNumber;i++) |
690 |
+ |
{ |
691 |
+ |
float xCenter=h1->GetBinCenter(i+1); |
692 |
+ |
float xWidth=(h1->GetBinWidth(i+1))*0.5; |
693 |
+ |
float nominatorError = h1->GetBinError(i+1); |
694 |
+ |
float nominator=h1->GetBinContent(i+1); |
695 |
+ |
float denominatorError=h2->GetBinError(i+1); |
696 |
+ |
float denominator=h2->GetBinContent(i+1); |
697 |
+ |
float errorN = 0; |
698 |
+ |
float errorP = computeRatioError(nominator,nominatorError,denominator,denominatorError); |
699 |
+ |
float syserr=sys->GetBinContent(i+1); |
700 |
+ |
float errorsys=0; |
701 |
+ |
if(id==1) // (is data) |
702 |
+ |
{ |
703 |
+ |
if(!precise) errorP = computeRatioError(nominator,statErrorP(nominator),denominator,statErrorP(denominator)); |
704 |
+ |
else errorP = computeRatioError(nominator,nominatorError,denominator,denominatorError); |
705 |
+ |
errorsys=computeRatioError(nominator,syserr,denominator,0); |
706 |
+ |
errorP = TMath::Sqrt(errorsys*errorsys+errorP*errorP); |
707 |
+ |
errorN = errorP; // symmetrize using statErrorP |
708 |
+ |
} else { |
709 |
+ |
errorN = computeRatioError(nominator,nominatorError,denominator,denominatorError); |
710 |
+ |
errorsys=computeRatioError(nominator,syserr,denominator,0); |
711 |
+ |
errorN = TMath::Sqrt(errorsys*errorsys+errorP*errorP); |
712 |
+ |
errorP = errorN; // symmetrize using statErrorP |
713 |
+ |
} |
714 |
+ |
if(denominator!=0) { |
715 |
+ |
graph->SetPoint(i, xCenter, nominator/denominator); |
716 |
+ |
graph->SetPointError(i,xWidth,xWidth,errorN,errorP); |
717 |
+ |
} |
718 |
+ |
else { |
719 |
+ |
graph->SetPoint(i, xCenter, -999); |
720 |
+ |
graph->SetPointError(i,xWidth,xWidth,errorN,errorP); |
721 |
+ |
} |
722 |
+ |
} |
723 |
+ |
return graph; |
724 |
+ |
} |
725 |
+ |
|
726 |
+ |
|
727 |
|
TGraphAsymmErrors *histRatio(TH1F *h1,TH1F *h2, int id, vector<float>binning, bool precise=false) |
728 |
|
{ |
729 |
|
int absJZBbinsNumber = binning.size()-1; |
960 |
|
|
961 |
|
if(incut=="id1==0") return "ee"; |
962 |
|
if(incut=="id1==1") return "#mu#mu"; |
963 |
< |
if(incut=="abs(mll-91.2)<20") return "|m_{l^{+}l^{-}}-m_{Z}|<20"; |
963 |
> |
if(incut=="abs(mll-91)<10") return "|m_{l^{+}l^{-}}-m_{Z}|<10"; |
964 |
|
if(incut=="pfJetGoodID[0]") return ""; |
965 |
|
if(incut=="pfJetGoodID[1]") return ""; |
966 |
|
if((int)incut.find("pfJetGoodNum")>-1) { |
1236 |
|
else return false; |
1237 |
|
} |
1238 |
|
|
1239 |
+ |
|
1240 |
|
////////////////////////////////////////////////////////////////////////////// |
1241 |
|
// |
1242 |
|
// http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c |
1249 |
|
/* usage: |
1250 |
|
double vm2, rss2; |
1251 |
|
process_mem_usage(vm2, rss2); |
1252 |
< |
cout << "Memory usage: VM: " << vm << "; RSS: " << rss << endl; |
1252 |
> |
cout << "Memory usage: VM: " << vm2 << "; RSS: " << rss2 << endl; |
1253 |
|
*/ |
1254 |
|
|
1255 |
|
void process_mem_usage(double& vm_usage, double& resident_set) |
1308 |
|
} |
1309 |
|
|
1310 |
|
|
1311 |
+ |
TText* WriteSelection(int njets) { |
1312 |
+ |
string sel="Loose selection"; |
1313 |
+ |
if(njets==3) sel="Tight selection"; |
1314 |
+ |
assert(njets==2||njets==3); |
1315 |
+ |
TText *sele = new TText(0.97,0.135,sel.c_str()); |
1316 |
+ |
sele->SetNDC(true); |
1317 |
+ |
sele->SetTextColor(TColor::GetColor("#848484")); |
1318 |
+ |
sele->SetTextFont(42); |
1319 |
+ |
sele->SetTextAlign(32); |
1320 |
+ |
sele->SetTextSize(0.03); |
1321 |
+ |
sele->SetTextAngle(270); |
1322 |
+ |
return sele; |
1323 |
+ |
} |
1324 |
+ |
|
1325 |
|
Double_t MarcosChi2TestX(const TH1* h1, const TH1* h2, Double_t &chi2, Int_t &ndf, Int_t &igood, Option_t *option) |
1326 |
|
{ |
1327 |
|
|
1344 |
|
return prob; |
1345 |
|
} |
1346 |
|
|
1347 |
< |
void save_with_ratio(TH1F *nominator, TH1F *denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false, bool extendrange=false, string yaxistitle="ratio") { |
1347 |
> |
void Save_With_Ratio(TH1F *nominator, TH1F *denominator, TVirtualPad *orig_canvas, string savemeas, bool do_bpred_ratio=false, bool extendrange=false, string yaxistitle="ratio",TH1F *syshisto=NULL) { |
1348 |
|
//this function saves the pad being passed as well as a new one including the ratio. |
1349 |
< |
CompleteSave(canvas,savemeas); |
1350 |
< |
|
1349 |
> |
|
1350 |
> |
orig_canvas->cd(); |
1351 |
> |
orig_canvas->Update(); |
1352 |
> |
CompleteSave(orig_canvas,savemeas); |
1353 |
> |
TVirtualPad *canvas = (TVirtualPad*) orig_canvas->Clone("TempCanvas");//otherwise the Ratio_main_canvas will own our pad and destroy it upon deletion |
1354 |
> |
|
1355 |
|
float bottommargin=gStyle->GetPadBottomMargin(); |
1356 |
|
float canvas_height=gStyle->GetCanvasDefH(); |
1357 |
|
float canvas_width=gStyle->GetCanvasDefW(); |
1362 |
|
|
1363 |
|
float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace); |
1364 |
|
|
1365 |
< |
TCanvas *main_canvas = new TCanvas("main_canvas","main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace))); |
1365 |
> |
TCanvas *Ratio_main_canvas = new TCanvas("Ratio_main_canvas","Ratio_main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace))); |
1366 |
|
TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad |
1367 |
|
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 |
1368 |
|
TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad |
1369 |
|
|
1370 |
< |
main_canvas->Range(0,0,1,1); |
1371 |
< |
main_canvas->SetBorderSize(0); |
1372 |
< |
main_canvas->SetFrameFillColor(0); |
1370 |
> |
Ratio_main_canvas->Range(0,0,1,1); |
1371 |
> |
Ratio_main_canvas->SetBorderSize(0); |
1372 |
> |
Ratio_main_canvas->SetFrameFillColor(0); |
1373 |
|
|
1374 |
|
mainpad->Draw(); |
1375 |
|
mainpad->cd(); |
1380 |
|
canvas->Range(0,0,1,1); |
1381 |
|
canvas->Draw("same"); |
1382 |
|
mainpad->Modified(); |
1383 |
< |
main_canvas->cd(); |
1383 |
> |
Ratio_main_canvas->cd(); |
1384 |
|
coverpad->Draw(); |
1385 |
|
coverpad->cd(); |
1386 |
|
coverpad->Range(0,0,1,1); |
1388 |
|
coverpad->SetBorderSize(0); |
1389 |
|
coverpad->SetFrameFillColor(0); |
1390 |
|
coverpad->Modified(); |
1391 |
< |
main_canvas->cd(); |
1391 |
> |
Ratio_main_canvas->cd(); |
1392 |
|
bottompad->SetTopMargin(ratiotopmargin); |
1393 |
|
bottompad->SetBottomMargin(ratiobottommargin); |
1394 |
|
bottompad->Draw(); |
1398 |
|
TH1F *ratio = (TH1F*)nominator->Clone(GetNumericHistoName().c_str()); |
1399 |
|
ratio->Divide(denominator); |
1400 |
|
|
1294 |
– |
|
1401 |
|
TGraphAsymmErrors *eratio; |
1402 |
+ |
TH1F *SystDown; |
1403 |
+ |
TH1F *SystUp; |
1404 |
+ |
|
1405 |
|
if(!do_bpred_ratio) eratio = produce_ratio_graph(ratio); |
1406 |
|
else { |
1407 |
|
bool using_data=false; |
1408 |
|
if((int)savemeas.find("Data")>0) using_data=true; |
1409 |
|
eratio = histRatio(nominator,denominator,using_data,PlottingSetup::global_ratio_binning,false); |
1410 |
+ |
if(syshisto!=0) { |
1411 |
+ |
SystDown = (TH1F*)syshisto->Clone("SystDown"); |
1412 |
+ |
SystUp = (TH1F*)syshisto->Clone("SystUp"); |
1413 |
+ |
for(int i=1;i<=syshisto->GetNbinsX();i++) { |
1414 |
+ |
SystDown->SetBinContent(i,1-syshisto->GetBinContent(i)); |
1415 |
+ |
SystUp->SetBinContent(i,1+syshisto->GetBinContent(i)); |
1416 |
+ |
} |
1417 |
+ |
SystDown->SetLineColor(TColor::GetColor("#006DE1")); |
1418 |
+ |
SystUp->SetLineColor(TColor::GetColor("#006DE1")); |
1419 |
+ |
} |
1420 |
|
for(int i=1;i<=ratio->GetNbinsX();i++) { |
1421 |
|
ratio->SetBinContent(i,0); |
1422 |
|
ratio->SetBinError(i,0); |
1423 |
|
} |
1424 |
+ |
|
1425 |
+ |
} |
1426 |
+ |
|
1427 |
+ |
if(syshisto && !do_bpred_ratio) { |
1428 |
+ |
SystDown = (TH1F*)syshisto->Clone("SystDown"); |
1429 |
+ |
SystUp = (TH1F*)syshisto->Clone("SystUp"); |
1430 |
+ |
for(int i=1;i<=syshisto->GetNbinsX();i++) { |
1431 |
+ |
SystDown->SetBinContent(i,1-syshisto->GetBinContent(i)); |
1432 |
+ |
SystUp->SetBinContent(i,1+syshisto->GetBinContent(i)); |
1433 |
+ |
} |
1434 |
+ |
SystDown->SetLineColor(TColor::GetColor("#006DE1")); |
1435 |
+ |
SystUp->SetLineColor(TColor::GetColor("#006DE1")); |
1436 |
|
} |
1437 |
|
eratio->SetFillColor(TColor::GetColor("#00ADE1")); |
1438 |
|
|
1439 |
|
ratio->SetTitle(""); |
1440 |
< |
ratio->GetYaxis()->SetRangeUser(0.5,1.5); |
1440 |
> |
ratio->GetYaxis()->SetRangeUser(0.0,2.0); |
1441 |
|
if(do_bpred_ratio) ratio->GetYaxis()->SetRangeUser(0.0,2.0); |
1442 |
|
if(extendrange) ratio->GetYaxis()->SetRangeUser(0.0,4.0); |
1443 |
|
ratio->GetXaxis()->SetTitle(nominator->GetXaxis()->GetTitle()); |
1454 |
|
ratio->SetFillColor(TColor::GetColor("#58D3F7")); |
1455 |
|
ratio->SetMarkerSize(0); |
1456 |
|
ratio->Draw("e2"); |
1457 |
< |
eratio->Draw("2"); |
1457 |
> |
|
1458 |
> |
TGraphAsymmErrors *ratio_center = (TGraphAsymmErrors*)eratio->Clone("ratio_center"); |
1459 |
> |
for(int i=0;i<ratio_center->GetN();i++) { |
1460 |
> |
ratio_center->SetPointError(i,ratio_center->GetErrorXlow(i),ratio_center->GetErrorXhigh(i),0.005,0.005); |
1461 |
> |
} |
1462 |
> |
|
1463 |
> |
ratio_center->SetFillColor(TColor::GetColor("#006381")); |
1464 |
> |
|
1465 |
> |
if(syshisto!=0) { |
1466 |
> |
// sysratio->Draw("2"); |
1467 |
> |
// eratio->Draw("2,same"); |
1468 |
> |
eratio->Draw("2"); |
1469 |
> |
SystDown->Draw("histo,same"); |
1470 |
> |
SystUp->Draw("histo,same"); |
1471 |
> |
} else { |
1472 |
> |
eratio->Draw("2"); |
1473 |
> |
} |
1474 |
> |
ratio_center->Draw("2"); |
1475 |
|
ratio->Draw("same,axis"); |
1476 |
|
TLine *oneline = new TLine(ratio->GetXaxis()->GetBinLowEdge(1),1,ratio->GetXaxis()->GetBinLowEdge(ratio->GetNbinsX())+ratio->GetXaxis()->GetBinWidth(ratio->GetNbinsX()),1); |
1477 |
|
oneline->SetLineStyle(2); |
1478 |
|
oneline->SetLineColor(kBlue); |
1479 |
|
oneline->Draw("same"); |
1480 |
|
|
1481 |
< |
main_canvas->cd(); |
1482 |
< |
main_canvas->Modified(); |
1483 |
< |
main_canvas->cd(); |
1484 |
< |
main_canvas->SetSelected(main_canvas); |
1481 |
> |
Ratio_main_canvas->cd(); |
1482 |
> |
Ratio_main_canvas->Modified(); |
1483 |
> |
Ratio_main_canvas->cd(); |
1484 |
> |
Ratio_main_canvas->SetSelected(Ratio_main_canvas); |
1485 |
|
|
1486 |
< |
CompleteSave(main_canvas,savemeas+"_withratio"); |
1486 |
> |
CompleteSave(Ratio_main_canvas,savemeas+"_withratio"); |
1487 |
|
bottompad->cd(); |
1488 |
|
|
1489 |
|
Double_t chi2; |
1511 |
|
CompleteRatio->SetTextAlign(31); |
1512 |
|
CompleteRatio->Draw(); |
1513 |
|
|
1514 |
< |
CompleteSave(main_canvas,savemeas+"_withratio_and_Chi2"); |
1514 |
> |
CompleteSave(Ratio_main_canvas,savemeas+"_withratio_and_Chi2"); |
1515 |
|
|
1516 |
|
// float KS = nominator->KolmogorovTest(denominator); |
1517 |
|
// stringstream KStext; |
1518 |
|
// Chi2text << "KS = " << KS << endl; |
1519 |
|
//cout << "Found : " << KStext.str() << endl; |
1520 |
|
|
1521 |
< |
|
1522 |
< |
delete main_canvas; |
1521 |
> |
delete eratio; |
1522 |
> |
delete ratio_center; |
1523 |
> |
delete ratio; |
1524 |
> |
delete Ratio_main_canvas; |
1525 |
|
} |
1526 |
|
|
1527 |
+ |
void save_with_ratio_and_sys_band(TH1F *nominator, TH1F *denominator, TVirtualPad *orig_canvas, string savemeas, bool do_bpred_ratio=false, bool extendrange=false, string yaxistitle="ratio",TH1F *syshisto=NULL) { |
1528 |
+ |
//this function saves the pad being passed as well as a new one including the SysRatio. |
1529 |
+ |
orig_canvas->cd(); |
1530 |
+ |
orig_canvas->Update(); |
1531 |
+ |
CompleteSave(orig_canvas,savemeas); |
1532 |
+ |
|
1533 |
+ |
TVirtualPad *canvas = (TVirtualPad*) orig_canvas->Clone("TempCanvas");//otherwise the Ratio_main_canvas will own our pad and destroy it upon deletion |
1534 |
+ |
|
1535 |
+ |
float bottommargin=gStyle->GetPadBottomMargin(); |
1536 |
+ |
float canvas_height=gStyle->GetCanvasDefH(); |
1537 |
+ |
float canvas_width=gStyle->GetCanvasDefW(); |
1538 |
+ |
float ratiospace=0.25;// space the ratio should take up (relative to original pad) |
1539 |
+ |
|
1540 |
+ |
float ratiobottommargin=0.3; |
1541 |
+ |
float ratiotopmargin=0.1; |
1542 |
+ |
|
1543 |
+ |
float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace); |
1544 |
+ |
|
1545 |
+ |
TCanvas *Ratio_main_canvas = new TCanvas("Ratio_main_canvas","Ratio_main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace))); |
1546 |
+ |
TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad |
1547 |
+ |
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 |
1548 |
+ |
TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad |
1549 |
+ |
|
1550 |
+ |
Ratio_main_canvas->Range(0,0,1,1); |
1551 |
+ |
Ratio_main_canvas->SetBorderSize(0); |
1552 |
+ |
Ratio_main_canvas->SetFrameFillColor(0); |
1553 |
+ |
|
1554 |
+ |
mainpad->Draw(); |
1555 |
+ |
mainpad->cd(); |
1556 |
+ |
mainpad->Range(0,0,1,1); |
1557 |
+ |
mainpad->SetFillColor(kWhite); |
1558 |
+ |
mainpad->SetBorderSize(0); |
1559 |
+ |
mainpad->SetFrameFillColor(0); |
1560 |
+ |
canvas->Range(0,0,1,1); |
1561 |
+ |
canvas->Draw("same"); |
1562 |
+ |
mainpad->Modified(); |
1563 |
+ |
Ratio_main_canvas->cd(); |
1564 |
+ |
coverpad->Draw(); |
1565 |
+ |
coverpad->cd(); |
1566 |
+ |
coverpad->Range(0,0,1,1); |
1567 |
+ |
coverpad->SetFillColor(kWhite); |
1568 |
+ |
coverpad->SetBorderSize(0); |
1569 |
+ |
coverpad->SetFrameFillColor(0); |
1570 |
+ |
coverpad->Modified(); |
1571 |
+ |
Ratio_main_canvas->cd(); |
1572 |
+ |
bottompad->SetTopMargin(ratiotopmargin); |
1573 |
+ |
bottompad->SetBottomMargin(ratiobottommargin); |
1574 |
+ |
bottompad->Draw(); |
1575 |
+ |
bottompad->cd(); |
1576 |
+ |
bottompad->Range(0,0,1,1); |
1577 |
+ |
bottompad->SetFillColor(kWhite); |
1578 |
+ |
TH1F *ratio = (TH1F*)nominator->Clone(GetNumericHistoName().c_str()); |
1579 |
+ |
ratio->Divide(denominator); |
1580 |
+ |
|
1581 |
+ |
|
1582 |
+ |
TGraphAsymmErrors *eratio; |
1583 |
+ |
TGraphAsymmErrors *SysEnvelope = new TGraphAsymmErrors(); |
1584 |
+ |
|
1585 |
+ |
if(syshisto && !do_bpred_ratio) { |
1586 |
+ |
for(int i=1;i<=syshisto->GetNbinsX();i++) { |
1587 |
+ |
float dx=syshisto->GetBinWidth(i)/2.0; |
1588 |
+ |
float dy=syshisto->GetBinContent(i); |
1589 |
+ |
if(dy<0.01) dy=0.07; |
1590 |
+ |
SysEnvelope->SetPoint(i-1,syshisto->GetBinCenter(i),1.0); |
1591 |
+ |
SysEnvelope->SetPointError(i-1,dx,dx,dy,dy); |
1592 |
+ |
} |
1593 |
+ |
SysEnvelope->SetFillColor(TColor::GetColor("#006DE1")); |
1594 |
+ |
} |
1595 |
+ |
|
1596 |
+ |
ratio->SetTitle(""); |
1597 |
+ |
ratio->GetYaxis()->SetRangeUser(0.0,2.0); |
1598 |
+ |
if(do_bpred_ratio) ratio->GetYaxis()->SetRangeUser(0.0,2.0); |
1599 |
+ |
if(extendrange) ratio->GetYaxis()->SetRangeUser(0.0,4.0); |
1600 |
+ |
ratio->GetXaxis()->SetTitle(nominator->GetXaxis()->GetTitle()); |
1601 |
+ |
ratio->GetXaxis()->CenterTitle(); |
1602 |
+ |
ratio->GetYaxis()->SetTitle(yaxistitle.c_str()); |
1603 |
+ |
ratio->GetYaxis()->SetTitleOffset(0.4); |
1604 |
+ |
ratio->GetYaxis()->CenterTitle(); |
1605 |
+ |
ratio->SetStats(0); |
1606 |
+ |
ratio->GetXaxis()->SetLabelSize(xstretchfactor*ratio->GetXaxis()->GetLabelSize()); |
1607 |
+ |
ratio->GetYaxis()->SetLabelSize(xstretchfactor*ratio->GetYaxis()->GetLabelSize()); |
1608 |
+ |
ratio->GetXaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize()); |
1609 |
+ |
ratio->GetYaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize()); |
1610 |
+ |
ratio->GetYaxis()->SetNdivisions(502,false); |
1611 |
+ |
ratio->SetFillColor(TColor::GetColor("#58D3F7")); |
1612 |
+ |
ratio->Draw("e1"); |
1613 |
+ |
|
1614 |
+ |
if(syshisto!=0) { |
1615 |
+ |
SysEnvelope->SetFillColor(TColor::GetColor("#FE9A2E")); |
1616 |
+ |
SysEnvelope->Draw("2,same"); |
1617 |
+ |
ratio->Draw("e1,same"); |
1618 |
+ |
} else { |
1619 |
+ |
eratio->Draw("1"); |
1620 |
+ |
} |
1621 |
+ |
ratio->Draw("same,axis"); |
1622 |
+ |
TLine *oneline = new TLine(ratio->GetXaxis()->GetBinLowEdge(1),1,ratio->GetXaxis()->GetBinLowEdge(ratio->GetNbinsX())+ratio->GetXaxis()->GetBinWidth(ratio->GetNbinsX()),1); |
1623 |
+ |
oneline->SetLineStyle(2); |
1624 |
+ |
oneline->SetLineColor(kBlue); |
1625 |
+ |
oneline->Draw("same"); |
1626 |
+ |
|
1627 |
+ |
Ratio_main_canvas->cd(); |
1628 |
+ |
Ratio_main_canvas->Modified(); |
1629 |
+ |
Ratio_main_canvas->cd(); |
1630 |
+ |
Ratio_main_canvas->SetSelected(Ratio_main_canvas); |
1631 |
+ |
|
1632 |
+ |
CompleteSave(Ratio_main_canvas,savemeas+"_withSysRatio"); |
1633 |
+ |
bottompad->cd(); |
1634 |
+ |
|
1635 |
+ |
Double_t chi2; |
1636 |
+ |
Int_t ndf,igood; |
1637 |
+ |
Double_t chi2prob = MarcosChi2TestX(nominator,denominator,chi2,ndf,igood,"UW"); |
1638 |
+ |
|
1639 |
+ |
stringstream Chi2text; |
1640 |
+ |
Chi2text << "#chi^{2} / ndf: " << chi2 << " / " << ndf; |
1641 |
+ |
stringstream Chi2probtext; |
1642 |
+ |
Chi2probtext << "#chi^{2} prob: " << chi2prob; |
1643 |
+ |
TText* chi2box = write_text(0.02,0.11,Chi2text.str()); |
1644 |
+ |
chi2box->SetTextSize(0.08); |
1645 |
+ |
chi2box->SetTextAlign(11); |
1646 |
+ |
chi2box->Draw(); |
1647 |
+ |
TText* chi2probbox = write_text(0.02,0.04,Chi2probtext.str()); |
1648 |
+ |
chi2probbox->SetTextSize(0.08); |
1649 |
+ |
chi2probbox->SetTextAlign(11); |
1650 |
+ |
chi2probbox->Draw(); |
1651 |
+ |
|
1652 |
+ |
stringstream CompRatio; |
1653 |
+ |
CompRatio << "Ratio: " << nominator->Integral() << " / " << denominator->Integral() << " \n " << nominator->Integral()/denominator->Integral(); |
1654 |
+ |
TText *CompleteRatio = write_text(0.98,0.04,CompRatio.str()); |
1655 |
+ |
CompleteRatio->SetTextSize(0.08); |
1656 |
+ |
CompleteRatio->SetTextAlign(31); |
1657 |
+ |
CompleteRatio->Draw(); |
1658 |
+ |
|
1659 |
+ |
CompleteSave(Ratio_main_canvas,savemeas+"_withSysRatio_and_Chi2"); |
1660 |
+ |
delete Ratio_main_canvas; |
1661 |
+ |
delete ratio; |
1662 |
+ |
} |
1663 |
|
|
1664 |
< |
TH1F* CollapseStack(THStack stack) { |
1664 |
> |
TH1F* CollapseStack(THStack stack,TString hname="CollapsedStack") { |
1665 |
|
TH1F *bhist = ((TH1F*)((stack.GetHists())->At(0))); |
1666 |
< |
TH1F *basehisto = (TH1F*)bhist->Clone("base"); |
1666 |
> |
TH1F *basehisto = (TH1F*)bhist->Clone(hname); |
1667 |
|
TIter next(stack.GetHists()); |
1668 |
|
TH1F *h; |
1669 |
|
int counter=0; |
1675 |
|
return basehisto; |
1676 |
|
} |
1677 |
|
|
1678 |
< |
void save_with_ratio(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) { |
1679 |
< |
save_with_ratio(nominator, CollapseStack(denominator), canvas, savemeas, do_bpred_ratio); |
1678 |
> |
void Save_With_Ratio(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) { |
1679 |
> |
TH1F *denominator_histo = (TH1F*) CollapseStack(denominator); |
1680 |
> |
Save_With_Ratio(nominator, denominator_histo, canvas, savemeas, do_bpred_ratio); |
1681 |
> |
delete denominator_histo; |
1682 |
|
} |
1683 |
|
|
1684 |
|
void flag_this_change(string function, int line, int checked=0) { |
1794 |
|
perror ("Couldn't open the directory"); |
1795 |
|
} |
1796 |
|
|
1797 |
+ |
void ClearHisto(TH1* histo) { |
1798 |
+ |
for(int ix=0;ix<=histo->GetNbinsX()+1;ix++) {//also reset over- and underflow |
1799 |
+ |
histo->SetBinContent(ix,0); |
1800 |
+ |
histo->SetBinContent(ix,0); |
1801 |
+ |
} |
1802 |
+ |
} |
1803 |
+ |
|
1804 |
+ |
void AddSquared(TH1F *histo, TH1F *addthis, float weight) { |
1805 |
+ |
for(int ix=1;ix<=addthis->GetNbinsX()+1;ix++) {//also include over- and underflow |
1806 |
+ |
float bincenter=addthis->GetBinCenter(ix); |
1807 |
+ |
int nBinHisto= histo->FindBin(bincenter); |
1808 |
+ |
float old_content=histo->GetBinContent(nBinHisto); |
1809 |
+ |
histo->SetBinContent(nBinHisto,old_content+((addthis->GetBinContent(ix))*(addthis->GetBinContent(ix))*weight)); |
1810 |
+ |
} |
1811 |
+ |
} |
1812 |
+ |
|
1813 |
+ |
void SQRT(TH1* histo) { |
1814 |
+ |
for(int ix=0;ix<=histo->GetNbinsX()+1;ix++) {//also include over- and underflow |
1815 |
+ |
histo->SetBinContent(ix,TMath::Sqrt(histo->GetBinContent(ix))); |
1816 |
+ |
} |
1817 |
+ |
} |
1818 |
+ |
|
1819 |
|
/*string GetCompleteHostname() { |
1820 |
|
struct addrinfo hints, *info, *p; |
1821 |
|
int gai_result; |
1863 |
|
name=ReplaceCharacter(name,"]","_"); |
1864 |
|
name=ReplaceCharacter(name,"{","_"); |
1865 |
|
name=ReplaceCharacter(name,"}","_"); |
1866 |
+ |
name=ReplaceCharacter(name,"(","_"); |
1867 |
+ |
name=ReplaceCharacter(name,")","_"); |
1868 |
+ |
name=ReplaceCharacter(name," ","_"); |
1869 |
|
name=ReplaceCharacter(name,".","_"); |
1870 |
|
name=ReplaceCharacter(name,",","_"); |
1871 |
|
name=ReplaceCharacter(name,";","_"); |
1880 |
|
return name; |
1881 |
|
} |
1882 |
|
|
1883 |
+ |
TPolyLine* GetFitUncertaintyShape(TF1 *fit, float low, float high,float x0,float x1) { |
1884 |
+ |
int nPoints=1000; |
1885 |
+ |
double x[nPoints+1]; |
1886 |
+ |
double y[nPoints]; |
1887 |
+ |
|
1888 |
+ |
float par1=fit->GetParameter(0); |
1889 |
+ |
float dpar1=fit->GetParError(0); |
1890 |
+ |
float par2=fit->GetParameter(1); |
1891 |
+ |
float dpar2=fit->GetParError(1); |
1892 |
+ |
|
1893 |
+ |
float step=(x1-x0)/(nPoints/2.0 -1); |
1894 |
+ |
for(int i=0;i<nPoints/2.0;i++) { |
1895 |
+ |
x[i]=x0+i*step; |
1896 |
+ |
y[i]=(par1+x[i]*par2) - sqrt(dpar1*dpar1+dpar2*dpar2*x[i]*x[i]); |
1897 |
+ |
x[nPoints-1-i]=x[i]; |
1898 |
+ |
y[nPoints-1-i]=(par1+x[i]*par2) + sqrt(dpar1*dpar1+dpar2*dpar2*x[i]*x[i]); |
1899 |
+ |
if(y[i]<low) y[i]=low; |
1900 |
+ |
if(y[i]>high) y[i]=high; |
1901 |
+ |
if(y[nPoints-1-i]<low) y[nPoints-1-i]=low; |
1902 |
+ |
if(y[nPoints-1-i]>high) y[nPoints-1-i]=high; |
1903 |
+ |
} |
1904 |
+ |
|
1905 |
+ |
x[nPoints]=x[0]; |
1906 |
+ |
y[nPoints]=y[0]; |
1907 |
+ |
|
1908 |
+ |
TPolyLine *l = new TPolyLine(nPoints+1,x,y); |
1909 |
+ |
l->SetFillColor(TColor::GetColor("#5858FA")); |
1910 |
+ |
l->SetLineColor(TColor::GetColor("#5858FA")); |
1911 |
+ |
l->SetLineWidth(1); |
1912 |
+ |
return l; |
1913 |
+ |
} |
1914 |
+ |
|
1915 |
+ |
//code for ReplaceAll copied from |
1916 |
+ |
//http://stackoverflow.com/questions/5343190/c-how-do-i-replace-all-instances-of-of-a-string-with-another-string |
1917 |
+ |
string ReplaceAll(string str, string from, string to) { |
1918 |
+ |
size_t start_pos = 0; |
1919 |
+ |
while((start_pos = str.find(from, start_pos)) != std::string::npos) { |
1920 |
+ |
str.replace(start_pos, from.length(), to); |
1921 |
+ |
start_pos += to.length(); // ... |
1922 |
+ |
} |
1923 |
+ |
return str; |
1924 |
+ |
} |
1925 |
+ |
|
1926 |
+ |
TPolyLine* GetFitUncertaintyShape(TH1 *histo, string fitname, float low, float high) { |
1927 |
+ |
TF1 *fit = (TF1*)histo->GetFunction(fitname.c_str()); |
1928 |
+ |
if(!fit) { |
1929 |
+ |
cout << "CANNOT PRODUCE FIT UNCERTAINTY AS THERE IS NO FIT CALLED " << fitname << " IN " << histo->GetName() << endl; |
1930 |
+ |
return NULL; |
1931 |
+ |
} |
1932 |
+ |
float x0=histo->GetBinLowEdge(1); |
1933 |
+ |
float x1=histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()); |
1934 |
+ |
return GetFitUncertaintyShape(fit, low, high,x0,x1); |
1935 |
+ |
} |
1936 |
+ |
|
1937 |
+ |
TPolyLine* GetFitUncertaintyShape(TGraphErrors *gr, string fitname, float low, float high, float minx=-999, float maxx=-999) { |
1938 |
+ |
TF1 *fit = (TF1*)gr->GetFunction(fitname.c_str()); |
1939 |
+ |
if(!fit) { |
1940 |
+ |
cout << "CANNOT PRODUCE FIT UNCERTAINTY AS THERE IS NO FIT CALLED " << fitname << " IN " << gr->GetName() << endl; |
1941 |
+ |
return NULL; |
1942 |
+ |
} |
1943 |
+ |
double x,y; |
1944 |
+ |
gr->GetPoint(0,x,y); |
1945 |
+ |
float min=x; |
1946 |
+ |
gr->GetPoint(gr->GetN()-1,x,y); |
1947 |
+ |
float max=x; |
1948 |
+ |
if(minx>-999 && maxx>-999 && minx<maxx) { |
1949 |
+ |
max=maxx; |
1950 |
+ |
min=minx; |
1951 |
+ |
} |
1952 |
+ |
return GetFitUncertaintyShape(fit, low, high,min,max); |
1953 |
+ |
} |
1954 |
+ |
|
1955 |
|
stringstream all_bugs; |
1956 |
|
|
1957 |
|
void bug_tracker(string function, int line, string description) { |
1989 |
|
//TODO: Write a bug summary at the end. |
1990 |
|
|
1991 |
|
float pSTAR(float mglu, float mlsp, float mchi2) { |
1992 |
< |
float mz=91.2; |
1992 |
> |
float mz=91.0; |
1993 |
|
float res=((mchi2*mchi2)-(mlsp+mz)*(mlsp+mz)); |
1994 |
|
res*=((mchi2*mchi2)-(mlsp-mz)*(mlsp-mz)); |
1995 |
|
res=TMath::Sqrt(res)/(2*mchi2); |
2002 |
|
res=TMath::Sqrt(res)/(2*massmother); |
2003 |
|
return res; |
2004 |
|
} |
2005 |
+ |
|
2006 |
+ |
void FindMinMax(TGraphErrors *gr, float &min, float &max) { |
2007 |
+ |
double x,y; |
2008 |
+ |
gr->GetPoint(0,x,y); |
2009 |
+ |
min=500*y; |
2010 |
+ |
max=0.0002*y; |
2011 |
+ |
for(int i=0;i<gr->GetN();i++) { |
2012 |
+ |
gr->GetPoint(i,x,y); |
2013 |
+ |
cout << "Point at " << x << "/" << y << " with error " << gr->GetErrorY(i) << endl; |
2014 |
+ |
float potmin=y-1.5*gr->GetErrorY(i); // taking 1.5 times the error to allow for enough space to present the plot |
2015 |
+ |
float potmax=y+1.5*gr->GetErrorY(i); // taking 1.5 times the error to allow for enough space to present the plot |
2016 |
+ |
if(potmin<min) min=potmin; |
2017 |
+ |
if(potmax>max) max=potmax; |
2018 |
+ |
} |
2019 |
+ |
} |
2020 |
+ |
|
2021 |
+ |
|
2022 |
+ |
void CleanLegends() { |
2023 |
+ |
for(int ihist=(int)PlottingSetup::FakeHistoHeap.size()-1;ihist>=0;ihist--) { |
2024 |
+ |
PlottingSetup::FakeHistoHeap[ihist]->Delete(); |
2025 |
+ |
PlottingSetup::FakeHistoHeap.pop_back(); |
2026 |
+ |
} |
2027 |
+ |
} |
2028 |
+ |
|
2029 |
+ |
string DigitsAfterComma(float number, int digits) { |
2030 |
+ |
float temp=number*pow(10.0,digits); |
2031 |
+ |
temp=int(temp)/pow(10.0,digits); |
2032 |
+ |
return any2string(temp); |
2033 |
+ |
} |