Suggestion: Option to require integer binning

Hi, I quite like to use the TTree::Draw method and I enjoy its automatic binning system. As I understand it, before filling “real” bins, it fills up a buffer with the non-binned values. Once the buffer is full, it then selects maximum and minimum edges, sets up bins, and then all further data is binned accordingly.

This is very useful, but I wonder if it would be simple to add an option: that the automatically-determined bin edges line up on the integers. Often the X coordinate of a histogram is integer-valued, and it makes no sense to have bin edges between integers. You can tell because often newbies think a “TH1I” is for this purpose.

The idea would be to maintain the convenient automatic range determination, and the default number of bins, but to flex the final result so that the bins coincide with integers (possibly integer-multiple wide in the case of large ranges).

Does anyone else think this would be useful? Or is there a short way to achieve the same result with a user-provided function?

In a first approximation I would say that you can provide your own histogram with bins aligned on integers and use it in TTree::Draw with the “>>” operator.

Did you find one case where the binwidth or edge is not a multiple of an integer when the variable type is an integer? TTree::Draw already look at this case and makes the relevant optimization.