0

I am able to extract a TH2 histogram from ROOT using the h = f[...].to_numpy() of uproot. This I can then plot with mplhep as a hist2dplot(h).

However, I have the problem that I would like to rebin the original histogram and then plot this. I could not find a working example of rebinning (that I can understand) with mplhep and I cannot find any such way to do it in uproot.

I tried doing this with rebinning/reshaping the arrays, but then I am again stuck at how to plot this exactly.

How do you do it? Is there an easy way? Any hints are welcomed :)

nyw
  • 195
  • 2
  • 11
  • 1
    Yes! There's one more library you needed to know about: https://github.com/scikit-hep/hist . Say `h = f[...].to_hist()` to get a hist object, then you can use this syntax to do the slicing/rebinning: https://uhi.readthedocs.io/en/latest/indexing.html . Calling `h.plot()` internally calls `hist2dplot(h)` from mplhep (it pulls all of these libraries together). – Jim Pivarski Jun 07 '22 at 18:09
  • Hi Jim :)! I am trying to do this as we speak, but probably this does not work for TProfile2D, no (`NotImplementedError`)? With a TH2F, I am able to use the `.to_hist()` and plot it. However, I have to admit, I don't understand exactly how to rebin a 2D histogram, as the examples from the link show only 1D, or am I wrong? If I am to go from `[100x300]` bins to `[50,100]` show should the syntax look like ? `h2 = h[:bh.rebin(2):bh.rebin(3) ?!` Later edit: I answered my question alone. It should be `h2 = h[::bh.rebin(2),::bh.rebin(3)]` – nyw Jun 07 '22 at 18:48
  • With this solved, I am now curious if there is something that can be done for the TProfile2D or is it still WIP? :) – nyw Jun 07 '22 at 18:57
  • I had forgotten about that (last edit: 2 years ago); the NotImplementedError says that an equivalent hist does not exist (https://github.com/scikit-hep/uproot4/blob/6fea96e3e61814cdeb21a3527c215f1911759d9a/src/uproot/behaviors/TProfile2D.py#L105). I find that hard to believe, though I'm the one who wrote it. Maybe ping `@henryiii` in an issue, maybe on hist, rather than Uproot? There must be some equivalent of TProfile2D. – Jim Pivarski Jun 07 '22 at 20:12

0 Answers0