Using ROOT histograms in Python.
ROOT histograms implement the Unified Histogram Interface (UHI), a standard protocol that makes ROOT histograms interoperable with the broader Python scientific ecosystem. This compliance standardizes histogram operations, making tasks like plotting, indexing, and slicing more intuitive and consistent.
A one-page quick reference covering the API.
ROOT histograms implement the PlottableHistogram protocol. Any plotting library that accepts an object that follows the protocol can plot ROOT histogram objects.
You can read more about the protocol on the UHI plotting page.
For 2D histograms, use hep.hist2dplot:
ROOT histograms implement the UHI indexing specification. This introduces a unified syntax for accessing and setting bin values, as well as slicing histogram axes.
You can read more about the syntax on the UHI Indexing page.
The loc, undeflow, overflow, rebin and sum tags are imported from the ROOT.uhi module.
nbins+1 where 0 is the underflow bin and nbins+1 is the overflow (see conventions for numbering bins). In contrast, UHI inherits 0-based indexing from numpy array conventions where 0 is the first valid element and n-1 is the last valid element. Our implementation complies with the UHI conventions by implementing the following syntax:h[underflow] returns the underflow bin (equivalent to h.GetBinContent(0)).h[0] returns the first valid bin (equivalent to h.GetBinContent(1)).h[-1] returns the last valid bin (equivalent to h.GetBinContent(nbins)).h[overflow] returns the overflow bin (equivalent to h.GetBinContent(nbins+1)).sumans = h[a:b:sum] --> ans is the integral value.ROOT histograms can be serialized to a shared UHI format and deserialized into any UHI-compatible library, enabling histogram exchange between ROOT, boost-histogram, hist and others without manual conversion.