Skip to content

Commit

Permalink
Comparison to Ocelot test with ARES EA
Browse files Browse the repository at this point in the history
  • Loading branch information
jank324 committed Sep 3, 2023
1 parent e7ef902 commit 377f4c0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cheetah/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def ocelot2cheetah(element, warnings: bool = True) -> "acc.Element":
else:
if warnings:
print(
f"WARNING: Unknown element {element.id}, replacing with drift section."
f"WARNING: Unknown element {element.id} of type {type(element)},"
" replacing with drift section."
)
return acc.Drift(element.l, name=element.id)

Expand Down
45 changes: 45 additions & 0 deletions test/test_compare_ocelot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import test.ARESlatticeStage3v1_9 as ares
from copy import deepcopy

import numpy as np
Expand Down Expand Up @@ -157,3 +158,47 @@ def test_solenoid():
assert np.allclose(
outgoing_beam.particles[:, :6], outgoing_p_array.rparticles.transpose()
)


def test_ares_ea():
"""
Test that the tracking results through a Experimental Area (EA) lattice of the ARES
accelerator at DESY match those using Ocelot.
"""
cell = cheetah.utils.subcell_of_ocelot(ares.cell, "AREASOLA1", "AREABSCR1")
ares.areamqzm1.k1 = 5.0
ares.areamqzm2.k1 = -5.0
ares.areamcvm1.k1 = 1e-3
ares.areamqzm3.k1 = 5.0
ares.areamchm1.k1 = -2e-3

# Cheetah
incoming_beam = cheetah.ParticleBeam.from_astra(
"benchmark/cheetah/ACHIP_EA1_2021.1351.001"
)
cheetah_segment = cheetah.Segment.from_ocelot(cell)
outgoing_beam = cheetah_segment.track(incoming_beam)

# Ocelot
incoming_p_array = ocelot.astraBeam2particleArray(
"benchmark/cheetah/ACHIP_EA1_2021.1351.001", print_params=False
)
lattice = ocelot.MagneticLattice(cell)
navigator = ocelot.Navigator(lattice)
_, outgoing_p_array = ocelot.track(lattice, deepcopy(incoming_p_array), navigator)

assert np.isclose(outgoing_beam.mu_x, outgoing_p_array.x().mean())
assert np.isclose(outgoing_beam.mu_xp, outgoing_p_array.px().mean())
assert np.isclose(outgoing_beam.mu_y, outgoing_p_array.y().mean())
assert np.isclose(outgoing_beam.mu_yp, outgoing_p_array.py().mean())
assert np.isclose(outgoing_beam.mu_s, outgoing_p_array.tau().mean(), atol=1e-7)
assert np.isclose(outgoing_beam.mu_p, outgoing_p_array.p().mean())

assert np.allclose(outgoing_beam.xs, outgoing_p_array.x())
assert np.allclose(outgoing_beam.xps, outgoing_p_array.px())
assert np.allclose(outgoing_beam.ys, outgoing_p_array.y())
assert np.allclose(outgoing_beam.yps, outgoing_p_array.py())
assert np.allclose(
outgoing_beam.ss, outgoing_p_array.tau(), atol=1e-7, rtol=1e-1
) # TODO: Why do we need such large tolerances?
assert np.allclose(outgoing_beam.ps, outgoing_p_array.p())

0 comments on commit 377f4c0

Please sign in to comment.