TH1::Rebin confused about dividers

Dear experts,

This is very minor and may well be a machine dependent problem. In some cases, when rebinning histograms I get the complaint:
TH1D::Rebin:0: RuntimeWarning: ngroup=5 must be an exact divider of nbins=60

Since 5 is an exact divider of 60 something must have gone wrong. I’m working from within PyROOT but the value for ngroup is an int and ngroup/hist.GetXaxis().GetNbins() is really zero if looked at in python.

I don’t know what’s happening here. A bit of playing shows that with ngroup=5 it’s reproducible (complaints both about nbins=60 and nbins=130), with ngroup=1 there’s no issue and with ngroup=2 the only complaints are about nbins=130.

Any ideas about what’s causing this?

Cheers,
Jeroen

Jeroen,

If this works with pure C++, post the problem to the pyroot thread.

Rene

Hi Rene,

I just checked to be really sure:

  • the issue is also present from the CINT command line
  • the issue is also present in 5.18/00
  • the issue is also present on other machines with a different (much newer) Scientific Linux install
  • the issue is also present with v5.18.00 on OS X
  • when copying the histogram to another file the same still happens, so it’s not something freaky with the environment/file/etc.
  • it even happens with a new histogram:

root [0] TH1D* h = new TH1D("h", "h", 60, 0., 10.) root [1] h->Rebin(5) Warning in <TH1D::Rebin>: ngroup=5 must be an exact divider of nbins=60 (class TH1*)0xa106e70 root [2]

and more interestingly

root [0] TH1D* h = new TH1D("h","h", 60, 0., 10.) root [1] h->Rebin(2) (class TH1*)0x2028a00 root [2]

I have a suspicion that in TH1::Rebin the division of the integers (ngroup/nbins) is kept as a float and the % operation does not give the expected result because of that. I don’t know why this would work for some values and not for others, but I may be confused.

Cheers,
Jeroen

Hi Jeroen,

I have fixed the problem in the SVN trunk. It was not a division/rounding problem,
but a logic error. Thanks for reporting this case.

Rene

Hi Rene,

I’m using
ROOT 5.18/00 (trunk@21744, Jan 17 2008, 15:15:00 on linux)
on SLC 4 linux machine and I see the
same messages when I call Rebin(). But I don’t see
patched binary distribution for 5.18 so I need to use
this release as I cannot rebuild it on this system. Should
I move to 5.19 ? or this is just something that I can
ignore? (as it looks like the warning is wrong and
the rebined histogram seems to be fine)

Regards,
Chul Su

[quote=“brun”]Hi Jeroen,

I have fixed the problem in the SVN trunk. It was not a division/rounding problem,
but a logic error. Thanks for reporting this case.

Rene[/quote]

Move to version 5.19 or better wait for the coming production release 5.20 this coming wednesday.

Rene

Hi Rene,

Your message was not clear to me, you mean
the actual Rebin() can give a wrong re-binned histogram
w/ 5.18/00 ? (then, I may need to do manual re-binning
for now until we have a production release next week).

Regards,
Chul Su

[quote=“brun”]Move to version 5.19 or better wait for the coming production release 5.20 this coming wednesday.

Rene[/quote]

Hello,

I also have also experienced this problem. I had been using ROOT 5.14 on Debian Etch which would rebin quite happily for any integer ngroup less than the number of bins. I discovered the the error given above with ROOT 5.18 on Mac 10.4. I upgraded the Mac today to ROOT 5.20.

Using the example given above by jhegeman:

root [0] TH1D* h = new TH1D("h","h",60,0.,10.) 
root [1] h->Rebin(5)              // exact divider             
(class TH1*)0x2833400
root [2] h->GetNbinsX()
(const Int_t)(12)
root [3] TH1D* h2 = new TH1D("h2","h2",60,0.,10.)   // same histogram
root [4] h2->Rebin(7)             // not exact divider               
Warning in <TH1D::Rebin>: ngroup=7 must be an exact divider of nbins=60
(class TH1*)0x281f000
root [5] h2->GetNbinsX()                         
(const Int_t)(8)

In both cases the Rebin function does as the documentation states:

root.cern.ch/root/html520/TH1.html#TH1:Rebin

However, in the case of ngroup not being an exact divider of nbinsx an apparently spurious warning is issued. I would appreciate someone verifying my train of thought.

Thank you.