TH1.Divide not working with variable bin widths

Dividing histograms with (the same) variable bin widths gives a histogram with uniform bin widths.

I created a script to demonstrate the bug. Please see attached. It fills two random histograms, rebins them with variable bin widths, and then divides them. (1.62 KB)


As specified in the documentation, the method is meant to replace the contents of ratio with the contents of the division of numer and denom. The methods is not creating a new histogram, but rather using the existing one.

Although some basic consistency is checked, the method does not check bin by bin limits. It is the user responsibility to do so. Ideally, this should be checked by all the methods, but unfortunately it is not. I will add this to my TODO list and implement it as soon as possible, but in principle, as I said before, it is user’s responsibility to do so.

Have a look to the code I sent you, it’s just one of the ways you can do this to work correctly.

plot_rebin_divide.C (1.36 KB)

Thank you for the reply. I now see that it is the TH1F constructor that is making the binning and the Divide call does not edit it. Using Clone, I verify that I am able to copy the binning for the new histogram. Thank you for the solution.