https://github.com/apn-pucky/pylhe

Lightweight Python interface to read Les Houches Event (LHE) files

https://github.com/apn-pucky/pylhe

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.9%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Lightweight Python interface to read Les Houches Event (LHE) files

Basic Info
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Fork of scikit-hep/pylhe
Created over 2 years ago · Last pushed 10 months ago

https://github.com/APN-Pucky/pylhe/blob/main/

# pylhe: Python LHE interface

pylhe logo

[![GitHub Project](https://img.shields.io/badge/GitHub--blue?style=social&logo=GitHub)](https://github.com/scikit-hep/pylhe)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1217031.svg)](https://doi.org/10.5281/zenodo.1217031)
[![Scikit-HEP](https://scikit-hep.org/assets/images/Scikit--HEP-Project-blue.svg)](https://scikit-hep.org/)

[![PyPI version](https://img.shields.io/pypi/v/pylhe.svg)](https://pypi.org/project/pylhe/)
[![Conda-forge version](https://img.shields.io/conda/vn/conda-forge/pylhe.svg)](https://github.com/conda-forge/pylhe-feedstock)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/pylhe.svg)](https://pypi.org/project/pylhe/)

[![GitHub Actions Status](https://github.com/scikit-hep/pylhe/actions/workflows/ci.yml/badge.svg)](https://github.com/scikit-hep/pylhe/actions/workflows/ci.yml?query=branch%3Amain)
[![Code Coverage](https://codecov.io/gh/scikit-hep/pylhe/graph/badge.svg?branch=main)](https://codecov.io/gh/scikit-hep/pylhe?branch=main)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/scikit-hep/pylhe/main.svg)](https://results.pre-commit.ci/latest/github/scikit-hep/pylhe/main)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Small and thin Python interface to read [Les Houches Event (LHE)](https://inspirehep.net/record/725284) files


## Tested Monte Carlo Generators' LHE output

| Generator                                      | Tested Versions       |
|------------------------------------------------|-----------------------|
| [MadGraph5](https://launchpad.net/mg5amcnlo)   | 2.0.0, 2.2.1, 3.5.8   |
| [POWHEG-BOX-V2](http://powhegbox.mib.infn.it/) | r4027                 |
| [Pythia](https://pythia.org/)                  | 6.413, 8.3.14         |
| [Sherpa](https://sherpa-team.gitlab.io/)       | 3.0.1                 |
| [Whizard](https://whizard.hepforge.org/)       | 3.1.4                 |

Note: test files are provided via the [scikit-hep-testdata](https://github.com/scikit-hep/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](https://graphviz.org/).

## Get started

The example below provides a simple overview.
Full functionality can be inspected from the functions provided in the `pylhe` module.

### Reading

```python
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](examples/write_monte_carlo_example.ipynb) or [filter](examples/filter_events_example.ipynb).
The values in the sketch below are intentionally left empty since they depend on the use-case.
The data structure of `pylhe` is:

```python
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.2}",
  version = {v0.9.2},
  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](https://allcontributors.org/docs/en/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

Iason Krommydas
Iason Krommydas

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification.

Owner

  • Name: Alexander Puck Neuwirth
  • Login: APN-Pucky
  • Kind: user
  • Company: Uni Münster

GitHub Events

Total
  • Push event: 37
  • Create event: 4
Last Year
  • Push event: 37
  • Create event: 4