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.36 by buchmann, Mon Apr 8 14:09:50 2013 UTC

# Line 1236 | Line 1236 | bool Contains(string wholestring, string
1236    else return false;
1237   }
1238  
1239 +
1240   //////////////////////////////////////////////////////////////////////////////
1241   //
1242   // http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c
# Line 1248 | Line 1249 | bool Contains(string wholestring, string
1249   /* usage:
1250   double vm2, rss2;
1251   process_mem_usage(vm2, rss2);
1252 < cout << "Memory usage: VM: " << vm << "; RSS: " << rss << endl;
1252 > cout << "Memory usage: VM: " << vm2 << "; RSS: " << rss2 << endl;
1253   */
1254  
1255   void process_mem_usage(double& vm_usage, double& resident_set)
# Line 1307 | Line 1308 | TGraphAsymmErrors* produce_ratio_graph(T
1308   }
1309  
1310  
1311 + TText* WriteSelection(int njets) {
1312 +  string sel="Loose selection";
1313 +  if(njets==3) sel="Tight selection";
1314 +  assert(njets==2||njets==3);
1315 +  TText *sele = new TText(0.97,0.135,sel.c_str());
1316 +  sele->SetNDC(true);
1317 +  sele->SetTextColor(TColor::GetColor("#848484"));
1318 +  sele->SetTextFont(42);
1319 +  sele->SetTextAlign(32);
1320 +  sele->SetTextSize(0.03);
1321 +  sele->SetTextAngle(270);
1322 +  return sele;
1323 + }
1324 +
1325   Double_t MarcosChi2TestX(const TH1* h1, const TH1* h2, Double_t &chi2, Int_t &ndf, Int_t &igood, Option_t *option)
1326   {
1327  
# Line 1329 | Line 1344 | Double_t MarcosChi2TestX(const TH1* h1,
1344     return prob;
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) {
1347 > 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) {
1348    //this function saves the pad being passed as well as a new one including the ratio.
1349 <  CompleteSave(canvas,savemeas);
1349 >  
1350 >  orig_canvas->cd();
1351 >  orig_canvas->Update();
1352 >  CompleteSave(orig_canvas,savemeas);
1353 >  TVirtualPad *canvas = (TVirtualPad*) orig_canvas->Clone("TempCanvas");//otherwise the Ratio_main_canvas will own our pad and destroy it upon deletion
1354    
1355    float bottommargin=gStyle->GetPadBottomMargin();
1356    float canvas_height=gStyle->GetCanvasDefH();
# Line 1343 | Line 1362 | void save_with_ratio(TH1F *nominator, TH
1362    
1363    float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace);
1364    
1365 <  TCanvas *main_canvas = new TCanvas("main_canvas","main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1365 >  TCanvas *Ratio_main_canvas = new TCanvas("Ratio_main_canvas","Ratio_main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1366    TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad
1367    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
1368    TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad
1369    
1370 <  main_canvas->Range(0,0,1,1);
1371 <  main_canvas->SetBorderSize(0);
1372 <  main_canvas->SetFrameFillColor(0);
1370 >  Ratio_main_canvas->Range(0,0,1,1);
1371 >  Ratio_main_canvas->SetBorderSize(0);
1372 >  Ratio_main_canvas->SetFrameFillColor(0);
1373    
1374    mainpad->Draw();
1375    mainpad->cd();
# Line 1361 | Line 1380 | void save_with_ratio(TH1F *nominator, TH
1380    canvas->Range(0,0,1,1);
1381    canvas->Draw("same");
1382    mainpad->Modified();
1383 <  main_canvas->cd();
1383 >  Ratio_main_canvas->cd();
1384    coverpad->Draw();
1385    coverpad->cd();
1386    coverpad->Range(0,0,1,1);
# Line 1369 | Line 1388 | void save_with_ratio(TH1F *nominator, TH
1388    coverpad->SetBorderSize(0);
1389    coverpad->SetFrameFillColor(0);
1390    coverpad->Modified();
1391 <  main_canvas->cd();
1391 >  Ratio_main_canvas->cd();
1392    bottompad->SetTopMargin(ratiotopmargin);
1393    bottompad->SetBottomMargin(ratiobottommargin);
1394    bottompad->Draw();
# Line 1459 | Line 1478 | void save_with_ratio(TH1F *nominator, TH
1478    oneline->SetLineColor(kBlue);
1479    oneline->Draw("same");
1480  
1481 <  main_canvas->cd();
1482 <  main_canvas->Modified();
1483 <  main_canvas->cd();
1484 <  main_canvas->SetSelected(main_canvas);
1481 >  Ratio_main_canvas->cd();
1482 >  Ratio_main_canvas->Modified();
1483 >  Ratio_main_canvas->cd();
1484 >  Ratio_main_canvas->SetSelected(Ratio_main_canvas);
1485    
1486 <  CompleteSave(main_canvas,savemeas+"_withratio");
1486 >  CompleteSave(Ratio_main_canvas,savemeas+"_withratio");
1487    bottompad->cd();
1488    
1489    Double_t chi2;
# Line 1492 | Line 1511 | void save_with_ratio(TH1F *nominator, TH
1511    CompleteRatio->SetTextAlign(31);
1512    CompleteRatio->Draw();
1513    
1514 <  CompleteSave(main_canvas,savemeas+"_withratio_and_Chi2");
1514 >  CompleteSave(Ratio_main_canvas,savemeas+"_withratio_and_Chi2");
1515  
1516   //  float KS   = nominator->KolmogorovTest(denominator);
1517   //  stringstream KStext;
# Line 1502 | Line 1521 | void save_with_ratio(TH1F *nominator, TH
1521    delete eratio;
1522    delete ratio_center;
1523    delete ratio;
1524 <  delete main_canvas;
1524 >  delete Ratio_main_canvas;
1525   }
1526  
1527 < 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) {
1527 > 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) {
1528    //this function saves the pad being passed as well as a new one including the SysRatio.
1529 <  CompleteSave(canvas,savemeas);
1529 >  orig_canvas->cd();
1530 >  orig_canvas->Update();
1531 >  CompleteSave(orig_canvas,savemeas);
1532 >  
1533 >  TVirtualPad *canvas = (TVirtualPad*) orig_canvas->Clone("TempCanvas");//otherwise the Ratio_main_canvas will own our pad and destroy it upon deletion
1534  
1535    float bottommargin=gStyle->GetPadBottomMargin();
1536    float canvas_height=gStyle->GetCanvasDefH();
# Line 1519 | Line 1542 | void save_with_ratio_and_sys_band(TH1F *
1542    
1543    float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace);
1544    
1545 <  TCanvas *main_canvas = new TCanvas("main_canvas","main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1545 >  TCanvas *Ratio_main_canvas = new TCanvas("Ratio_main_canvas","Ratio_main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1546    TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad
1547    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
1548    TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad
1549    
1550 <  main_canvas->Range(0,0,1,1);
1551 <  main_canvas->SetBorderSize(0);
1552 <  main_canvas->SetFrameFillColor(0);
1550 >  Ratio_main_canvas->Range(0,0,1,1);
1551 >  Ratio_main_canvas->SetBorderSize(0);
1552 >  Ratio_main_canvas->SetFrameFillColor(0);
1553    
1554    mainpad->Draw();
1555    mainpad->cd();
# Line 1537 | Line 1560 | void save_with_ratio_and_sys_band(TH1F *
1560    canvas->Range(0,0,1,1);
1561    canvas->Draw("same");
1562    mainpad->Modified();
1563 <  main_canvas->cd();
1563 >  Ratio_main_canvas->cd();
1564    coverpad->Draw();
1565    coverpad->cd();
1566    coverpad->Range(0,0,1,1);
# Line 1545 | Line 1568 | void save_with_ratio_and_sys_band(TH1F *
1568    coverpad->SetBorderSize(0);
1569    coverpad->SetFrameFillColor(0);
1570    coverpad->Modified();
1571 <  main_canvas->cd();
1571 >  Ratio_main_canvas->cd();
1572    bottompad->SetTopMargin(ratiotopmargin);
1573    bottompad->SetBottomMargin(ratiobottommargin);
1574    bottompad->Draw();
# Line 1601 | Line 1624 | void save_with_ratio_and_sys_band(TH1F *
1624    oneline->SetLineColor(kBlue);
1625    oneline->Draw("same");
1626  
1627 <  main_canvas->cd();
1628 <  main_canvas->Modified();
1629 <  main_canvas->cd();
1630 <  main_canvas->SetSelected(main_canvas);
1627 >  Ratio_main_canvas->cd();
1628 >  Ratio_main_canvas->Modified();
1629 >  Ratio_main_canvas->cd();
1630 >  Ratio_main_canvas->SetSelected(Ratio_main_canvas);
1631    
1632 <  CompleteSave(main_canvas,savemeas+"_withSysRatio");
1632 >  CompleteSave(Ratio_main_canvas,savemeas+"_withSysRatio");
1633    bottompad->cd();
1634    
1635    Double_t chi2;
# Line 1633 | Line 1656 | void save_with_ratio_and_sys_band(TH1F *
1656    CompleteRatio->SetTextAlign(31);
1657    CompleteRatio->Draw();
1658    
1659 <  CompleteSave(main_canvas,savemeas+"_withSysRatio_and_Chi2");
1660 <  delete main_canvas;
1659 >  CompleteSave(Ratio_main_canvas,savemeas+"_withSysRatio_and_Chi2");
1660 >  delete Ratio_main_canvas;
1661    delete ratio;
1662   }
1663  
# Line 1652 | Line 1675 | TH1F* CollapseStack(THStack stack,TStrin
1675     return basehisto;
1676   }
1677  
1678 < void save_with_ratio(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) {
1679 <  TH1F *denominator_histo = CollapseStack(denominator);
1680 <  save_with_ratio(nominator, denominator_histo, canvas, savemeas, do_bpred_ratio);
1678 > void Save_With_Ratio(TH1F *nominator, THStack denominator, TVirtualPad *canvas, string savemeas, bool do_bpred_ratio=false) {
1679 >  TH1F *denominator_histo = (TH1F*) CollapseStack(denominator);
1680 >  Save_With_Ratio(nominator, denominator_histo, canvas, savemeas, do_bpred_ratio);
1681    delete denominator_histo;
1682   }
1683  
# Line 1883 | Line 1906 | TPolyLine* GetFitUncertaintyShape(TF1 *f
1906    y[nPoints]=y[0];
1907    
1908    TPolyLine *l = new TPolyLine(nPoints+1,x,y);
1909 <  l->SetFillColor(TColor::GetColor("#5858FA"));
1910 <  l->SetLineColor(TColor::GetColor("#5858FA"));
1909 >  l->SetFillColor(TColor::GetColor("#A2A2FA"));
1910 >  l->SetLineColor(TColor::GetColor("#A2A2FA"));
1911    l->SetLineWidth(1);
1912    return l;
1913   }  
# Line 2002 | Line 2025 | void CleanLegends() {
2025      PlottingSetup::FakeHistoHeap.pop_back();
2026    }
2027   }
2028 +
2029 + string DigitsAfterComma(float number, int digits) {
2030 +  float temp=number*pow(10.0,digits);
2031 +  temp=int(temp)/pow(10.0,digits);
2032 +  return any2string(temp);
2033 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines