From d531d29a6a4506e487286fb4a54343d71e7c4d33 Mon Sep 17 00:00:00 2001 From: austin-hoover Date: Tue, 15 Sep 2026 18:43:10 -0400 Subject: [PATCH 1/5] 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/5] 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() From f600f1d518c52b89e5bfdd4a6d8c5dee2a0e8f55 Mon Sep 17 00:00:00 2001 From: austin-hoover Date: Fri, 9 Oct 2026 14:49:13 -0400 Subject: [PATCH 3/5] Revert "Just use original calculation and add if statement" This reverts commit 48d43808222976c2f6f970ffa1e3f53ed9940a1c. --- py/orbit/matrix_lattice/MATRIX_Lattice.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/py/orbit/matrix_lattice/MATRIX_Lattice.py b/py/orbit/matrix_lattice/MATRIX_Lattice.py index afbadd2b..db32c550 100644 --- a/py/orbit/matrix_lattice/MATRIX_Lattice.py +++ b/py/orbit/matrix_lattice/MATRIX_Lattice.py @@ -247,9 +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))) - if delta_phi < 0: - delta_phi += math.pi + + 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 6546114bf7462b8017e4dc5676c81dce5a31be1d Mon Sep 17 00:00:00 2001 From: austin-hoover Date: Fri, 9 Oct 2026 14:57:05 -0400 Subject: [PATCH 4/5] Use atan2 --- py/orbit/matrix_lattice/MATRIX_Lattice.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/py/orbit/matrix_lattice/MATRIX_Lattice.py b/py/orbit/matrix_lattice/MATRIX_Lattice.py index db32c550..08303fc2 100644 --- a/py/orbit/matrix_lattice/MATRIX_Lattice.py +++ b/py/orbit/matrix_lattice/MATRIX_Lattice.py @@ -247,11 +247,10 @@ 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.atan2( + mt.get(ind0, ind1), + beta_0 * mt.get(ind0, ind0) - alpha_0 * mt.get(ind0, ind1) + ) phi = phi + delta_phi track_v = track_m.mult(track_v) position = position + matrixNode.getLength() From 5216b52a5e787efdcf138588822b563a356a51a3 Mon Sep 17 00:00:00 2001 From: austin-hoover Date: Fri, 9 Oct 2026 15:08:19 -0400 Subject: [PATCH 5/5] 2pi addition --- py/orbit/matrix_lattice/MATRIX_Lattice.py | 1 + 1 file changed, 1 insertion(+) diff --git a/py/orbit/matrix_lattice/MATRIX_Lattice.py b/py/orbit/matrix_lattice/MATRIX_Lattice.py index 08303fc2..a9e5c23e 100644 --- a/py/orbit/matrix_lattice/MATRIX_Lattice.py +++ b/py/orbit/matrix_lattice/MATRIX_Lattice.py @@ -251,6 +251,7 @@ def trackTwissData(self, alpha, beta, direction="x"): mt.get(ind0, ind1), beta_0 * mt.get(ind0, ind0) - alpha_0 * mt.get(ind0, ind1) ) + delta_phi = delta_phi % (2.0 * math.pi) phi = phi + delta_phi track_v = track_m.mult(track_v) position = position + matrixNode.getLength()