Hans Dembinski | TU Dortmund
PyPI https://pypi.org/project/pyhepmc
Source https://github.com/scikit-hep/pyhepmc
Documentation https://scikit-hep.org/pyhepmc
Latest release v2.7.1
Generator (Pythia, ...) $\longrightarrow$ HepMC3 file $\longrightarrow$ detector simulation, Rivet, ...
pyhepmc.open
import pyhepmc
with pyhepmc.open("sibyll21.dat") as f:
for event in f:
... # do something with event
from particle import Particle # great synergies
# energy, PDG ID, name of final-state particles in the record (sorted)
def en(p): return p.momentum.e
def name(p): return Particle.from_pdgid(p.pid).name
sorted([(en(p), p.pid, name(p)) for p in event.particles if p.status == 1])
[(0.21799583733081818, -211, 'pi-'), (0.2832586169242859, 211, 'pi+'), (0.2986985743045807, -211, 'pi-'), (0.3166664242744446, -211, 'pi-'), (0.3245152235031128, 22, 'gamma'), (0.3567061126232147, 211, 'pi+'), (0.5115386843681335, 22, 'gamma'), (0.5509395003318787, 22, 'gamma'), (0.5818261504173279, 22, 'gamma'), (0.876023530960083, 211, 'pi+'), (1.4933778047561646, 22, 'gamma'), (1.5073537826538086, 2212, 'p'), (1.5396702289581299, 22, 'gamma'), (1.607804298400879, 22, 'gamma'), (1.9595634937286377, 22, 'gamma'), (7.576014518737793, 2212, 'p')]
event.run_info
GenRunInfo(tools=[ToolInfo(name='SIBYLL', version='2.1', description='')], weight_names=[], attributes={})
# mark all vertices with photon children as "sparkly"
for v in event.vertices:
if any(q.pid == 22 for q in v.particles_out):
v.attributes["sparkly"] = True
with pyhepmc.open("output.xz", "w") as f: # or .gz or .bz2
f.write(event)