Skip to content

Target Material Module

Import the target material utilites from spyral_utils.nuclear.target

Module containing AT-TPC representation of target materials and their associated energy loss calculations.

Target materials can be defined as either the corresponding CAtima name or a compound array.

Classes should never be directly instantiated, rather use the load_target function to do the work for you.

Classes:

Name Description
TargetData

Raw target dataclass, should never be instantiated directly by user

GasTarget

AT-TPC representation of a gas target

SolidTarget

AT-TPC representation of a gas target

Functions:

Name Description
deserialize_target_data

Deserialize raw target data from JSON. Should never be used directly.

serialize_target_data

Serialize raw target data to JSON. Should never be used directly.

load_target

Load a target from JSON. This is what should be used to load a target.

save_target

Save a targe to JSON. This is what should be used to save a target.

GasMixtureTarget

Source code in src/spyral_utils/nuclear/target.py
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
class GasMixtureTarget:
    def __init__(
        self,
        components: list[list[tuple[int, int, int]]],
        volume_fractions: list[float],
        pressure: float,
        nuclear_map: NuclearDataMap,
    ):
        self.components = components
        self.volume_fractions = volume_fractions
        self.pressure = pressure
        self.equivalent_compound: list[tuple[int, int, int]] = []
        self.average_molar_mass = 0.0
        self.density = 0.0
        self.pretty_string: str = "(GasMix)"
        self.ugly_string: str = "(GasMix)"
        for fraction, component in zip(self.volume_fractions, self.components):
            self.pretty_string += f"[{fraction*100.0:.0}%-"
            self.ugly_string += f"[{fraction*100.0:.0}%-"
            for z, a, s in component:
                self.pretty_string += (
                    f"{nuclear_map.get_data(z, a).pretty_iso_symbol}<sub>{s}</sub>"
                )
                self.ugly_string += f"{nuclear_map.get_data(z, a).isotopic_symbol}{s}"
            self.pretty_string += "]"
            self.ugly_string += "]"

        for compound, fraction in zip(self.components, self.volume_fractions):
            scale = int(100.0 * fraction)
            for element_z, element_a, element_s in compound:
                self.equivalent_compound.append(
                    (element_z, element_a, element_s * scale)
                )
                self.average_molar_mass += element_a * element_s * fraction

        self.density = (
            self.average_molar_mass * self.pressure / (GAS_CONSTANT * ROOM_TEMPERATURE)
        )
        # Construct the target material
        self.material = catima.Material()
        for (
            z,
            a,
            s,
        ) in self.equivalent_compound:
            self.material.add_element(
                nuclear_map.get_data(z, a).atomic_mass, z, float(s)
            )
        self.material.density(self.density)

    def get_dedx(self, projectile_data: NucleusData, projectile_energy: float) -> float:
        """Calculate the stopping power of the target for a projectile

        Parameters
        ----------
        projectile_data: NucleusData
            the projectile type
        projectile_energy: float
            the projectile kinetic energy in MeV

        Returns
        -------
        float
            dEdx in MeV/g/cm^2
        """
        mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
        projectile = catima.Projectile(mass_u, projectile_data.Z)
        projectile.T(projectile_energy / mass_u)
        return catima.dedx(projectile, self.material)

    def get_angular_straggling(
        self, projectile_data: NucleusData, projectile_energy: float
    ) -> float:
        """Calculate the angular straggling for a projectile

        Parameters
        ----------
        projectile_data: NucleusData
            the projectile type
        projectile_energy: float
            the projectile kinetic energy in MeV

        Returns
        -------
        float
            angular straggling in radians
        """
        mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
        projectile = catima.Projectile(
            mass_u, projectile_data.Z, T=projectile_energy / mass_u
        )
        return catima.calculate(projectile, self.material).get_dict()["sigma_a"]

    def get_energy_loss(
        self,
        projectile_data: NucleusData,
        projectile_energy: float,
        distances: np.ndarray,
    ) -> np.ndarray:
        """
        Calculate the energy loss of a projectile traveling over a set of distances

        Parameters
        ----------
        projectile_data: NucleusData
            the projectile type
        projectile_energy: float
            the projectile kinetic energy in MeV
        distances: ndarray
            a set of distances in meters over which to calculate the energy loss

        Returns
        -------
        ndarray
            set of energy losses
        """
        mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
        projectile = catima.Projectile(
            mass_u, projectile_data.Z, T=projectile_energy / mass_u
        )
        eloss = np.zeros(len(distances))
        for idx, distance in enumerate(distances):
            self.material.thickness_cm(distance * 100.0)
            projectile.T(projectile_energy / mass_u)
            eloss[idx] = catima.calculate(projectile, self.material).get_dict()["Eloss"]
        return eloss

    def get_range(
        self, projectile_data: NucleusData, projectile_energy: float
    ) -> float:
        """Calculate the range of a projectile in the target

        Parameters
        ----------
        projectile_data: NucleusData
            the projectile type
        projectile_energy: float
            the projectile kinetic energy in MeV

        Returns
        -------
        float
            The range in m
        """
        mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
        projectile = catima.Projectile(
            mass_u, projectile_data.Z, T=projectile_energy / mass_u
        )
        range_gcm2 = catima.calculate(projectile, self.material).get_dict()["range"]
        range_m = range_gcm2 / self.material.density() * 0.01
        return range_m

    def get_number_density(self) -> float:
        """Get the number density of gas molecules

        Returns
        -------
        Number density of gas molecules in molecules/cm^3
        """
        return self.material.number_density()

