Bins with equal number of entries

Dear,

I want to have a TH1 binning with every bin having the same number of entries, however, I’m also plotting another histogram on the same canvas, and I want this second TH1 to have the same binning as the first one. It is important because I need a ratio plot of the two. The first part of my question was already asked, but I can’t find a solution. I’m sure this method is intensively used, is there a function or an efficient way to implement it?

Many thanks!

may be @moneta can help. But if each bin have the same number of entries and if each entry has the same weight you will get a flat histogram ?

Hi,

If you have the data points before , this can be done with the TKDTreeBinning class, which optimally divide the space (find your bin histograms) to have same content in each bin.
An example (in 2D) is here

The histogram will be flat, but since the bin volumes are different, one is interested in displaying the data density, i.e. number of events in bin divided by the bin volume

Lorenzo

1 Like

Hi Couet and Lorenzo,

Many thanks for the solution, indeed I meant bins with the same number of entries but different bin widths, since the data is not uniformly distributed. Basically, I want to reduce the statistical errors in the tails of the distributions, so I’m not sure if this is the best way to do it. If you have any other suggestions, I would be very grateful to hear them!