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

Bugfix/madx misalignments #306

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
51 changes: 51 additions & 0 deletions tests/test_madloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,57 @@ def gen_options(opt1):
line=list(ml.iter_elements())


def test_shift_tilt_order():
mad = Madx()

src="""
k1=1.;
elm: multipole,
knl:={0.0,-k1},
ksl={0.0,0.0},
angle=0.0,
tilt=0.0,
lrad=1;
seq: sequence, l=1;
elm1:elm, at=1;
endsequence;
beam;
use,sequence=seq;
select,pattern=elm,flag=error;
ealign,
DX=+0.1, DY=0.0, DS=0.0,
DPHI=0.0, DTHETA=0.0, DPSI=1.,
AREX=0.0, AREY=0.0;
track,onepass;
start,x=0.1,y=0.2,t=0.0;
run,turns=1;
endtrack;
"""

mad.input(src)

line = xt.Line.from_madx_sequence(mad.sequence.seq, apply_madx_errors=True)
for elements in line.elements:
print(elements.to_dict())
part = xp.Particles(x=0.1, y=0.2)
tracker = line.build_tracker()
tracker.track(part)

madtrack = mad.table["tracksumm"]
xsuite_x = part.x[-1]
xsuite_px = part.px[-1]
xsuite_y = part.y[-1]
xsuite_py = part.py[-1]

madx_x = madtrack["x"][-1]
madx_px = madtrack["px"][-1]
madx_y = madtrack["y"][-1]
madx_py = madtrack["py"][-1]

assert abs(xsuite_x - madx_x) < 1.e-15
assert abs(xsuite_px - madx_px) < 1.e-15
assert abs(xsuite_y - madx_y) < 1.e-15
assert abs(xsuite_py - madx_py) < 1.e-15

def test_matrix():
mad = Madx()
Expand Down
32 changes: 16 additions & 16 deletions xtrack/mad_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,14 +409,6 @@ def __init__(self, mad_el, enable_errors, classes, Builder):

def entry(self):
out = []
if self.tilt:
out.append(
self.Builder(
self.name + "_tilt_entry",
self.classes.SRotation,
angle=self.tilt,
)
)
if self.dx or self.dy:
out.append(
self.Builder(
Expand All @@ -426,10 +418,26 @@ def entry(self):
dy=self.dy,
)
)
if self.tilt:
out.append(
self.Builder(
self.name + "_tilt_entry",
self.classes.SRotation,
angle=self.tilt,
)
)
return out

def exit(self):
out = []
if self.tilt:
out.append(
self.Builder(
self.name + "_tilt_exit",
self.classes.SRotation,
angle=-self.tilt,
)
)
if self.dx or self.dy:
out.append(
self.Builder(
Expand All @@ -439,14 +447,6 @@ def exit(self):
dy=-self.dy,
)
)
if self.tilt:
out.append(
self.Builder(
self.name + "_tilt_exit",
self.classes.SRotation,
angle=-self.tilt,
)
)
return out


Expand Down