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

Added classmethod to read LHE event data #177 #182

Merged
merged 4 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 29 additions & 0 deletions graphicle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,35 @@
DataType = ty.TypeVar("DataType")


class LheEventInterface(ty.Protocol):
"""Interface for a generic Les Houches event.

:group: base

.. versionadded:: 0.4.0
"""

@property
def pdg(self) -> IntVector:
...

@property
def pmu(self) -> AnyVector:
...

@property
def color(self) -> AnyVector:
...

@property
def helicity(self) -> HalfIntVector:
...

@property
def status(self) -> HalfIntVector:
...


class EventInterface(ty.Protocol):
"""Defines the interface for a generic event object expected by
graphicle's routines. Attributes are stored as numpy arrays, with
Expand Down
30 changes: 30 additions & 0 deletions graphicle/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,36 @@ def copy(self) -> "ParticleSet":
"""Copies the underlying data into a new ParticleSet instance."""
return _composite_copy(self)

@classmethod
def from_lhe_event(cls, event: base.LheEventInterface) -> "ParticleSet":
"""Creates a ParticleSet instance directly from a data structure
holding LHE data. This is useful when you want to study the hard
process, without needing to shower or hadronize.

.. versionadded:: 0.4.0

Parameters
----------
event : LheEventInterface
A data structure with attributes "pdg", "pmu", "color",
"helicity", and "status". These attributes provide access to
numpy arrays, which hold the underlying Les Houches event
data.

Returns
-------
ParticleSet
A composite object, wrapping the data provided in Graphicle
objects, and providing a unified interface to them.
"""
props = ("pdg", "pmu", "color", "helicity", "status")
pcls = cls.from_numpy(**{name: getattr(event, name) for name in props})
pcls.final = MaskArray(np.zeros(len(pcls), dtype=np.bool_))
status_map = {-1: -21, 1: -23, -2: -22, 2: -22, 3: -22, -9: -12}
for old_code, new_code in status_map.items():
pcls.status.data[pcls.status.data == old_code] = new_code
return pcls

@classmethod
def from_numpy(
cls,
Expand Down
Loading