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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines