Skip to content

Commit e05117b

Browse files
committed
Aperture Test: Add Drift
This way, we can test if "s" was set to the right value.
1 parent d0f3f4f commit e05117b

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

examples/aperture/README.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ Proton beam undergoing collimation by a rectangular boundary aperture.
88

99
We use a 250 MeV proton beam with a horizontal rms beam size of 1.56 mm and a vertical rms beam size of 2.21 mm.
1010

11-
The beam is scraped by a 1 mm x 1.5 mm rectangular aperture.
11+
After a short drift of 0.123, the beam is scraped by a 1 mm x 1.5 mm rectangular aperture.
1212

1313
In this test, the initial values of :math:`\sigma_x`, :math:`\sigma_y`, :math:`\sigma_t`, :math:`\epsilon_x`, :math:`\epsilon_y`, and :math:`\epsilon_t` must agree with nominal values.
14-
The test fails if any of the final coordinates for the valid (not lost) particles lie outside the aperture boundary.
14+
The test fails if:
15+
16+
* any of the final coordinates for the valid (not lost) particles lie outside the aperture boundary or
17+
* any of the lost particles are inside the aperture boundary or
18+
* if the sum of lost and kept particles is not equal to the initial particles or
19+
* if the recorded position :math:`s` for the lost particles does not coincide with the drift distance.
1520

1621

1722
Run

examples/aperture/analysis_aperture.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ def get_moments(beam):
5353
assert num_particles == len(initial)
5454
# we lost particles in apertures
5555
assert num_particles > len(final)
56-
print(len(final))
57-
print(len(particles_lost))
5856
assert num_particles == len(particles_lost) + len(final)
5957

6058
print("Initial Beam:")
@@ -111,3 +109,8 @@ def get_moments(beam):
111109
print(f" y_max={particles_lost['position_y'].max()}")
112110
print(f" y_min={particles_lost['position_y'].min()}")
113111
assert np.greater_equal(dy.max(), 0.0)
112+
113+
# check that s is set correctly
114+
lost_at_s = particles_lost["s_lost"]
115+
drift_s = np.ones_like(lost_at_s) * 0.123
116+
assert np.allclose(lost_at_s, drift_s)

examples/aperture/input_aperture.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ beam.mutpt = 0.0
2121
###############################################################################
2222
# Beamline: lattice elements and segments
2323
###############################################################################
24-
lattice.elements = monitor collimator monitor
24+
lattice.elements = monitor drift collimator monitor
2525
lattice.nslice = 1
2626

2727
monitor.type = beam_monitor
2828
monitor.backend = h5
2929

30+
drift.type = drift
31+
drift.ds = 0.123
32+
3033
collimator.type = aperture
3134
collimator.shape = rectangular
3235
collimator.xmax = 1.0e-3

examples/aperture/run_aperture.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
sim.lattice.extend(
5151
[
5252
monitor,
53+
elements.Drift(0.123),
5354
elements.Aperture(xmax=1.0e-3, ymax=1.5e-3, shape="rectangular"),
5455
monitor,
5556
]

0 commit comments

Comments
 (0)