LHEH5/HDF5 example

import shutil
from tempfile import NamedTemporaryFile
from urllib.request import urlopen

import hist

import pylhe
url = "https://zenodo.org/records/7751000/files/l2_1.hdf5?download=1"
with urlopen(url) as response, NamedTemporaryFile(suffix=".hdf5") as tmp:
    shutil.copyfileobj(response, tmp)
    tmp.flush()

    lhe = pylhe.LHEFile.fromfile(tmp.name)
arr = pylhe.to_awkward(lhe)
higgs = arr.particles[(abs(arr.particles.id) == 25) & (arr.particles.status == 1)]
mass_hist = hist.Hist.new.Reg(30, 0, 50).Int64()
# only take first higgs per event
mass_hist.fill(
    higgs.vector[:, 0].pt,
    weight=arr.eventinfo.weight,
)
0 50 Axis 0
Regular(30, 0, 50, label='Axis 0')

Int64() Σ=7047002756.0 (22394099927.0 with flow)
artists = mass_hist.plot1d()
ax = artists[0].stairs.axes
# ax.set_yscale("log")
ax.set_xlabel("P_T [GeV]")
ax.set_ylabel("Count");
../_images/0ce15da20eda836c55d86f1ee90d2be731755beb9a5c9655f2588e432ad85276.png