Discussion:
[ROOT] TAxis strange behaviour
Simone Bifani
2011-03-23 13:23:46 UTC
Permalink
Hi,

it looks like the GetXmax method is not working properly when retrieving
the y-axis maximum of a TH1 histogram

root [0] TH1D *hHisto = new TH1D("","",10,0,10)
root [1] hHisto->FillRandom("gaus")
root [2] hHisto->GetYaxis()->GetXmax()
(const Double_t)1.00000000000000000e+00

while it should be something like 6640 (see attached plot)
I checked few ROOT versions (5.26, 5.28, and trunk) and I always
experienced the same behaviour

Am I doing something wrong or is there a bug?

Thanks,
s.
Olivier Couet
2011-03-23 13:30:53 UTC
Permalink
For a 1D histogram you should do:

hHisto->GetMaximum()
Post by Simone Bifani
hHisto->GetYaxis()->GetXmax()
Simone Bifani
2011-03-23 13:34:54 UTC
Permalink
Hi Olivier,

as far as I know (and I actually just tested) GetMaximum returns the
maximum bin content and not the maximum of the y-axis

s.
Post by Olivier Couet
hHisto->GetMaximum()
Post by Simone Bifani
hHisto->GetYaxis()->GetXmax()
Olivier Couet
2011-03-23 13:42:23 UTC
Permalink
One possible way:

hHisto->GetMaximum()*(1+gStyle->GetHistTopMargin());

-----Original Message-----
From: Simone Bifani
Sent: Wednesday, March 23, 2011 2:35 PM
To: Olivier Couet
Cc: roottalk (Mailing list discussing all aspects of the ROOT system.)
Subject: Re: [ROOT] TAxis strange behaviour

Hi Olivier,

as far as I know (and I actually just tested) GetMaximum returns the maximum bin content and not the maximum of the y-axis

s.
Post by Olivier Couet
hHisto->GetMaximum()
Post by Simone Bifani
hHisto->GetYaxis()->GetXmax()
Simone Bifani
2011-03-23 13:46:31 UTC
Permalink
Hi,

because I need the y-axis maximum to create a TGaxis I did the following
to temporary solve this problem

hCL->GetYaxis()->SetRangeUser(1.e-1, 4. * hCL->GetMaximum());
TGaxis *aEta = new TGaxis(hCL->GetXaxis()->GetXmin(),
hCL->GetMaximum(), hCL->GetXaxis()->GetXmax(), hCL->GetMaximum(), 2.,
4.5, 5, "-");

However it seems quite misleading to me that SetRangeUser changes the
histogram Maximum but not the YAxis Xmax

Nevertheless I suppose you should check the GetYaxis()->GetXmax()
behaviour as I believe it is not working as it should


Thanks,
s.
Post by Olivier Couet
hHisto->GetMaximum()*(1+gStyle->GetHistTopMargin());
-----Original Message-----
From: Simone Bifani
Sent: Wednesday, March 23, 2011 2:35 PM
To: Olivier Couet
Cc: roottalk (Mailing list discussing all aspects of the ROOT system.)
Subject: Re: [ROOT] TAxis strange behaviour
Hi Olivier,
as far as I know (and I actually just tested) GetMaximum returns the maximum bin content and not the maximum of the y-axis
s.
Post by Olivier Couet
hHisto->GetMaximum()
Post by Simone Bifani
hHisto->GetYaxis()->GetXmax()
Philip Rodrigues
2011-03-23 13:42:54 UTC
Permalink
Hi Simone,
GetMaximum acts in a rather confusing way, see the documentation:
http://root.cern.ch/root/html/TH1#TH1:GetMaximum

To get the maximum value on the y axis, TCanvas::GetUymax() seems to work for
me (you may have to call TCanvas::Update() after calling the histogram).

Regards,
Philip
Post by Simone Bifani
Hi Olivier,
as far as I know (and I actually just tested) GetMaximum returns the
maximum bin content and not the maximum of the y-axis
s.
Post by Olivier Couet
hHisto->GetMaximum()
Post by Simone Bifani
hHisto->GetYaxis()->GetXmax()
Olivier Couet
2011-03-24 09:22:08 UTC
Permalink
Simone,



TAxis hold the bins. On a 1D histogram you have bins only along the X axis.

That's why the Y axis behaves differently, it does not really exist until you plot the histo.

Now the 2nd recipe I gave you works even without plotting the histo.

Olivier



-----Original Message-----

From: Simone Bifani

Sent: Wednesday, March 23, 2011 2:47 PM

To: Olivier Couet

Cc: roottalk (Mailing list discussing all aspects of the ROOT system.)

Subject: Re: [ROOT] TAxis strange behaviour



Hi,



because I need the y-axis maximum to create a TGaxis I did the following to temporary solve this problem



hCL->GetYaxis()->SetRangeUser(1.e-1, 4. * hCL->GetMaximum());

TGaxis *aEta = new TGaxis(hCL->GetXaxis()->GetXmin(),

hCL->GetMaximum(), hCL->GetXaxis()->GetXmax(), hCL->GetMaximum(), 2.,

4.5, 5, "-");



However it seems quite misleading to me that SetRangeUser changes the histogram Maximum but not the YAxis Xmax



Nevertheless I suppose you should check the GetYaxis()->GetXmax() behaviour as I believe it is not working as it should





Thanks,

s.

Continue reading on narkive:
Loading...