Z peak example

We will plot a invariant mass distribution from a LHE input file.

First, some basic imports.

import hist

import pylhe
# Use an example LHE file from package scikit-hep-testdata
from skhep_testdata import data_path

lhe_file = data_path("pylhe-drell-yan-ll-lhe.gz")

Prepare a histogram to calculate the invariant mass of two particles.

mass_hist = hist.Hist.new.Reg(30, 50, 150).Int64()

Use the generator provided by pylhe to read the events.

events = pylhe.to_awkward(pylhe.read_lhe_with_attributes(lhe_file))
mass_hist.fill(
    (events.particles.vector[:, -1] + events.particles.vector[:, -2]).mass,
    weight=events.eventinfo.weight,
)
50 150 Axis 0
Regular(30, 50, 150, label='Axis 0')

Int64() Σ=13189080.0 (16780000.0 with flow)
artists = mass_hist.plot1d()
ax = artists[0].stairs.axes
ax.set_yscale("log")
ax.set_xlabel("Mass [GeV]")
ax.set_ylabel("Count");
../_images/37cdfc1f93657df2bc13802f4bf5a36634713c9e63be1e22665e0f91a26a28c1.png

pylhe also has helpful graph representation of events so you can view what the LHE events you are studying look like.

events = pylhe.read_lhe(lhe_file)
this_event = next(events)
this_event
../_images/32e29e211740589d363cd402258fccc308cbe92b3a8b2498aa441e3f7fbe1823.svg
this_event = next(events)
this_event
../_images/ea2c93154bb4a872839520115484504bcd573b1e61a0ea70ff3726bc2ca70f92.svg

You can also render these graphs into a PDF file.

this_event.graph.render(filename="z0-event", format="pdf", cleanup=True)
'z0-event.pdf'