39 |
|
#include <TPaveText.h> |
40 |
|
#include <TRandom.h> |
41 |
|
#include <TGraphErrors.h> |
42 |
+ |
#include <TROOT.h> |
43 |
+ |
#include <TPolyLine.h> |
44 |
+ |
|
45 |
+ |
#include "ValueClass.C" |
46 |
|
#ifndef Verbosity |
47 |
|
#define Verbosity 0 |
48 |
|
#endif |
65 |
|
int PaperMode=0; // PaperMode=true will suppress "Preliminary" in DrawPrelim() |
66 |
|
int Approved=0; // Approved=true will only plot approved plots |
67 |
|
bool is2012=true; |
68 |
+ |
bool is53reco=true; |
69 |
+ |
bool openBox = true; |
70 |
+ |
vector<TH1F*> FakeHistoHeap; |
71 |
+ |
bool DrawMetSignalRegionMllLines=false; // whether to draw the lines in mll plots for the MET signal region |
72 |
+ |
float ConsideredZWidth=20; |
73 |
+ |
bool IsIJZBAnalysis=false; |
74 |
|
} |
75 |
|
|
76 |
|
bool dopng=false; |
97 |
|
void write_info(string funcname, string text); |
98 |
|
string get_directory(); |
99 |
|
bool Contains(string wholestring, string findme); |
100 |
+ |
TH1F* CollapseStack(THStack stack,TString hname); |
101 |
+ |
TH1F* CollapseStack(THStack* stack,TString hname); |
102 |
|
//------------------------------------------------------------------------------------- |
103 |
|
|
104 |
|
template<typename U> |
266 |
|
} |
267 |
|
} |
268 |
|
|
269 |
+ |
void DeleteStack(THStack mcstack) { |
270 |
+ |
TH1F* h; |
271 |
+ |
TIter nextHist(mcstack.GetHists()); |
272 |
+ |
while ( h = (TH1F*)nextHist() ) { |
273 |
+ |
h->Delete(); |
274 |
+ |
} |
275 |
+ |
delete h; |
276 |
+ |
} |
277 |
+ |
|
278 |
+ |
|
279 |
+ |
void DeadEnd(string message) { |
280 |
+ |
dout << endl; |
281 |
+ |
dout << "\033[1;31m _ _ _ " << endl; |
282 |
+ |
dout << "\033[1;31m __| | ___ __ _ __| | ___ _ __ __| | " << endl; |
283 |
+ |
dout << "\033[1;31m / _` |/ _ \\/ _` |/ _` | / _ \\ '_ \\ / _` | " << endl; |
284 |
+ |
dout << "\033[1;31m| (_| | __/ (_| | (_| | | __/ | | | (_| | " << endl; |
285 |
+ |
dout << "\033[1;31m \\__,_|\\___|\\__,_|\\__,_| \\___|_| |_|\\__,_| " << endl; |
286 |
+ |
dout << "\033[1;31m " << endl; |
287 |
+ |
dout << "" << endl; |
288 |
+ |
dout << " A totally fatal error has occurred: " << endl; |
289 |
+ |
dout << " " << message << endl; |
290 |
+ |
dout << endl; |
291 |
+ |
dout << "If you do not know how to deal with this error message please call Customer Support Mumbai (or Zurich...) \033[0m" << endl; |
292 |
+ |
dout << " ... aborting now ... " << endl; |
293 |
+ |
assert(0); |
294 |
+ |
} |
295 |
+ |
|
296 |
+ |
|
297 |
+ |
void SanityChecks() { |
298 |
+ |
//this function gets called whenever samples are initialized (see ActiveSamples.C) |
299 |
+ |
//whatever is necessary for the code to run should be put here. |
300 |
+ |
|
301 |
+ |
if(gROOT->GetVersionInt()<53200) { |
302 |
+ |
DeadEnd("ROOT version outdated, you are using "+any2string(gROOT->GetVersionInt())+" but the earliest recommended version is 5.32.00"); |
303 |
+ |
} |
304 |
+ |
|
305 |
+ |
|
306 |
+ |
} |
307 |
+ |
|
308 |
|
void initialize_log() { |
309 |
|
if(!PlottingSetup::publicmode) { |
310 |
|
dout << "____________________________________________________________" << endl; |
444 |
|
|
445 |
|
|
446 |
|
void setlumi(float l) { |
447 |
< |
generaltoolboxlumi=l; |
447 |
> |
generaltoolboxlumi=l; |
448 |
|
} |
449 |
|
|
450 |
|
int write_first_line(vector<vector<string> > &entries) { |
602 |
|
string prel=" Preliminary"; |
603 |
|
if(PlottingSetup::PaperMode) prel=""; |
604 |
|
//prelimtext << "CMS Preliminary 2011 , #sqrt{s}= 7 TeV, L= O(1) fb^{-1}"; //temporary replacement |
605 |
+ |
// if(PlottingSetup::is53reco) prel += " 53X"; |
606 |
|
string energy="7 TeV"; |
607 |
|
if(PlottingSetup::is2012) energy="8 TeV"; |
608 |
|
if(writelumi == 0) { |
609 |
|
if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy; |
610 |
|
else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy; |
611 |
|
} else { |
612 |
< |
if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy << ", L_{int} = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}"; |
613 |
< |
else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy << ", L_{int} = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}"; |
612 |
> |
if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy << ", #scale[0.6]{#int}L dt = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}"; |
613 |
> |
else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy << ", #scale[0.6]{#int}L dt = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}"; |
614 |
|
} |
615 |
|
TPaveText *eventSelectionPaveText = new TPaveText(0.27, 0.93,0.77, 1.0,"blNDC"); |
616 |
|
eventSelectionPaveText->SetFillStyle(4000); |
688 |
|
return val; |
689 |
|
} |
690 |
|
|
691 |
+ |
TGraphAsymmErrors *SysAndStatRatio(TH1F *h1,TH1F *h2, TH1F *sys, int id, vector<float>binning, bool precise=false) { |
692 |
+ |
int absJZBbinsNumber = binning.size()-1; |
693 |
+ |
TGraphAsymmErrors* graph = new TGraphAsymmErrors(absJZBbinsNumber); |
694 |
+ |
for(int i=0;i<absJZBbinsNumber;i++) |
695 |
+ |
{ |
696 |
+ |
float xCenter=h1->GetBinCenter(i+1); |
697 |
+ |
float xWidth=(h1->GetBinWidth(i+1))*0.5; |
698 |
+ |
float nominatorError = h1->GetBinError(i+1); |
699 |
+ |
float nominator=h1->GetBinContent(i+1); |
700 |
+ |
float denominatorError=h2->GetBinError(i+1); |
701 |
+ |
float denominator=h2->GetBinContent(i+1); |
702 |
+ |
float errorN = 0; |
703 |
+ |
float errorP = computeRatioError(nominator,nominatorError,denominator,denominatorError); |
704 |
+ |
float syserr=sys->GetBinContent(i+1); |
705 |
+ |
float errorsys=0; |
706 |
+ |
if(id==1) // (is data) |
707 |
+ |
{ |
708 |
+ |
if(!precise) errorP = computeRatioError(nominator,statErrorP(nominator),denominator,statErrorP(denominator)); |
709 |
+ |
else errorP = computeRatioError(nominator,nominatorError,denominator,denominatorError); |
710 |
+ |
errorsys=computeRatioError(nominator,syserr,denominator,0); |
711 |
+ |
errorP = TMath::Sqrt(errorsys*errorsys+errorP*errorP); |
712 |
+ |
errorN = errorP; // symmetrize using statErrorP |
713 |
+ |
} else { |
714 |
+ |
errorN = computeRatioError(nominator,nominatorError,denominator,denominatorError); |
715 |
+ |
errorsys=computeRatioError(nominator,syserr,denominator,0); |
716 |
+ |
errorN = TMath::Sqrt(errorsys*errorsys+errorP*errorP); |
717 |
+ |
errorP = errorN; // symmetrize using statErrorP |
718 |
+ |
} |
719 |
+ |
if(denominator!=0) { |
720 |
+ |
graph->SetPoint(i, xCenter, nominator/denominator); |
721 |
+ |
graph->SetPointError(i,xWidth,xWidth,errorN,errorP); |
722 |
+ |
} |
723 |
+ |
else { |
724 |
+ |
graph->SetPoint(i, xCenter, -999); |
725 |
+ |
graph->SetPointError(i,xWidth,xWidth,errorN,errorP); |
726 |
+ |
} |
727 |
+ |
} |
728 |
+ |
return graph; |
729 |
+ |
} |
730 |
+ |
|
731 |
+ |
|
732 |
|
TGraphAsymmErrors *histRatio(TH1F *h1,TH1F *h2, int id, vector<float>binning, bool precise=false) |
733 |
|
{ |
734 |
|
int absJZBbinsNumber = binning.size()-1; |
965 |
|
|
966 |
|
if(incut=="id1==0") return "ee"; |
967 |
|
if(incut=="id1==1") return "#mu#mu"; |
968 |
< |
if(incut=="abs(mll-91.2)<20") return "|m_{l^{+}l^{-}}-m_{Z}|<20"; |
968 |
> |
if(incut=="abs(mll-91)<10") return "|m_{l^{+}l^{-}}-m_{Z}|<10"; |
969 |
|
if(incut=="pfJetGoodID[0]") return ""; |
970 |
|
if(incut=="pfJetGoodID[1]") return ""; |
971 |
|
if((int)incut.find("pfJetGoodNum")>-1) { |
1241 |
|
else return false; |
1242 |
|
} |
1243 |
|
|
1244 |
+ |
|
1245 |
|
////////////////////////////////////////////////////////////////////////////// |
1246 |
|
// |
1247 |
|
// http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c |
1254 |
|
/* usage: |
1255 |
|
double vm2, rss2; |
1256 |
|
process_mem_usage(vm2, rss2); |
1257 |
< |
cout << "Memory usage: VM: " << vm << "; RSS: " << rss << endl; |
1257 |
> |
cout << "Memory usage: VM: " << vm2 << "; RSS: " << rss2 << endl; |
1258 |
|
*/ |
1259 |
|
|
1260 |
|
void process_mem_usage(double& vm_usage, double& resident_set) |
1313 |
|
} |
1314 |
|
|
1315 |
|
|
1316 |
+ |
TLatex* WriteSelection(int njets) { |
1317 |
+ |
string sel="Loose selection"; |
1318 |
+ |
if(njets==3) sel="Low E_{T}^{miss} selection"; |
1319 |
+ |
assert(njets==2||njets==3); |
1320 |
+ |
TLatex *sele = new TLatex(0.97,0.135,sel.c_str()); |
1321 |
+ |
sele->SetNDC(true); |
1322 |
+ |
sele->SetTextColor(TColor::GetColor("#848484")); |
1323 |
+ |
sele->SetTextFont(42); |
1324 |
+ |
sele->SetTextAlign(32); |
1325 |
+ |
sele->SetTextSize(0.03); |
1326 |
+ |
sele->SetTextAngle(270); |
1327 |
+ |
return sele; |
1328 |
+ |
} |
1329 |
+ |
|
1330 |
|
Double_t MarcosChi2TestX(const TH1* h1, const TH1* h2, Double_t &chi2, Int_t &ndf, Int_t &igood, Option_t *option) |
1331 |
|
{ |
1332 |
|
|
1349 |
|
return prob; |
1350 |
|
} |
1351 |
|
|
1352 |
< |
void save_with_ratio(TH1F *nominator, TH1F *denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false, bool extendrange=false, string yaxistitle="ratio") { |
1352 |
> |
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) { |
1353 |
|
//this function saves the pad being passed as well as a new one including the ratio. |
1354 |
< |
CompleteSave(canvas,savemeas); |
1355 |
< |
|
1354 |
> |
|
1355 |
> |
orig_canvas->cd(); |
1356 |
> |
orig_canvas->Update(); |
1357 |
> |
CompleteSave(orig_canvas,savemeas); |
1358 |
> |
TVirtualPad *canvas = (TVirtualPad*) orig_canvas->Clone("TempCanvas");//otherwise the Ratio_main_canvas will own our pad and destroy it upon deletion |
1359 |
> |
|
1360 |
|
float bottommargin=gStyle->GetPadBottomMargin(); |
1361 |
|
float canvas_height=gStyle->GetCanvasDefH(); |
1362 |
|
float canvas_width=gStyle->GetCanvasDefW(); |
1367 |
|
|
1368 |
|
float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace); |
1369 |
|
|
1370 |
< |
TCanvas *main_canvas = new TCanvas("main_canvas","main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace))); |
1370 |
> |
TCanvas *Ratio_main_canvas = new TCanvas("Ratio_main_canvas","Ratio_main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace))); |
1371 |
|
TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad |
1372 |
|
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 |
1373 |
|
TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad |
1374 |
|
|
1375 |
< |
main_canvas->Range(0,0,1,1); |
1376 |
< |
main_canvas->SetBorderSize(0); |
1377 |
< |
main_canvas->SetFrameFillColor(0); |
1266 |
< |
|
1375 |
> |
Ratio_main_canvas->Range(0,0,1,1); |
1376 |
> |
Ratio_main_canvas->SetBorderSize(0); |
1377 |
> |
Ratio_main_canvas->SetFrameFillColor(0); |
1378 |
|
mainpad->Draw(); |
1379 |
|
mainpad->cd(); |
1380 |
|
mainpad->Range(0,0,1,1); |
1384 |
|
canvas->Range(0,0,1,1); |
1385 |
|
canvas->Draw("same"); |
1386 |
|
mainpad->Modified(); |
1387 |
< |
main_canvas->cd(); |
1387 |
> |
Ratio_main_canvas->cd(); |
1388 |
|
coverpad->Draw(); |
1389 |
|
coverpad->cd(); |
1390 |
|
coverpad->Range(0,0,1,1); |
1392 |
|
coverpad->SetBorderSize(0); |
1393 |
|
coverpad->SetFrameFillColor(0); |
1394 |
|
coverpad->Modified(); |
1395 |
< |
main_canvas->cd(); |
1395 |
> |
Ratio_main_canvas->cd(); |
1396 |
|
bottompad->SetTopMargin(ratiotopmargin); |
1397 |
|
bottompad->SetBottomMargin(ratiobottommargin); |
1398 |
|
bottompad->Draw(); |
1401 |
|
bottompad->SetFillColor(kWhite); |
1402 |
|
TH1F *ratio = (TH1F*)nominator->Clone(GetNumericHistoName().c_str()); |
1403 |
|
ratio->Divide(denominator); |
1293 |
– |
|
1294 |
– |
|
1404 |
|
TGraphAsymmErrors *eratio; |
1405 |
+ |
TH1F *SystDown; |
1406 |
+ |
TH1F *SystUp; |
1407 |
+ |
|
1408 |
|
if(!do_bpred_ratio) eratio = produce_ratio_graph(ratio); |
1409 |
|
else { |
1410 |
|
bool using_data=false; |
1411 |
|
if((int)savemeas.find("Data")>0) using_data=true; |
1412 |
|
eratio = histRatio(nominator,denominator,using_data,PlottingSetup::global_ratio_binning,false); |
1413 |
+ |
if(syshisto!=0) { |
1414 |
+ |
SystDown = (TH1F*)syshisto->Clone("SystDown"); |
1415 |
+ |
SystUp = (TH1F*)syshisto->Clone("SystUp"); |
1416 |
+ |
for(int i=1;i<=syshisto->GetNbinsX();i++) { |
1417 |
+ |
SystDown->SetBinContent(i,1-syshisto->GetBinContent(i)); |
1418 |
+ |
SystUp->SetBinContent(i,1+syshisto->GetBinContent(i)); |
1419 |
+ |
} |
1420 |
+ |
SystDown->SetLineColor(TColor::GetColor("#006DE1")); |
1421 |
+ |
SystUp->SetLineColor(TColor::GetColor("#006DE1")); |
1422 |
+ |
} |
1423 |
|
for(int i=1;i<=ratio->GetNbinsX();i++) { |
1424 |
|
ratio->SetBinContent(i,0); |
1425 |
|
ratio->SetBinError(i,0); |
1426 |
|
} |
1427 |
+ |
|
1428 |
+ |
} |
1429 |
+ |
|
1430 |
+ |
if(syshisto && !do_bpred_ratio) { |
1431 |
+ |
SystDown = (TH1F*)syshisto->Clone("SystDown"); |
1432 |
+ |
SystUp = (TH1F*)syshisto->Clone("SystUp"); |
1433 |
+ |
for(int i=1;i<=syshisto->GetNbinsX();i++) { |
1434 |
+ |
SystDown->SetBinContent(i,1-syshisto->GetBinContent(i)); |
1435 |
+ |
SystUp->SetBinContent(i,1+syshisto->GetBinContent(i)); |
1436 |
+ |
} |
1437 |
+ |
SystDown->SetLineColor(TColor::GetColor("#006DE1")); |
1438 |
+ |
SystUp->SetLineColor(TColor::GetColor("#006DE1")); |
1439 |
|
} |
1440 |
|
eratio->SetFillColor(TColor::GetColor("#00ADE1")); |
1307 |
– |
|
1441 |
|
ratio->SetTitle(""); |
1442 |
< |
ratio->GetYaxis()->SetRangeUser(0.5,1.5); |
1442 |
> |
ratio->GetYaxis()->SetRangeUser(0.0,2.0); |
1443 |
|
if(do_bpred_ratio) ratio->GetYaxis()->SetRangeUser(0.0,2.0); |
1444 |
|
if(extendrange) ratio->GetYaxis()->SetRangeUser(0.0,4.0); |
1445 |
|
ratio->GetXaxis()->SetTitle(nominator->GetXaxis()->GetTitle()); |
1455 |
|
ratio->GetYaxis()->SetNdivisions(502,false); |
1456 |
|
ratio->SetFillColor(TColor::GetColor("#58D3F7")); |
1457 |
|
ratio->SetMarkerSize(0); |
1458 |
< |
ratio->Draw("e2"); |
1459 |
< |
eratio->Draw("2"); |
1458 |
> |
ratio->Draw("e20"); |
1459 |
> |
|
1460 |
> |
TGraphAsymmErrors *ratio_center = (TGraphAsymmErrors*)eratio->Clone("ratio_center"); |
1461 |
> |
for(int i=0;i<ratio_center->GetN();i++) { |
1462 |
> |
ratio_center->SetPointError(i,ratio_center->GetErrorXlow(i),ratio_center->GetErrorXhigh(i),0.005,0.005); |
1463 |
> |
} |
1464 |
> |
ratio_center->SetFillColor(TColor::GetColor("#006381")); |
1465 |
> |
|
1466 |
> |
if(syshisto!=0) { |
1467 |
> |
// sysratio->Draw("2"); |
1468 |
> |
// eratio->Draw("2,same"); |
1469 |
> |
eratio->Draw("20"); |
1470 |
> |
SystDown->Draw("histo,same"); |
1471 |
> |
SystUp->Draw("histo,same"); |
1472 |
> |
} else { |
1473 |
> |
eratio->Draw("20"); |
1474 |
> |
} |
1475 |
> |
ratio_center->Draw("20"); |
1476 |
|
ratio->Draw("same,axis"); |
1477 |
|
TLine *oneline = new TLine(ratio->GetXaxis()->GetBinLowEdge(1),1,ratio->GetXaxis()->GetBinLowEdge(ratio->GetNbinsX())+ratio->GetXaxis()->GetBinWidth(ratio->GetNbinsX()),1); |
1478 |
|
oneline->SetLineStyle(2); |
1479 |
|
oneline->SetLineColor(kBlue); |
1480 |
|
oneline->Draw("same"); |
1481 |
< |
|
1482 |
< |
main_canvas->cd(); |
1483 |
< |
main_canvas->Modified(); |
1484 |
< |
main_canvas->cd(); |
1485 |
< |
main_canvas->SetSelected(main_canvas); |
1481 |
> |
if(PlottingSetup::DrawMetSignalRegionMllLines) { |
1482 |
> |
cout << "Drawing extra lines in ratio this time around ... " << endl; |
1483 |
> |
float RatioYMax=2.0; |
1484 |
> |
if(extendrange) RatioYMax=4.0; |
1485 |
> |
|
1486 |
> |
TLine *SRline = new TLine(70,0,70,RatioYMax); |
1487 |
> |
TLine *ZLowLine = new TLine(91.2-PlottingSetup::ConsideredZWidth,0,91.2-PlottingSetup::ConsideredZWidth,RatioYMax); |
1488 |
> |
TLine *ZHiLine = new TLine(91.2+PlottingSetup::ConsideredZWidth,0,91.2+PlottingSetup::ConsideredZWidth,RatioYMax); |
1489 |
> |
|
1490 |
> |
SRline->SetLineStyle(2); |
1491 |
> |
ZLowLine->SetLineStyle(2); |
1492 |
> |
ZHiLine->SetLineStyle(2); |
1493 |
> |
SRline->SetLineColor(kGray+2); |
1494 |
> |
ZLowLine->SetLineColor(kGray+2); |
1495 |
> |
ZHiLine->SetLineColor(kGray+2); |
1496 |
> |
SRline->Draw(); |
1497 |
> |
ZLowLine->Draw(); |
1498 |
> |
ZHiLine->Draw(); |
1499 |
> |
} |
1500 |
> |
|
1501 |
> |
Ratio_main_canvas->cd(); |
1502 |
> |
Ratio_main_canvas->Modified(); |
1503 |
> |
Ratio_main_canvas->cd(); |
1504 |
> |
Ratio_main_canvas->SetSelected(Ratio_main_canvas); |
1505 |
|
|
1506 |
< |
CompleteSave(main_canvas,savemeas+"_withratio"); |
1506 |
> |
CompleteSave(Ratio_main_canvas,savemeas+"_withratio"); |
1507 |
|
bottompad->cd(); |
1508 |
|
|
1509 |
|
Double_t chi2; |
1531 |
|
CompleteRatio->SetTextAlign(31); |
1532 |
|
CompleteRatio->Draw(); |
1533 |
|
|
1534 |
< |
CompleteSave(main_canvas,savemeas+"_withratio_and_Chi2"); |
1534 |
> |
CompleteSave(Ratio_main_canvas,savemeas+"_withratio_and_Chi2"); |
1535 |
|
|
1536 |
|
// float KS = nominator->KolmogorovTest(denominator); |
1537 |
|
// stringstream KStext; |
1538 |
|
// Chi2text << "KS = " << KS << endl; |
1539 |
|
//cout << "Found : " << KStext.str() << endl; |
1540 |
|
|
1541 |
+ |
delete eratio; |
1542 |
+ |
delete ratio_center; |
1543 |
+ |
delete ratio; |
1544 |
+ |
delete Ratio_main_canvas; |
1545 |
+ |
} |
1546 |
|
|
1547 |
< |
delete main_canvas; |
1547 |
> |
void Save_With_Ratio_And_Line(TH1F *nominator, TH1F *denominator, TVirtualPad *orig_canvas, string savemeas, bool do_bpred_ratio=false, bool extendrange=false, string yaxistitle="ratio",TH1F *syshisto=NULL) { |
1548 |
> |
PlottingSetup::ConsideredZWidth=10.0; |
1549 |
> |
PlottingSetup::DrawMetSignalRegionMllLines=true; |
1550 |
> |
Save_With_Ratio(nominator, denominator, orig_canvas, savemeas, do_bpred_ratio, extendrange, yaxistitle,syshisto); |
1551 |
> |
PlottingSetup::DrawMetSignalRegionMllLines=false; |
1552 |
> |
} |
1553 |
> |
|
1554 |
> |
void Save_With_Ratio_And_Line(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) { |
1555 |
> |
TH1F *denominator_histo = (TH1F*) CollapseStack(denominator,"TemporaryStack"); |
1556 |
> |
Save_With_Ratio_And_Line(nominator, denominator_histo, canvas, savemeas, do_bpred_ratio); |
1557 |
> |
delete denominator_histo; |
1558 |
|
} |
1559 |
|
|
1560 |
+ |
void save_with_ratio_and_sys_band(float ConsideredZWidth, TH1F *nominator, TH1F *denominator, TVirtualPad *orig_canvas, string savemeas, bool do_bpred_ratio=false, bool extendrange=false, string yaxistitle="ratio",TH1F *syshisto=NULL) { |
1561 |
+ |
//this function saves the pad being passed as well as a new one including the SysRatio. |
1562 |
+ |
orig_canvas->cd(); |
1563 |
+ |
orig_canvas->Update(); |
1564 |
+ |
CompleteSave(orig_canvas,savemeas); |
1565 |
+ |
|
1566 |
+ |
TVirtualPad *canvas = (TVirtualPad*) orig_canvas->Clone("TempCanvas");//otherwise the Ratio_main_canvas will own our pad and destroy it upon deletion |
1567 |
+ |
|
1568 |
+ |
float bottommargin=gStyle->GetPadBottomMargin(); |
1569 |
+ |
float canvas_height=gStyle->GetCanvasDefH(); |
1570 |
+ |
float canvas_width=gStyle->GetCanvasDefW(); |
1571 |
+ |
float ratiospace=0.25;// space the ratio should take up (relative to original pad) |
1572 |
+ |
|
1573 |
+ |
float ratiobottommargin=0.3; |
1574 |
+ |
float ratiotopmargin=0.1; |
1575 |
+ |
|
1576 |
+ |
float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace); |
1577 |
+ |
|
1578 |
+ |
TCanvas *Ratio_main_canvas = new TCanvas("Ratio_main_canvas","Ratio_main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace))); |
1579 |
+ |
TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad |
1580 |
+ |
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 |
1581 |
+ |
TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad |
1582 |
+ |
|
1583 |
+ |
Ratio_main_canvas->Range(0,0,1,1); |
1584 |
+ |
Ratio_main_canvas->SetBorderSize(0); |
1585 |
+ |
Ratio_main_canvas->SetFrameFillColor(0); |
1586 |
+ |
|
1587 |
+ |
mainpad->Draw(); |
1588 |
+ |
mainpad->cd(); |
1589 |
+ |
mainpad->Range(0,0,1,1); |
1590 |
+ |
mainpad->SetFillColor(kWhite); |
1591 |
+ |
mainpad->SetBorderSize(0); |
1592 |
+ |
mainpad->SetFrameFillColor(0); |
1593 |
+ |
canvas->Range(0,0,1,1); |
1594 |
+ |
canvas->Draw("same"); |
1595 |
+ |
mainpad->Modified(); |
1596 |
+ |
Ratio_main_canvas->cd(); |
1597 |
+ |
coverpad->Draw(); |
1598 |
+ |
coverpad->cd(); |
1599 |
+ |
coverpad->Range(0,0,1,1); |
1600 |
+ |
coverpad->SetFillColor(kWhite); |
1601 |
+ |
coverpad->SetBorderSize(0); |
1602 |
+ |
coverpad->SetFrameFillColor(0); |
1603 |
+ |
coverpad->Modified(); |
1604 |
+ |
Ratio_main_canvas->cd(); |
1605 |
+ |
bottompad->SetTopMargin(ratiotopmargin); |
1606 |
+ |
bottompad->SetBottomMargin(ratiobottommargin); |
1607 |
+ |
bottompad->Draw(); |
1608 |
+ |
bottompad->cd(); |
1609 |
+ |
bottompad->Range(0,0,1,1); |
1610 |
+ |
bottompad->SetFillColor(kWhite); |
1611 |
+ |
TH1F *ratio = (TH1F*)nominator->Clone(GetNumericHistoName().c_str()); |
1612 |
+ |
ratio->Divide(denominator); |
1613 |
+ |
|
1614 |
+ |
|
1615 |
+ |
TGraphAsymmErrors *eratio; |
1616 |
+ |
TGraphAsymmErrors *SysEnvelope = new TGraphAsymmErrors(); |
1617 |
+ |
|
1618 |
+ |
if(syshisto && !do_bpred_ratio) { |
1619 |
+ |
for(int i=1;i<=syshisto->GetNbinsX();i++) { |
1620 |
+ |
float dx=syshisto->GetBinWidth(i)/2.0; |
1621 |
+ |
float dy=syshisto->GetBinContent(i); |
1622 |
+ |
if(dy<0.01) dy=0.07; |
1623 |
+ |
SysEnvelope->SetPoint(i-1,syshisto->GetBinCenter(i),1.0); |
1624 |
+ |
SysEnvelope->SetPointError(i-1,dx,dx,dy,dy); |
1625 |
+ |
} |
1626 |
+ |
SysEnvelope->SetFillColor(TColor::GetColor("#006DE1")); |
1627 |
+ |
} |
1628 |
|
|
1629 |
< |
TH1F* CollapseStack(THStack stack) { |
1629 |
> |
ratio->SetTitle(""); |
1630 |
> |
ratio->GetYaxis()->SetRangeUser(0.0,2.0); |
1631 |
> |
if(do_bpred_ratio) ratio->GetYaxis()->SetRangeUser(0.0,2.0); |
1632 |
> |
if(extendrange) ratio->GetYaxis()->SetRangeUser(0.0,4.0); |
1633 |
> |
ratio->GetXaxis()->SetTitle(nominator->GetXaxis()->GetTitle()); |
1634 |
> |
ratio->GetXaxis()->CenterTitle(); |
1635 |
> |
ratio->GetYaxis()->SetTitle(yaxistitle.c_str()); |
1636 |
> |
ratio->GetYaxis()->SetTitleOffset(0.4); |
1637 |
> |
ratio->GetYaxis()->CenterTitle(); |
1638 |
> |
ratio->SetStats(0); |
1639 |
> |
ratio->GetXaxis()->SetLabelSize(xstretchfactor*ratio->GetXaxis()->GetLabelSize()); |
1640 |
> |
ratio->GetYaxis()->SetLabelSize(xstretchfactor*ratio->GetYaxis()->GetLabelSize()); |
1641 |
> |
ratio->GetXaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize()); |
1642 |
> |
ratio->GetYaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize()); |
1643 |
> |
ratio->GetYaxis()->SetNdivisions(502,false); |
1644 |
> |
ratio->SetFillColor(TColor::GetColor("#58D3F7")); |
1645 |
> |
ratio->Draw("e0"); |
1646 |
> |
|
1647 |
> |
if(syshisto!=0) { |
1648 |
> |
SysEnvelope->SetFillColor(TColor::GetColor("#FE9A2E")); |
1649 |
> |
SysEnvelope->Draw("2,0,same"); |
1650 |
> |
ratio->Draw("e0,same"); |
1651 |
> |
} else { |
1652 |
> |
eratio->Draw("0"); |
1653 |
> |
} |
1654 |
> |
ratio->Draw("same,axis"); |
1655 |
> |
TLine *oneline = new TLine(ratio->GetXaxis()->GetBinLowEdge(1),1,ratio->GetXaxis()->GetBinLowEdge(ratio->GetNbinsX())+ratio->GetXaxis()->GetBinWidth(ratio->GetNbinsX()),1); |
1656 |
> |
oneline->SetLineStyle(2); |
1657 |
> |
oneline->SetLineColor(kBlue); |
1658 |
> |
oneline->Draw("same"); |
1659 |
> |
|
1660 |
> |
|
1661 |
> |
|
1662 |
> |
if(ConsideredZWidth>0.1) { |
1663 |
> |
cout << "Drawing extra lines in ratio this time around ... " << endl; |
1664 |
> |
float RatioYMax=2.0; |
1665 |
> |
if(extendrange) RatioYMax=4.0; |
1666 |
> |
|
1667 |
> |
TLine *SRline = new TLine(70,0,70,RatioYMax); |
1668 |
> |
TLine *ZLowLine = new TLine(91.2-ConsideredZWidth,0,91.2-ConsideredZWidth,RatioYMax); |
1669 |
> |
TLine *ZHiLine = new TLine(91.2+ConsideredZWidth,0,91.2+ConsideredZWidth,RatioYMax); |
1670 |
> |
|
1671 |
> |
SRline->SetLineStyle(2); |
1672 |
> |
ZLowLine->SetLineStyle(2); |
1673 |
> |
ZHiLine->SetLineStyle(2); |
1674 |
> |
SRline->SetLineColor(kGray+2); |
1675 |
> |
ZLowLine->SetLineColor(kGray+2); |
1676 |
> |
ZHiLine->SetLineColor(kGray+2); |
1677 |
> |
SRline->Draw(); |
1678 |
> |
ZLowLine->Draw(); |
1679 |
> |
ZHiLine->Draw(); |
1680 |
> |
} |
1681 |
> |
|
1682 |
> |
Ratio_main_canvas->cd(); |
1683 |
> |
Ratio_main_canvas->Modified(); |
1684 |
> |
Ratio_main_canvas->cd(); |
1685 |
> |
Ratio_main_canvas->SetSelected(Ratio_main_canvas); |
1686 |
> |
|
1687 |
> |
CompleteSave(Ratio_main_canvas,savemeas+"_withSysRatio"); |
1688 |
> |
bottompad->cd(); |
1689 |
> |
|
1690 |
> |
Double_t chi2; |
1691 |
> |
Int_t ndf,igood; |
1692 |
> |
Double_t chi2prob = MarcosChi2TestX(nominator,denominator,chi2,ndf,igood,"UW"); |
1693 |
> |
|
1694 |
> |
stringstream Chi2text; |
1695 |
> |
Chi2text << "#chi^{2} / ndf: " << chi2 << " / " << ndf; |
1696 |
> |
stringstream Chi2probtext; |
1697 |
> |
Chi2probtext << "#chi^{2} prob: " << chi2prob; |
1698 |
> |
TText* chi2box = write_text(0.02,0.11,Chi2text.str()); |
1699 |
> |
chi2box->SetTextSize(0.08); |
1700 |
> |
chi2box->SetTextAlign(11); |
1701 |
> |
chi2box->Draw(); |
1702 |
> |
TText* chi2probbox = write_text(0.02,0.04,Chi2probtext.str()); |
1703 |
> |
chi2probbox->SetTextSize(0.08); |
1704 |
> |
chi2probbox->SetTextAlign(11); |
1705 |
> |
chi2probbox->Draw(); |
1706 |
> |
|
1707 |
> |
stringstream CompRatio; |
1708 |
> |
CompRatio << "Ratio: " << nominator->Integral() << " / " << denominator->Integral() << " \n " << nominator->Integral()/denominator->Integral(); |
1709 |
> |
TText *CompleteRatio = write_text(0.98,0.04,CompRatio.str()); |
1710 |
> |
CompleteRatio->SetTextSize(0.08); |
1711 |
> |
CompleteRatio->SetTextAlign(31); |
1712 |
> |
CompleteRatio->Draw(); |
1713 |
> |
|
1714 |
> |
CompleteSave(Ratio_main_canvas,savemeas+"_withSysRatio_and_Chi2"); |
1715 |
> |
delete Ratio_main_canvas; |
1716 |
> |
delete ratio; |
1717 |
> |
} |
1718 |
> |
|
1719 |
> |
TH1F* CollapseStack(THStack stack,TString hname="CollapsedStack") { |
1720 |
|
TH1F *bhist = ((TH1F*)((stack.GetHists())->At(0))); |
1721 |
< |
TH1F *basehisto = (TH1F*)bhist->Clone("base"); |
1721 |
> |
TH1F *basehisto = (TH1F*)bhist->Clone(hname); |
1722 |
|
TIter next(stack.GetHists()); |
1723 |
|
TH1F *h; |
1724 |
|
int counter=0; |
1730 |
|
return basehisto; |
1731 |
|
} |
1732 |
|
|
1733 |
< |
void save_with_ratio(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) { |
1734 |
< |
save_with_ratio(nominator, CollapseStack(denominator), canvas, savemeas, do_bpred_ratio); |
1733 |
> |
TH1F* CollapseStack(THStack *stack,TString hname="CollapsedStack") { |
1734 |
> |
TH1F *bhist = ((TH1F*)((stack->GetHists())->At(0))); |
1735 |
> |
TH1F *basehisto = (TH1F*)bhist->Clone(hname); |
1736 |
> |
TIter next(stack->GetHists()); |
1737 |
> |
TH1F *h; |
1738 |
> |
int counter=0; |
1739 |
> |
while ((h=(TH1F*)next())) { |
1740 |
> |
counter++; |
1741 |
> |
if(counter==1) continue; |
1742 |
> |
basehisto->Add(h); |
1743 |
> |
} |
1744 |
> |
return basehisto; |
1745 |
> |
} |
1746 |
> |
|
1747 |
> |
void Save_With_Ratio(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) { |
1748 |
> |
TH1F *denominator_histo = (TH1F*) CollapseStack(denominator); |
1749 |
> |
Save_With_Ratio(nominator, denominator_histo, canvas, savemeas, do_bpred_ratio); |
1750 |
> |
delete denominator_histo; |
1751 |
|
} |
1752 |
|
|
1753 |
|
void flag_this_change(string function, int line, int checked=0) { |
1863 |
|
perror ("Couldn't open the directory"); |
1864 |
|
} |
1865 |
|
|
1866 |
+ |
void ClearHisto(TH1* histo) { |
1867 |
+ |
for(int ix=0;ix<=histo->GetNbinsX()+1;ix++) {//also reset over- and underflow |
1868 |
+ |
histo->SetBinContent(ix,0); |
1869 |
+ |
histo->SetBinContent(ix,0); |
1870 |
+ |
} |
1871 |
+ |
} |
1872 |
+ |
|
1873 |
+ |
void AddSquared(TH1F *histo, TH1F *addthis, float weight) { |
1874 |
+ |
for(int ix=1;ix<=addthis->GetNbinsX()+1;ix++) {//also include over- and underflow |
1875 |
+ |
float bincenter=addthis->GetBinCenter(ix); |
1876 |
+ |
int nBinHisto= histo->FindBin(bincenter); |
1877 |
+ |
float old_content=histo->GetBinContent(nBinHisto); |
1878 |
+ |
histo->SetBinContent(nBinHisto,old_content+((addthis->GetBinContent(ix))*(addthis->GetBinContent(ix))*weight)); |
1879 |
+ |
} |
1880 |
+ |
} |
1881 |
+ |
|
1882 |
+ |
void SQRT(TH1* histo) { |
1883 |
+ |
for(int ix=0;ix<=histo->GetNbinsX()+1;ix++) {//also include over- and underflow |
1884 |
+ |
histo->SetBinContent(ix,TMath::Sqrt(histo->GetBinContent(ix))); |
1885 |
+ |
} |
1886 |
+ |
} |
1887 |
+ |
|
1888 |
|
/*string GetCompleteHostname() { |
1889 |
|
struct addrinfo hints, *info, *p; |
1890 |
|
int gai_result; |
1932 |
|
name=ReplaceCharacter(name,"]","_"); |
1933 |
|
name=ReplaceCharacter(name,"{","_"); |
1934 |
|
name=ReplaceCharacter(name,"}","_"); |
1935 |
+ |
name=ReplaceCharacter(name,"(","_"); |
1936 |
+ |
name=ReplaceCharacter(name,")","_"); |
1937 |
+ |
name=ReplaceCharacter(name," ","_"); |
1938 |
|
name=ReplaceCharacter(name,".","_"); |
1939 |
|
name=ReplaceCharacter(name,",","_"); |
1940 |
|
name=ReplaceCharacter(name,";","_"); |
1949 |
|
return name; |
1950 |
|
} |
1951 |
|
|
1952 |
+ |
TPolyLine* GetFitUncertaintyShape(TF1 *fit, float low, float high,float x0,float x1) { |
1953 |
+ |
int nPoints=1000; |
1954 |
+ |
double x[nPoints+1]; |
1955 |
+ |
double y[nPoints]; |
1956 |
+ |
|
1957 |
+ |
float par1=fit->GetParameter(0); |
1958 |
+ |
float dpar1=fit->GetParError(0); |
1959 |
+ |
float par2=fit->GetParameter(1); |
1960 |
+ |
float dpar2=fit->GetParError(1); |
1961 |
+ |
|
1962 |
+ |
float step=(x1-x0)/(nPoints/2.0 -1); |
1963 |
+ |
for(int i=0;i<nPoints/2.0;i++) { |
1964 |
+ |
x[i]=x0+i*step; |
1965 |
+ |
y[i]=(par1+x[i]*par2) - sqrt(dpar1*dpar1+dpar2*dpar2*x[i]*x[i]); |
1966 |
+ |
x[nPoints-1-i]=x[i]; |
1967 |
+ |
y[nPoints-1-i]=(par1+x[i]*par2) + sqrt(dpar1*dpar1+dpar2*dpar2*x[i]*x[i]); |
1968 |
+ |
if(y[i]<low) y[i]=low; |
1969 |
+ |
if(y[i]>high) y[i]=high; |
1970 |
+ |
if(y[nPoints-1-i]<low) y[nPoints-1-i]=low; |
1971 |
+ |
if(y[nPoints-1-i]>high) y[nPoints-1-i]=high; |
1972 |
+ |
} |
1973 |
+ |
|
1974 |
+ |
x[nPoints]=x[0]; |
1975 |
+ |
y[nPoints]=y[0]; |
1976 |
+ |
|
1977 |
+ |
TPolyLine *l = new TPolyLine(nPoints+1,x,y); |
1978 |
+ |
l->SetFillColor(TColor::GetColor("#A2A2FA")); |
1979 |
+ |
l->SetLineColor(TColor::GetColor("#A2A2FA")); |
1980 |
+ |
l->SetLineWidth(1); |
1981 |
+ |
return l; |
1982 |
+ |
} |
1983 |
+ |
|
1984 |
+ |
//code for ReplaceAll copied from |
1985 |
+ |
//http://stackoverflow.com/questions/5343190/c-how-do-i-replace-all-instances-of-of-a-string-with-another-string |
1986 |
+ |
string ReplaceAll(string str, string from, string to) { |
1987 |
+ |
size_t start_pos = 0; |
1988 |
+ |
while((start_pos = str.find(from, start_pos)) != std::string::npos) { |
1989 |
+ |
str.replace(start_pos, from.length(), to); |
1990 |
+ |
start_pos += to.length(); // ... |
1991 |
+ |
} |
1992 |
+ |
return str; |
1993 |
+ |
} |
1994 |
+ |
|
1995 |
+ |
TPolyLine* GetFitUncertaintyShape(TH1 *histo, string fitname, float low, float high) { |
1996 |
+ |
TF1 *fit = (TF1*)histo->GetFunction(fitname.c_str()); |
1997 |
+ |
if(!fit) { |
1998 |
+ |
cout << "CANNOT PRODUCE FIT UNCERTAINTY AS THERE IS NO FIT CALLED " << fitname << " IN " << histo->GetName() << endl; |
1999 |
+ |
return NULL; |
2000 |
+ |
} |
2001 |
+ |
float x0=histo->GetBinLowEdge(1); |
2002 |
+ |
float x1=histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()); |
2003 |
+ |
return GetFitUncertaintyShape(fit, low, high,x0,x1); |
2004 |
+ |
} |
2005 |
+ |
|
2006 |
+ |
TPolyLine* GetFitUncertaintyShape(TGraphErrors *gr, string fitname, float low, float high, float minx=-999, float maxx=-999) { |
2007 |
+ |
TF1 *fit = (TF1*)gr->GetFunction(fitname.c_str()); |
2008 |
+ |
if(!fit) { |
2009 |
+ |
cout << "CANNOT PRODUCE FIT UNCERTAINTY AS THERE IS NO FIT CALLED " << fitname << " IN " << gr->GetName() << endl; |
2010 |
+ |
return NULL; |
2011 |
+ |
} |
2012 |
+ |
double x,y; |
2013 |
+ |
gr->GetPoint(0,x,y); |
2014 |
+ |
float min=x; |
2015 |
+ |
gr->GetPoint(gr->GetN()-1,x,y); |
2016 |
+ |
float max=x; |
2017 |
+ |
if(minx>-999 && maxx>-999 && minx<maxx) { |
2018 |
+ |
max=maxx; |
2019 |
+ |
min=minx; |
2020 |
+ |
} |
2021 |
+ |
return GetFitUncertaintyShape(fit, low, high,min,max); |
2022 |
+ |
} |
2023 |
+ |
|
2024 |
|
stringstream all_bugs; |
2025 |
|
|
2026 |
|
void bug_tracker(string function, int line, string description) { |
2058 |
|
//TODO: Write a bug summary at the end. |
2059 |
|
|
2060 |
|
float pSTAR(float mglu, float mlsp, float mchi2) { |
2061 |
< |
float mz=91.2; |
2061 |
> |
float mz=91.0; |
2062 |
|
float res=((mchi2*mchi2)-(mlsp+mz)*(mlsp+mz)); |
2063 |
|
res*=((mchi2*mchi2)-(mlsp-mz)*(mlsp-mz)); |
2064 |
|
res=TMath::Sqrt(res)/(2*mchi2); |
2071 |
|
res=TMath::Sqrt(res)/(2*massmother); |
2072 |
|
return res; |
2073 |
|
} |
2074 |
+ |
|
2075 |
+ |
void FindMinMax(TGraphErrors *gr, float &min, float &max) { |
2076 |
+ |
double x,y; |
2077 |
+ |
gr->GetPoint(0,x,y); |
2078 |
+ |
min=500*y; |
2079 |
+ |
max=0.0002*y; |
2080 |
+ |
for(int i=0;i<gr->GetN();i++) { |
2081 |
+ |
gr->GetPoint(i,x,y); |
2082 |
+ |
cout << "Point at " << x << "/" << y << " with error " << gr->GetErrorY(i) << endl; |
2083 |
+ |
float potmin=y-1.5*gr->GetErrorY(i); // taking 1.5 times the error to allow for enough space to present the plot |
2084 |
+ |
float potmax=y+1.5*gr->GetErrorY(i); // taking 1.5 times the error to allow for enough space to present the plot |
2085 |
+ |
if(potmin<min) min=potmin; |
2086 |
+ |
if(potmax>max) max=potmax; |
2087 |
+ |
} |
2088 |
+ |
} |
2089 |
+ |
|
2090 |
+ |
|
2091 |
+ |
void CleanLegends() { |
2092 |
+ |
for(int ihist=(int)PlottingSetup::FakeHistoHeap.size()-1;ihist>=0;ihist--) { |
2093 |
+ |
PlottingSetup::FakeHistoHeap[ihist]->Delete(); |
2094 |
+ |
PlottingSetup::FakeHistoHeap.pop_back(); |
2095 |
+ |
} |
2096 |
+ |
} |
2097 |
+ |
|
2098 |
+ |
string DigitsAfterComma(float number, int digits) { |
2099 |
+ |
float temp=number*pow(10.0,digits); |
2100 |
+ |
temp=int(temp)/pow(10.0,digits); |
2101 |
+ |
return any2string(temp); |
2102 |
+ |
} |
2103 |
+ |
|
2104 |
+ |
|
2105 |
+ |
Value GetYield(TH1F *histo, float min, float max) { |
2106 |
+ |
float res=0.0; |
2107 |
+ |
float reserr=0.0; |
2108 |
+ |
for(int i=1;i<=histo->GetNbinsX();i++) { |
2109 |
+ |
if(histo->GetBinLowEdge(i)+histo->GetBinWidth(i)<=min) continue;// considered in the next bin |
2110 |
+ |
if(histo->GetBinLowEdge(i)>=max) continue;//above the threshold, out! |
2111 |
+ |
// cout << " added yield for bin [" << histo->GetBinLowEdge(i) << "," << histo->GetBinLowEdge(i)+histo->GetBinWidth(i) << "] which is " << histo->GetBinContent(i) << " in GetYield" << endl; |
2112 |
+ |
res+=histo->GetBinContent(i); |
2113 |
+ |
reserr=sqrt(reserr*reserr+histo->GetBinError(i)*histo->GetBinError(i)); |
2114 |
+ |
} |
2115 |
+ |
return Value(res,reserr); |
2116 |
+ |
} |
2117 |
+ |
|
2118 |
+ |
void ProduceYields(float min, float max, TH1F *data, THStack *stack) { |
2119 |
+ |
dout << " *************** <MC YIELDS> ********* " << endl; |
2120 |
+ |
dout << " Considering " << min << " < mll < " << max << " " << endl; |
2121 |
+ |
dout << " Data : " << GetYield(data,min,max) << endl; |
2122 |
+ |
TIter nextSF(stack->GetHists()); |
2123 |
+ |
TH1F* h; |
2124 |
+ |
while ( h = (TH1F*)nextSF() ) { |
2125 |
+ |
dout << " " << h->GetName() << " : " << GetYield(h,min,max) << endl; |
2126 |
+ |
} |
2127 |
+ |
dout << " *************** </MC YIELDS> ********* " << endl; |
2128 |
+ |
} |
2129 |
+ |
|
2130 |
+ |
|
2131 |
+ |
vector<pair<string,Value> > WriteYield(THStack *mc, float low, float high, bool quiet=false) { |
2132 |
+ |
TH1F *h; |
2133 |
+ |
vector<pair<string,Value> > result; |
2134 |
+ |
TIter NextHisto(mc->GetHists()); |
2135 |
+ |
while ( h = (TH1F*)NextHisto() ) { |
2136 |
+ |
float CurrBKG=0; |
2137 |
+ |
float CurrBKGErr=0; |
2138 |
+ |
for(int i=1;i<=h->GetNbinsX()+1;i++) { |
2139 |
+ |
if(h->GetBinLowEdge(i)+h->GetBinWidth(i)<=low) continue;// considered in the next bin |
2140 |
+ |
if(h->GetBinLowEdge(i)>=high) continue;//above the threshold, out! |
2141 |
+ |
CurrBKG+=h->GetBinContent(i); |
2142 |
+ |
CurrBKGErr=sqrt(CurrBKGErr*CurrBKGErr+h->GetBinError(i)*h->GetBinError(i)); |
2143 |
+ |
} |
2144 |
+ |
if(!quiet) dout << " " << h->GetName() << " : " << CurrBKG << " +/- " << CurrBKGErr << endl; |
2145 |
+ |
result.push_back(make_pair((string)h->GetName(),Value(CurrBKG,CurrBKGErr))); |
2146 |
+ |
} |
2147 |
+ |
|
2148 |
+ |
return result; |
2149 |
+ |
} |