Is the TH1 y-axis a dummy?

Hi,

Using ROOT v5.18/00 I’m confused about the function of the y-axis of the TH1. It does not appear to do anything.

Using the below macro:

[code]{
gROOT->Reset();

TH1D h(“h”, “h”, 100, 0., 1.);
TCanvas canvas(“canvas”);

h.Fill(.9);
h.Fill(.9);

std::cout << “===========================” << std::endl;

std::cout << “Before drawing:” << std::endl;
std::cout << " h.GetMaximum() = "
<< h.GetMaximum() << std::endl;
std::cout << " h.GetYaxis()->GetXmax() = "
<< h.GetYaxis()->GetXmax() << std::endl;

std::cout << std::endl;

h.Draw();
canvas.Update();

std::cout << “After drawing:” << std::endl;
std::cout << " h.GetMaximum() = "
<< h.GetMaximum() << std::endl;
std::cout << " h.GetYaxis()->GetXmax() = "
<< h.GetYaxis()->GetXmax() << std::endl;
std::cout << " gPad->GetFrame()->GetY2() = "
<< gPad->GetFrame()->GetY2() << std::endl;

std::cout << std::endl;

h.Scale(100.);
h.Draw();
canvas.Update();

std::cout << “After scaling:” << std::endl;
std::cout << " h.GetMaximum() = "
<< h.GetMaximum() << std::endl;
std::cout << " h.GetYaxis()->GetXmax() = "
<< h.GetYaxis()->GetXmax() << std::endl;
std::cout << " gPad->GetFrame()->GetY2() = "
<< gPad->GetFrame()->GetY2() << std::endl;
}[/code]

I get the following output:

[code]===========================
Before drawing:
h.GetMaximum() = 2
h.GetYaxis()->GetXmax() = 1

After drawing:
h.GetMaximum() = 2
h.GetYaxis()->GetXmax() = 1
gPad->GetFrame()->GetY2() = 2.1

After scaling:
h.GetMaximum() = 200
h.GetYaxis()->GetXmax() = 1
gPad->GetFrame()->GetY2() = 210[/code]

I think I’m convinced that the size of the drawn y-axis is a property of the current pad’s frame but what is the y-axis supposed to do?

Cheers,
Jeroen

You should always use TH1::GetMaximum to find out the maxiimum bin content,
yaxis is not used for 1-d histograms, and zaxis is not used from a 2-d histogram.

Rene

Thanks Rene,

I guess that makes sense.

What I wanted to do, by the way, was not to find out the maximum of the histogram but that of the axis, to draw a line. I thought I had always used the histogram’s axes for this. Anyway…

Cheers,
Jeroen

Jeroen,

You are looking for the pad range or frame range. For the frame range do
gPad->GetUxmin(), Uxmax, Uymin, Uymax

Rene