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.19 by buchmann, Fri Sep 14 10:19:04 2012 UTC vs.
Revision 1.38 by buchmann, Tue Apr 9 14:13:51 2013 UTC

# Line 40 | Line 40
40   #include <TRandom.h>
41   #include <TGraphErrors.h>
42   #include <TROOT.h>
43 + #include <TPolyLine.h>
44 +
45   #ifndef Verbosity
46   #define Verbosity 0
47   #endif
# Line 63 | Line 65 | namespace PlottingSetup {
65      int Approved=0; // Approved=true will only plot approved plots
66      bool is2012=true;
67      bool is53reco=true;
68 <    bool openBox = false;
68 >    bool openBox = true;
69 >    vector<TH1F*> FakeHistoHeap;
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 90 | 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   //-------------------------------------------------------------------------------------
100  
101   template<typename U>
# Line 257 | Line 263 | void ensure_directory_exists(string this
263    }
264   }
265  
266 + void DeleteStack(THStack mcstack) {
267 +  TH1F* h;
268 +  TIter nextHist(mcstack.GetHists());
269 +  while ( h = (TH1F*)nextHist() ) {
270 +    h->Delete();
271 +  }
272 +  delete h;
273 + }
274 +
275 +
276   void DeadEnd(string message) {
277    dout << endl;
278    dout << "\033[1;31m     _                _                  _  " << endl;
# Line 425 | Line 441 | void CompleteSave(TVirtualPad *can, stri
441  
442  
443   void setlumi(float l) {
444 < generaltoolboxlumi=l;
444 >  generaltoolboxlumi=l;
445   }
446  
447   int write_first_line(vector<vector<string> > &entries) {
# Line 583 | Line 599 | void DrawPrelim(float writelumi=generalt
599    string prel=" Preliminary";
600    if(PlottingSetup::PaperMode) prel="";
601    //prelimtext << "CMS Preliminary 2011 , #sqrt{s}= 7 TeV, L= O(1) fb^{-1}"; //temporary replacement
602 <  if(PlottingSetup::is53reco) prel += " 53X";
602 > //  if(PlottingSetup::is53reco) prel += " 53X";
603    string energy="7 TeV";
604    if(PlottingSetup::is2012) energy="8 TeV";
605    if(writelumi == 0) {
606      if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy;
607      else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy;
608    } else {
609 <    if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy << ", L_{int} = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
610 <     else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy << ", L_{int} = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
609 >    if(isMC) prelimtext << "CMS Simulation, #sqrt{s} = " << energy << ", #scale[0.6]{#int} L dt = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
610 >     else prelimtext << "CMS" << prel << ", #sqrt{s} = " << energy << ", #scale[0.6]{#int} L dt = " << std::setprecision(3) <<writelumi<<" "<<barn<<"^{-1}";
611    }
612    TPaveText *eventSelectionPaveText = new TPaveText(0.27, 0.93,0.77, 1.0,"blNDC");
613    eventSelectionPaveText->SetFillStyle(4000);
# Line 946 | Line 962 | string interpret_cut(string incut, bool
962    
963      if(incut=="id1==0") return "ee";
964      if(incut=="id1==1") return "#mu#mu";
965 <    if(incut=="abs(mll-91.2)<20") return "|m_{l^{+}l^{-}}-m_{Z}|<20";
965 >    if(incut=="abs(mll-91)<10") return "|m_{l^{+}l^{-}}-m_{Z}|<10";
966      if(incut=="pfJetGoodID[0]") return "";
967      if(incut=="pfJetGoodID[1]") return "";
968      if((int)incut.find("pfJetGoodNum")>-1) {
# Line 1222 | Line 1238 | bool Contains(string wholestring, string
1238    else return false;
1239   }
1240  
1241 +
1242   //////////////////////////////////////////////////////////////////////////////
1243   //
1244   // http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c
# Line 1234 | Line 1251 | bool Contains(string wholestring, string
1251   /* usage:
1252   double vm2, rss2;
1253   process_mem_usage(vm2, rss2);
1254 < cout << "Memory usage: VM: " << vm << "; RSS: " << rss << endl;
1254 > cout << "Memory usage: VM: " << vm2 << "; RSS: " << rss2 << endl;
1255   */
1256  
1257   void process_mem_usage(double& vm_usage, double& resident_set)
# Line 1293 | Line 1310 | TGraphAsymmErrors* produce_ratio_graph(T
1310   }
1311  
1312  
1313 + TLatex* WriteSelection(int njets) {
1314 +  string sel="Loose selection";
1315 +  if(njets==3) sel="Low E_{T}^{miss}";
1316 +  assert(njets==2||njets==3);
1317 +  TLatex *sele = new TLatex(0.97,0.135,sel.c_str());
1318 +  sele->SetNDC(true);
1319 +  sele->SetTextColor(TColor::GetColor("#848484"));
1320 +  sele->SetTextFont(42);
1321 +  sele->SetTextAlign(32);
1322 +  sele->SetTextSize(0.03);
1323 +  sele->SetTextAngle(270);
1324 +  return sele;
1325 + }
1326 +
1327   Double_t MarcosChi2TestX(const TH1* h1, const TH1* h2, Double_t &chi2, Int_t &ndf, Int_t &igood, Option_t *option)
1328   {
1329  
# Line 1315 | Line 1346 | Double_t MarcosChi2TestX(const TH1* h1,
1346     return prob;
1347   }
1348  
1349 < /*void save_with_difference(TH1F *obs, vector<TH1F*> predictions, vector<float> prediction_weights, vector<float> prediction_uncerts, TVirtualPad *canvas, string savemeas) {
1350 <  if(predictions.size()<1) {
1320 <    write_warning(__FUNCTION__,"Cannot make a pred-obs prediction plot because the prediction vector is empty. aborting!");
1321 <    return;
1322 <  }
1323 <  TH1F *comppred = predictions[0]->Clone("comppred");
1324 <  comppred->Scale(prediction_weights[0]);
1325 <  for(int i=1;i<predictions.size();i++) comppred->Add(predictions[i],prediction_weights[i]);
1326 <  
1327 <  TH1F *statpred = (TH1F*)comppred->Clone("statpred");
1328 <  for(int i=1;i<=statpred->GetNbinsX();i++) statpred->SetBinContent(0);
1329 <  
1330 <  TH1F *syspred = predictions[0];
1331 <  for(int i=1;i<=syspred->GetNbinsX();i++) syspred->SetBinContent(i,prediction_weights[0]*prediction_weights[0]*prediction_uncerts[0]*prediction_uncerts[0]*syspred->GetBinContent(i)*syspred->GetBinContent(i));
1332 <  for(int i=1;i<predictions.size();i++) {
1333 <    for(int ibin=1;ibin<=predictions[i]->GetNbinsX();ibin++) {
1334 <      float newentry=syspred->GetBinContent(ibin);
1335 <      newentry+=(predictions[i]->GetBinContent(ibin))*(predictions[i]->GetBinContent(ibin))*prediction_weights[i]*prediction_weights[i]*prediction_uncerts[i]*prediction_uncerts[i];
1336 <      syspred->SetBinContent(ibin,newentry);
1337 <    }
1338 <  }
1339 <  for(int ibin=1;ibin<=syspred->GetNbinsX();ibin++) {
1340 <    syspred->SetBinError(ibin,syspred->GetBinContent(i)+statpred->GetBinError());
1341 <    syspred->SetBinContent(ibin,0);
1342 <  }
1349 > 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) {
1350 >  //this function saves the pad being passed as well as a new one including the ratio.
1351    
1352 +  orig_canvas->cd();
1353 +  orig_canvas->Update();
1354 +  CompleteSave(orig_canvas,savemeas);
1355 +  TVirtualPad *canvas = (TVirtualPad*) orig_canvas->Clone("TempCanvas");//otherwise the Ratio_main_canvas will own our pad and destroy it upon deletion
1356    
1345 }
1346 */
1347 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) {
1348  //this function saves the pad being passed as well as a new one including the ratio.
1349  CompleteSave(canvas,savemeas);
1350
1357    float bottommargin=gStyle->GetPadBottomMargin();
1358    float canvas_height=gStyle->GetCanvasDefH();
1359    float canvas_width=gStyle->GetCanvasDefW();
# Line 1358 | Line 1364 | void save_with_ratio(TH1F *nominator, TH
1364    
1365    float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace);
1366    
1367 <  TCanvas *main_canvas = new TCanvas("main_canvas","main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1367 >  TCanvas *Ratio_main_canvas = new TCanvas("Ratio_main_canvas","Ratio_main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1368    TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad
1369    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
1370    TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad
1371    
1372 <  main_canvas->Range(0,0,1,1);
1373 <  main_canvas->SetBorderSize(0);
1374 <  main_canvas->SetFrameFillColor(0);
1372 >  Ratio_main_canvas->Range(0,0,1,1);
1373 >  Ratio_main_canvas->SetBorderSize(0);
1374 >  Ratio_main_canvas->SetFrameFillColor(0);
1375    
1376    mainpad->Draw();
1377    mainpad->cd();
# Line 1376 | 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 1384 | 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 1394 | Line 1400 | void save_with_ratio(TH1F *nominator, TH
1400    TH1F *ratio = (TH1F*)nominator->Clone(GetNumericHistoName().c_str());
1401    ratio->Divide(denominator);
1402  
1397
1403    TGraphAsymmErrors *eratio;
1404    TH1F *SystDown;
1405    TH1F *SystUp;
# Line 1420 | Line 1425 | void save_with_ratio(TH1F *nominator, TH
1425       }
1426      
1427    }
1423  eratio->SetFillColor(TColor::GetColor("#00ADE1"));
1428    
1429 +  if(syshisto && !do_bpred_ratio) {
1430 +       SystDown = (TH1F*)syshisto->Clone("SystDown");
1431 +       SystUp = (TH1F*)syshisto->Clone("SystUp");
1432 +       for(int i=1;i<=syshisto->GetNbinsX();i++) {
1433 +         SystDown->SetBinContent(i,1-syshisto->GetBinContent(i));
1434 +         SystUp->SetBinContent(i,1+syshisto->GetBinContent(i));
1435 +       }
1436 +       SystDown->SetLineColor(TColor::GetColor("#006DE1"));
1437 +       SystUp->SetLineColor(TColor::GetColor("#006DE1"));
1438 +  }
1439 +  eratio->SetFillColor(TColor::GetColor("#00ADE1"));
1440  
1441    ratio->SetTitle("");
1442 <  ratio->GetYaxis()->SetRangeUser(0.5,1.5);
1442 >  ratio->GetYaxis()->SetRangeUser(0.0,2.0);
1443    if(do_bpred_ratio) ratio->GetYaxis()->SetRangeUser(0.0,2.0);
1444    if(extendrange) ratio->GetYaxis()->SetRangeUser(0.0,4.0);
1445    ratio->GetXaxis()->SetTitle(nominator->GetXaxis()->GetTitle());
# Line 1441 | Line 1456 | void save_with_ratio(TH1F *nominator, TH
1456    ratio->SetFillColor(TColor::GetColor("#58D3F7"));
1457    ratio->SetMarkerSize(0);
1458    ratio->Draw("e2");
1459 +  
1460 +  TGraphAsymmErrors *ratio_center = (TGraphAsymmErrors*)eratio->Clone("ratio_center");
1461 +  for(int i=0;i<ratio_center->GetN();i++) {
1462 +    ratio_center->SetPointError(i,ratio_center->GetErrorXlow(i),ratio_center->GetErrorXhigh(i),0.005,0.005);
1463 +  }
1464 +  
1465 +  ratio_center->SetFillColor(TColor::GetColor("#006381"));
1466 +  
1467    if(syshisto!=0) {
1468   //    sysratio->Draw("2");
1469   //    eratio->Draw("2,same");
# Line 1450 | Line 1473 | void save_with_ratio(TH1F *nominator, TH
1473    } else {
1474      eratio->Draw("2");
1475    }
1476 +  ratio_center->Draw("2");
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");
1458
1459  main_canvas->cd();
1460  main_canvas->Modified();
1461  main_canvas->cd();
1462  main_canvas->SetSelected(main_canvas);
1482    
1483 <  CompleteSave(main_canvas,savemeas+"_withratio");
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 >
1504 >
1505 >  Ratio_main_canvas->cd();
1506 >  Ratio_main_canvas->Modified();
1507 >  Ratio_main_canvas->cd();
1508 >  Ratio_main_canvas->SetSelected(Ratio_main_canvas);
1509 >  
1510 >  CompleteSave(Ratio_main_canvas,savemeas+"_withratio");
1511    bottompad->cd();
1512    
1513    Double_t chi2;
# Line 1489 | Line 1535 | void save_with_ratio(TH1F *nominator, TH
1535    CompleteRatio->SetTextAlign(31);
1536    CompleteRatio->Draw();
1537    
1538 <  CompleteSave(main_canvas,savemeas+"_withratio_and_Chi2");
1538 >  CompleteSave(Ratio_main_canvas,savemeas+"_withratio_and_Chi2");
1539  
1540   //  float KS   = nominator->KolmogorovTest(denominator);
1541   //  stringstream KStext;
1542   //  Chi2text << "KS = " << KS << endl;
1543   //cout << "Found : " << KStext.str() << endl;
1544  
1545 +  delete eratio;
1546 +  delete ratio_center;
1547 +  delete ratio;
1548 +  delete Ratio_main_canvas;
1549 + }
1550  
1551 <  delete main_canvas;
1551 > 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) {
1552 >  PlottingSetup::ConsideredZWidth=10.0;
1553 >  PlottingSetup::DrawMetSignalRegionMllLines=true;
1554 >  Save_With_Ratio(nominator, denominator, orig_canvas, savemeas, do_bpred_ratio, extendrange, yaxistitle,syshisto);
1555 >  PlottingSetup::DrawMetSignalRegionMllLines=false;
1556 > }
1557 >  
1558 > void Save_With_Ratio_And_Line(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) {
1559 >  TH1F *denominator_histo = (TH1F*) CollapseStack(denominator,"TemporaryStack");
1560 >  Save_With_Ratio_And_Line(nominator, denominator_histo, canvas, savemeas, do_bpred_ratio);
1561 >  delete denominator_histo;
1562   }
1563  
1564 < void save_with_ratio_and_sys_band(TH1F *nominator, TH1F *denominator, TVirtualPad *canvas, string savemeas, float systematic, string yaxistitle="SysRatio") {
1564 > 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) {
1565    //this function saves the pad being passed as well as a new one including the SysRatio.
1566 <  CompleteSave(canvas,savemeas);
1566 >  orig_canvas->cd();
1567 >  orig_canvas->Update();
1568 >  CompleteSave(orig_canvas,savemeas);
1569 >  
1570 >  TVirtualPad *canvas = (TVirtualPad*) orig_canvas->Clone("TempCanvas");//otherwise the Ratio_main_canvas will own our pad and destroy it upon deletion
1571  
1572    float bottommargin=gStyle->GetPadBottomMargin();
1573    float canvas_height=gStyle->GetCanvasDefH();
1574    float canvas_width=gStyle->GetCanvasDefW();
1575 <  float SysRatiospace=0.25;// space the SysRatio should take up (relative to original pad)
1575 >  float ratiospace=0.25;// space the ratio should take up (relative to original pad)
1576    
1577 <  float SysRatiobottommargin=0.3;
1578 <  float SysRatiotopmargin=0.1;
1577 >  float ratiobottommargin=0.3;
1578 >  float ratiotopmargin=0.1;
1579    
1580 <  float xstretchfactor=((1-SysRatiospace)*(1-gStyle->GetPadTopMargin()))/((1)*SysRatiospace);
1580 >  float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace);
1581    
1582 <  TCanvas *MainCanvas = new TCanvas("MainCanvas","MainCanvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+SysRatiospace)));
1583 <  TPad *MainPad = new TPad("MainPad","MainPad",0,1-(1.0/(1+SysRatiospace)),1,1);//top (main) pad
1584 <  TPad *CoverPad = new TPad("CoverPad","CoverPad",gStyle->GetPadLeftMargin()-0.008,1-(1.0/(1+SysRatiospace))-0.04,1,1-(1.0/(1+SysRatiospace))+0.103);//pad covering up the x scale
1585 <  TPad *BottomPad = new TPad("BottomPad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+SysRatiospace))-0.015); //bottom pad
1586 <  
1587 <  MainCanvas->Range(0,0,1,1);
1588 <  MainCanvas->SetBorderSize(0);
1589 <  MainCanvas->SetFrameFillColor(0);
1590 <  
1591 <  MainPad->Draw();
1592 <  MainPad->cd();
1593 <  MainPad->Range(0,0,1,1);
1594 <  MainPad->SetFillColor(kWhite);
1595 <  MainPad->SetBorderSize(0);
1596 <  MainPad->SetFrameFillColor(0);
1582 >  TCanvas *Ratio_main_canvas = new TCanvas("Ratio_main_canvas","Ratio_main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1583 >  TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad
1584 >  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
1585 >  TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad
1586 >  
1587 >  Ratio_main_canvas->Range(0,0,1,1);
1588 >  Ratio_main_canvas->SetBorderSize(0);
1589 >  Ratio_main_canvas->SetFrameFillColor(0);
1590 >  
1591 >  mainpad->Draw();
1592 >  mainpad->cd();
1593 >  mainpad->Range(0,0,1,1);
1594 >  mainpad->SetFillColor(kWhite);
1595 >  mainpad->SetBorderSize(0);
1596 >  mainpad->SetFrameFillColor(0);
1597    canvas->Range(0,0,1,1);
1598    canvas->Draw("same");
1599 <  MainPad->Modified();
1600 <  MainCanvas->cd();
1601 <  CoverPad->Draw();
1602 <  CoverPad->cd();
1603 <  CoverPad->Range(0,0,1,1);
1604 <  CoverPad->SetFillColor(kWhite);
1605 <  CoverPad->SetBorderSize(0);
1606 <  CoverPad->SetFrameFillColor(0);
1607 <  CoverPad->Modified();
1608 <  MainCanvas->cd();
1609 <  BottomPad->SetTopMargin(SysRatiotopmargin);
1610 <  BottomPad->SetBottomMargin(SysRatiobottommargin);
1611 <  BottomPad->Draw();
1612 <  BottomPad->cd();
1613 <  BottomPad->Range(0,0,1,1);
1614 <  BottomPad->SetFillColor(kWhite);
1615 <  TH1F *SysRatio = (TH1F*)nominator->Clone(GetNumericHistoName().c_str());
1616 <  SysRatio->Divide(denominator);
1599 >  mainpad->Modified();
1600 >  Ratio_main_canvas->cd();
1601 >  coverpad->Draw();
1602 >  coverpad->cd();
1603 >  coverpad->Range(0,0,1,1);
1604 >  coverpad->SetFillColor(kWhite);
1605 >  coverpad->SetBorderSize(0);
1606 >  coverpad->SetFrameFillColor(0);
1607 >  coverpad->Modified();
1608 >  Ratio_main_canvas->cd();
1609 >  bottompad->SetTopMargin(ratiotopmargin);
1610 >  bottompad->SetBottomMargin(ratiobottommargin);
1611 >  bottompad->Draw();
1612 >  bottompad->cd();
1613 >  bottompad->Range(0,0,1,1);
1614 >  bottompad->SetFillColor(kWhite);
1615 >  TH1F *ratio = (TH1F*)nominator->Clone(GetNumericHistoName().c_str());
1616 >  ratio->Divide(denominator);
1617  
1618  
1619 +  TGraphAsymmErrors *eratio;
1620 +  TGraphAsymmErrors *SysEnvelope = new TGraphAsymmErrors();
1621 +  
1622 +  if(syshisto && !do_bpred_ratio) {
1623 +       for(int i=1;i<=syshisto->GetNbinsX();i++) {
1624 +         float dx=syshisto->GetBinWidth(i)/2.0;
1625 +         float dy=syshisto->GetBinContent(i);
1626 +         if(dy<0.01) dy=0.07;
1627 +         SysEnvelope->SetPoint(i-1,syshisto->GetBinCenter(i),1.0);
1628 +         SysEnvelope->SetPointError(i-1,dx,dx,dy,dy);
1629 +       }
1630 +       SysEnvelope->SetFillColor(TColor::GetColor("#006DE1"));
1631 +  }
1632  
1633 <  SysRatio->SetTitle("");
1634 <  SysRatio->GetYaxis()->SetRangeUser(0.0,2.0);
1635 <  SysRatio->GetXaxis()->SetTitle(nominator->GetXaxis()->GetTitle());
1636 <  SysRatio->GetXaxis()->CenterTitle();
1637 <  SysRatio->GetYaxis()->SetTitle(yaxistitle.c_str());
1638 <  SysRatio->GetYaxis()->SetTitleOffset(0.4);
1639 <  SysRatio->GetYaxis()->CenterTitle();
1640 <  SysRatio->SetStats(0);
1641 <  SysRatio->GetXaxis()->SetLabelSize(xstretchfactor*SysRatio->GetXaxis()->GetLabelSize());
1642 <  SysRatio->GetYaxis()->SetLabelSize(xstretchfactor*SysRatio->GetYaxis()->GetLabelSize());
1643 <  SysRatio->GetXaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize());
1644 <  SysRatio->GetYaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize());
1645 <  SysRatio->GetYaxis()->SetNdivisions(502,false);
1646 <  SysRatio->SetFillColor(TColor::GetColor("#58D3F7"));
1647 <  TBox *sysbox = new TBox(SysRatio->GetXaxis()->GetBinLowEdge(1),1-systematic,SysRatio->GetXaxis()->GetBinLowEdge(SysRatio->GetNbinsX())+SysRatio->GetXaxis()->GetBinWidth(SysRatio->GetNbinsX()),1+systematic);
1648 <  sysbox->SetFillColor(TColor::GetColor("#82FA58")); // light green
1649 <  
1572 <  SysRatio->SetMarkerSize(0);
1573 <  SysRatio->Draw();
1574 <  sysbox->Draw();
1575 <  SysRatio->Draw("same");
1633 >  ratio->SetTitle("");
1634 >  ratio->GetYaxis()->SetRangeUser(0.0,2.0);
1635 >  if(do_bpred_ratio) ratio->GetYaxis()->SetRangeUser(0.0,2.0);
1636 >  if(extendrange) ratio->GetYaxis()->SetRangeUser(0.0,4.0);
1637 >  ratio->GetXaxis()->SetTitle(nominator->GetXaxis()->GetTitle());
1638 >  ratio->GetXaxis()->CenterTitle();
1639 >  ratio->GetYaxis()->SetTitle(yaxistitle.c_str());
1640 >  ratio->GetYaxis()->SetTitleOffset(0.4);
1641 >  ratio->GetYaxis()->CenterTitle();
1642 >  ratio->SetStats(0);
1643 >  ratio->GetXaxis()->SetLabelSize(xstretchfactor*ratio->GetXaxis()->GetLabelSize());
1644 >  ratio->GetYaxis()->SetLabelSize(xstretchfactor*ratio->GetYaxis()->GetLabelSize());
1645 >  ratio->GetXaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize());
1646 >  ratio->GetYaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize());
1647 >  ratio->GetYaxis()->SetNdivisions(502,false);
1648 >  ratio->SetFillColor(TColor::GetColor("#58D3F7"));
1649 >  ratio->Draw("e1");
1650    
1651 <  SysRatio->Draw("same,axis");
1652 <  TLine *oneline = new TLine(SysRatio->GetXaxis()->GetBinLowEdge(1),1,SysRatio->GetXaxis()->GetBinLowEdge(SysRatio->GetNbinsX())+SysRatio->GetXaxis()->GetBinWidth(SysRatio->GetNbinsX()),1);
1651 >  if(syshisto!=0) {
1652 >    SysEnvelope->SetFillColor(TColor::GetColor("#FE9A2E"));
1653 >    SysEnvelope->Draw("2,same");
1654 >    ratio->Draw("e1,same");
1655 >  } else {
1656 >    eratio->Draw("1");
1657 >  }
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");
1663 +  
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;
1695 +  Int_t ndf,igood;
1696 +  Double_t chi2prob = MarcosChi2TestX(nominator,denominator,chi2,ndf,igood,"UW");
1697  
1698 <  MainCanvas->cd();
1699 <  MainCanvas->Modified();
1700 <  MainCanvas->cd();
1701 <  MainCanvas->SetSelected(MainCanvas);
1702 <  
1703 <  CompleteSave(MainCanvas,savemeas+"_withSYSSysRatio");
1704 <  cout << __LINE__ << endl;
1705 <  delete SysRatio;
1706 <  cout << __LINE__ << endl;
1707 <  delete MainCanvas;
1708 <  cout << __LINE__ << endl;
1698 >  stringstream Chi2text;
1699 >  Chi2text << "#chi^{2} / ndf: " << chi2 << " / " << ndf;
1700 >  stringstream Chi2probtext;
1701 >  Chi2probtext << "#chi^{2} prob: " << chi2prob;
1702 >  TText* chi2box = write_text(0.02,0.11,Chi2text.str());
1703 >  chi2box->SetTextSize(0.08);
1704 >  chi2box->SetTextAlign(11);
1705 >  chi2box->Draw();
1706 >  TText* chi2probbox = write_text(0.02,0.04,Chi2probtext.str());
1707 >  chi2probbox->SetTextSize(0.08);
1708 >  chi2probbox->SetTextAlign(11);
1709 >  chi2probbox->Draw();
1710 >  
1711 >  stringstream CompRatio;
1712 >  CompRatio << "Ratio: " << nominator->Integral() << " / " << denominator->Integral() << " \n " << nominator->Integral()/denominator->Integral();
1713 >  TText *CompleteRatio = write_text(0.98,0.04,CompRatio.str());
1714 >  CompleteRatio->SetTextSize(0.08);
1715 >  CompleteRatio->SetTextAlign(31);
1716 >  CompleteRatio->Draw();
1717 >  
1718 >  CompleteSave(Ratio_main_canvas,savemeas+"_withSysRatio_and_Chi2");
1719 >  delete Ratio_main_canvas;
1720 >  delete ratio;
1721   }
1722  
1723 < TH1F* CollapseStack(THStack stack) {
1723 > TH1F* CollapseStack(THStack stack,TString hname="CollapsedStack") {
1724     TH1F *bhist = ((TH1F*)((stack.GetHists())->At(0)));
1725 <   TH1F *basehisto = (TH1F*)bhist->Clone("base");
1725 >   TH1F *basehisto = (TH1F*)bhist->Clone(hname);
1726     TIter next(stack.GetHists());
1727     TH1F *h;
1728     int counter=0;
# Line 1607 | Line 1734 | TH1F* CollapseStack(THStack stack) {
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 > void Save_With_Ratio(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) {
1738 >  TH1F *denominator_histo = (TH1F*) CollapseStack(denominator);
1739 >  Save_With_Ratio(nominator, denominator_histo, canvas, savemeas, do_bpred_ratio);
1740 >  delete denominator_histo;
1741   }
1742  
1743   void flag_this_change(string function, int line, int checked=0) {
# Line 1793 | Line 1922 | string removefunnystring(string name) {
1922    name=ReplaceCharacter(name,"]","_");
1923    name=ReplaceCharacter(name,"{","_");
1924    name=ReplaceCharacter(name,"}","_");
1925 +  name=ReplaceCharacter(name,"(","_");
1926 +  name=ReplaceCharacter(name,")","_");
1927 +  name=ReplaceCharacter(name," ","_");
1928    name=ReplaceCharacter(name,".","_");
1929    name=ReplaceCharacter(name,",","_");
1930    name=ReplaceCharacter(name,";","_");
# Line 1807 | Line 1939 | string removefunnystring(string name) {
1939    return name;
1940   }
1941  
1942 + TPolyLine* GetFitUncertaintyShape(TF1 *fit, float low, float high,float x0,float x1) {
1943 +  int nPoints=1000;
1944 +  double x[nPoints+1];
1945 +  double y[nPoints];
1946 +  
1947 +  float par1=fit->GetParameter(0);
1948 +  float dpar1=fit->GetParError(0);
1949 +  float par2=fit->GetParameter(1);
1950 +  float dpar2=fit->GetParError(1);
1951 +    
1952 +  float step=(x1-x0)/(nPoints/2.0 -1);
1953 +  for(int i=0;i<nPoints/2.0;i++) {
1954 +    x[i]=x0+i*step;
1955 +    y[i]=(par1+x[i]*par2)    -    sqrt(dpar1*dpar1+dpar2*dpar2*x[i]*x[i]);
1956 +    x[nPoints-1-i]=x[i];
1957 +    y[nPoints-1-i]=(par1+x[i]*par2)    +    sqrt(dpar1*dpar1+dpar2*dpar2*x[i]*x[i]);
1958 +    if(y[i]<low) y[i]=low;
1959 +    if(y[i]>high) y[i]=high;
1960 +    if(y[nPoints-1-i]<low) y[nPoints-1-i]=low;
1961 +    if(y[nPoints-1-i]>high) y[nPoints-1-i]=high;
1962 +  }
1963 +  
1964 +  x[nPoints]=x[0];
1965 +  y[nPoints]=y[0];
1966 +  
1967 +  TPolyLine *l = new TPolyLine(nPoints+1,x,y);
1968 +  l->SetFillColor(TColor::GetColor("#A2A2FA"));
1969 +  l->SetLineColor(TColor::GetColor("#A2A2FA"));
1970 +  l->SetLineWidth(1);
1971 +  return l;
1972 + }  
1973 +
1974 + //code for ReplaceAll copied from
1975 + //http://stackoverflow.com/questions/5343190/c-how-do-i-replace-all-instances-of-of-a-string-with-another-string
1976 + string ReplaceAll(string str, string from, string to) {
1977 +    size_t start_pos = 0;
1978 +    while((start_pos = str.find(from, start_pos)) != std::string::npos) {
1979 +         str.replace(start_pos, from.length(), to);
1980 +         start_pos += to.length(); // ...
1981 +    }
1982 +    return str;
1983 + }
1984 +
1985 + TPolyLine* GetFitUncertaintyShape(TH1 *histo, string fitname, float low, float high) {
1986 +  TF1 *fit = (TF1*)histo->GetFunction(fitname.c_str());
1987 +  if(!fit) {
1988 +    cout << "CANNOT PRODUCE FIT UNCERTAINTY AS THERE IS NO FIT CALLED " << fitname << " IN " << histo->GetName() << endl;
1989 +    return NULL;
1990 +  }
1991 +  float x0=histo->GetBinLowEdge(1);
1992 +  float x1=histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX());
1993 +  return GetFitUncertaintyShape(fit, low, high,x0,x1);
1994 + }
1995 +
1996 + TPolyLine* GetFitUncertaintyShape(TGraphErrors *gr, string fitname, float low, float high, float minx=-999, float maxx=-999) {
1997 +  TF1 *fit = (TF1*)gr->GetFunction(fitname.c_str());
1998 +  if(!fit) {
1999 +    cout << "CANNOT PRODUCE FIT UNCERTAINTY AS THERE IS NO FIT CALLED " << fitname << " IN " << gr->GetName() << endl;
2000 +    return NULL;
2001 +  }
2002 +  double x,y;
2003 +  gr->GetPoint(0,x,y);
2004 +  float min=x;
2005 +  gr->GetPoint(gr->GetN()-1,x,y);
2006 +  float max=x;
2007 +  if(minx>-999 && maxx>-999 && minx<maxx) {
2008 +    max=maxx;
2009 +    min=minx;
2010 +  }
2011 +  return GetFitUncertaintyShape(fit, low, high,min,max);
2012 + }
2013 +
2014   stringstream all_bugs;
2015  
2016   void bug_tracker(string function, int line, string description) {
# Line 1844 | Line 2048 | void bug_tracker(string function, int li
2048   //TODO: Write a bug summary at the end.
2049  
2050   float pSTAR(float mglu, float mlsp, float mchi2) {
2051 <        float mz=91.2;
2051 >        float mz=91.0;
2052          float res=((mchi2*mchi2)-(mlsp+mz)*(mlsp+mz));
2053          res*=((mchi2*mchi2)-(mlsp-mz)*(mlsp-mz));
2054          res=TMath::Sqrt(res)/(2*mchi2);
# Line 1857 | Line 2061 | float generalizedpSTAR(float massmother,
2061          res=TMath::Sqrt(res)/(2*massmother);
2062          return res;
2063   }
2064 +
2065 + void FindMinMax(TGraphErrors *gr, float &min, float &max) {
2066 +  double x,y;
2067 +  gr->GetPoint(0,x,y);
2068 +  min=500*y;
2069 +  max=0.0002*y;
2070 +  for(int i=0;i<gr->GetN();i++) {
2071 +    gr->GetPoint(i,x,y);
2072 +    cout << "Point at " << x << "/" << y << " with error " << gr->GetErrorY(i) << endl;
2073 +    float potmin=y-1.5*gr->GetErrorY(i); // taking 1.5 times the error to allow for enough space to present the plot
2074 +    float potmax=y+1.5*gr->GetErrorY(i); // taking 1.5 times the error to allow for enough space to present the plot
2075 +    if(potmin<min) min=potmin;
2076 +    if(potmax>max) max=potmax;
2077 +  }
2078 + }
2079 +
2080 +
2081 + void CleanLegends() {
2082 +  for(int ihist=(int)PlottingSetup::FakeHistoHeap.size()-1;ihist>=0;ihist--) {
2083 +    PlottingSetup::FakeHistoHeap[ihist]->Delete();
2084 +    PlottingSetup::FakeHistoHeap.pop_back();
2085 +  }
2086 + }
2087 +
2088 + string DigitsAfterComma(float number, int digits) {
2089 +  float temp=number*pow(10.0,digits);
2090 +  temp=int(temp)/pow(10.0,digits);
2091 +  return any2string(temp);
2092 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines