Download src/gnn4colliders/data/sample.py from HWresearch/GNN4Colliders: direct link, hf CLI and curl.
- Browser
- Download file 1.66 kB
-
https://huggingface.co/HWresearch/GNN4Colliders/resolve/refs%2Fpr%2F13/src/gnn4colliders/data/sample.py
- Command line
-
hf download hf://HWresearch/GNN4Colliders@refs/pr/13/src/gnn4colliders/data/sample.py
-
curl -L -o sample.py https://huggingface.co/HWresearch/GNN4Colliders/resolve/refs%2Fpr%2F13/src/gnn4colliders/data/sample.py
1.66 kB
| """Architecture-neutral representation of one collider event.""" | |
| from __future__ import annotations | |
| from collections.abc import Mapping | |
| from dataclasses import dataclass | |
| from typing import Any | |
| import numpy as np | |
| from .metadata import EventMetadata | |
| class EventSample: | |
| """One event before conversion into a model-specific representation. | |
| ``objects`` is a read-only mapping of selected ROOT branch names to the | |
| event's scalar or jagged values. Keeping branch values here lets the | |
| shared feature layer consume the sample without introducing DGL or model | |
| classes into the data package. | |
| """ | |
| objects: Mapping[str, Any] | |
| label: Any | |
| global_features: np.ndarray | |
| event_index: int | |
| metadata: EventMetadata | None = None | |
| def branches(self) -> Mapping[str, Any]: | |
| """Alias that makes the raw branch-level representation explicit.""" | |
| return self.objects | |
| def event_metadata(self) -> EventMetadata: | |
| """Return the required named metadata for this event.""" | |
| if self.metadata is None: | |
| raise ValueError("sample has no named metadata") | |
| return self.metadata | |
| def tracking(self): | |
| """Compatibility view for callers still expecting a tracking row. | |
| New code must use :attr:`event_metadata`; this view is deliberately | |
| created only when an old caller asks for it and is never propagated by | |
| the new data pipeline. | |
| """ | |
| import numpy as np | |
| metadata = self.event_metadata | |
| return np.asarray([metadata.fold, metadata.weight], dtype=np.float32) | |