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.28 by buchmann, Wed Jan 16 17:11:23 2013 UTC vs.
Revision 1.45 by buchmann, Thu Jun 13 16:04:18 2013 UTC

# Line 42 | Line 42
42   #include <TROOT.h>
43   #include <TPolyLine.h>
44  
45 + #include "ValueClass.C"
46   #ifndef Verbosity
47   #define Verbosity 0
48   #endif
# Line 67 | Line 68 | namespace PlottingSetup {
68      bool is53reco=true;
69      bool openBox = true;
70      vector<TH1F*> FakeHistoHeap;
71 <
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;
# Line 94 | Line 97 | void write_error(string funcname, string
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>
# Line 339 | Line 344 | void extract_cbaf_dir(string curpath) {
344    if(position<0) position=curpath.find("/DistributedModelCalculations");
345    if(position<0) position=curpath.find("/various_assignments");
346    if(position<0) position=curpath.find("/exchange");
347 +  if(position<0) position=curpath.find("/iJZB");
348    PlottingSetup::cbafbasedir=curpath.substr(0,position);
349   }
350  
# Line 597 | Line 603 | void DrawPrelim(float writelumi=generalt
603    string prel=" Preliminary";
604    if(PlottingSetup::PaperMode) prel="";
605    //prelimtext << "CMS Preliminary 2011 , #sqrt{s}= 7 TeV, L= O(1) fb^{-1}"; //temporary replacement
606 <  if(PlottingSetup::is53reco) prel += " 53X";
606 > //  if(PlottingSetup::is53reco) prel += " 53X";
607    string energy="7 TeV";
608    if(PlottingSetup::is2012) energy="8 TeV";
609    if(writelumi == 0) {
610      if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy;
611      else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy;
612    } else {
613 <    if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy << ", L_{int} = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
614 <     else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy << ", L_{int} = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
613 >    if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy << ", #scale[0.6]{#int}L dt = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
614 >     else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy << ", #scale[0.6]{#int}L dt = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
615    }
616    TPaveText *eventSelectionPaveText = new TPaveText(0.27, 0.93,0.77, 1.0,"blNDC");
617    eventSelectionPaveText->SetFillStyle(4000);
# Line 1236 | Line 1242 | bool Contains(string wholestring, string
1242    else return false;
1243   }
1244  
1245 +
1246   //////////////////////////////////////////////////////////////////////////////
1247   //
1248   // http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c
# Line 1248 | Line 1255 | bool Contains(string wholestring, string
1255   /* usage:
1256   double vm2, rss2;
1257   process_mem_usage(vm2, rss2);
1258 < cout << "Memory usage: VM: " << vm << "; RSS: " << rss << endl;
1258 > cout << "Memory usage: VM: " << vm2 << "; RSS: " << rss2 << endl;
1259   */
1260  
1261   void process_mem_usage(double& vm_usage, double& resident_set)
# Line 1307 | Line 1314 | TGraphAsymmErrors* produce_ratio_graph(T
1314   }
1315  
1316  
1317 + TLatex* WriteSelection(int njets) {
1318 +  string sel="Loose selection";
1319 +  if(njets==3) sel="Low E_{T}^{miss} selection";
1320 +  assert(njets==2||njets==3);
1321 +  TLatex *sele = new TLatex(0.97,0.135,sel.c_str());
1322 +  sele->SetNDC(true);
1323 +  sele->SetTextColor(TColor::GetColor("#848484"));
1324 +  sele->SetTextFont(42);
1325 +  sele->SetTextAlign(32);
1326 +  sele->SetTextSize(0.03);
1327 +  sele->SetTextAngle(270);
1328 +  return sele;
1329 + }
1330 +
1331   Double_t MarcosChi2TestX(const TH1* h1, const TH1* h2, Double_t &chi2, Int_t &ndf, Int_t &igood, Option_t *option)
1332   {
1333  
# Line 1329 | Line 1350 | Double_t MarcosChi2TestX(const TH1* h1,
1350     return prob;
1351   }
1352  
1353 < 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) {
1353 > 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) {
1354    //this function saves the pad being passed as well as a new one including the ratio.
1355 <  CompleteSave(canvas,savemeas);
1356 <
1355 >  
1356 >  orig_canvas->cd();
1357 >  orig_canvas->Update();
1358 >  CompleteSave(orig_canvas,savemeas);
1359 >  TVirtualPad *canvas = (TVirtualPad*) orig_canvas->Clone("TempCanvas");//otherwise the Ratio_main_canvas will own our pad and destroy it upon deletion
1360 >  
1361    float bottommargin=gStyle->GetPadBottomMargin();
1362    float canvas_height=gStyle->GetCanvasDefH();
1363    float canvas_width=gStyle->GetCanvasDefW();
# Line 1343 | Line 1368 | void save_with_ratio(TH1F *nominator, TH
1368    
1369    float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace);
1370    
1371 <  TCanvas *main_canvas = new TCanvas("main_canvas","main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1371 >  TCanvas *Ratio_main_canvas = new TCanvas("Ratio_main_canvas","Ratio_main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1372    TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad
1373    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
1374    TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad
1375    
1376 <  main_canvas->Range(0,0,1,1);
1377 <  main_canvas->SetBorderSize(0);
1378 <  main_canvas->SetFrameFillColor(0);
1354 <  
1376 >  Ratio_main_canvas->Range(0,0,1,1);
1377 >  Ratio_main_canvas->SetBorderSize(0);
1378 >  Ratio_main_canvas->SetFrameFillColor(0);
1379    mainpad->Draw();
1380    mainpad->cd();
1381    mainpad->Range(0,0,1,1);
# Line 1361 | Line 1385 | void save_with_ratio(TH1F *nominator, TH
1385    canvas->Range(0,0,1,1);
1386    canvas->Draw("same");
1387    mainpad->Modified();
1388 <  main_canvas->cd();
1388 >  Ratio_main_canvas->cd();
1389    coverpad->Draw();
1390    coverpad->cd();
1391    coverpad->Range(0,0,1,1);
# Line 1369 | Line 1393 | void save_with_ratio(TH1F *nominator, TH
1393    coverpad->SetBorderSize(0);
1394    coverpad->SetFrameFillColor(0);
1395    coverpad->Modified();
1396 <  main_canvas->cd();
1396 >  Ratio_main_canvas->cd();
1397    bottompad->SetTopMargin(ratiotopmargin);
1398    bottompad->SetBottomMargin(ratiobottommargin);
1399    bottompad->Draw();
# Line 1378 | Line 1402 | void save_with_ratio(TH1F *nominator, TH
1402    bottompad->SetFillColor(kWhite);
1403    TH1F *ratio = (TH1F*)nominator->Clone(GetNumericHistoName().c_str());
1404    ratio->Divide(denominator);
1381
1405    TGraphAsymmErrors *eratio;
1406    TH1F *SystDown;
1407    TH1F *SystUp;
# Line 1416 | Line 1439 | void save_with_ratio(TH1F *nominator, TH
1439         SystUp->SetLineColor(TColor::GetColor("#006DE1"));
1440    }
1441    eratio->SetFillColor(TColor::GetColor("#00ADE1"));
1419
1442    ratio->SetTitle("");
1443    ratio->GetYaxis()->SetRangeUser(0.0,2.0);
1444    if(do_bpred_ratio) ratio->GetYaxis()->SetRangeUser(0.0,2.0);
# Line 1434 | Line 1456 | void save_with_ratio(TH1F *nominator, TH
1456    ratio->GetYaxis()->SetNdivisions(502,false);
1457    ratio->SetFillColor(TColor::GetColor("#58D3F7"));
1458    ratio->SetMarkerSize(0);
1459 <  ratio->Draw("e2");
1459 >  ratio->Draw("e20");
1460    
1461    TGraphAsymmErrors *ratio_center = (TGraphAsymmErrors*)eratio->Clone("ratio_center");
1462    for(int i=0;i<ratio_center->GetN();i++) {
1463      ratio_center->SetPointError(i,ratio_center->GetErrorXlow(i),ratio_center->GetErrorXhigh(i),0.005,0.005);
1464    }
1443  
1465    ratio_center->SetFillColor(TColor::GetColor("#006381"));
1466    
1467    if(syshisto!=0) {
1468   //    sysratio->Draw("2");
1469   //    eratio->Draw("2,same");
1470 <    eratio->Draw("2");
1470 >    eratio->Draw("20");
1471      SystDown->Draw("histo,same");
1472      SystUp->Draw("histo,same");
1473    } else {
1474 <    eratio->Draw("2");
1474 >    eratio->Draw("20");
1475    }
1476 <  ratio_center->Draw("2");
1476 >  ratio_center->Draw("20");
1477    ratio->Draw("same,axis");
1478    TLine *oneline = new TLine(ratio->GetXaxis()->GetBinLowEdge(1),1,ratio->GetXaxis()->GetBinLowEdge(ratio->GetNbinsX())+ratio->GetXaxis()->GetBinWidth(ratio->GetNbinsX()),1);
1479    oneline->SetLineStyle(2);
1480    oneline->SetLineColor(kBlue);
1481    oneline->Draw("same");
1482 <
1483 <  main_canvas->cd();
1484 <  main_canvas->Modified();
1485 <  main_canvas->cd();
1486 <  main_canvas->SetSelected(main_canvas);
1482 >  if(PlottingSetup::DrawMetSignalRegionMllLines) {
1483 >    cout << "Drawing extra lines in ratio this time around ... " << endl;
1484 >    float RatioYMax=2.0;
1485 >    if(extendrange) RatioYMax=4.0;
1486 >    
1487 >    TLine *SRline   = new TLine(70,0,70,RatioYMax);
1488 >    TLine *ZLowLine = new TLine(91.2-PlottingSetup::ConsideredZWidth,0,91.2-PlottingSetup::ConsideredZWidth,RatioYMax);
1489 >    TLine *ZHiLine  = new TLine(91.2+PlottingSetup::ConsideredZWidth,0,91.2+PlottingSetup::ConsideredZWidth,RatioYMax);
1490 >  
1491 >    SRline->SetLineStyle(2);
1492 >    ZLowLine->SetLineStyle(2);
1493 >    ZHiLine->SetLineStyle(2);
1494 >    SRline->SetLineColor(kGray+2);
1495 >    ZLowLine->SetLineColor(kGray+2);
1496 >    ZHiLine->SetLineColor(kGray+2);
1497 >    SRline->Draw();
1498 >    ZLowLine->Draw();
1499 >    ZHiLine->Draw();
1500 >  }
1501 >      
1502 >  Ratio_main_canvas->cd();
1503 >  Ratio_main_canvas->Modified();
1504 >  Ratio_main_canvas->cd();
1505 >  Ratio_main_canvas->SetSelected(Ratio_main_canvas);
1506    
1507 <  CompleteSave(main_canvas,savemeas+"_withratio");
1507 >  CompleteSave(Ratio_main_canvas,savemeas+"_withratio");
1508    bottompad->cd();
1509    
1510    Double_t chi2;
# Line 1492 | Line 1532 | void save_with_ratio(TH1F *nominator, TH
1532    CompleteRatio->SetTextAlign(31);
1533    CompleteRatio->Draw();
1534    
1535 <  CompleteSave(main_canvas,savemeas+"_withratio_and_Chi2");
1535 >  CompleteSave(Ratio_main_canvas,savemeas+"_withratio_and_Chi2");
1536  
1537   //  float KS   = nominator->KolmogorovTest(denominator);
1538   //  stringstream KStext;
1539   //  Chi2text << "KS = " << KS << endl;
1540   //cout << "Found : " << KStext.str() << endl;
1541  
1542 <  delete main_canvas;
1542 >  delete eratio;
1543 >  delete ratio_center;
1544 >  delete ratio;
1545 >  delete Ratio_main_canvas;
1546   }
1547  
1548 < void save_with_ratio_and_sys_band(TH1F *nominator, TH1F *denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false, bool extendrange=false, string yaxistitle="ratio",TH1F *syshisto=NULL) {
1548 > 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) {
1549 >  PlottingSetup::ConsideredZWidth=10.0;
1550 >  PlottingSetup::DrawMetSignalRegionMllLines=true;
1551 >  Save_With_Ratio(nominator, denominator, orig_canvas, savemeas, do_bpred_ratio, extendrange, yaxistitle,syshisto);
1552 >  PlottingSetup::DrawMetSignalRegionMllLines=false;
1553 > }
1554 >  
1555 > void Save_With_Ratio_And_Line(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) {
1556 >  TH1F *denominator_histo = (TH1F*) CollapseStack(denominator,"TemporaryStack");
1557 >  Save_With_Ratio_And_Line(nominator, denominator_histo, canvas, savemeas, do_bpred_ratio);
1558 >  delete denominator_histo;
1559 > }
1560 >
1561 > 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) {
1562    //this function saves the pad being passed as well as a new one including the SysRatio.
1563 <  CompleteSave(canvas,savemeas);
1563 >  orig_canvas->cd();
1564 >  orig_canvas->Update();
1565 >  CompleteSave(orig_canvas,savemeas);
1566 >  
1567 >  TVirtualPad *canvas = (TVirtualPad*) orig_canvas->Clone("TempCanvas");//otherwise the Ratio_main_canvas will own our pad and destroy it upon deletion
1568  
1569    float bottommargin=gStyle->GetPadBottomMargin();
1570    float canvas_height=gStyle->GetCanvasDefH();
# Line 1516 | Line 1576 | void save_with_ratio_and_sys_band(TH1F *
1576    
1577    float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace);
1578    
1579 <  TCanvas *main_canvas = new TCanvas("main_canvas","main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1579 >  TCanvas *Ratio_main_canvas = new TCanvas("Ratio_main_canvas","Ratio_main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1580    TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad
1581    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
1582    TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad
1583    
1584 <  main_canvas->Range(0,0,1,1);
1585 <  main_canvas->SetBorderSize(0);
1586 <  main_canvas->SetFrameFillColor(0);
1584 >  Ratio_main_canvas->Range(0,0,1,1);
1585 >  Ratio_main_canvas->SetBorderSize(0);
1586 >  Ratio_main_canvas->SetFrameFillColor(0);
1587    
1588    mainpad->Draw();
1589    mainpad->cd();
# Line 1534 | Line 1594 | void save_with_ratio_and_sys_band(TH1F *
1594    canvas->Range(0,0,1,1);
1595    canvas->Draw("same");
1596    mainpad->Modified();
1597 <  main_canvas->cd();
1597 >  Ratio_main_canvas->cd();
1598    coverpad->Draw();
1599    coverpad->cd();
1600    coverpad->Range(0,0,1,1);
# Line 1542 | Line 1602 | void save_with_ratio_and_sys_band(TH1F *
1602    coverpad->SetBorderSize(0);
1603    coverpad->SetFrameFillColor(0);
1604    coverpad->Modified();
1605 <  main_canvas->cd();
1605 >  Ratio_main_canvas->cd();
1606    bottompad->SetTopMargin(ratiotopmargin);
1607    bottompad->SetBottomMargin(ratiobottommargin);
1608    bottompad->Draw();
1609    bottompad->cd();
1610    bottompad->Range(0,0,1,1);
1611    bottompad->SetFillColor(kWhite);
1612 +  
1613    TH1F *ratio = (TH1F*)nominator->Clone(GetNumericHistoName().c_str());
1614    ratio->Divide(denominator);
1615 +  for(int i=1;i<=ratio->GetNbinsX();i++) {
1616 +    if(denominator->GetBinContent(i)==0) {
1617 +      ratio->SetBinContent(i,-1);
1618 +    }
1619 +  }
1620  
1621  
1556  TGraphAsymmErrors *eratio;
1622    TGraphAsymmErrors *SysEnvelope = new TGraphAsymmErrors();
1623    
1624    if(syshisto && !do_bpred_ratio) {
# Line 1583 | Line 1648 | void save_with_ratio_and_sys_band(TH1F *
1648    ratio->GetYaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize());
1649    ratio->GetYaxis()->SetNdivisions(502,false);
1650    ratio->SetFillColor(TColor::GetColor("#58D3F7"));
1651 <  ratio->Draw("e1");
1651 >  ratio->Draw("e0");
1652 >  
1653 >  SysEnvelope->SetFillColor(TColor::GetColor("#FE9A2E"));
1654 >  SysEnvelope->Draw("2,0,same");
1655 >  ratio->Draw("e0,same");
1656    
1588  if(syshisto!=0) {
1589    SysEnvelope->SetFillColor(TColor::GetColor("#FE9A2E"));
1590    SysEnvelope->Draw("2,same");
1591    ratio->Draw("e1,same");
1592  } else {
1593    eratio->Draw("1");
1594  }
1657    ratio->Draw("same,axis");
1658    TLine *oneline = new TLine(ratio->GetXaxis()->GetBinLowEdge(1),1,ratio->GetXaxis()->GetBinLowEdge(ratio->GetNbinsX())+ratio->GetXaxis()->GetBinWidth(ratio->GetNbinsX()),1);
1659    oneline->SetLineStyle(2);
1660    oneline->SetLineColor(kBlue);
1661    oneline->Draw("same");
1600
1601  main_canvas->cd();
1602  main_canvas->Modified();
1603  main_canvas->cd();
1604  main_canvas->SetSelected(main_canvas);
1662    
1663 <  CompleteSave(main_canvas,savemeas+"_withSysRatio");
1663 >  
1664 >  
1665 >  if(ConsideredZWidth>0.1) {
1666 >    cout << "Drawing extra lines in ratio this time around ... " << endl;
1667 >    float RatioYMax=2.0;
1668 >    if(extendrange) RatioYMax=4.0;
1669 >    
1670 >    TLine *SRline   = new TLine(70,0,70,RatioYMax);
1671 >    TLine *ZLowLine = new TLine(91.2-ConsideredZWidth,0,91.2-ConsideredZWidth,RatioYMax);
1672 >    TLine *ZHiLine  = new TLine(91.2+ConsideredZWidth,0,91.2+ConsideredZWidth,RatioYMax);
1673 >  
1674 >    SRline->SetLineStyle(2);
1675 >    ZLowLine->SetLineStyle(2);
1676 >    ZHiLine->SetLineStyle(2);
1677 >    SRline->SetLineColor(kGray+2);
1678 >    ZLowLine->SetLineColor(kGray+2);
1679 >    ZHiLine->SetLineColor(kGray+2);
1680 >    SRline->Draw();
1681 >    ZLowLine->Draw();
1682 >    ZHiLine->Draw();
1683 >  }
1684 >
1685 >  Ratio_main_canvas->cd();
1686 >  Ratio_main_canvas->Modified();
1687 >  Ratio_main_canvas->cd();
1688 >  Ratio_main_canvas->SetSelected(Ratio_main_canvas);
1689 >  
1690 >  CompleteSave(Ratio_main_canvas,savemeas+"_withSysRatio");
1691    bottompad->cd();
1692    
1693    Double_t chi2;
# Line 1630 | Line 1714 | void save_with_ratio_and_sys_band(TH1F *
1714    CompleteRatio->SetTextAlign(31);
1715    CompleteRatio->Draw();
1716    
1717 <  CompleteSave(main_canvas,savemeas+"_withSysRatio_and_Chi2");
1718 <  delete main_canvas;
1717 >  CompleteSave(Ratio_main_canvas,savemeas+"_withSysRatio_and_Chi2");
1718 >  delete Ratio_main_canvas;
1719 >  delete ratio;
1720   }
1721  
1722 < TH1F* CollapseStack(THStack stack,TString hname="base") {
1722 > TH1F* CollapseStack(THStack stack,TString hname="CollapsedStack") {
1723     TH1F *bhist = ((TH1F*)((stack.GetHists())->At(0)));
1724     TH1F *basehisto = (TH1F*)bhist->Clone(hname);
1725     TIter next(stack.GetHists());
# Line 1648 | Line 1733 | TH1F* CollapseStack(THStack stack,TStrin
1733     return basehisto;
1734   }
1735  
1736 < void save_with_ratio(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) {
1737 <  save_with_ratio(nominator, CollapseStack(denominator), canvas, savemeas, do_bpred_ratio);
1736 > TH1F* CollapseStack(THStack *stack,TString hname="CollapsedStack") {
1737 >   TH1F *bhist = ((TH1F*)((stack->GetHists())->At(0)));
1738 >   TH1F *basehisto = (TH1F*)bhist->Clone(hname);
1739 >   TIter next(stack->GetHists());
1740 >   TH1F *h;
1741 >   int counter=0;
1742 >   while ((h=(TH1F*)next())) {
1743 >     counter++;
1744 >     if(counter==1) continue;
1745 >     basehisto->Add(h);
1746 >   }
1747 >   return basehisto;
1748 > }
1749 >
1750 > void Save_With_Ratio(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) {
1751 >  TH1F *denominator_histo = (TH1F*) CollapseStack(denominator);
1752 >  Save_With_Ratio(nominator, denominator_histo, canvas, savemeas, do_bpred_ratio);
1753 >  delete denominator_histo;
1754   }
1755  
1756   void flag_this_change(string function, int line, int checked=0) {
# Line 1768 | Line 1869 | void process_directory(TString directory
1869   void ClearHisto(TH1* histo) {
1870      for(int ix=0;ix<=histo->GetNbinsX()+1;ix++) {//also reset over- and underflow
1871          histo->SetBinContent(ix,0);
1872 <        histo->SetBinContent(ix,0);
1872 >        histo->SetBinError(ix,0);
1873      }
1874   }
1875  
# Line 1877 | Line 1978 | TPolyLine* GetFitUncertaintyShape(TF1 *f
1978    y[nPoints]=y[0];
1979    
1980    TPolyLine *l = new TPolyLine(nPoints+1,x,y);
1981 <  l->SetFillColor(TColor::GetColor("#5858FA"));
1982 <  l->SetLineColor(TColor::GetColor("#5858FA"));
1981 >  l->SetFillColor(TColor::GetColor("#A2A2FA"));
1982 >  l->SetLineColor(TColor::GetColor("#A2A2FA"));
1983    l->SetLineWidth(1);
1984    return l;
1985   }  
# Line 1991 | Line 2092 | void FindMinMax(TGraphErrors *gr, float
2092  
2093  
2094   void CleanLegends() {
1994  cout << "----------------------- before deleting anything -----------------------" << endl;
1995  gROOT->ls();
1996  cout << "---------------------- /before deleting anything -----------------------" << endl;
1997  
2095    for(int ihist=(int)PlottingSetup::FakeHistoHeap.size()-1;ihist>=0;ihist--) {
1999    cout << "Deleting item " << ihist << endl;
2000    cout << "    " << PlottingSetup::FakeHistoHeap[ihist]->GetName() << " , " << PlottingSetup::FakeHistoHeap[ihist]->GetTitle() << endl;
2096      PlottingSetup::FakeHistoHeap[ihist]->Delete();
2097      PlottingSetup::FakeHistoHeap.pop_back();
2098    }
2099   }
2100 +
2101 + string DigitsAfterComma(float number, int digits) {
2102 +  float temp=number*pow(10.0,digits);
2103 +  temp=int(temp)/pow(10.0,digits);
2104 +  return any2string(temp);
2105 + }
2106 +
2107 +
2108 + Value GetYield(TH1F *histo, float min, float max) {
2109 +  float res=0.0;
2110 +  float reserr=0.0;
2111 +  for(int i=1;i<=histo->GetNbinsX();i++) {
2112 +      if(histo->GetBinLowEdge(i)+histo->GetBinWidth(i)<=min) continue;// considered in the next bin
2113 +      if(histo->GetBinLowEdge(i)>=max) continue;//above the threshold, out!
2114 + //      cout << "         added yield for bin [" << histo->GetBinLowEdge(i) << "," << histo->GetBinLowEdge(i)+histo->GetBinWidth(i) << "] which is " << histo->GetBinContent(i) << "   in GetYield" << endl;
2115 +      res+=histo->GetBinContent(i);
2116 +      reserr=sqrt(reserr*reserr+histo->GetBinError(i)*histo->GetBinError(i));
2117 +  }
2118 +  return Value(res,reserr);
2119 + }
2120 +
2121 + void ProduceYields(float min, float max, TH1F *data, THStack *stack) {
2122 +  dout << "   *************** <MC YIELDS> ********* " << endl;
2123 +  dout << "   Considering " << min << " < mll < " << max << "           " << endl;
2124 +  dout << "   Data : " << GetYield(data,min,max)  << endl;
2125 +  TIter nextSF(stack->GetHists());
2126 +  TH1F* h;
2127 +  while ( h = (TH1F*)nextSF() ) {
2128 +    dout << "   " << h->GetName() << " : " << GetYield(h,min,max)  << endl;
2129 +  }
2130 +  dout << "   *************** </MC YIELDS> ********* " << endl;
2131 + }
2132 +
2133 +  
2134 + vector<pair<string,Value> > WriteYield(THStack *mc, float low, float high, bool quiet=false) {
2135 +  TH1F *h;
2136 +  vector<pair<string,Value> > result;
2137 +  TIter NextHisto(mc->GetHists());
2138 +  while ( h = (TH1F*)NextHisto() ) {
2139 +    float CurrBKG=0;
2140 +    float CurrBKGErr=0;
2141 +    for(int i=1;i<=h->GetNbinsX()+1;i++) {
2142 +      if(h->GetBinLowEdge(i)+h->GetBinWidth(i)<=low) continue;// considered in the next bin
2143 +      if(h->GetBinLowEdge(i)>=high) continue;//above the threshold, out!
2144 +      CurrBKG+=h->GetBinContent(i);
2145 +      CurrBKGErr=sqrt(CurrBKGErr*CurrBKGErr+h->GetBinError(i)*h->GetBinError(i));
2146 +    }
2147 +    if(!quiet) dout << "      " << h->GetName() << " : " << CurrBKG << " +/- " << CurrBKGErr << endl;
2148 +    result.push_back(make_pair((string)h->GetName(),Value(CurrBKG,CurrBKGErr)));
2149 +  }
2150 +  
2151 +  return result;
2152 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines