Skip to main content

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

Project description

pylhe: Python LHE interface

pylhe logo

GitHub Project DOI Scikit-HEP

PyPI version Conda-forge version Supported Python versions

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

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

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.

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.read_lhe_with_attributes(lhe_file)
print(f"Number of events: {pylhe.read_num_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
write_lhe_file(file.init, file.events, "myevents.lhe.gz", rwgt=True, weights=False)

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: v0.9.1}",
  version = {v0.9.1},
  doi = {10.5281/zenodo.1217031},
  url = {https://github.com/scikit-hep/pylhe},
}

Contributors

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

Matthew Feickert
Matthew Feickert

🚧 🎨 💻 📖
Lukas
Lukas

🚧 🎨 💻 📖
Eduardo Rodrigues
Eduardo Rodrigues

🚧 💻 📖
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

💻
Alexander Puck Neuwirth
Alexander Puck Neuwirth

💻

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-0.9.1.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

pylhe-0.9.1-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pylhe-0.9.1.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pylhe-0.9.1.tar.gz
Algorithm Hash digest
SHA256 920c84f344f4e4dbcc080d11a51b4a9d34dec6edadc6feacd258732ba729a668
MD5 5af4f5903deed966182416f0f9308927
BLAKE2b-256 cf76bfcf49d2df49ec91cb7174c41f00d03b73de8f818ae280ad523b36eb4cb5

See more details on using hashes here.

Provenance

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

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

Attestations:

File details

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

File metadata

  • Download URL: pylhe-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pylhe-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 406f8418d84e240ccb3174b7692416c6b5c993f41f432af96e59b390017baaf9
MD5 7327cc70387829c53eb9d4604624a29e
BLAKE2b-256 cdc41a6616e2f3037407696b06b7fd0105f541c2cfb26cf6097821751aa5043e

See more details on using hashes here.

Provenance

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

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

Attestations:

Supported by

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