Skip to content

Particle ID

Import the Particle ID tools from spyral_utils.nuclear.particle_id

ParticleID dataclass

Thin wrapper over spyral-utils Cut2D that attaches a NucleusData

Used to gate on particle groups in Brho and dEdx

Attributes:

Name Type Description
cut Cut2D

A spyral-utils Cut2D on brho and dEdx estimated parameters

nucleus NucleusData

The nucleus species associated with this ID

Source code in src/spyral_utils/nuclear/particle_id.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@dataclass
class ParticleID:
    """Thin wrapper over spyral-utils Cut2D that attaches a NucleusData

    Used to gate on particle groups in Brho and dEdx

    Attributes
    ----------
    cut: spyral_utils.plot.Cut2D
        A spyral-utils Cut2D on brho and dEdx estimated parameters
    nucleus: NucleusData
        The nucleus species associated with this ID

    """

    cut: Cut2D
    nucleus: NucleusData

deserialize_particle_id(path, nuclear_map)

Load a ParticleID from a JSON file

Parameters:

Name Type Description Default
path Path

The path to a JSON file containing a ParticleID

required
nuclear_map NuclearDataMap

An instance of a spyral_utils.nuclear.NuclearDataMap

required

Returns:

Type Description
ParticleID | None

The deserialized ParticleID or None on failure

Source code in src/spyral_utils/nuclear/particle_id.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def deserialize_particle_id(
    path: Path, nuclear_map: NuclearDataMap
) -> ParticleID | None:
    """Load a ParticleID from a JSON file

    Parameters
    ----------
    path: Path
        The path to a JSON file containing a ParticleID
    nuclear_map: NuclearDataMap
        An instance of a spyral_utils.nuclear.NuclearDataMap

    Returns
    -------
    ParticleID | None
        The deserialized ParticleID or None on failure
    """
    try:
        with open(path, "r") as cut_file:
            json_data = load(cut_file)
            if (
                "name" not in json_data
                or "vertices" not in json_data
                or "Z" not in json_data
                or "A" not in json_data
            ):
                print(
                    f"ParticleID could not load cut in {path}, the requested data is not present."
                )
                return None

            xaxis = DEFAULT_CUT_AXIS
            yaxis = DEFAULT_CUT_AXIS
            if "xaxis" in json_data and "yaxis" in json_data:
                xaxis = json_data["xaxis"]
                yaxis = json_data["yaxis"]

            pid = ParticleID(
                Cut2D(
                    json_data["name"], json_data["vertices"], x_axis=xaxis, y_axis=yaxis
                ),
                nuclear_map.get_data(json_data["Z"], json_data["A"]),
            )

            if pid.nucleus.A == 0:
                print(
                    f'Nucleus Z: {json_data["Z"]} A: {json_data["A"]} requested by ParticleID {json_data["name"]} does not exist.'
                )
                return None

            return pid
    except Exception as error:
        print(f"Could not deserialize ParticleID with error: {error}")
        return None