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.29 by buchmann, Wed Jan 16 17:11:37 2013 UTC vs.
Revision 1.34 by buchmann, Thu Feb 7 14:30:09 2013 UTC

# Line 1307 | Line 1307 | TGraphAsymmErrors* produce_ratio_graph(T
1307   }
1308  
1309  
1310 + TText* WriteSelection(int njets) {
1311 +  string sel="Loose selection";
1312 +  if(njets==3) sel="Tight selection";
1313 +  assert(njets==2||njets==3);
1314 +  TText *sele = new TText(0.97,0.135,sel.c_str());
1315 +  sele->SetNDC(true);
1316 +  sele->SetTextColor(TColor::GetColor("#848484"));
1317 +  sele->SetTextFont(42);
1318 +  sele->SetTextAlign(32);
1319 +  sele->SetTextSize(0.03);
1320 +  sele->SetTextAngle(270);
1321 +  return sele;
1322 + }
1323 +
1324   Double_t MarcosChi2TestX(const TH1* h1, const TH1* h2, Double_t &chi2, Int_t &ndf, Int_t &igood, Option_t *option)
1325   {
1326  
# Line 1329 | Line 1343 | Double_t MarcosChi2TestX(const TH1* h1,
1343     return prob;
1344   }
1345  
1346 < 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) {
1346 > 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) {
1347    //this function saves the pad being passed as well as a new one including the ratio.
1348 <  CompleteSave(canvas,savemeas);
1349 <
1348 >  
1349 >  orig_canvas->cd();
1350 >  orig_canvas->Update();
1351 >  CompleteSave(orig_canvas,savemeas);
1352 >  TVirtualPad *canvas = (TVirtualPad*) orig_canvas->Clone("TempCanvas");//otherwise the Ratio_main_canvas will own our pad and destroy it upon deletion
1353 >  
1354    float bottommargin=gStyle->GetPadBottomMargin();
1355    float canvas_height=gStyle->GetCanvasDefH();
1356    float canvas_width=gStyle->GetCanvasDefW();
# Line 1343 | Line 1361 | void save_with_ratio(TH1F *nominator, TH
1361    
1362    float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace);
1363    
1364 <  TCanvas *main_canvas = new TCanvas("main_canvas","main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1364 >  TCanvas *Ratio_main_canvas = new TCanvas("Ratio_main_canvas","Ratio_main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1365    TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad
1366    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
1367    TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad
1368    
1369 <  main_canvas->Range(0,0,1,1);
1370 <  main_canvas->SetBorderSize(0);
1371 <  main_canvas->SetFrameFillColor(0);
1369 >  Ratio_main_canvas->Range(0,0,1,1);
1370 >  Ratio_main_canvas->SetBorderSize(0);
1371 >  Ratio_main_canvas->SetFrameFillColor(0);
1372    
1373    mainpad->Draw();
1374    mainpad->cd();
# Line 1361 | Line 1379 | void save_with_ratio(TH1F *nominator, TH
1379    canvas->Range(0,0,1,1);
1380    canvas->Draw("same");
1381    mainpad->Modified();
1382 <  main_canvas->cd();
1382 >  Ratio_main_canvas->cd();
1383    coverpad->Draw();
1384    coverpad->cd();
1385    coverpad->Range(0,0,1,1);
# Line 1369 | Line 1387 | void save_with_ratio(TH1F *nominator, TH
1387    coverpad->SetBorderSize(0);
1388    coverpad->SetFrameFillColor(0);
1389    coverpad->Modified();
1390 <  main_canvas->cd();
1390 >  Ratio_main_canvas->cd();
1391    bottompad->SetTopMargin(ratiotopmargin);
1392    bottompad->SetBottomMargin(ratiobottommargin);
1393    bottompad->Draw();
# Line 1459 | Line 1477 | void save_with_ratio(TH1F *nominator, TH
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);
1480 >  Ratio_main_canvas->cd();
1481 >  Ratio_main_canvas->Modified();
1482 >  Ratio_main_canvas->cd();
1483 >  Ratio_main_canvas->SetSelected(Ratio_main_canvas);
1484    
1485 <  CompleteSave(main_canvas,savemeas+"_withratio");
1485 >  CompleteSave(Ratio_main_canvas,savemeas+"_withratio");
1486    bottompad->cd();
1487    
1488    Double_t chi2;
# Line 1492 | Line 1510 | void save_with_ratio(TH1F *nominator, TH
1510    CompleteRatio->SetTextAlign(31);
1511    CompleteRatio->Draw();
1512    
1513 <  CompleteSave(main_canvas,savemeas+"_withratio_and_Chi2");
1513 >  CompleteSave(Ratio_main_canvas,savemeas+"_withratio_and_Chi2");
1514  
1515   //  float KS   = nominator->KolmogorovTest(denominator);
1516   //  stringstream KStext;
1517   //  Chi2text << "KS = " << KS << endl;
1518   //cout << "Found : " << KStext.str() << endl;
1519  
1520 <  delete main_canvas;
1520 >  delete eratio;
1521 >  delete ratio_center;
1522 >  delete ratio;
1523 >  delete Ratio_main_canvas;
1524   }
1525  
1526 < 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) {
1526 > 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) {
1527    //this function saves the pad being passed as well as a new one including the SysRatio.
1528 <  CompleteSave(canvas,savemeas);
1528 >  orig_canvas->cd();
1529 >  orig_canvas->Update();
1530 >  CompleteSave(orig_canvas,savemeas);
1531 >  
1532 >  TVirtualPad *canvas = (TVirtualPad*) orig_canvas->Clone("TempCanvas");//otherwise the Ratio_main_canvas will own our pad and destroy it upon deletion
1533  
1534    float bottommargin=gStyle->GetPadBottomMargin();
1535    float canvas_height=gStyle->GetCanvasDefH();
# Line 1516 | Line 1541 | void save_with_ratio_and_sys_band(TH1F *
1541    
1542    float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace);
1543    
1544 <  TCanvas *main_canvas = new TCanvas("main_canvas","main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1544 >  TCanvas *Ratio_main_canvas = new TCanvas("Ratio_main_canvas","Ratio_main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1545    TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad
1546    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
1547    TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad
1548    
1549 <  main_canvas->Range(0,0,1,1);
1550 <  main_canvas->SetBorderSize(0);
1551 <  main_canvas->SetFrameFillColor(0);
1549 >  Ratio_main_canvas->Range(0,0,1,1);
1550 >  Ratio_main_canvas->SetBorderSize(0);
1551 >  Ratio_main_canvas->SetFrameFillColor(0);
1552    
1553    mainpad->Draw();
1554    mainpad->cd();
# Line 1534 | Line 1559 | void save_with_ratio_and_sys_band(TH1F *
1559    canvas->Range(0,0,1,1);
1560    canvas->Draw("same");
1561    mainpad->Modified();
1562 <  main_canvas->cd();
1562 >  Ratio_main_canvas->cd();
1563    coverpad->Draw();
1564    coverpad->cd();
1565    coverpad->Range(0,0,1,1);
# Line 1542 | Line 1567 | void save_with_ratio_and_sys_band(TH1F *
1567    coverpad->SetBorderSize(0);
1568    coverpad->SetFrameFillColor(0);
1569    coverpad->Modified();
1570 <  main_canvas->cd();
1570 >  Ratio_main_canvas->cd();
1571    bottompad->SetTopMargin(ratiotopmargin);
1572    bottompad->SetBottomMargin(ratiobottommargin);
1573    bottompad->Draw();
# Line 1598 | Line 1623 | void save_with_ratio_and_sys_band(TH1F *
1623    oneline->SetLineColor(kBlue);
1624    oneline->Draw("same");
1625  
1626 <  main_canvas->cd();
1627 <  main_canvas->Modified();
1628 <  main_canvas->cd();
1629 <  main_canvas->SetSelected(main_canvas);
1626 >  Ratio_main_canvas->cd();
1627 >  Ratio_main_canvas->Modified();
1628 >  Ratio_main_canvas->cd();
1629 >  Ratio_main_canvas->SetSelected(Ratio_main_canvas);
1630    
1631 <  CompleteSave(main_canvas,savemeas+"_withSysRatio");
1631 >  CompleteSave(Ratio_main_canvas,savemeas+"_withSysRatio");
1632    bottompad->cd();
1633    
1634    Double_t chi2;
# Line 1630 | Line 1655 | void save_with_ratio_and_sys_band(TH1F *
1655    CompleteRatio->SetTextAlign(31);
1656    CompleteRatio->Draw();
1657    
1658 <  CompleteSave(main_canvas,savemeas+"_withSysRatio_and_Chi2");
1659 <  delete main_canvas;
1658 >  CompleteSave(Ratio_main_canvas,savemeas+"_withSysRatio_and_Chi2");
1659 >  delete Ratio_main_canvas;
1660 >  delete ratio;
1661   }
1662  
1663 < TH1F* CollapseStack(THStack stack,TString hname="base") {
1663 > TH1F* CollapseStack(THStack stack,TString hname="CollapsedStack") {
1664     TH1F *bhist = ((TH1F*)((stack.GetHists())->At(0)));
1665     TH1F *basehisto = (TH1F*)bhist->Clone(hname);
1666     TIter next(stack.GetHists());
# Line 1648 | Line 1674 | TH1F* CollapseStack(THStack stack,TStrin
1674     return basehisto;
1675   }
1676  
1677 < void save_with_ratio(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) {
1678 <  save_with_ratio(nominator, CollapseStack(denominator), canvas, savemeas, do_bpred_ratio);
1677 > void Save_With_Ratio(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) {
1678 >  TH1F *denominator_histo = (TH1F*) CollapseStack(denominator);
1679 >  Save_With_Ratio(nominator, denominator_histo, canvas, savemeas, do_bpred_ratio);
1680 >  delete denominator_histo;
1681   }
1682  
1683   void flag_this_change(string function, int line, int checked=0) {
# Line 1992 | Line 2020 | void FindMinMax(TGraphErrors *gr, float
2020  
2021   void CleanLegends() {
2022    for(int ihist=(int)PlottingSetup::FakeHistoHeap.size()-1;ihist>=0;ihist--) {
1995    cout << "Deleting item " << ihist << endl;
1996    cout << "    " << PlottingSetup::FakeHistoHeap[ihist]->GetName() << " , " << PlottingSetup::FakeHistoHeap[ihist]->GetTitle() << endl;
2023      PlottingSetup::FakeHistoHeap[ihist]->Delete();
2024      PlottingSetup::FakeHistoHeap.pop_back();
2025    }
2026   }
2027 +
2028 + string DigitsAfterComma(float number, int digits) {
2029 +  float temp=number*pow(10.0,digits);
2030 +  temp=int(temp)/pow(10.0,digits);
2031 +  return any2string(temp);
2032 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines