ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/GeneralToolBox.C
(Generate patch)

Comparing UserCode/cbrown/Development/Plotting/Modules/GeneralToolBox.C (file contents):
Revision 1.11 by buchmann, Wed Jun 6 08:24:13 2012 UTC vs.
Revision 1.32 by buchmann, Thu Jan 24 08:21:38 2013 UTC

# Line 39 | Line 39
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
# Line 61 | Line 64 | namespace PlottingSetup {
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;
# Line 254 | Line 261 | void ensure_directory_exists(string this
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;
# Line 393 | Line 439 | void CompleteSave(TVirtualPad *can, stri
439  
440  
441   void setlumi(float l) {
442 < generaltoolboxlumi=l;
442 >  generaltoolboxlumi=l;
443   }
444  
445   int write_first_line(vector<vector<string> > &entries) {
# Line 551 | Line 597 | void DrawPrelim(float writelumi=generalt
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) {
# Line 636 | Line 683 | float computeProductError(float a, float
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;
# Line 872 | Line 960 | string interpret_cut(string incut, bool
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) {
# Line 1241 | Line 1329 | Double_t MarcosChi2TestX(const TH1* h1,
1329     return prob;
1330   }
1331  
1332 < void save_with_ratio(TH1F *nominator, TH1F *denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false, bool extendrange=false, string yaxistitle="ratio") {
1332 > 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) {
1333    //this function saves the pad being passed as well as a new one including the ratio.
1334 +  
1335 +  TVirtualPad *canvas = (TVirtualPad*) orig_canvas->Clone("TempCanvas");//otherwise the main_canvas will own our pad and destroy it upon deletion
1336    CompleteSave(canvas,savemeas);
1337 <
1337 >  
1338    float bottommargin=gStyle->GetPadBottomMargin();
1339    float canvas_height=gStyle->GetCanvasDefH();
1340    float canvas_width=gStyle->GetCanvasDefW();
# Line 1291 | Line 1381 | void save_with_ratio(TH1F *nominator, TH
1381    TH1F *ratio = (TH1F*)nominator->Clone(GetNumericHistoName().c_str());
1382    ratio->Divide(denominator);
1383  
1294
1384    TGraphAsymmErrors *eratio;
1385 +  TH1F *SystDown;
1386 +  TH1F *SystUp;
1387 +  
1388    if(!do_bpred_ratio) eratio = produce_ratio_graph(ratio);
1389    else {
1390       bool using_data=false;
1391       if((int)savemeas.find("Data")>0) using_data=true;
1392       eratio = histRatio(nominator,denominator,using_data,PlottingSetup::global_ratio_binning,false);
1393 +     if(syshisto!=0) {
1394 +       SystDown = (TH1F*)syshisto->Clone("SystDown");
1395 +       SystUp = (TH1F*)syshisto->Clone("SystUp");
1396 +       for(int i=1;i<=syshisto->GetNbinsX();i++) {
1397 +         SystDown->SetBinContent(i,1-syshisto->GetBinContent(i));
1398 +         SystUp->SetBinContent(i,1+syshisto->GetBinContent(i));
1399 +       }
1400 +       SystDown->SetLineColor(TColor::GetColor("#006DE1"));
1401 +       SystUp->SetLineColor(TColor::GetColor("#006DE1"));
1402 +     }
1403       for(int i=1;i<=ratio->GetNbinsX();i++) {
1404          ratio->SetBinContent(i,0);
1405          ratio->SetBinError(i,0);
1406       }
1407 +    
1408 +  }
1409 +  
1410 +  if(syshisto && !do_bpred_ratio) {
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    eratio->SetFillColor(TColor::GetColor("#00ADE1"));
1421  
1422    ratio->SetTitle("");
1423 <  ratio->GetYaxis()->SetRangeUser(0.5,1.5);
1423 >  ratio->GetYaxis()->SetRangeUser(0.0,2.0);
1424    if(do_bpred_ratio) ratio->GetYaxis()->SetRangeUser(0.0,2.0);
1425    if(extendrange) ratio->GetYaxis()->SetRangeUser(0.0,4.0);
1426    ratio->GetXaxis()->SetTitle(nominator->GetXaxis()->GetTitle());
# Line 1323 | Line 1437 | void save_with_ratio(TH1F *nominator, TH
1437    ratio->SetFillColor(TColor::GetColor("#58D3F7"));
1438    ratio->SetMarkerSize(0);
1439    ratio->Draw("e2");
1440 <  eratio->Draw("2");
1440 >  
1441 >  TGraphAsymmErrors *ratio_center = (TGraphAsymmErrors*)eratio->Clone("ratio_center");
1442 >  for(int i=0;i<ratio_center->GetN();i++) {
1443 >    ratio_center->SetPointError(i,ratio_center->GetErrorXlow(i),ratio_center->GetErrorXhigh(i),0.005,0.005);
1444 >  }
1445 >  
1446 >  ratio_center->SetFillColor(TColor::GetColor("#006381"));
1447 >  
1448 >  if(syshisto!=0) {
1449 > //    sysratio->Draw("2");
1450 > //    eratio->Draw("2,same");
1451 >    eratio->Draw("2");
1452 >    SystDown->Draw("histo,same");
1453 >    SystUp->Draw("histo,same");
1454 >  } else {
1455 >    eratio->Draw("2");
1456 >  }
1457 >  ratio_center->Draw("2");
1458    ratio->Draw("same,axis");
1459    TLine *oneline = new TLine(ratio->GetXaxis()->GetBinLowEdge(1),1,ratio->GetXaxis()->GetBinLowEdge(ratio->GetNbinsX())+ratio->GetXaxis()->GetBinWidth(ratio->GetNbinsX()),1);
1460    oneline->SetLineStyle(2);
# Line 1370 | Line 1501 | void save_with_ratio(TH1F *nominator, TH
1501   //  Chi2text << "KS = " << KS << endl;
1502   //cout << "Found : " << KStext.str() << endl;
1503  
1504 <
1504 >  delete eratio;
1505 >  delete ratio_center;
1506 >  delete ratio;
1507    delete main_canvas;
1508   }
1509  
1510 + 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) {
1511 +  //this function saves the pad being passed as well as a new one including the SysRatio.
1512 +  TVirtualPad *canvas = (TVirtualPad*) orig_canvas->Clone("TempCanvas");//otherwise the main_canvas will own our pad and destroy it upon deletion
1513 +  CompleteSave(canvas,savemeas);
1514 +
1515 +  float bottommargin=gStyle->GetPadBottomMargin();
1516 +  float canvas_height=gStyle->GetCanvasDefH();
1517 +  float canvas_width=gStyle->GetCanvasDefW();
1518 +  float ratiospace=0.25;// space the ratio should take up (relative to original pad)
1519 +  
1520 +  float ratiobottommargin=0.3;
1521 +  float ratiotopmargin=0.1;
1522 +  
1523 +  float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace);
1524 +  
1525 +  TCanvas *main_canvas = new TCanvas("main_canvas","main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1526 +  TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad
1527 +  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
1528 +  TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad
1529 +  
1530 +  main_canvas->Range(0,0,1,1);
1531 +  main_canvas->SetBorderSize(0);
1532 +  main_canvas->SetFrameFillColor(0);
1533 +  
1534 +  mainpad->Draw();
1535 +  mainpad->cd();
1536 +  mainpad->Range(0,0,1,1);
1537 +  mainpad->SetFillColor(kWhite);
1538 +  mainpad->SetBorderSize(0);
1539 +  mainpad->SetFrameFillColor(0);
1540 +  canvas->Range(0,0,1,1);
1541 +  canvas->Draw("same");
1542 +  mainpad->Modified();
1543 +  main_canvas->cd();
1544 +  coverpad->Draw();
1545 +  coverpad->cd();
1546 +  coverpad->Range(0,0,1,1);
1547 +  coverpad->SetFillColor(kWhite);
1548 +  coverpad->SetBorderSize(0);
1549 +  coverpad->SetFrameFillColor(0);
1550 +  coverpad->Modified();
1551 +  main_canvas->cd();
1552 +  bottompad->SetTopMargin(ratiotopmargin);
1553 +  bottompad->SetBottomMargin(ratiobottommargin);
1554 +  bottompad->Draw();
1555 +  bottompad->cd();
1556 +  bottompad->Range(0,0,1,1);
1557 +  bottompad->SetFillColor(kWhite);
1558 +  TH1F *ratio = (TH1F*)nominator->Clone(GetNumericHistoName().c_str());
1559 +  ratio->Divide(denominator);
1560 +
1561  
1562 < TH1F* CollapseStack(THStack stack) {
1562 >  TGraphAsymmErrors *eratio;
1563 >  TGraphAsymmErrors *SysEnvelope = new TGraphAsymmErrors();
1564 >  
1565 >  if(syshisto && !do_bpred_ratio) {
1566 >       for(int i=1;i<=syshisto->GetNbinsX();i++) {
1567 >         float dx=syshisto->GetBinWidth(i)/2.0;
1568 >         float dy=syshisto->GetBinContent(i);
1569 >         if(dy<0.01) dy=0.07;
1570 >         SysEnvelope->SetPoint(i-1,syshisto->GetBinCenter(i),1.0);
1571 >         SysEnvelope->SetPointError(i-1,dx,dx,dy,dy);
1572 >       }
1573 >       SysEnvelope->SetFillColor(TColor::GetColor("#006DE1"));
1574 >  }
1575 >
1576 >  ratio->SetTitle("");
1577 >  ratio->GetYaxis()->SetRangeUser(0.0,2.0);
1578 >  if(do_bpred_ratio) ratio->GetYaxis()->SetRangeUser(0.0,2.0);
1579 >  if(extendrange) ratio->GetYaxis()->SetRangeUser(0.0,4.0);
1580 >  ratio->GetXaxis()->SetTitle(nominator->GetXaxis()->GetTitle());
1581 >  ratio->GetXaxis()->CenterTitle();
1582 >  ratio->GetYaxis()->SetTitle(yaxistitle.c_str());
1583 >  ratio->GetYaxis()->SetTitleOffset(0.4);
1584 >  ratio->GetYaxis()->CenterTitle();
1585 >  ratio->SetStats(0);
1586 >  ratio->GetXaxis()->SetLabelSize(xstretchfactor*ratio->GetXaxis()->GetLabelSize());
1587 >  ratio->GetYaxis()->SetLabelSize(xstretchfactor*ratio->GetYaxis()->GetLabelSize());
1588 >  ratio->GetXaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize());
1589 >  ratio->GetYaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize());
1590 >  ratio->GetYaxis()->SetNdivisions(502,false);
1591 >  ratio->SetFillColor(TColor::GetColor("#58D3F7"));
1592 >  ratio->Draw("e1");
1593 >  
1594 >  if(syshisto!=0) {
1595 >    SysEnvelope->SetFillColor(TColor::GetColor("#FE9A2E"));
1596 >    SysEnvelope->Draw("2,same");
1597 >    ratio->Draw("e1,same");
1598 >  } else {
1599 >    eratio->Draw("1");
1600 >  }
1601 >  ratio->Draw("same,axis");
1602 >  TLine *oneline = new TLine(ratio->GetXaxis()->GetBinLowEdge(1),1,ratio->GetXaxis()->GetBinLowEdge(ratio->GetNbinsX())+ratio->GetXaxis()->GetBinWidth(ratio->GetNbinsX()),1);
1603 >  oneline->SetLineStyle(2);
1604 >  oneline->SetLineColor(kBlue);
1605 >  oneline->Draw("same");
1606 >
1607 >  main_canvas->cd();
1608 >  main_canvas->Modified();
1609 >  main_canvas->cd();
1610 >  main_canvas->SetSelected(main_canvas);
1611 >  
1612 >  CompleteSave(main_canvas,savemeas+"_withSysRatio");
1613 >  bottompad->cd();
1614 >  
1615 >  Double_t chi2;
1616 >  Int_t ndf,igood;
1617 >  Double_t chi2prob = MarcosChi2TestX(nominator,denominator,chi2,ndf,igood,"UW");
1618 >
1619 >  stringstream Chi2text;
1620 >  Chi2text << "#chi^{2} / ndf: " << chi2 << " / " << ndf;
1621 >  stringstream Chi2probtext;
1622 >  Chi2probtext << "#chi^{2} prob: " << chi2prob;
1623 >  TText* chi2box = write_text(0.02,0.11,Chi2text.str());
1624 >  chi2box->SetTextSize(0.08);
1625 >  chi2box->SetTextAlign(11);
1626 >  chi2box->Draw();
1627 >  TText* chi2probbox = write_text(0.02,0.04,Chi2probtext.str());
1628 >  chi2probbox->SetTextSize(0.08);
1629 >  chi2probbox->SetTextAlign(11);
1630 >  chi2probbox->Draw();
1631 >  
1632 >  stringstream CompRatio;
1633 >  CompRatio << "Ratio: " << nominator->Integral() << " / " << denominator->Integral() << " \n " << nominator->Integral()/denominator->Integral();
1634 >  TText *CompleteRatio = write_text(0.98,0.04,CompRatio.str());
1635 >  CompleteRatio->SetTextSize(0.08);
1636 >  CompleteRatio->SetTextAlign(31);
1637 >  CompleteRatio->Draw();
1638 >  
1639 >  CompleteSave(main_canvas,savemeas+"_withSysRatio_and_Chi2");
1640 >  delete main_canvas;
1641 >  delete ratio;
1642 > }
1643 >
1644 > TH1F* CollapseStack(THStack stack,TString hname="CollapsedStack") {
1645     TH1F *bhist = ((TH1F*)((stack.GetHists())->At(0)));
1646 <   TH1F *basehisto = (TH1F*)bhist->Clone("base");
1646 >   TH1F *basehisto = (TH1F*)bhist->Clone(hname);
1647     TIter next(stack.GetHists());
1648     TH1F *h;
1649     int counter=0;
# Line 1389 | Line 1655 | TH1F* CollapseStack(THStack stack) {
1655     return basehisto;
1656   }
1657  
1658 < void save_with_ratio(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) {
1659 <  save_with_ratio(nominator, CollapseStack(denominator), canvas, savemeas, do_bpred_ratio);
1658 > void Save_With_Ratio(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) {
1659 >  TH1F *denominator_histo = (TH1F*) CollapseStack(denominator);
1660 >  Save_With_Ratio(nominator, denominator_histo, canvas, savemeas, do_bpred_ratio);
1661 >  delete denominator_histo;
1662   }
1663  
1664   void flag_this_change(string function, int line, int checked=0) {
# Line 1506 | Line 1774 | void process_directory(TString directory
1774                  perror ("Couldn't open the directory");
1775   }
1776  
1777 + void ClearHisto(TH1* histo) {
1778 +    for(int ix=0;ix<=histo->GetNbinsX()+1;ix++) {//also reset over- and underflow
1779 +        histo->SetBinContent(ix,0);
1780 +        histo->SetBinContent(ix,0);
1781 +    }
1782 + }
1783 +
1784 + void AddSquared(TH1F *histo, TH1F *addthis, float weight) {
1785 +    for(int ix=1;ix<=addthis->GetNbinsX()+1;ix++) {//also include over- and underflow
1786 +        float bincenter=addthis->GetBinCenter(ix);
1787 +        int nBinHisto= histo->FindBin(bincenter);
1788 +        float old_content=histo->GetBinContent(nBinHisto);
1789 +        histo->SetBinContent(nBinHisto,old_content+((addthis->GetBinContent(ix))*(addthis->GetBinContent(ix))*weight));
1790 +    }
1791 + }
1792 +
1793 + void SQRT(TH1* histo) {
1794 +    for(int ix=0;ix<=histo->GetNbinsX()+1;ix++) {//also include over- and underflow
1795 +        histo->SetBinContent(ix,TMath::Sqrt(histo->GetBinContent(ix)));
1796 +    }
1797 + }
1798 +
1799   /*string GetCompleteHostname() {
1800    struct addrinfo hints, *info, *p;
1801    int gai_result;
# Line 1553 | Line 1843 | string removefunnystring(string name) {
1843    name=ReplaceCharacter(name,"]","_");
1844    name=ReplaceCharacter(name,"{","_");
1845    name=ReplaceCharacter(name,"}","_");
1846 +  name=ReplaceCharacter(name,"(","_");
1847 +  name=ReplaceCharacter(name,")","_");
1848 +  name=ReplaceCharacter(name," ","_");
1849    name=ReplaceCharacter(name,".","_");
1850    name=ReplaceCharacter(name,",","_");
1851    name=ReplaceCharacter(name,";","_");
# Line 1567 | Line 1860 | string removefunnystring(string name) {
1860    return name;
1861   }
1862  
1863 + TPolyLine* GetFitUncertaintyShape(TF1 *fit, float low, float high,float x0,float x1) {
1864 +  int nPoints=1000;
1865 +  double x[nPoints+1];
1866 +  double y[nPoints];
1867 +  
1868 +  float par1=fit->GetParameter(0);
1869 +  float dpar1=fit->GetParError(0);
1870 +  float par2=fit->GetParameter(1);
1871 +  float dpar2=fit->GetParError(1);
1872 +    
1873 +  float step=(x1-x0)/(nPoints/2.0 -1);
1874 +  for(int i=0;i<nPoints/2.0;i++) {
1875 +    x[i]=x0+i*step;
1876 +    y[i]=(par1+x[i]*par2)    -    sqrt(dpar1*dpar1+dpar2*dpar2*x[i]*x[i]);
1877 +    x[nPoints-1-i]=x[i];
1878 +    y[nPoints-1-i]=(par1+x[i]*par2)    +    sqrt(dpar1*dpar1+dpar2*dpar2*x[i]*x[i]);
1879 +    if(y[i]<low) y[i]=low;
1880 +    if(y[i]>high) y[i]=high;
1881 +    if(y[nPoints-1-i]<low) y[nPoints-1-i]=low;
1882 +    if(y[nPoints-1-i]>high) y[nPoints-1-i]=high;
1883 +  }
1884 +  
1885 +  x[nPoints]=x[0];
1886 +  y[nPoints]=y[0];
1887 +  
1888 +  TPolyLine *l = new TPolyLine(nPoints+1,x,y);
1889 +  l->SetFillColor(TColor::GetColor("#5858FA"));
1890 +  l->SetLineColor(TColor::GetColor("#5858FA"));
1891 +  l->SetLineWidth(1);
1892 +  return l;
1893 + }  
1894 +
1895 + //code for ReplaceAll copied from
1896 + //http://stackoverflow.com/questions/5343190/c-how-do-i-replace-all-instances-of-of-a-string-with-another-string
1897 + string ReplaceAll(string str, string from, string to) {
1898 +    size_t start_pos = 0;
1899 +    while((start_pos = str.find(from, start_pos)) != std::string::npos) {
1900 +         str.replace(start_pos, from.length(), to);
1901 +         start_pos += to.length(); // ...
1902 +    }
1903 +    return str;
1904 + }
1905 +
1906 + TPolyLine* GetFitUncertaintyShape(TH1 *histo, string fitname, float low, float high) {
1907 +  TF1 *fit = (TF1*)histo->GetFunction(fitname.c_str());
1908 +  if(!fit) {
1909 +    cout << "CANNOT PRODUCE FIT UNCERTAINTY AS THERE IS NO FIT CALLED " << fitname << " IN " << histo->GetName() << endl;
1910 +    return NULL;
1911 +  }
1912 +  float x0=histo->GetBinLowEdge(1);
1913 +  float x1=histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX());
1914 +  return GetFitUncertaintyShape(fit, low, high,x0,x1);
1915 + }
1916 +
1917 + TPolyLine* GetFitUncertaintyShape(TGraphErrors *gr, string fitname, float low, float high, float minx=-999, float maxx=-999) {
1918 +  TF1 *fit = (TF1*)gr->GetFunction(fitname.c_str());
1919 +  if(!fit) {
1920 +    cout << "CANNOT PRODUCE FIT UNCERTAINTY AS THERE IS NO FIT CALLED " << fitname << " IN " << gr->GetName() << endl;
1921 +    return NULL;
1922 +  }
1923 +  double x,y;
1924 +  gr->GetPoint(0,x,y);
1925 +  float min=x;
1926 +  gr->GetPoint(gr->GetN()-1,x,y);
1927 +  float max=x;
1928 +  if(minx>-999 && maxx>-999 && minx<maxx) {
1929 +    max=maxx;
1930 +    min=minx;
1931 +  }
1932 +  return GetFitUncertaintyShape(fit, low, high,min,max);
1933 + }
1934 +
1935   stringstream all_bugs;
1936  
1937   void bug_tracker(string function, int line, string description) {
# Line 1604 | Line 1969 | void bug_tracker(string function, int li
1969   //TODO: Write a bug summary at the end.
1970  
1971   float pSTAR(float mglu, float mlsp, float mchi2) {
1972 <        float mz=91.2;
1972 >        float mz=91.0;
1973          float res=((mchi2*mchi2)-(mlsp+mz)*(mlsp+mz));
1974          res*=((mchi2*mchi2)-(mlsp-mz)*(mlsp-mz));
1975          res=TMath::Sqrt(res)/(2*mchi2);
# Line 1617 | Line 1982 | float generalizedpSTAR(float massmother,
1982          res=TMath::Sqrt(res)/(2*massmother);
1983          return res;
1984   }
1985 +
1986 + void FindMinMax(TGraphErrors *gr, float &min, float &max) {
1987 +  double x,y;
1988 +  gr->GetPoint(0,x,y);
1989 +  min=500*y;
1990 +  max=0.0002*y;
1991 +  for(int i=0;i<gr->GetN();i++) {
1992 +    gr->GetPoint(i,x,y);
1993 +    cout << "Point at " << x << "/" << y << " with error " << gr->GetErrorY(i) << endl;
1994 +    float potmin=y-1.5*gr->GetErrorY(i); // taking 1.5 times the error to allow for enough space to present the plot
1995 +    float potmax=y+1.5*gr->GetErrorY(i); // taking 1.5 times the error to allow for enough space to present the plot
1996 +    if(potmin<min) min=potmin;
1997 +    if(potmax>max) max=potmax;
1998 +  }
1999 + }
2000 +
2001 +
2002 + void CleanLegends() {
2003 +  for(int ihist=(int)PlottingSetup::FakeHistoHeap.size()-1;ihist>=0;ihist--) {
2004 +    PlottingSetup::FakeHistoHeap[ihist]->Delete();
2005 +    PlottingSetup::FakeHistoHeap.pop_back();
2006 +  }
2007 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines