Hello,
I found an issue with histograms with automatic bins, it looks like a bug, but maybe I misunderstand something about automatic bins, so I’m asking here first. I reduced the problem to a simple example code.
Currently I use root-5.28.00b on Gentoo Linux.
The following code does what I want to do, bins are fixed:
{
TCanvas c1("c1","",200,10,1024,768);
TH1I h1("h1","h1",100,0,100);
TH1I h2("h2","h2",100,0,100);
for (int i=0; i<2000; i++)
h1.Fill(1);
for (int i=0; i<100; i++)
h2.Fill(1);
h2.Scale(h1.Integral()/h2.Integral());
h1.SetLineColor(kRed);
h2.SetLineColor(kGreen);
h1.Draw("");
h2.Draw("sames");
c1.Update();
TPaveStats *st;
st = (TPaveStats*)h1.GetListOfFunctions()->FindObject("stats");
st->SetX1NDC(0.80); st->SetX2NDC(0.99);
st->SetY1NDC(0.87); st->SetY2NDC(0.99);
st = (TPaveStats*)h2.GetListOfFunctions()->FindObject("stats");
st->SetX1NDC(0.80); st->SetX2NDC(0.99);
st->SetY1NDC(0.74); st->SetY2NDC(0.86);
st->Draw();
c1.Update();
c1.Print("scaling_fixed.png");
}
h2 is scaled to match h1 integral, the only bin for each histogram has equal height, Integral values on TPaveStats are right and match original values.
Then I use adaptive bins (with xmax < xmin), code is essentially the same, except for histograms initialization:
{
TCanvas c1("c1","",200,10,1024,768);
TH1I h1("h1","h1",100,0,-1);
TH1I h2("h2","h2",100,0,-1);
for (int i=0; i<2000; i++)
h1.Fill(1);
for (int i=0; i<100; i++)
h2.Fill(1);
h2.Scale(h1.Integral()/h2.Integral());
h1.SetLineColor(kRed);
h2.SetLineColor(kGreen);
h1.Draw("");
h2.Draw("sames");
c1.Update();
TPaveStats *st;
st = (TPaveStats*)h1.GetListOfFunctions()->FindObject("stats");
st->SetX1NDC(0.80); st->SetX2NDC(0.99);
st->SetY1NDC(0.87); st->SetY2NDC(0.99);
st = (TPaveStats*)h2.GetListOfFunctions()->FindObject("stats");
st->SetX1NDC(0.80); st->SetX2NDC(0.99);
st->SetY1NDC(0.74); st->SetY2NDC(0.86);
st->Draw();
c1.Update();
c1.Print("scaling_adaptive.png");
}
And I got a total mess here:
- h2 is not scaled at all and is displayed at its original height;
- Number of entries for h2 is doubled! I have no idea why.
Am I doing something wrong, or this is bug?