pythonuproot

rebinning hist object from linear bins to log(x) bins in scikit-hep hist


I am trying to rebin my hist objects from linear bins to log(x) bins. I see on the UHI read the docs on indexing (https://uhi.readthedocs.io/en/latest/indexing.html#) that it is possible to linear rebin with h == h[::rebin(2)], but this gives all bins the same width still. Is it possible to rebin with user defined bin edges? In this case, I wanted log(x) bins. If it is not possible, I am also thinking about making a new hist object that meets the log(x) bins by slicing the original histogram in a loop, each loop being each bin edges.


Solution

  • Linear to log won't work because edges can't move. Ultimately variable space rebinning boils down to "map x bins into one" over and over, where x changes. The final set of bin edges will always be a subset of the original bin edges. You can make them sort-of log space with rounding to the nearest linear bin edge (but I'd highly recommend waiting for the next release of boost-histogram, as full UHI support including variable rebinding is currently an open PR that I'm going to be working on this week).

    It is much better to do a log binning on the original data, then you'll have actual log-spaced bin edges.