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/5570a5e9143b1904dce3bebf0d1be8e5b66569bb591730c2864e902d55880a73.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/5a0b3c560dca9b16fa2cf0b9162d434edfbe49871fd2f2d053d9f54d2415bb0d.svg
this_event = next(events)
this_event
../_images/ff0667ad02da1bd47c9736995fede5ca23c11bd534aab59660d174af420ae1b4.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'
print(this_event)
LHEEvent(eventinfo=LHEEventInfo(nparticles=5, pid=1, weight=1678.21, scale=91.67326, aqed=0.007546771, aqcd=0.129885), particles=[LHEParticle(id=2, status=-1, mother1=0, mother2=0, color1=501, color2=0, px=0.0, py=0.0, pz=225.28790807, e=225.28790807, m=0.0, lifetime=0.0, spin=-1.0), LHEParticle(id=-2, status=-1, mother1=0, mother2=0, color1=0, color2=501, px=-0.0, py=-0.0, pz=-9.3258299877, e=9.3258299877, m=0.0, lifetime=0.0, spin=1.0), LHEParticle(id=23, status=2, mother1=1, mother2=2, color1=0, color2=0, px=0.0, py=0.0, pz=215.96207808, e=234.61373806, m=91.673261728, lifetime=0.0, spin=0.0), LHEParticle(id=-13, status=1, mother1=3, mother2=3, color1=0, color2=0, px=-32.117860394, py=-4.61084611, pz=25.124142411, e=41.037048993, m=0.0, lifetime=0.0, spin=1.0), LHEParticle(id=13, status=1, mother1=3, mother2=3, color1=0, color2=0, px=32.117860394, py=4.61084611, pz=190.83793567, e=193.57668907, m=0.0, lifetime=0.0, spin=-1.0)], weights=None, attributes=None, optional=None, _graph=<graphviz.graphs.Digraph object at 0x7fad05803890>)