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

Updates to Stack #18

Merged
merged 2 commits into from
Feb 20, 2025
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
4 changes: 2 additions & 2 deletions src/cr39py/filtration/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ def lateral_straggle(self, particle: str, E_in: u.Quantity) -> u.Quantity:

Returns
-------
R : u.Quantity
Projected range of the particle in the layer.
straggle : u.Quantity
Lateral straggle of the particle in the stack.
"""
straggle_interp = self.srim_data(particle).lateral_straggle_interpolator

Expand Down
37 changes: 37 additions & 0 deletions src/cr39py/filtration/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,40 @@ def ranging_energy_loss(

"""
return E_in - self.range_down(particle, E_in, dx=dx)

def lateral_straggle(self, particle: str, E_in: u.Quantity) -> u.Quantity:
"""
Calculate the lateral straggle of a particle in the stack.

If the particle passes through the stack, this is the straggle experienced by the particle in the stack.
If the particle stops in the stack, this is the total straggle up to the stopping point.

This model assumes that the lateral straggle is additive in each layer.

See the `~cr39py.filtration.srim.SRIMData` class for formal definition of this quantity.

Parameters
----------
particle : str
Incident particle

E_in : u.Quantity
Energy of the particle before ranging in the stack.

Returns
-------
straggle : u.Quantity
Lateral straggle of the particle in the stack.
"""
straggle = 0 * u.um
for l in self.layers:
straggle += l.lateral_straggle(particle, E_in)

# Range down the particle energy before calculating straggle in the next layer
E_in = l.range_down(particle, E_in)

# If the particle has stopped, return the accumulated straggle
if E_in.m <= 0:
return straggle

return straggle
14 changes: 14 additions & 0 deletions tests/filtration/test_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,17 @@ def test_stack_ranging_energy_loss():
Elost = s.ranging_energy_loss("Deuteron", Ein)

assert np.isclose(Elost, Ein - Eout, rtol=0.01)


cases = [
("100 um Ta, 100 um Al", "Proton", 12 * u.MeV, 14.52 * u.um),
# Case where particle will stop in the stack
("100 um Ta, 2000 um Al", "Proton", 1 * u.MeV, 1.12 * u.um),
]


@pytest.mark.parametrize("stack,particle,energy,expected", cases)
def test_stack_lateral_straggle(stack, particle, energy, expected):
s = Stack.from_string(stack)
straggle = s.lateral_straggle(particle, energy)
assert np.isclose(straggle, expected, rtol=0.01)