From d531d29a6a4506e487286fb4a54343d71e7c4d33 Mon Sep 17 00:00:00 2001 From: austin-hoover Date: Tue, 15 Sep 2026 18:43:10 -0400 Subject: [PATCH 1/2] Avoid losing pi in phase advance calculation in MATRIX_Lattice --- py/orbit/matrix_lattice/MATRIX_Lattice.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/py/orbit/matrix_lattice/MATRIX_Lattice.py b/py/orbit/matrix_lattice/MATRIX_Lattice.py index 22380391..db32c550 100644 --- a/py/orbit/matrix_lattice/MATRIX_Lattice.py +++ b/py/orbit/matrix_lattice/MATRIX_Lattice.py @@ -247,7 +247,11 @@ def trackTwissData(self, alpha, beta, direction="x"): track_m.set(2, 2, mt.get(ind1, ind1) * mt.get(ind1, ind1)) alpha_0 = track_v.get(0) beta_0 = track_v.get(1) - delta_phi = math.atan(mt.get(ind0, ind1) / (beta_0 * mt.get(ind0, ind0) - alpha_0 * mt.get(ind0, ind1))) + + upper = mt.get(ind0, ind1) + lower = beta_0 * mt.get(ind0, ind0) - alpha_0 * mt.get(ind0, ind1) + delta_phi = math.atan2(upper, lower) % (2.0 * math.pi) + phi = phi + delta_phi track_v = track_m.mult(track_v) position = position + matrixNode.getLength() From 48d43808222976c2f6f970ffa1e3f53ed9940a1c Mon Sep 17 00:00:00 2001 From: austin-hoover Date: Tue, 15 Sep 2026 18:51:54 -0400 Subject: [PATCH 2/2] Just use original calculation and add if statement --- py/orbit/matrix_lattice/MATRIX_Lattice.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/py/orbit/matrix_lattice/MATRIX_Lattice.py b/py/orbit/matrix_lattice/MATRIX_Lattice.py index db32c550..afbadd2b 100644 --- a/py/orbit/matrix_lattice/MATRIX_Lattice.py +++ b/py/orbit/matrix_lattice/MATRIX_Lattice.py @@ -247,11 +247,9 @@ def trackTwissData(self, alpha, beta, direction="x"): track_m.set(2, 2, mt.get(ind1, ind1) * mt.get(ind1, ind1)) alpha_0 = track_v.get(0) beta_0 = track_v.get(1) - - upper = mt.get(ind0, ind1) - lower = beta_0 * mt.get(ind0, ind0) - alpha_0 * mt.get(ind0, ind1) - delta_phi = math.atan2(upper, lower) % (2.0 * math.pi) - + delta_phi = math.atan(mt.get(ind0, ind1) / (beta_0 * mt.get(ind0, ind0) - alpha_0 * mt.get(ind0, ind1))) + if delta_phi < 0: + delta_phi += math.pi phi = phi + delta_phi track_v = track_m.mult(track_v) position = position + matrixNode.getLength()