File size: 1,657 Bytes
916755e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""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


@dataclass(frozen=True)
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

    @property
    def branches(self) -> Mapping[str, Any]:
        """Alias that makes the raw branch-level representation explicit."""

        return self.objects

    @property
    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

    @property
    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)