Roofit: how to get range of Y scale from plotted frame?

I’m wondering why, when querying the Y-scale limits from plotted frame of the rooplot object, it doesn’t return real values, but [0.1]? The same results is from TPad::GetUymin()/TPad::GetUymax() In this case, the range of the X axis is returned correctly. Example is on basic roofit example:

#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "TCanvas.h"
#include "RooPlot.h"
#include "TAxis.h"
using namespace RooFit;

void rf101_basics()
{
  // S e t u p   m o d e l
  // ---------------------

  // Declare variables x,mean,sigma with associated name, title, initial value and allowed range
  RooRealVar x("x", "x", -10, 10);
  RooRealVar mean("mean", "mean of gaussian", 1, -10, 10);
  RooRealVar sigma("sigma", "width of gaussian", 1, 0.1, 10);

  // Build gaussian p.d.f in terms of x,mean and sigma
  RooGaussian gauss("gauss", "gaussian PDF", x, mean, sigma);

  // Construct plot frame in 'x'
  RooPlot *xframe = x.frame(Title("Gaussian p.d.f."));

  // P l o t   m o d e l   a n d   c h a n g e   p a r a m e t e r   v a l u e s
  // ---------------------------------------------------------------------------

  // Plot gauss in frame (i.e. in x)
  gauss.plotOn(xframe);

  // Change the value of sigma to 3
  sigma.setVal(3);

  // Plot gauss in frame (i.e. in x) and draw frame on canvas
  gauss.plotOn(xframe, LineColor(kRed));

  // G e n e r a t e   e v e n t s
  // -----------------------------

  // Generate a dataset of 1000 events in x from gauss
  RooDataSet *data = gauss.generate(x, 10000);

  // Make a second plot frame in x and draw both the
  // data and the p.d.f in the frame
  RooPlot *xframe2 = x.frame(Title("Gaussian p.d.f. with data"));
  data->plotOn(xframe2);
  gauss.plotOn(xframe2);

  // F i t   m o d e l   t o   d a t a
  // -----------------------------

  // Fit pdf to data
  gauss.fitTo(*data);

  // Print values of mean and sigma (that now reflect fitted values and errors)
  mean.Print();
  sigma.Print();

  // Draw all frames on a canvas
  TCanvas *c = new TCanvas("rf101_basics", "rf101_basics", 800, 400);
  c->Divide(2);
  c->cd(1);
  gPad->SetLeftMargin(0.15);
  xframe->GetYaxis()->SetTitleOffset(1.6);
  xframe->Draw();
  c->cd(2);
  gPad->SetLeftMargin(0.15);
  xframe2->GetYaxis()->SetTitleOffset(1.6);
  xframe2->Draw();

  Double_t
	 xmi = xframe2->GetXaxis()->GetXmin(),
	 xma = xframe2->GetXaxis()->GetXmax(),
	 ymi = xframe2->GetYaxis()->GetXmin(),
	 yma = xframe2->GetYaxis()->GetXmax();

  Info("rf101_basics","xmi=%g, xma=%g, ymi=%g, yma=%g",xmi,xma,ymi,yma);
}

And the output

Info in <rf101_basics>: xmi=-10, xma=10, ymi=0, yma=1

RooPlot produces the given structure (given by gPad->ls()):

Canvas Name=rf101_basics Title=rf101_basics Option=
 TCanvas fXlowNDC=0 fYlowNDC=0 fWNDC=1 fHNDC=1 Name= rf101_basics Title= rf101_basics Option=
  OBJ: TList	TList	Doubly linked list : 0
   TFrame  X1= -10.000000 Y1=0.000000 X2=10.000000 Y2=321.832719
   OBJ: TH1D	frame_7fc476d8c710	Gaussian p.d.f. with data : 0 at: 0x7fc476d8dd90
   OBJ: RooHist	h_gaussData	Histogram of gaussData_plot__x : 0 at: 0x7fc476d90420
   OBJ: RooCurve	gauss_Norm[x]	Projection of gaussian PDF : 0 at: 0x7fc476d996a0
   OBJ: TH1D	frame_7fc476d8c710	Gaussian p.d.f. with data : 0 at: 0x7fc476d8dd90
   OBJ: TPaveText	title  	X1= -4.659315 Y1=335.591072 X2=3.325982 Y2=360.050359

As you can see the limits you are looking for are hold by the TFrame. You can do:

 gPad->GetFrame()->GetY2();

Thanks, Olivier,

But in my root version 6.18/04 I have a different structure and get the same results:

  Double_t
    xmi = xframe2->GetXaxis()->GetXmin(),
    xma = xframe2->GetXaxis()->GetXmax(),
    ymi = xframe2->GetYaxis()->GetXmin(),
    //    yma = xframe2->GetYaxis()->GetXmax();                                                                                                                                                                     
    yma	= gPad->GetFrame()->GetY2();
  gPad->ls();

  Info("rf101_basics","xmi=%g, xma=%g, ymi=%g, yma=%g",xmi,xma,ymi,yma);

and the output

TPad fXlowNDC=0.51 fYlowNDC=0.01 fWNDC=0.48 fHNDC=0.98 Name= rf101_basics_2 Title= rf101_basics_2 Option=
 OBJ: TList	TList	Doubly linked list : 0
  OBJ: TH1D	frame_2fc9c50	Gaussian p.d.f. with data : 0 at: 0x371f430
  OBJ: RooHist	h_gaussData	Histogram of gaussData_plot__x : 0 at: 0x398db20
  OBJ: RooCurve	gauss_Norm[x]	Projection of gaussian PDF : 0 at: 0x35c9710
  OBJ: TH1D	frame_2fc9c50	Gaussian p.d.f. with data : 0 at: 0x371f430
Info in <rf101_basics>: xmi=-10, xma=10, ymi=0, yma=1

 [...]
 gPad->Update();
  Double_t
	 xmi = xframe2->GetXaxis()->GetXmin(),
	 xma = xframe2->GetXaxis()->GetXmax(),
	 ymi = xframe2->GetYaxis()->GetXmin(),
	 yma = gPad->GetFrame()->GetY2();;

  Info("rf101_basics","xmi=%g, xma=%g, ymi=%g, yma=%g",xmi,xma,ymi,yma);
}

gives:

Info in <rf101_basics>: xmi=-10, xma=10, ymi=0, yma=321.833

It works now, thank you very much for help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.