Uproot 3

3.14.4 · maintenance · verified Thu Apr 16

Uproot 3 is a Python library designed for reading and writing ROOT files, a data format prevalent in high-energy physics, using pure Python and NumPy. It facilitates the conversion of ROOT data into familiar Python data structures like NumPy arrays. This version (3.x) is currently in maintenance mode, superseded by `uproot4`, and receives only critical bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple ROOT file, then open it and read data from specified branches using `uproot3`. It shows accessing a single branch directly and multiple branches via a tree object, converting them into NumPy arrays.

import uproot3
import numpy as np
import os

# Create a dummy ROOT file for demonstration purposes
# In a real application, you would open an existing file
filename = "my_dummy_data.root"

with uproot3.recreate(filename) as file:
    file["tree"] = {"branch1": np.array([1, 2, 3, 4, 5]), "branch2": np.array([10.1, 20.2, 30.3, 40.4, 50.5])}

# Open the ROOT file and read data from a specific branch
with uproot3.open(filename) as file:
    branch_data = file["tree/branch1"].array()
    print(f"Data from branch1: {branch_data}")
    
    # Accessing multiple branches
    tree = file["tree"]
    branch2_data = tree.array("branch2")
    print(f"Data from branch2: {branch2_data}")

# Clean up the dummy file
os.remove(filename)

view raw JSON →