get_angular_straggling(projectile_data, projectile_energy)

Calculate the angular straggling for a projectile

Parameters:

Name Type Description Default
projectile_data NucleusData

the projectile type

required
projectile_energy float

the projectile kinetic energy in MeV

required

Returns:

Type Description
float

angular straggling in radians

Source code in src/spyral_utils/nuclear/target.py
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
def get_angular_straggling(
    self, projectile_data: NucleusData, projectile_energy: float
) -> float:
    """Calculate the angular straggling for a projectile

    Parameters
    ----------
    projectile_data: NucleusData
        the projectile type
    projectile_energy: float
        the projectile kinetic energy in MeV

    Returns
    -------
    float
        angular straggling in radians
    """
    mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
    projectile = catima.Projectile(
        mass_u, projectile_data.Z, T=projectile_energy / mass_u
    )
    return catima.calculate(projectile, self.material).get_dict()["sigma_a"]

get_dedx(projectile_data, projectile_energy)

Calculate the stopping power of the target for a projectile

Parameters:

Name Type Description Default
projectile_data NucleusData

the projectile type

required
projectile_energy float

the projectile kinetic energy in MeV

required

Returns:

Type Description
float

dEdx in MeV/g/cm^2

Source code in src/spyral_utils/nuclear/target.py
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
def get_dedx(self, projectile_data: NucleusData, projectile_energy: float) -> float:
    """Calculate the stopping power of the target for a projectile

    Parameters
    ----------
    projectile_data: NucleusData
        the projectile type
    projectile_energy: float
        the projectile kinetic energy in MeV

    Returns
    -------
    float
        dEdx in MeV/g/cm^2
    """
    mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
    projectile = catima.Projectile(mass_u, projectile_data.Z)
    projectile.T(projectile_energy / mass_u)
    return catima.dedx(projectile, self.material)

get_energy_loss(projectile_data, projectile_energy, distances)

Calculate the energy loss of a projectile traveling over a set of distances

Parameters:

Name Type Description Default
projectile_data NucleusData

the projectile type

required
projectile_energy float

the projectile kinetic energy in MeV

required
distances ndarray

a set of distances in meters over which to calculate the energy loss

required

Returns:

Type Description
ndarray

set of energy losses

Source code in src/spyral_utils/nuclear/target.py
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
def get_energy_loss(
    self,
    projectile_data: NucleusData,
    projectile_energy: float,
    distances: np.ndarray,
) -> np.ndarray:
    """
    Calculate the energy loss of a projectile traveling over a set of distances

    Parameters
    ----------
    projectile_data: NucleusData
        the projectile type
    projectile_energy: float
        the projectile kinetic energy in MeV
    distances: ndarray
        a set of distances in meters over which to calculate the energy loss

    Returns
    -------
    ndarray
        set of energy losses
    """
    mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
    projectile = catima.Projectile(
        mass_u, projectile_data.Z, T=projectile_energy / mass_u
    )
    eloss = np.zeros(len(distances))
    for idx, distance in enumerate(distances):
        self.material.thickness_cm(distance * 100.0)
        projectile.T(projectile_energy / mass_u)
        eloss[idx] = catima.calculate(projectile, self.material).get_dict()["Eloss"]
    return eloss

get_number_density()

Get the number density of gas molecules

Returns:

Type Description
Number density of gas molecules in molecules/cm^3
Source code in src/spyral_utils/nuclear/target.py
636
637
638
639
640
641
642
643
def get_number_density(self) -> float:
    """Get the number density of gas molecules

    Returns
    -------
    Number density of gas molecules in molecules/cm^3
    """
    return self.material.number_density()

get_range(projectile_data, projectile_energy)

Calculate the range of a projectile in the target

Parameters:

Name Type Description Default
projectile_data NucleusData

the projectile type

required
projectile_energy float

the projectile kinetic energy in MeV

required

Returns:

Type Description
float

The range in m

Source code in src/spyral_utils/nuclear/target.py
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
def get_range(
    self, projectile_data: NucleusData, projectile_energy: float
) -> float:
    """Calculate the range of a projectile in the target

    Parameters
    ----------
    projectile_data: NucleusData
        the projectile type
    projectile_energy: float
        the projectile kinetic energy in MeV

    Returns
    -------
    float
        The range in m
    """
    mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
    projectile = catima.Projectile(
        mass_u, projectile_data.Z, T=projectile_energy / mass_u
    )
    range_gcm2 = catima.calculate(projectile, self.material).get_dict()["range"]
    range_m = range_gcm2 / self.material.density() * 0.01
    return range_m

GasTarget

An AT-TPC gas target

Gas target for which energy loss can be calculated using pycatima. Can perform several types of energy loss calculations (straggling, dEdx, energy lost, etc.)

Attributes:

Name Type Description
data TargetData

The raw target data from a JSON file

ugly_string str

A string representation without rich formatting

pretty_string str

A string representation with rich formatting

material Material

The catima representation of the target

density float

The target density in g/cm^3

Methods:

Name Description
get_dedx

get the stopping power (dEdx) for a projectile in this target

get_angular_straggling

get the angular straggling for a projectile in this target

get_energy_loss

get the energy loss values for a projectile travelling distances through the target

Source code in src/spyral_utils/nuclear/target.py
 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
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
class GasTarget:
    """An AT-TPC gas target

    Gas target for which energy loss can be calculated using pycatima. Can perform several types of
    energy loss calculations (straggling, dEdx, energy lost, etc.)

    Attributes
    ----------
    data: TargetData
        The raw target data from a JSON file
    ugly_string: str
        A string representation without rich formatting
    pretty_string: str
        A string representation with rich formatting
    material: catima.Material
        The catima representation of the target
    density: float
        The target density in g/cm^3

    Methods
    -------
    get_dedx(projectile_data: NucleusData, projectile_energy: float) -> float
        get the stopping power (dEdx) for a projectile in this target
    get_angular_straggling(projectile_data: NucleusData, projectile_energy: float) -> float:
        get the angular straggling for a projectile in this target
    get_energy_loss(projectile_data: NucleusData, projectile_energy: float, distances: ndarray) -> ndarray:
        get the energy loss values for a projectile travelling distances through the target
    """

    def __init__(
        self,
        compound: list[tuple[int, int, int]],
        pressure: float,
        nuclear_data: NuclearDataMap,
    ):
        self.compound = compound
        self.pressure = pressure  # Torr
        molar_mass: float = 0.0
        for z, a, s in self.compound:
            molar_mass += a * s
        self.density: float = (
            molar_mass * self.pressure / (GAS_CONSTANT * ROOM_TEMPERATURE)
        )
        self.pretty_string: str = "(Gas)" + "".join(
            [
                f"{nuclear_data.get_data(z, a).pretty_iso_symbol}<sub>{s}</sub>"
                for (z, a, s) in self.compound
            ]
        )
        self.ugly_string: str = "(Gas)" + "".join(
            [
                f"{nuclear_data.get_data(z, a).isotopic_symbol}{s}"
                for (z, a, s) in self.compound
            ]
        )

        # Construct the target material
        self.material = catima.Material()
        for (
            z,
            a,
            s,
        ) in self.compound:
            self.material.add_element(
                nuclear_data.get_data(z, a).atomic_mass, z, float(s)
            )
        self.material.density(self.density)

    def __str__(self) -> str:
        return self.pretty_string

    def get_dedx(self, projectile_data: NucleusData, projectile_energy: float) -> float:
        """Calculate the stopping power of the target for a projectile

        Parameters
        ----------
        projectile_data: NucleusData
            the projectile type
        projectile_energy: float
            the projectile kinetic energy in MeV

        Returns
        -------
        float
            dEdx in MeV/g/cm^2
        """
        mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
        projectile = catima.Projectile(mass_u, projectile_data.Z)
        projectile.T(projectile_energy / mass_u)
        return catima.dedx(projectile, self.material)

    def get_angular_straggling(
        self, projectile_data: NucleusData, projectile_energy: float
    ) -> float:
        """Calculate the angular straggling for a projectile

        Parameters
        ----------
        projectile_data: NucleusData
            the projectile type
        projectile_energy: float
            the projectile kinetic energy in MeV

        Returns
        -------
        float
            angular straggling in radians
        """
        mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
        projectile = catima.Projectile(
            mass_u, projectile_data.Z, T=projectile_energy / mass_u
        )
        return catima.calculate(projectile, self.material).get_dict()["sigma_a"]

    def get_energy_loss(
        self,
        projectile_data: NucleusData,
        projectile_energy: float,
        distances: np.ndarray,
    ) -> np.ndarray:
        """
        Calculate the energy loss of a projectile traveling over a set of distances

        Parameters
        ----------
        projectile_data: NucleusData
            the projectile type
        projectile_energy: float
            the projectile kinetic energy in MeV
        distances: ndarray
            a set of distances in meters over which to calculate the energy loss

        Returns
        -------
        ndarray
            set of energy losses
        """
        mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
        projectile = catima.Projectile(
            mass_u, projectile_data.Z, T=projectile_energy / mass_u
        )
        eloss = np.zeros(len(distances))
        for idx, distance in enumerate(distances):
            self.material.thickness_cm(distance * 100.0)
            projectile.T(projectile_energy / mass_u)
            eloss[idx] = catima.calculate(projectile, self.material).get_dict()["Eloss"]
        return eloss

    def get_range(
        self, projectile_data: NucleusData, projectile_energy: float
    ) -> float:
        """Calculate the range of a projectile in the target

        Parameters
        ----------
        projectile_data: NucleusData
            the projectile type
        projectile_energy: float
            the projectile kinetic energy in MeV

        Returns
        -------
        float
            The range in m
        """
        mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
        projectile = catima.Projectile(
            mass_u, projectile_data.Z, T=projectile_energy / mass_u
        )
        range_gcm2 = catima.calculate(projectile, self.material).get_dict()["range"]
        range_m = range_gcm2 / self.material.density() * 0.01
        return range_m

    def get_number_density(self) -> float:
        """Get the number density of gas molecules

        Returns
        -------
        Number density of gas molecules in molecules/cm^3
        """
        return self.material.number_density()

get_angular_straggling(projectile_data, projectile_energy)

Calculate the angular straggling for a projectile

Parameters:

Name Type Description Default
projectile_data NucleusData

the projectile type

required
projectile_energy float

the projectile kinetic energy in MeV

required

Returns:

Type Description
float

angular straggling in radians

Source code in src/spyral_utils/nuclear/target.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
def get_angular_straggling(
    self, projectile_data: NucleusData, projectile_energy: float
) -> float:
    """Calculate the angular straggling for a projectile

    Parameters
    ----------
    projectile_data: NucleusData
        the projectile type
    projectile_energy: float
        the projectile kinetic energy in MeV

    Returns
    -------
    float
        angular straggling in radians
    """
    mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
    projectile = catima.Projectile(
        mass_u, projectile_data.Z, T=projectile_energy / mass_u
    )
    return catima.calculate(projectile, self.material).get_dict()["sigma_a"]

get_dedx(projectile_data, projectile_energy)

Calculate the stopping power of the target for a projectile

Parameters:

Name Type Description Default
projectile_data NucleusData

the projectile type

required
projectile_energy float

the projectile kinetic energy in MeV

required

Returns:

Type Description
float

dEdx in MeV/g/cm^2

Source code in src/spyral_utils/nuclear/target.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def get_dedx(self, projectile_data: NucleusData, projectile_energy: float) -> float:
    """Calculate the stopping power of the target for a projectile

    Parameters
    ----------
    projectile_data: NucleusData
        the projectile type
    projectile_energy: float
        the projectile kinetic energy in MeV

    Returns
    -------
    float
        dEdx in MeV/g/cm^2
    """
    mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
    projectile = catima.Projectile(mass_u, projectile_data.Z)
    projectile.T(projectile_energy / mass_u)
    return catima.dedx(projectile, self.material)

get_energy_loss(projectile_data, projectile_energy, distances)

Calculate the energy loss of a projectile traveling over a set of distances

Parameters:

Name Type Description Default
projectile_data NucleusData

the projectile type

required
projectile_energy float

the projectile kinetic energy in MeV

required
distances ndarray

a set of distances in meters over which to calculate the energy loss

required

Returns:

Type Description
ndarray

set of energy losses

Source code in src/spyral_utils/nuclear/target.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
def get_energy_loss(
    self,
    projectile_data: NucleusData,
    projectile_energy: float,
    distances: np.ndarray,
) -> np.ndarray:
    """
    Calculate the energy loss of a projectile traveling over a set of distances

    Parameters
    ----------
    projectile_data: NucleusData
        the projectile type
    projectile_energy: float
        the projectile kinetic energy in MeV
    distances: ndarray
        a set of distances in meters over which to calculate the energy loss

    Returns
    -------
    ndarray
        set of energy losses
    """
    mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
    projectile = catima.Projectile(
        mass_u, projectile_data.Z, T=projectile_energy / mass_u
    )
    eloss = np.zeros(len(distances))
    for idx, distance in enumerate(distances):
        self.material.thickness_cm(distance * 100.0)
        projectile.T(projectile_energy / mass_u)
        eloss[idx] = catima.calculate(projectile, self.material).get_dict()["Eloss"]
    return eloss

get_number_density()

Get the number density of gas molecules

Returns:

Type Description
Number density of gas molecules in molecules/cm^3
Source code in src/spyral_utils/nuclear/target.py
214
215
216
217
218
219
220
221
def get_number_density(self) -> float:
    """Get the number density of gas molecules

    Returns
    -------
    Number density of gas molecules in molecules/cm^3
    """
    return self.material.number_density()

get_range(projectile_data, projectile_energy)

Calculate the range of a projectile in the target

Parameters:

Name Type Description Default
projectile_data NucleusData

the projectile type

required
projectile_energy float

the projectile kinetic energy in MeV

required

Returns:

Type Description
float

The range in m

Source code in src/spyral_utils/nuclear/target.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
def get_range(
    self, projectile_data: NucleusData, projectile_energy: float
) -> float:
    """Calculate the range of a projectile in the target

    Parameters
    ----------
    projectile_data: NucleusData
        the projectile type
    projectile_energy: float
        the projectile kinetic energy in MeV

    Returns
    -------
    float
        The range in m
    """
    mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
    projectile = catima.Projectile(
        mass_u, projectile_data.Z, T=projectile_energy / mass_u
    )
    range_gcm2 = catima.calculate(projectile, self.material).get_dict()["range"]
    range_m = range_gcm2 / self.material.density() * 0.01
    return range_m

SolidTarget

An AT-TPC gas target

Gas target for which energy loss can be calculated using pycatima. Can perform several types of energy loss calculations (straggling, dEdx, energy lost, etc.)

Attributes:

Name Type Description
data TargetData

The raw target data from a JSON file

ugly_string str

A string representation without rich formatting

pretty_string str

A string representation with rich formatting

material Material

The catima representation of the target

Methods:

Name Description
get_dedx

get the stopping power (dEdx) for a projectile in this target

get_angular_straggling

get the angular straggling for a projectile in this target

get_energy_loss

get the energy loss values for a projectile travelling distances through the target

Source code in src/spyral_utils/nuclear/target.py
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
class SolidTarget:
    """An AT-TPC gas target

    Gas target for which energy loss can be calculated using pycatima. Can perform several types of
    energy loss calculations (straggling, dEdx, energy lost, etc.)

    Attributes
    ----------
    data: TargetData
        The raw target data from a JSON file
    ugly_string: str
        A string representation without rich formatting
    pretty_string: str
        A string representation with rich formatting
    material: catima.Material
        The catima representation of the target

    Methods
    -------
    get_dedx(projectile_data: NucleusData, projectile_energy: float) -> float
        get the stopping power (dEdx) for a projectile in this target
    get_angular_straggling(projectile_data: NucleusData, projectile_energy: float) -> float:
        get the angular straggling for a projectile in this target
    get_energy_loss(projectile_data: NucleusData, projectile_energy: float, distances: ndarray) -> ndarray:
        get the energy loss values for a projectile travelling distances through the target
    """

    UG2G: float = 1.0e-6  # convert ug to g

    def __init__(
        self,
        compound: list[tuple[int, int, int]],
        thickness: float,
        nuclear_data: NuclearDataMap,
    ):
        self.compound = compound
        self.thickness = thickness

        self.pretty_string: str = "(Solid)" + "".join(
            [
                f"{nuclear_data.get_data(z, a).pretty_iso_symbol}<sub>{s}</sub>"
                for (z, a, s) in self.compound
            ]
        )
        self.ugly_string: str = "(Solid)" + "".join(
            [
                f"{nuclear_data.get_data(z, a).isotopic_symbol}{s}"
                for (z, a, s) in self.compound
            ]
        )

        # Construct the target material
        self.material = catima.Material()
        for (
            z,
            a,
            s,
        ) in self.compound:
            self.material.add_element(
                nuclear_data.get_data(z, a).atomic_mass, z, float(s)
            )
        self.material.thickness(self.thickness * self.UG2G)  # Convert ug/cm^2 to g/cm^2

    def get_dedx(self, projectile_data: NucleusData, projectile_energy: float) -> float:
        """Calculate the stopping power of the target for a projectile

        Parameters
        ----------
        projectile_data: NucleusData
            the projectile type
        projectile_energy: float
            the projectile kinetic energy in MeV

        Returns
        -------
        float
            dEdx in MeV/g/cm^2
        """
        mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
        projectile = catima.Projectile(mass_u, projectile_data.Z)
        projectile.T(projectile_energy / mass_u)
        return catima.dedx(projectile, self.material)

    def get_angular_straggling(
        self, projectile_data: NucleusData, projectile_energy: float
    ) -> float:
        """Calculate the angular straggling for a projectile

        Parameters
        ----------
        projectile_data: NucleusData
            the projectile type
        projectile_energy: float
            the projectile kinetic energy in MeV

        Returns
        -------
        float
            angular straggling in radians
        """
        mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
        projectile = catima.Projectile(
            mass_u, projectile_data.Z, T=projectile_energy / mass_u
        )
        return catima.calculate(projectile, self.material).get_dict()["sigma_a"]

    def get_energy_loss(
        self,
        projectile_data: NucleusData,
        projectile_energy: float,
        incident_angles: np.ndarray,
    ) -> np.ndarray:
        """Calculate the energy loss of a projectile traveling through the solid target for a given set of incident angles

        Assumes travelling through the entire target at an incident angle.

        Parameters
        ----------
        projectile_data: NucleusData
            the projectile type
        projectile_energy: float
            the projectile kinetic energy in MeV
        incident_angles: ndarray
            a set of incident angles, describing the angle between the particle trajectory and the normal of the target surface

        Returns
        -------
        ndarray
            set of energy losses
        """
        mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
        projectile = catima.Projectile(
            mass_u, projectile_data.Z, T=projectile_energy / mass_u
        )
        eloss = np.zeros(len(incident_angles))
        nominal_thickness = self.material.thickness()
        for idx, angle in enumerate(incident_angles):
            self.material.thickness(nominal_thickness / abs(np.cos(angle)))
            projectile.T(projectile_energy / mass_u)
            eloss[idx] = catima.calculate(projectile, self.material).get_dict()["Eloss"]
        self.material.thickness(nominal_thickness)
        return eloss

    def get_range(
        self, projectile_data: NucleusData, projectile_energy: float
    ) -> float:
        """Calculate the range of a projectile in the target in g/cm^2

        Parameters
        ----------
        projectile_data: NucleusData
            the projectile type
        projectile_energy: float
            the projectile kinetic energy in MeV

        Returns
        -------
        float
            The range in g/cm^2
        """
        mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
        projectile = catima.Projectile(
            mass_u, projectile_data.Z, T=projectile_energy / mass_u
        )

        return catima.calculate(projectile, self.material).get_dict()["range"]

get_angular_straggling(projectile_data, projectile_energy)

Calculate the angular straggling for a projectile

Parameters:

Name Type Description Default
projectile_data NucleusData

the projectile type

required
projectile_energy float

the projectile kinetic energy in MeV

required

Returns:

Type Description
float

angular straggling in radians

Source code in src/spyral_utils/nuclear/target.py
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
def get_angular_straggling(
    self, projectile_data: NucleusData, projectile_energy: float
) -> float:
    """Calculate the angular straggling for a projectile

    Parameters
    ----------
    projectile_data: NucleusData
        the projectile type
    projectile_energy: float
        the projectile kinetic energy in MeV

    Returns
    -------
    float
        angular straggling in radians
    """
    mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
    projectile = catima.Projectile(
        mass_u, projectile_data.Z, T=projectile_energy / mass_u
    )
    return catima.calculate(projectile, self.material).get_dict()["sigma_a"]

get_dedx(projectile_data, projectile_energy)

Calculate the stopping power of the target for a projectile

Parameters:

Name Type Description Default
projectile_data NucleusData

the projectile type

required
projectile_energy float

the projectile kinetic energy in MeV

required

Returns:

Type Description
float

dEdx in MeV/g/cm^2

Source code in src/spyral_utils/nuclear/target.py
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
def get_dedx(self, projectile_data: NucleusData, projectile_energy: float) -> float:
    """Calculate the stopping power of the target for a projectile

    Parameters
    ----------
    projectile_data: NucleusData
        the projectile type
    projectile_energy: float
        the projectile kinetic energy in MeV

    Returns
    -------
    float
        dEdx in MeV/g/cm^2
    """
    mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
    projectile = catima.Projectile(mass_u, projectile_data.Z)
    projectile.T(projectile_energy / mass_u)
    return catima.dedx(projectile, self.material)

get_energy_loss(projectile_data, projectile_energy, incident_angles)

Calculate the energy loss of a projectile traveling through the solid target for a given set of incident angles

Assumes travelling through the entire target at an incident angle.

Parameters:

Name Type Description Default
projectile_data NucleusData

the projectile type

required
projectile_energy float

the projectile kinetic energy in MeV

required
incident_angles ndarray

a set of incident angles, describing the angle between the particle trajectory and the normal of the target surface

required

Returns:

Type Description
ndarray

set of energy losses

Source code in src/spyral_utils/nuclear/target.py
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
def get_energy_loss(
    self,
    projectile_data: NucleusData,
    projectile_energy: float,
    incident_angles: np.ndarray,
) -> np.ndarray:
    """Calculate the energy loss of a projectile traveling through the solid target for a given set of incident angles

    Assumes travelling through the entire target at an incident angle.

    Parameters
    ----------
    projectile_data: NucleusData
        the projectile type
    projectile_energy: float
        the projectile kinetic energy in MeV
    incident_angles: ndarray
        a set of incident angles, describing the angle between the particle trajectory and the normal of the target surface

    Returns
    -------
    ndarray
        set of energy losses
    """
    mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
    projectile = catima.Projectile(
        mass_u, projectile_data.Z, T=projectile_energy / mass_u
    )
    eloss = np.zeros(len(incident_angles))
    nominal_thickness = self.material.thickness()
    for idx, angle in enumerate(incident_angles):
        self.material.thickness(nominal_thickness / abs(np.cos(angle)))
        projectile.T(projectile_energy / mass_u)
        eloss[idx] = catima.calculate(projectile, self.material).get_dict()["Eloss"]
    self.material.thickness(nominal_thickness)
    return eloss

get_range(projectile_data, projectile_energy)

Calculate the range of a projectile in the target in g/cm^2

Parameters:

Name Type Description Default
projectile_data NucleusData

the projectile type

required
projectile_energy float

the projectile kinetic energy in MeV

required

Returns:

Type Description
float

The range in g/cm^2

Source code in src/spyral_utils/nuclear/target.py
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
def get_range(
    self, projectile_data: NucleusData, projectile_energy: float
) -> float:
    """Calculate the range of a projectile in the target in g/cm^2

    Parameters
    ----------
    projectile_data: NucleusData
        the projectile type
    projectile_energy: float
        the projectile kinetic energy in MeV

    Returns
    -------
    float
        The range in g/cm^2
    """
    mass_u = projectile_data.mass / AMU_2_MEV  # convert to u
    projectile = catima.Projectile(
        mass_u, projectile_data.Z, T=projectile_energy / mass_u
    )

    return catima.calculate(projectile, self.material).get_dict()["range"]

deserialize_gas_target_data(target_path, nuclear_map)

Deserialize gas target data from a JSON file

Parameters:

Name Type Description Default
target_path Path

Path to JSON file containing gas target data

required

Returns:

Type Description
GasTarget | None

If the data loaded successfully, returns a GasTarget. Otherwise returns None.

Source code in src/spyral_utils/nuclear/target.py
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
def deserialize_gas_target_data(
    target_path: Path, nuclear_map: NuclearDataMap
) -> GasTarget | None:
    """Deserialize gas target data from a JSON file

    Parameters
    ----------
    target_path: Path
        Path to JSON file containing gas target data

    Returns
    -------
    GasTarget | None
        If the data loaded successfully, returns a GasTarget. Otherwise returns None.
    """
    with open(target_path, "r") as target_file:
        json_data = load(target_file)
        if "compound" not in json_data or "pressure(Torr)" not in json_data:
            return None
        else:
            return GasTarget(
                json_data["compound"], json_data["pressure(Torr)"], nuclear_map
            )

deserialize_mixture_data(path, nuclear_map)

Deserialize gas mixture target data from a JSON file

Parameters:

Name Type Description Default
path Path

Path to JSON file containing target data

required

Returns:

Type Description
GasMixtureTarget | None

If the data loaded successfully, returns a GasMixtureTarget. Otherwise returns None.

Source code in src/spyral_utils/nuclear/target.py
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
def deserialize_mixture_data(
    path: Path, nuclear_map: NuclearDataMap
) -> GasMixtureTarget | None:
    """Deserialize gas mixture target data from a JSON file

    Parameters
    ----------
    path: Path
        Path to JSON file containing target data

    Returns
    -------
    GasMixtureTarget | None
        If the data loaded successfully, returns a GasMixtureTarget. Otherwise returns None.
    """
    with open(path, "r") as mix_file:
        json_data = load(mix_file)
        if (
            "components" not in json_data
            or "volume_fractions" not in json_data
            or "pressure(Torr)" not in json_data
        ):
            return None
        return GasMixtureTarget(
            components=json_data["components"],
            volume_fractions=json_data["volume_fractions"],
            pressure=json_data["pressure(Torr)"],
            nuclear_map=nuclear_map,
        )

deserialize_solid_target_data(target_path, nuclear_map)

Deserialize solid target data from a JSON file

Parameters:

Name Type Description Default
target_path Path

Path to JSON file containing target data

required

Returns:

Type Description
SolidTarget | None

If the data loaded successfully, returns a SolidTarget. Otherwise returns None.

Source code in src/spyral_utils/nuclear/target.py
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
def deserialize_solid_target_data(
    target_path: Path, nuclear_map: NuclearDataMap
) -> SolidTarget | None:
    """Deserialize solid target data from a JSON file

    Parameters
    ----------
    target_path: Path
        Path to JSON file containing target data

    Returns
    -------
    SolidTarget | None
        If the data loaded successfully, returns a SolidTarget. Otherwise returns None.
    """
    with open(target_path, "r") as target_file:
        json_data = load(target_file)
        if "compound" not in json_data or "thickness(ug/cm^2)" not in json_data:
            return None
        else:
            return SolidTarget(
                json_data["compound"], json_data["thickness(ug/cm^2)"], nuclear_map
            )

load_target(target_path, nuclear_map)

Load a target from a JSON file

Read the JSON data, and construct the appropriate target type.

Parameters:

Name Type Description Default
target_path Path

Path to JSON data

required
nuclear_map NuclearDataMap

Nucleus mass data

required

Returns:

Type Description
GasTarget | SolidTarget | GasMixtureTarget

Return a GasTarget, GasMixtureTarget, or SolidTarget where appropriate. Raises a TargetError on failure.

Source code in src/spyral_utils/nuclear/target.py
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
def load_target(
    target_path: Path, nuclear_map: NuclearDataMap
) -> GasTarget | SolidTarget | GasMixtureTarget:
    """Load a target from a JSON file

    Read the JSON data, and construct the appropriate target type.

    Parameters
    ----------
    target_path: Path
        Path to JSON data
    nuclear_map: NuclearDataMap
        Nucleus mass data

    Returns
    -------
    GasTarget | SolidTarget | GasMixtureTarget
        Return a GasTarget, GasMixtureTarget, or SolidTarget where appropriate. Raises a
        TargetError on failure.
    """
    gas = deserialize_gas_target_data(target_path, nuclear_map)
    if gas is not None:
        return gas
    solid = deserialize_solid_target_data(target_path, nuclear_map)
    if solid is not None:
        return solid
    mix = deserialize_mixture_data(target_path, nuclear_map)
    if mix is not None:
        return mix
    raise TargetError(f"Invalid format for target data at {target_path}")

save_target(target_path, target)

Write a target to a JSON file

Create the JSON data, and write to disk.

Parameters:

Name Type Description Default
target_path Path

Path to JSON data file

required
target GasTarget | SolidTarget | GasMixtureTarget

Target to be written

required
Source code in src/spyral_utils/nuclear/target.py
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
def save_target(target_path: Path, target: GasTarget | SolidTarget | GasMixtureTarget):
    """Write a target to a JSON file

    Create the JSON data, and write to disk.

    Parameters
    ----------
    target_path: Path
        Path to JSON data file
    target: GasTarget | SolidTarget | GasMixtureTarget
        Target to be written
    """
    if isinstance(target, GasTarget):
        serialize_gas_target_data(target_path, target)
    elif isinstance(target, SolidTarget):
        serialize_solid_target_data(target_path, target)
    elif isinstance(target, GasMixtureTarget):
        serialize_mixture_data(target_path, target)
    else:
        raise TargetError(
            f"Object {target} does not match any known target type and could not be saved"
        )

serialize_gas_target_data(target_path, data)

Serialize gas target data to JSON file

Parameters:

Name Type Description Default
target_path Path

Path to JSON file to write target data

required
data GasTarget

data to be written

required
Source code in src/spyral_utils/nuclear/target.py
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
def serialize_gas_target_data(target_path: Path, data: GasTarget) -> None:
    """Serialize gas target data to JSON file

    Parameters
    ----------
    target_path: Path
        Path to JSON file to write target data
    data: GasTarget
        data to be written
    """
    with open(target_path, "w") as target_file:
        json_str = dumps(
            data,
            default=lambda data: {
                "compound": data.compound,
                "pressure(Torr)": data.pressure,
            },
        )
        target_file.write(json_str)

serialize_mixture_data(target_path, data)

Serialize gas mixture target data to JSON file

Parameters:

Name Type Description Default
target_path Path

Path to JSON file to write target data

required
data GasMixtureTarget

data to be written

required
Source code in src/spyral_utils/nuclear/target.py
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
def serialize_mixture_data(target_path: Path, data: GasMixtureTarget) -> None:
    """Serialize gas mixture target data to JSON file

    Parameters
    ----------
    target_path: Path
        Path to JSON file to write target data
    data: GasMixtureTarget
        data to be written
    """
    with open(target_path, "w") as target_file:
        json_str = dumps(
            data,
            default=lambda data: {
                "components": data.components,
                "volume_fractions": data.volume_fractions,
                "pressure(Torr)": data.pressure,
            },
        )
        target_file.write(json_str)

serialize_solid_target_data(target_path, data)

Serialize solid target data to JSON file

Parameters:

Name Type Description Default
target_path Path

Path to JSON file to write target data

required
data SolidTarget

data to be written

required
Source code in src/spyral_utils/nuclear/target.py
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
def serialize_solid_target_data(target_path: Path, data: SolidTarget) -> None:
    """Serialize solid target data to JSON file

    Parameters
    ----------
    target_path: Path
        Path to JSON file to write target data
    data: SolidTarget
        data to be written
    """
    with open(target_path, "w") as target_file:
        json_str = dumps(
            data,
            default=lambda data: {
                "compound": data.compound,
                "thickness(ug/cm^2)": data.thickness,
            },
        )
        target_file.write(json_str)