Skip to main content

A small package to get structured data out of Les Houches Event files

Project description

pylhe: A Lightweight Python interface to Les Houches Event files

pylhe logo

GitHub Project DOI Scikit-HEP

RTD Docs Live Docs

PyPI version Conda-forge version Supported Python versions

GitHub Actions Status Code Coverage pre-commit.ci status Code style: black

Binder

Small and thin Python interface to read Les Houches Event (LHE) files

Tested Monte Carlo Generators' LHE output

Generator Tested Versions
MadGraph5 2.0.0, 2.2.1, 3.5.8
POWHEG-BOX-V2 r4027
Pythia 6.413, 8.3.14
Sherpa 3.0.1
Whizard 3.1.4

Note: test files are provided via the scikit-hep-testdata package. Please open an issue of create directly a PR for the inclusion of new files for testing.

Install

To install pylhe from PyPI you can just do

python -m pip install pylhe

The visualization capabilities require the external dependency of Graphviz.

Get started

The example below provides a simple overview. Full functionality can be inspected from the functions provided in the pylhe module. For more information about the LHE format, see the LHE format documentation.

Reading

import itertools

# You can use LHE files from scikit-hep-testdata
from skhep_testdata import data_path

import pylhe

lhe_file = data_path("pylhe-testlhef3.lhe")
events = pylhe.LHEFile.fromfile(lhe_file).events
print(f"Number of events: {pylhe.LHEFile.count_events(lhe_file)}")

# Get event 1
event = next(itertools.islice(events, 1, 2))

# A DOT language graph of the event can be inspected as follows
print(event.graph.source)

# The graph is nicely displayed as SVG in Jupyter notebooks
event

# To save a DOT graph render the graph to a supported image format
# (refer to the Graphviz documentation for more)
event.graph.render(filename="test", format="png", cleanup=True)
event.graph.render(filename="test", format="pdf", cleanup=True)

Writing

For a full example see write or filter. The values in the sketch below are intentionally left empty since they depend on the use-case. The data structure of pylhe is:

import pylhe

file = pylhe.LHEFile(
    init=pylhe.LHEInit(
        initInfo=pylhe.LHEInitInfo(
            beamA=...,
            beamB=...,
            energyA=...,
            energyB=...,
            PDFgroupA=...,
            PDFgroupB=...,
            PDFsetA=...,
            PDFsetB=...,
            weightinStrategy=...,
            numProcesses=...,
        ),
        procInfo=pylhe.LHEProcInfo(
            xSection=...,
            error=...,
            unitWeight=...,
            procId=...,
        ),
    ),
    events=[
        pylhe.LHEEvent(
            eventinfo=pylhe.LHEEventInfo(
                nparticles=...,
                pid=...,
                weight=...,
                scale=...,
                aqed=...,
                aqcd=...,
            ),
            particles=[
                pylhe.LHEParticle(
                    id=...,
                    status=...,
                    mother1=...,
                    mother2=...,
                    color1=...,
                    color2=...,
                    px=...,
                    py=...,
                    pz=...,
                    e=...,
                    m=...,
                    lifetime=...,
                    spin=...,
                ),
            ],
            weights=None,
            attributes=None,
            optional=None,
        ),
    ],
)

# write to file, compressed if gz/gzip suffix
file.tofile("myevents.lhe.gz", lheformat=pylhe.LHEXMLFormat(compress=True))

Citation

The preferred BibTeX entry for citation of pylhe is

@software{pylhe,
  author = {Lukas Heinrich and Matthew Feickert and Eduardo Rodrigues and Alexander Puck Neuwirth},
  title = "{pylhe: v2.0.0}",
  version = {v2.0.0},
  doi = {10.5281/zenodo.1217031},
  url = {https://github.com/scikit-hep/pylhe},
}

pylhe has been referenced in:

Contributors

We hereby acknowledge the contributors that made this project possible (emoji key):

Matthew Feickert
Matthew Feickert

🚧 🎨 💻 📖
Lukas
Lukas

🚧 🎨 💻 📖
Eduardo Rodrigues
Eduardo Rodrigues

🚧 💻 📖
Alexander Puck Neuwirth
Alexander Puck Neuwirth

🚧 🎨 💻 📖
Johannes Schumann
Johannes Schumann

💻
Henry Schreiner
Henry Schreiner

💻
ariaradick
ariaradick

💻
Junghwan John Goh
Junghwan John Goh

💻
fuenfundachtzig
fuenfundachtzig

💻
Shantanu Gontia
Shantanu Gontia

💻
Tom Eichlersmith
Tom Eichlersmith

💻
Iason Krommydas
Iason Krommydas

💻 📖

This project follows the all-contributors specification.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylhe-2.0.0.tar.gz (42.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pylhe-2.0.0-py3-none-any.whl (25.7 kB view details)

Uploaded Python 3

File details

Details for the file pylhe-2.0.0.tar.gz.

File metadata

  • Download URL: pylhe-2.0.0.tar.gz
  • Upload date:
  • Size: 42.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pylhe-2.0.0.tar.gz
Algorithm Hash digest
SHA256 36fee45bb13a79ff2067aecc6659d415e7519ddc972274260fa38114d502beec
MD5 c9d47661a8f9d8c2c93dde1c57db7124
BLAKE2b-256 82ac49a526b723cd4354a9a616dc483930c6b1f13102291d640e19ce6e39a599

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylhe-2.0.0.tar.gz:

Publisher: publish-package.yml on scikit-hep/pylhe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pylhe-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: pylhe-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 25.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pylhe-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bca97075289c462e24b27bb0db788e3dde0aee9543d20f9ee1c4d75209be7d5c
MD5 b6b15dd2d8b0124421e638a16b50e4f7
BLAKE2b-256 1aae181e4555c622575f8f787b5720237f045386692d074aa6c2aaf53495e857

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylhe-2.0.0-py3-none-any.whl:

Publisher: publish-package.yml on scikit-hep/pylhe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page