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.43 by buchmann, Sun May 12 20:22:53 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   }
74  
75   bool dopng=false;
# Line 94 | Line 96 | void write_error(string funcname, string
96   void write_info(string funcname, string text);
97   string get_directory();
98   bool Contains(string wholestring, string findme);
99 + TH1F* CollapseStack(THStack stack,TString hname);
100 + TH1F* CollapseStack(THStack* stack,TString hname);
101   //-------------------------------------------------------------------------------------
102  
103   template<typename U>
# Line 597 | Line 601 | void DrawPrelim(float writelumi=generalt
601    string prel=" Preliminary";
602    if(PlottingSetup::PaperMode) prel="";
603    //prelimtext << "CMS Preliminary 2011 , #sqrt{s}= 7 TeV, L= O(1) fb^{-1}"; //temporary replacement
604 <  if(PlottingSetup::is53reco) prel += " 53X";
604 > //  if(PlottingSetup::is53reco) prel += " 53X";
605    string energy="7 TeV";
606    if(PlottingSetup::is2012) energy="8 TeV";
607    if(writelumi == 0) {
608      if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy;
609      else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy;
610    } else {
611 <    if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy << ", L_{int} = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
612 <     else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy << ", L_{int} = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
611 >    if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy << ", #scale[0.6]{#int}L dt = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
612 >     else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy << ", #scale[0.6]{#int}L dt = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
613    }
614    TPaveText *eventSelectionPaveText = new TPaveText(0.27, 0.93,0.77, 1.0,"blNDC");
615    eventSelectionPaveText->SetFillStyle(4000);
# Line 1236 | Line 1240 | bool Contains(string wholestring, string
1240    else return false;
1241   }
1242  
1243 +
1244   //////////////////////////////////////////////////////////////////////////////
1245   //
1246   // http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c
# Line 1248 | Line 1253 | bool Contains(string wholestring, string
1253   /* usage:
1254   double vm2, rss2;
1255   process_mem_usage(vm2, rss2);
1256 < cout << "Memory usage: VM: " << vm << "; RSS: " << rss << endl;
1256 > cout << "Memory usage: VM: " << vm2 << "; RSS: " << rss2 << endl;
1257   */
1258  
1259   void process_mem_usage(double& vm_usage, double& resident_set)
# Line 1307 | Line 1312 | TGraphAsymmErrors* produce_ratio_graph(T
1312   }
1313  
1314  
1315 < TText* WriteSelection(int njets) {
1315 > TLatex* WriteSelection(int njets) {
1316    string sel="Loose selection";
1317 <  if(njets==3) sel="Tight selection";
1317 >  if(njets==3) sel="Low E_{T}^{miss} selection";
1318    assert(njets==2||njets==3);
1319 <  TText *sele = new TText(0.97,0.135,sel.c_str());
1319 >  TLatex *sele = new TLatex(0.97,0.135,sel.c_str());
1320    sele->SetNDC(true);
1321    sele->SetTextColor(TColor::GetColor("#848484"));
1322    sele->SetTextFont(42);
# Line 1369 | Line 1374 | void Save_With_Ratio(TH1F *nominator, TH
1374    Ratio_main_canvas->Range(0,0,1,1);
1375    Ratio_main_canvas->SetBorderSize(0);
1376    Ratio_main_canvas->SetFrameFillColor(0);
1372  
1377    mainpad->Draw();
1378    mainpad->cd();
1379    mainpad->Range(0,0,1,1);
# Line 1396 | Line 1400 | void Save_With_Ratio(TH1F *nominator, TH
1400    bottompad->SetFillColor(kWhite);
1401    TH1F *ratio = (TH1F*)nominator->Clone(GetNumericHistoName().c_str());
1402    ratio->Divide(denominator);
1399
1403    TGraphAsymmErrors *eratio;
1404    TH1F *SystDown;
1405    TH1F *SystUp;
# Line 1434 | Line 1437 | void Save_With_Ratio(TH1F *nominator, TH
1437         SystUp->SetLineColor(TColor::GetColor("#006DE1"));
1438    }
1439    eratio->SetFillColor(TColor::GetColor("#00ADE1"));
1437
1440    ratio->SetTitle("");
1441    ratio->GetYaxis()->SetRangeUser(0.0,2.0);
1442    if(do_bpred_ratio) ratio->GetYaxis()->SetRangeUser(0.0,2.0);
# Line 1452 | Line 1454 | void Save_With_Ratio(TH1F *nominator, TH
1454    ratio->GetYaxis()->SetNdivisions(502,false);
1455    ratio->SetFillColor(TColor::GetColor("#58D3F7"));
1456    ratio->SetMarkerSize(0);
1457 <  ratio->Draw("e2");
1457 >  ratio->Draw("e20");
1458    
1459    TGraphAsymmErrors *ratio_center = (TGraphAsymmErrors*)eratio->Clone("ratio_center");
1460    for(int i=0;i<ratio_center->GetN();i++) {
1461      ratio_center->SetPointError(i,ratio_center->GetErrorXlow(i),ratio_center->GetErrorXhigh(i),0.005,0.005);
1462    }
1461  
1463    ratio_center->SetFillColor(TColor::GetColor("#006381"));
1464    
1465    if(syshisto!=0) {
1466   //    sysratio->Draw("2");
1467   //    eratio->Draw("2,same");
1468 <    eratio->Draw("2");
1468 >    eratio->Draw("20");
1469      SystDown->Draw("histo,same");
1470      SystUp->Draw("histo,same");
1471    } else {
1472 <    eratio->Draw("2");
1472 >    eratio->Draw("20");
1473    }
1474 <  ratio_center->Draw("2");
1474 >  ratio_center->Draw("20");
1475    ratio->Draw("same,axis");
1476    TLine *oneline = new TLine(ratio->GetXaxis()->GetBinLowEdge(1),1,ratio->GetXaxis()->GetBinLowEdge(ratio->GetNbinsX())+ratio->GetXaxis()->GetBinWidth(ratio->GetNbinsX()),1);
1477    oneline->SetLineStyle(2);
1478    oneline->SetLineColor(kBlue);
1479    oneline->Draw("same");
1480 <
1480 >  if(PlottingSetup::DrawMetSignalRegionMllLines) {
1481 >    cout << "Drawing extra lines in ratio this time around ... " << endl;
1482 >    float RatioYMax=2.0;
1483 >    if(extendrange) RatioYMax=4.0;
1484 >    
1485 >    TLine *SRline   = new TLine(70,0,70,RatioYMax);
1486 >    TLine *ZLowLine = new TLine(91.2-PlottingSetup::ConsideredZWidth,0,91.2-PlottingSetup::ConsideredZWidth,RatioYMax);
1487 >    TLine *ZHiLine  = new TLine(91.2+PlottingSetup::ConsideredZWidth,0,91.2+PlottingSetup::ConsideredZWidth,RatioYMax);
1488 >  
1489 >    SRline->SetLineStyle(2);
1490 >    ZLowLine->SetLineStyle(2);
1491 >    ZHiLine->SetLineStyle(2);
1492 >    SRline->SetLineColor(kGray+2);
1493 >    ZLowLine->SetLineColor(kGray+2);
1494 >    ZHiLine->SetLineColor(kGray+2);
1495 >    SRline->Draw();
1496 >    ZLowLine->Draw();
1497 >    ZHiLine->Draw();
1498 >  }
1499 >      
1500    Ratio_main_canvas->cd();
1501    Ratio_main_canvas->Modified();
1502    Ratio_main_canvas->cd();
# Line 1523 | Line 1543 | void Save_With_Ratio(TH1F *nominator, TH
1543    delete Ratio_main_canvas;
1544   }
1545  
1546 < 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) {
1546 > 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) {
1547 >  PlottingSetup::ConsideredZWidth=10.0;
1548 >  PlottingSetup::DrawMetSignalRegionMllLines=true;
1549 >  Save_With_Ratio(nominator, denominator, orig_canvas, savemeas, do_bpred_ratio, extendrange, yaxistitle,syshisto);
1550 >  PlottingSetup::DrawMetSignalRegionMllLines=false;
1551 > }
1552 >  
1553 > void Save_With_Ratio_And_Line(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) {
1554 >  TH1F *denominator_histo = (TH1F*) CollapseStack(denominator,"TemporaryStack");
1555 >  Save_With_Ratio_And_Line(nominator, denominator_histo, canvas, savemeas, do_bpred_ratio);
1556 >  delete denominator_histo;
1557 > }
1558 >
1559 > 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) {
1560    //this function saves the pad being passed as well as a new one including the SysRatio.
1561    orig_canvas->cd();
1562    orig_canvas->Update();
# Line 1608 | Line 1641 | void save_with_ratio_and_sys_band(TH1F *
1641    ratio->GetYaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize());
1642    ratio->GetYaxis()->SetNdivisions(502,false);
1643    ratio->SetFillColor(TColor::GetColor("#58D3F7"));
1644 <  ratio->Draw("e1");
1644 >  ratio->Draw("e0");
1645    
1646    if(syshisto!=0) {
1647      SysEnvelope->SetFillColor(TColor::GetColor("#FE9A2E"));
1648 <    SysEnvelope->Draw("2,same");
1649 <    ratio->Draw("e1,same");
1648 >    SysEnvelope->Draw("2,0,same");
1649 >    ratio->Draw("e0,same");
1650    } else {
1651 <    eratio->Draw("1");
1651 >    eratio->Draw("0");
1652    }
1653    ratio->Draw("same,axis");
1654    TLine *oneline = new TLine(ratio->GetXaxis()->GetBinLowEdge(1),1,ratio->GetXaxis()->GetBinLowEdge(ratio->GetNbinsX())+ratio->GetXaxis()->GetBinWidth(ratio->GetNbinsX()),1);
1655    oneline->SetLineStyle(2);
1656    oneline->SetLineColor(kBlue);
1657    oneline->Draw("same");
1658 +  
1659 +  
1660 +  
1661 +  if(ConsideredZWidth>0.1) {
1662 +    cout << "Drawing extra lines in ratio this time around ... " << endl;
1663 +    float RatioYMax=2.0;
1664 +    if(extendrange) RatioYMax=4.0;
1665 +    
1666 +    TLine *SRline   = new TLine(70,0,70,RatioYMax);
1667 +    TLine *ZLowLine = new TLine(91.2-ConsideredZWidth,0,91.2-ConsideredZWidth,RatioYMax);
1668 +    TLine *ZHiLine  = new TLine(91.2+ConsideredZWidth,0,91.2+ConsideredZWidth,RatioYMax);
1669 +  
1670 +    SRline->SetLineStyle(2);
1671 +    ZLowLine->SetLineStyle(2);
1672 +    ZHiLine->SetLineStyle(2);
1673 +    SRline->SetLineColor(kGray+2);
1674 +    ZLowLine->SetLineColor(kGray+2);
1675 +    ZHiLine->SetLineColor(kGray+2);
1676 +    SRline->Draw();
1677 +    ZLowLine->Draw();
1678 +    ZHiLine->Draw();
1679 +  }
1680  
1681    Ratio_main_canvas->cd();
1682    Ratio_main_canvas->Modified();
# Line 1674 | Line 1729 | TH1F* CollapseStack(THStack stack,TStrin
1729     return basehisto;
1730   }
1731  
1732 + TH1F* CollapseStack(THStack *stack,TString hname="CollapsedStack") {
1733 +   TH1F *bhist = ((TH1F*)((stack->GetHists())->At(0)));
1734 +   TH1F *basehisto = (TH1F*)bhist->Clone(hname);
1735 +   TIter next(stack->GetHists());
1736 +   TH1F *h;
1737 +   int counter=0;
1738 +   while ((h=(TH1F*)next())) {
1739 +     counter++;
1740 +     if(counter==1) continue;
1741 +     basehisto->Add(h);
1742 +   }
1743 +   return basehisto;
1744 + }
1745 +
1746   void Save_With_Ratio(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) {
1747    TH1F *denominator_histo = (TH1F*) CollapseStack(denominator);
1748    Save_With_Ratio(nominator, denominator_histo, canvas, savemeas, do_bpred_ratio);
# Line 1905 | Line 1974 | TPolyLine* GetFitUncertaintyShape(TF1 *f
1974    y[nPoints]=y[0];
1975    
1976    TPolyLine *l = new TPolyLine(nPoints+1,x,y);
1977 <  l->SetFillColor(TColor::GetColor("#5858FA"));
1978 <  l->SetLineColor(TColor::GetColor("#5858FA"));
1977 >  l->SetFillColor(TColor::GetColor("#A2A2FA"));
1978 >  l->SetLineColor(TColor::GetColor("#A2A2FA"));
1979    l->SetLineWidth(1);
1980    return l;
1981   }  
# Line 2030 | Line 2099 | string DigitsAfterComma(float number, in
2099    temp=int(temp)/pow(10.0,digits);
2100    return any2string(temp);
2101   }
2102 +
2103 +
2104 + Value GetYield(TH1F *histo, float min, float max) {
2105 +  float res=0.0;
2106 +  float reserr=0.0;
2107 +  for(int i=1;i<=histo->GetNbinsX();i++) {
2108 +      if(histo->GetBinLowEdge(i)+histo->GetBinWidth(i)<=min) continue;// considered in the next bin
2109 +      if(histo->GetBinLowEdge(i)>=max) continue;//above the threshold, out!
2110 + //      cout << "         added yield for bin [" << histo->GetBinLowEdge(i) << "," << histo->GetBinLowEdge(i)+histo->GetBinWidth(i) << "] which is " << histo->GetBinContent(i) << "   in GetYield" << endl;
2111 +      res+=histo->GetBinContent(i);
2112 +      reserr=sqrt(reserr*reserr+histo->GetBinError(i)*histo->GetBinError(i));
2113 +  }
2114 +  return Value(res,reserr);
2115 + }
2116 +
2117 + void ProduceYields(float min, float max, TH1F *data, THStack *stack) {
2118 +  dout << "   *************** <MC YIELDS> ********* " << endl;
2119 +  dout << "   Considering " << min << " < mll < " << max << "           " << endl;
2120 +  dout << "   Data : " << GetYield(data,min,max)  << endl;
2121 +  TIter nextSF(stack->GetHists());
2122 +  TH1F* h;
2123 +  while ( h = (TH1F*)nextSF() ) {
2124 +    dout << "   " << h->GetName() << " : " << GetYield(h,min,max)  << endl;
2125 +  }
2126 +  dout << "   *************** </MC YIELDS> ********* " << endl;
2127 + }
2128 +
2129 +  
2130 + void WriteYield(THStack *mc, float low, float high) {
2131 +  TH1F *h;
2132 +  TIter NextHisto(mc->GetHists());
2133 +  while ( h = (TH1F*)NextHisto() ) {
2134 +    float CurrBKG=0;
2135 +    float CurrBKGErr=0;
2136 +    for(int i=1;i<=h->GetNbinsX()+1;i++) {
2137 +      if(h->GetBinLowEdge(i)+h->GetBinWidth(i)<=low) continue;// considered in the next bin
2138 +      if(h->GetBinLowEdge(i)>=high) continue;//above the threshold, out!
2139 +      CurrBKG+=h->GetBinContent(i);
2140 +      CurrBKGErr=sqrt(CurrBKGErr*CurrBKGErr+h->GetBinError(i)*h->GetBinError(i));
2141 +    }
2142 +    dout << "      " << h->GetName() << " : " << CurrBKG << " +/- " << CurrBKGErr << endl;
2143 +  }
2144 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines