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.31 by buchmann, Mon Jan 21 11:39:02 2013 UTC vs.
Revision 1.42 by buchmann, Fri May 3 09:04:24 2013 UTC

# Line 67 | Line 67 | namespace PlottingSetup {
67      bool is53reco=true;
68      bool openBox = true;
69      vector<TH1F*> FakeHistoHeap;
70 <
70 >    bool DrawMetSignalRegionMllLines=false; // whether to draw the lines in mll plots for the MET signal region
71 >    float ConsideredZWidth=20;
72   }
73  
74   bool dopng=false;
# Line 94 | Line 95 | void write_error(string funcname, string
95   void write_info(string funcname, string text);
96   string get_directory();
97   bool Contains(string wholestring, string findme);
98 + TH1F* CollapseStack(THStack stack,TString hname);
99 + TH1F* CollapseStack(THStack* stack,TString hname);
100   //-------------------------------------------------------------------------------------
101  
102   template<typename U>
# Line 597 | Line 600 | void DrawPrelim(float writelumi=generalt
600    string prel=" Preliminary";
601    if(PlottingSetup::PaperMode) prel="";
602    //prelimtext << "CMS Preliminary 2011 , #sqrt{s}= 7 TeV, L= O(1) fb^{-1}"; //temporary replacement
603 <  if(PlottingSetup::is53reco) prel += " 53X";
603 > //  if(PlottingSetup::is53reco) prel += " 53X";
604    string energy="7 TeV";
605    if(PlottingSetup::is2012) energy="8 TeV";
606    if(writelumi == 0) {
607      if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy;
608      else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy;
609    } else {
610 <    if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy << ", L_{int} = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
611 <     else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy << ", L_{int} = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
610 >    if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy << ", #scale[0.6]{#int}L dt = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
611 >     else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy << ", #scale[0.6]{#int}L dt = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
612    }
613    TPaveText *eventSelectionPaveText = new TPaveText(0.27, 0.93,0.77, 1.0,"blNDC");
614    eventSelectionPaveText->SetFillStyle(4000);
# Line 1236 | Line 1239 | bool Contains(string wholestring, string
1239    else return false;
1240   }
1241  
1242 +
1243   //////////////////////////////////////////////////////////////////////////////
1244   //
1245   // http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c
# Line 1248 | Line 1252 | bool Contains(string wholestring, string
1252   /* usage:
1253   double vm2, rss2;
1254   process_mem_usage(vm2, rss2);
1255 < cout << "Memory usage: VM: " << vm << "; RSS: " << rss << endl;
1255 > cout << "Memory usage: VM: " << vm2 << "; RSS: " << rss2 << endl;
1256   */
1257  
1258   void process_mem_usage(double& vm_usage, double& resident_set)
# Line 1307 | Line 1311 | TGraphAsymmErrors* produce_ratio_graph(T
1311   }
1312  
1313  
1314 + TLatex* WriteSelection(int njets) {
1315 +  string sel="Loose selection";
1316 +  if(njets==3) sel="Low E_{T}^{miss} selection";
1317 +  assert(njets==2||njets==3);
1318 +  TLatex *sele = new TLatex(0.97,0.135,sel.c_str());
1319 +  sele->SetNDC(true);
1320 +  sele->SetTextColor(TColor::GetColor("#848484"));
1321 +  sele->SetTextFont(42);
1322 +  sele->SetTextAlign(32);
1323 +  sele->SetTextSize(0.03);
1324 +  sele->SetTextAngle(270);
1325 +  return sele;
1326 + }
1327 +
1328   Double_t MarcosChi2TestX(const TH1* h1, const TH1* h2, Double_t &chi2, Int_t &ndf, Int_t &igood, Option_t *option)
1329   {
1330  
# Line 1329 | Line 1347 | Double_t MarcosChi2TestX(const TH1* h1,
1347     return prob;
1348   }
1349  
1350 < 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) {
1350 > 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) {
1351    //this function saves the pad being passed as well as a new one including the ratio.
1352 <  CompleteSave(canvas,savemeas);
1352 >  
1353 >  orig_canvas->cd();
1354 >  orig_canvas->Update();
1355 >  CompleteSave(orig_canvas,savemeas);
1356 >  TVirtualPad *canvas = (TVirtualPad*) orig_canvas->Clone("TempCanvas");//otherwise the Ratio_main_canvas will own our pad and destroy it upon deletion
1357    
1358    float bottommargin=gStyle->GetPadBottomMargin();
1359    float canvas_height=gStyle->GetCanvasDefH();
# Line 1343 | Line 1365 | void save_with_ratio(TH1F *nominator, TH
1365    
1366    float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace);
1367    
1368 <  TCanvas *main_canvas = new TCanvas("main_canvas","main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1368 >  TCanvas *Ratio_main_canvas = new TCanvas("Ratio_main_canvas","Ratio_main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1369    TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad
1370    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
1371    TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad
1372    
1373 <  main_canvas->Range(0,0,1,1);
1374 <  main_canvas->SetBorderSize(0);
1375 <  main_canvas->SetFrameFillColor(0);
1354 <  
1373 >  Ratio_main_canvas->Range(0,0,1,1);
1374 >  Ratio_main_canvas->SetBorderSize(0);
1375 >  Ratio_main_canvas->SetFrameFillColor(0);
1376    mainpad->Draw();
1377    mainpad->cd();
1378    mainpad->Range(0,0,1,1);
# Line 1361 | Line 1382 | void save_with_ratio(TH1F *nominator, TH
1382    canvas->Range(0,0,1,1);
1383    canvas->Draw("same");
1384    mainpad->Modified();
1385 <  main_canvas->cd();
1385 >  Ratio_main_canvas->cd();
1386    coverpad->Draw();
1387    coverpad->cd();
1388    coverpad->Range(0,0,1,1);
# Line 1369 | Line 1390 | void save_with_ratio(TH1F *nominator, TH
1390    coverpad->SetBorderSize(0);
1391    coverpad->SetFrameFillColor(0);
1392    coverpad->Modified();
1393 <  main_canvas->cd();
1393 >  Ratio_main_canvas->cd();
1394    bottompad->SetTopMargin(ratiotopmargin);
1395    bottompad->SetBottomMargin(ratiobottommargin);
1396    bottompad->Draw();
# Line 1378 | Line 1399 | void save_with_ratio(TH1F *nominator, TH
1399    bottompad->SetFillColor(kWhite);
1400    TH1F *ratio = (TH1F*)nominator->Clone(GetNumericHistoName().c_str());
1401    ratio->Divide(denominator);
1381
1402    TGraphAsymmErrors *eratio;
1403    TH1F *SystDown;
1404    TH1F *SystUp;
# Line 1416 | Line 1436 | void save_with_ratio(TH1F *nominator, TH
1436         SystUp->SetLineColor(TColor::GetColor("#006DE1"));
1437    }
1438    eratio->SetFillColor(TColor::GetColor("#00ADE1"));
1419
1439    ratio->SetTitle("");
1440    ratio->GetYaxis()->SetRangeUser(0.0,2.0);
1441    if(do_bpred_ratio) ratio->GetYaxis()->SetRangeUser(0.0,2.0);
# Line 1434 | Line 1453 | void save_with_ratio(TH1F *nominator, TH
1453    ratio->GetYaxis()->SetNdivisions(502,false);
1454    ratio->SetFillColor(TColor::GetColor("#58D3F7"));
1455    ratio->SetMarkerSize(0);
1456 <  ratio->Draw("e2");
1456 >  ratio->Draw("e20");
1457    
1458    TGraphAsymmErrors *ratio_center = (TGraphAsymmErrors*)eratio->Clone("ratio_center");
1459    for(int i=0;i<ratio_center->GetN();i++) {
1460      ratio_center->SetPointError(i,ratio_center->GetErrorXlow(i),ratio_center->GetErrorXhigh(i),0.005,0.005);
1461    }
1443  
1462    ratio_center->SetFillColor(TColor::GetColor("#006381"));
1463    
1464    if(syshisto!=0) {
1465   //    sysratio->Draw("2");
1466   //    eratio->Draw("2,same");
1467 <    eratio->Draw("2");
1467 >    eratio->Draw("20");
1468      SystDown->Draw("histo,same");
1469      SystUp->Draw("histo,same");
1470    } else {
1471 <    eratio->Draw("2");
1471 >    eratio->Draw("20");
1472    }
1473 <  ratio_center->Draw("2");
1473 >  ratio_center->Draw("20");
1474    ratio->Draw("same,axis");
1475    TLine *oneline = new TLine(ratio->GetXaxis()->GetBinLowEdge(1),1,ratio->GetXaxis()->GetBinLowEdge(ratio->GetNbinsX())+ratio->GetXaxis()->GetBinWidth(ratio->GetNbinsX()),1);
1476    oneline->SetLineStyle(2);
1477    oneline->SetLineColor(kBlue);
1478    oneline->Draw("same");
1479 <
1480 <  main_canvas->cd();
1481 <  main_canvas->Modified();
1482 <  main_canvas->cd();
1483 <  main_canvas->SetSelected(main_canvas);
1479 >  if(PlottingSetup::DrawMetSignalRegionMllLines) {
1480 >    cout << "Drawing extra lines in ratio this time around ... " << endl;
1481 >    float RatioYMax=2.0;
1482 >    if(extendrange) RatioYMax=4.0;
1483 >    
1484 >    TLine *SRline   = new TLine(70,0,70,RatioYMax);
1485 >    TLine *ZLowLine = new TLine(91.2-PlottingSetup::ConsideredZWidth,0,91.2-PlottingSetup::ConsideredZWidth,RatioYMax);
1486 >    TLine *ZHiLine  = new TLine(91.2+PlottingSetup::ConsideredZWidth,0,91.2+PlottingSetup::ConsideredZWidth,RatioYMax);
1487 >  
1488 >    SRline->SetLineStyle(2);
1489 >    ZLowLine->SetLineStyle(2);
1490 >    ZHiLine->SetLineStyle(2);
1491 >    SRline->SetLineColor(kGray+2);
1492 >    ZLowLine->SetLineColor(kGray+2);
1493 >    ZHiLine->SetLineColor(kGray+2);
1494 >    SRline->Draw();
1495 >    ZLowLine->Draw();
1496 >    ZHiLine->Draw();
1497 >  }
1498 >      
1499 >  Ratio_main_canvas->cd();
1500 >  Ratio_main_canvas->Modified();
1501 >  Ratio_main_canvas->cd();
1502 >  Ratio_main_canvas->SetSelected(Ratio_main_canvas);
1503    
1504 <  CompleteSave(main_canvas,savemeas+"_withratio");
1504 >  CompleteSave(Ratio_main_canvas,savemeas+"_withratio");
1505    bottompad->cd();
1506    
1507    Double_t chi2;
# Line 1492 | Line 1529 | void save_with_ratio(TH1F *nominator, TH
1529    CompleteRatio->SetTextAlign(31);
1530    CompleteRatio->Draw();
1531    
1532 <  CompleteSave(main_canvas,savemeas+"_withratio_and_Chi2");
1532 >  CompleteSave(Ratio_main_canvas,savemeas+"_withratio_and_Chi2");
1533  
1534   //  float KS   = nominator->KolmogorovTest(denominator);
1535   //  stringstream KStext;
# Line 1502 | Line 1539 | void save_with_ratio(TH1F *nominator, TH
1539    delete eratio;
1540    delete ratio_center;
1541    delete ratio;
1542 <  delete main_canvas;
1542 >  delete Ratio_main_canvas;
1543 > }
1544 >
1545 > 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) {
1546 >  PlottingSetup::ConsideredZWidth=10.0;
1547 >  PlottingSetup::DrawMetSignalRegionMllLines=true;
1548 >  Save_With_Ratio(nominator, denominator, orig_canvas, savemeas, do_bpred_ratio, extendrange, yaxistitle,syshisto);
1549 >  PlottingSetup::DrawMetSignalRegionMllLines=false;
1550 > }
1551 >  
1552 > void Save_With_Ratio_And_Line(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) {
1553 >  TH1F *denominator_histo = (TH1F*) CollapseStack(denominator,"TemporaryStack");
1554 >  Save_With_Ratio_And_Line(nominator, denominator_histo, canvas, savemeas, do_bpred_ratio);
1555 >  delete denominator_histo;
1556   }
1557  
1558 < 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) {
1558 > 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) {
1559    //this function saves the pad being passed as well as a new one including the SysRatio.
1560 <  CompleteSave(canvas,savemeas);
1560 >  orig_canvas->cd();
1561 >  orig_canvas->Update();
1562 >  CompleteSave(orig_canvas,savemeas);
1563 >  
1564 >  TVirtualPad *canvas = (TVirtualPad*) orig_canvas->Clone("TempCanvas");//otherwise the Ratio_main_canvas will own our pad and destroy it upon deletion
1565  
1566    float bottommargin=gStyle->GetPadBottomMargin();
1567    float canvas_height=gStyle->GetCanvasDefH();
# Line 1519 | Line 1573 | void save_with_ratio_and_sys_band(TH1F *
1573    
1574    float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace);
1575    
1576 <  TCanvas *main_canvas = new TCanvas("main_canvas","main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1576 >  TCanvas *Ratio_main_canvas = new TCanvas("Ratio_main_canvas","Ratio_main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1577    TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad
1578    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
1579    TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad
1580    
1581 <  main_canvas->Range(0,0,1,1);
1582 <  main_canvas->SetBorderSize(0);
1583 <  main_canvas->SetFrameFillColor(0);
1581 >  Ratio_main_canvas->Range(0,0,1,1);
1582 >  Ratio_main_canvas->SetBorderSize(0);
1583 >  Ratio_main_canvas->SetFrameFillColor(0);
1584    
1585    mainpad->Draw();
1586    mainpad->cd();
# Line 1537 | Line 1591 | void save_with_ratio_and_sys_band(TH1F *
1591    canvas->Range(0,0,1,1);
1592    canvas->Draw("same");
1593    mainpad->Modified();
1594 <  main_canvas->cd();
1594 >  Ratio_main_canvas->cd();
1595    coverpad->Draw();
1596    coverpad->cd();
1597    coverpad->Range(0,0,1,1);
# Line 1545 | Line 1599 | void save_with_ratio_and_sys_band(TH1F *
1599    coverpad->SetBorderSize(0);
1600    coverpad->SetFrameFillColor(0);
1601    coverpad->Modified();
1602 <  main_canvas->cd();
1602 >  Ratio_main_canvas->cd();
1603    bottompad->SetTopMargin(ratiotopmargin);
1604    bottompad->SetBottomMargin(ratiobottommargin);
1605    bottompad->Draw();
# Line 1586 | Line 1640 | void save_with_ratio_and_sys_band(TH1F *
1640    ratio->GetYaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize());
1641    ratio->GetYaxis()->SetNdivisions(502,false);
1642    ratio->SetFillColor(TColor::GetColor("#58D3F7"));
1643 <  ratio->Draw("e1");
1643 >  ratio->Draw("e0");
1644    
1645    if(syshisto!=0) {
1646      SysEnvelope->SetFillColor(TColor::GetColor("#FE9A2E"));
1647 <    SysEnvelope->Draw("2,same");
1648 <    ratio->Draw("e1,same");
1647 >    SysEnvelope->Draw("2,0,same");
1648 >    ratio->Draw("e0,same");
1649    } else {
1650 <    eratio->Draw("1");
1650 >    eratio->Draw("0");
1651    }
1652    ratio->Draw("same,axis");
1653    TLine *oneline = new TLine(ratio->GetXaxis()->GetBinLowEdge(1),1,ratio->GetXaxis()->GetBinLowEdge(ratio->GetNbinsX())+ratio->GetXaxis()->GetBinWidth(ratio->GetNbinsX()),1);
1654    oneline->SetLineStyle(2);
1655    oneline->SetLineColor(kBlue);
1656    oneline->Draw("same");
1603
1604  main_canvas->cd();
1605  main_canvas->Modified();
1606  main_canvas->cd();
1607  main_canvas->SetSelected(main_canvas);
1657    
1658 <  CompleteSave(main_canvas,savemeas+"_withSysRatio");
1658 >  
1659 >  
1660 >  if(ConsideredZWidth>0.1) {
1661 >    cout << "Drawing extra lines in ratio this time around ... " << endl;
1662 >    float RatioYMax=2.0;
1663 >    if(extendrange) RatioYMax=4.0;
1664 >    
1665 >    TLine *SRline   = new TLine(70,0,70,RatioYMax);
1666 >    TLine *ZLowLine = new TLine(91.2-ConsideredZWidth,0,91.2-ConsideredZWidth,RatioYMax);
1667 >    TLine *ZHiLine  = new TLine(91.2+ConsideredZWidth,0,91.2+ConsideredZWidth,RatioYMax);
1668 >  
1669 >    SRline->SetLineStyle(2);
1670 >    ZLowLine->SetLineStyle(2);
1671 >    ZHiLine->SetLineStyle(2);
1672 >    SRline->SetLineColor(kGray+2);
1673 >    ZLowLine->SetLineColor(kGray+2);
1674 >    ZHiLine->SetLineColor(kGray+2);
1675 >    SRline->Draw();
1676 >    ZLowLine->Draw();
1677 >    ZHiLine->Draw();
1678 >  }
1679 >
1680 >  Ratio_main_canvas->cd();
1681 >  Ratio_main_canvas->Modified();
1682 >  Ratio_main_canvas->cd();
1683 >  Ratio_main_canvas->SetSelected(Ratio_main_canvas);
1684 >  
1685 >  CompleteSave(Ratio_main_canvas,savemeas+"_withSysRatio");
1686    bottompad->cd();
1687    
1688    Double_t chi2;
# Line 1633 | Line 1709 | void save_with_ratio_and_sys_band(TH1F *
1709    CompleteRatio->SetTextAlign(31);
1710    CompleteRatio->Draw();
1711    
1712 <  CompleteSave(main_canvas,savemeas+"_withSysRatio_and_Chi2");
1713 <  delete main_canvas;
1712 >  CompleteSave(Ratio_main_canvas,savemeas+"_withSysRatio_and_Chi2");
1713 >  delete Ratio_main_canvas;
1714    delete ratio;
1715   }
1716  
# Line 1652 | Line 1728 | TH1F* CollapseStack(THStack stack,TStrin
1728     return basehisto;
1729   }
1730  
1731 < void save_with_ratio(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) {
1732 <  TH1F *denominator_histo = CollapseStack(denominator);
1733 <  save_with_ratio(nominator, denominator_histo, canvas, savemeas, do_bpred_ratio);
1731 > TH1F* CollapseStack(THStack *stack,TString hname="CollapsedStack") {
1732 >   TH1F *bhist = ((TH1F*)((stack->GetHists())->At(0)));
1733 >   TH1F *basehisto = (TH1F*)bhist->Clone(hname);
1734 >   TIter next(stack->GetHists());
1735 >   TH1F *h;
1736 >   int counter=0;
1737 >   while ((h=(TH1F*)next())) {
1738 >     counter++;
1739 >     if(counter==1) continue;
1740 >     basehisto->Add(h);
1741 >   }
1742 >   return basehisto;
1743 > }
1744 >
1745 > void Save_With_Ratio(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) {
1746 >  TH1F *denominator_histo = (TH1F*) CollapseStack(denominator);
1747 >  Save_With_Ratio(nominator, denominator_histo, canvas, savemeas, do_bpred_ratio);
1748    delete denominator_histo;
1749   }
1750  
# Line 1883 | Line 1973 | TPolyLine* GetFitUncertaintyShape(TF1 *f
1973    y[nPoints]=y[0];
1974    
1975    TPolyLine *l = new TPolyLine(nPoints+1,x,y);
1976 <  l->SetFillColor(TColor::GetColor("#5858FA"));
1977 <  l->SetLineColor(TColor::GetColor("#5858FA"));
1976 >  l->SetFillColor(TColor::GetColor("#A2A2FA"));
1977 >  l->SetLineColor(TColor::GetColor("#A2A2FA"));
1978    l->SetLineWidth(1);
1979    return l;
1980   }  
# Line 2002 | Line 2092 | void CleanLegends() {
2092      PlottingSetup::FakeHistoHeap.pop_back();
2093    }
2094   }
2095 +
2096 + string DigitsAfterComma(float number, int digits) {
2097 +  float temp=number*pow(10.0,digits);
2098 +  temp=int(temp)/pow(10.0,digits);
2099 +  return any2string(temp);
2100 + }
2101 +
2102 +
2103 + float GetYield(TH1F *histo, float min, float max) {
2104 +  float res=0.0;
2105 +  for(int i=1;i<=histo->GetNbinsX();i++) {
2106 +      if(histo->GetBinLowEdge(i)+histo->GetBinWidth(i)<=min) continue;// considered in the next bin
2107 +      if(histo->GetBinLowEdge(i)>=max) continue;//above the threshold, out!
2108 + //      cout << "         added yield for bin [" << histo->GetBinLowEdge(i) << "," << histo->GetBinLowEdge(i)+histo->GetBinWidth(i) << "] which is " << histo->GetBinContent(i) << "   in GetYield" << endl;
2109 +      res+=histo->GetBinContent(i);
2110 +  }
2111 +  return res;
2112 + }
2113 +
2114 + void ProduceYields(float min, float max, TH1F *data, THStack *stack) {
2115 +  dout << "   *************** <MC YIELDS> ********* " << endl;
2116 +  dout << "   Considering " << min << " < mll < " << max << "           " << endl;
2117 +  dout << "   Data : " << GetYield(data,min,max)  << endl;
2118 +  TIter nextSF(stack->GetHists());
2119 +  TH1F* h;
2120 +  while ( h = (TH1F*)nextSF() ) {
2121 +    dout << "   " << h->GetName() << " : " << GetYield(h,min,max)  << endl;
2122 +  }
2123 +  dout << "   *************** </MC YIELDS> ********* " << endl;
2124 + }
2125 +
2126 +  
2127 + void WriteYield(THStack *mc, float low, float high) {
2128 +  TH1F *h;
2129 +  TIter NextHisto(mc->GetHists());
2130 +  while ( h = (TH1F*)NextHisto() ) {
2131 +    float CurrBKG=0;
2132 +    float CurrBKGErr=0;
2133 +    for(int i=1;i<=h->GetNbinsX()+1;i++) {
2134 +      if(h->GetBinLowEdge(i)+h->GetBinWidth(i)<=low) continue;// considered in the next bin
2135 +      if(h->GetBinLowEdge(i)>=high) continue;//above the threshold, out!
2136 +      CurrBKG+=h->GetBinContent(i);
2137 +      CurrBKGErr=sqrt(CurrBKGErr*CurrBKGErr+h->GetBinError(i)*h->GetBinError(i));
2138 +    }
2139 +    dout << "      " << h->GetName() << " : " << CurrBKG << " +/- " << CurrBKGErr << endl;
2140 +  }
2141 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines