Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: limit number of particles using the eventinfo #103

Merged
merged 20 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
947bbe8
take particles up to the eventinfo.nparticles. otherwise put into the…
jhgoh Oct 31, 2021
c6b9653
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 31, 2021
b105fd8
synchronize with the master branch
jhgoh Dec 11, 2021
f7eb1d5
Add test
eduardo-rodrigues May 11, 2022
d26f0bb
Please linting checks
eduardo-rodrigues May 11, 2022
349c26b
ci: Add semantic PR check GHA workflow (#123)
matthewfeickert May 26, 2022
175da2c
feat: Add IPython visualisation and switch to graphviz (#118)
eduardo-rodrigues May 26, 2022
07dea53
refactor: Use absolute imports over explicit relative imports (#124)
matthewfeickert May 26, 2022
8d32ab0
feat: Use tbump over bump2version (#125)
matthewfeickert May 26, 2022
c8eabdd
Bump version: 0.2.1 → 0.3.0
matthewfeickert May 26, 2022
af5a20f
docs: Update dev team affiliations (#126)
matthewfeickert Jun 2, 2022
04297da
docs: Add Eduardo Rodrigues to dev team (#127)
matthewfeickert Jun 2, 2022
a8a047a
chore: [pre-commit.ci] pre-commit autoupdate (#129)
pre-commit-ci[bot] Jun 6, 2022
90f9427
docs: Add a 'get started' example to the README (#130)
eduardo-rodrigues Jun 20, 2022
a9bb55b
chore: [pre-commit.ci] pre-commit autoupdate (#133)
pre-commit-ci[bot] Jul 5, 2022
de0c065
take particles up to the eventinfo.nparticles. otherwise put into the…
jhgoh Oct 31, 2021
072de06
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 31, 2021
24c1dcc
synchronize with the master branch
jhgoh Dec 11, 2021
ab873bb
Merge branch 'master' into fixReadLHE
eduardo-rodrigues Aug 25, 2022
df72add
Cover lines added/changed
eduardo-rodrigues Aug 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,38 @@ event.graph.render(filename="test", format="png", cleanup=True)
event.graph.render(filename="test", format="pdf", cleanup=True)
```

## Get started

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

```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)
```

## Citation

The preferred BibTeX entry for citation of `pylhe` is
Expand Down
5 changes: 3 additions & 2 deletions src/pylhe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,10 @@ def read_lhe(filepath):
with _extract_fileobj(filepath) as fileobj:
for event, element in ET.iterparse(fileobj, events=["end"]):
if element.tag == "event":
data = element.text.split("\n")[1:-1]
data = element.text.strip().split("\n")
eduardo-rodrigues marked this conversation as resolved.
Show resolved Hide resolved
eventdata, particles = data[0], data[1:]
eventinfo = LHEEventInfo.fromstring(eventdata)
particles = particles[: int(eventinfo.nparticles)]
eduardo-rodrigues marked this conversation as resolved.
Show resolved Hide resolved
particle_objs = [LHEParticle.fromstring(p) for p in particles]
yield LHEEvent(eventinfo, particle_objs)
except ET.ParseError as excep:
Expand All @@ -303,7 +304,7 @@ def read_lhe_with_attributes(filepath):
for event, element in ET.iterparse(fileobj, events=["end"]):
if element.tag == "event":
eventdict = {}
data = element.text.split("\n")[1:-1]
data = element.text.strip().split("\n")
eventdata, particles = data[0], data[1:]
eventdict["eventinfo"] = LHEEventInfo.fromstring(eventdata)
eventdict["particles"] = []
Expand Down
22 changes: 21 additions & 1 deletion tests/test_lhe_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,25 @@ def test_lhe_init(testdata_gzip_file):


def test_read_lhe(testdata_gzip_file):
assert pylhe.read_lhe(TEST_FILE)
assert pylhe.read_lhe(testdata_gzip_file)


def test_read_lhe_internals():
events = pylhe.read_lhe(TEST_FILE)

assert events
for e in events:
assert e is not None


def test_issue_102():
"""
Test a file containing lines starting with "#aMCatNLO".
"""
test_file = skhep_testdata.data_path("pylhe-testlhef3.lhe")

assert pylhe.read_num_events(test_file) == 59
assert (
pylhe.read_lhe(test_file).__sizeof__()
== pylhe.read_lhe_with_attributes(test_file).__sizeof__()
)