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.34 by buchmann, Thu Feb 7 14:30:09 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 < TText* WriteSelection(int njets) {
1317 > TLatex* WriteSelection(int njets) {
1318    string sel="Loose selection";
1319 <  if(njets==3) sel="Tight selection";
1319 >  if(njets==3) sel="Low E_{T}^{miss} selection";
1320    assert(njets==2||njets==3);
1321 <  TText *sele = new TText(0.97,0.135,sel.c_str());
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);
# Line 1369 | Line 1376 | void Save_With_Ratio(TH1F *nominator, TH
1376    Ratio_main_canvas->Range(0,0,1,1);
1377    Ratio_main_canvas->SetBorderSize(0);
1378    Ratio_main_canvas->SetFrameFillColor(0);
1372  
1379    mainpad->Draw();
1380    mainpad->cd();
1381    mainpad->Range(0,0,1,1);
# Line 1396 | 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);
1399
1405    TGraphAsymmErrors *eratio;
1406    TH1F *SystDown;
1407    TH1F *SystUp;
# Line 1434 | Line 1439 | void Save_With_Ratio(TH1F *nominator, TH
1439         SystUp->SetLineColor(TColor::GetColor("#006DE1"));
1440    }
1441    eratio->SetFillColor(TColor::GetColor("#00ADE1"));
1437
1442    ratio->SetTitle("");
1443    ratio->GetYaxis()->SetRangeUser(0.0,2.0);
1444    if(do_bpred_ratio) ratio->GetYaxis()->SetRangeUser(0.0,2.0);
# Line 1452 | 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    }
1461  
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 <
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();
# Line 1523 | Line 1545 | void Save_With_Ratio(TH1F *nominator, TH
1545    delete Ratio_main_canvas;
1546   }
1547  
1548 < 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) {
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    orig_canvas->cd();
1564    orig_canvas->Update();
# Line 1574 | Line 1609 | void save_with_ratio_and_sys_band(TH1F *
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  
1581  TGraphAsymmErrors *eratio;
1622    TGraphAsymmErrors *SysEnvelope = new TGraphAsymmErrors();
1623    
1624    if(syshisto && !do_bpred_ratio) {
# Line 1608 | 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    
1613  if(syshisto!=0) {
1614    SysEnvelope->SetFillColor(TColor::GetColor("#FE9A2E"));
1615    SysEnvelope->Draw("2,same");
1616    ratio->Draw("e1,same");
1617  } else {
1618    eratio->Draw("1");
1619  }
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");
1662 +  
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();
# Line 1674 | Line 1733 | TH1F* CollapseStack(THStack stack,TStrin
1733     return basehisto;
1734   }
1735  
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);
# Line 1796 | 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 1905 | 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 2030 | Line 2103 | string DigitsAfterComma(float number, in
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