|
| 1 | +--- |
| 2 | + title: "Level Up Your Histogram Analysis Using ROOT’s UHI" |
| 3 | + layout: archive |
| 4 | + author: Silia Taider |
| 5 | +--- |
| 6 | + |
| 7 | +What if you could intuitively manipulate your ROOT histograms, create stunning plots with your favorite Python libraries, and perform advanced operations--all with **Pythonic ease**? |
| 8 | + |
| 9 | +Starting from **ROOT 6.36**, the Unified Histogram Interface (UHI) bridges the gap between ROOT's powerful features and Python's intuitive APIs, taking your data analysis workflow to the next level! |
| 10 | + |
| 11 | +## What is UHI? |
| 12 | + |
| 13 | +The [Unified Histogram Interface (UHI)](https://uhi.readthedocs.io/en/latest/index.html) is a modern API designed to standardize and simplify histogram operations in Python. |
| 14 | +Fully implemented now in ROOT, UHI ensures that all ROOT histogram classes--derived from [TH1](https://root.cern/doc/master/classTH1.html)--can leverage a consistent **intuitive** interface for Python developers, enhanced with a powerful set of functionalities like **slicing**, **indexing**, as well as native integration with popular Python **plotting** libraries, making ROOT histograms more versatile than ever. |
| 15 | + |
| 16 | +## How about a quick demo? |
| 17 | + |
| 18 | +Let me show you how you can fill your histograms with [NymPy](https://numpy.org/) arrays directly: |
| 19 | + |
| 20 | +```python |
| 21 | +import matplotlib.pyplot as plt |
| 22 | +import mplhep as hep |
| 23 | +import numpy as np |
| 24 | +import ROOT |
| 25 | + |
| 26 | +h1 = ROOT.TH1F("h1", "", 40, -4, 4) |
| 27 | +h1[...] = np.random.uniform(0, 1, 40) |
| 28 | +hep.histplot(h1, label="h1", linewidth=2, yerr=False) |
| 29 | +plt.title("My histo") |
| 30 | +plt.show() |
| 31 | +``` |
| 32 | +Et voilà! |
| 33 | +<center> |
| 34 | + <img |
| 35 | + src="{{'/assets/images/blog/posts/2025-06-06-uhi-for-root/blog_uhi_th1.png' | relative_url}}" |
| 36 | + style="width: 100%" /> |
| 37 | +</center> |
| 38 | + |
| 39 | +You can also easily plot ROOT histograms with libraries like [Matplolib](https://matplotlib.org/) that don't directly support UHI yet (using a small trick--can you spot it?): |
| 40 | + |
| 41 | +```python |
| 42 | +h2 = ROOT.TH2D("h2", "h2", 10, 0, 1, 10, 0, 1) |
| 43 | +h2[...] = np.random.uniform(0, 1, (10, 10)) |
| 44 | + |
| 45 | +plt.imshow(h2.values()) |
| 46 | +plt.colorbar(label='Counts') |
| 47 | +plt.title("My 2D histo") |
| 48 | +plt.show() |
| 49 | +``` |
| 50 | +<center> |
| 51 | + <img |
| 52 | + src="{{'/assets/images/blog/posts/2025-06-06-uhi-for-root/blog_uhi_th2.png' | relative_url}}" |
| 53 | + style="width: 100%" /> |
| 54 | +</center> |
| 55 | + |
| 56 | +## Ready to Level Up Your Histogram Analysis? |
| 57 | +With UHI, ROOT histograms now offer Python developers an intuitive, modern, and powerful API. |
| 58 | +Check out the [ROOT UHI documentation](https://root.cern/doc/master/group__uhi__docs.html) for more implementation details and examples! |
0 commit comments