From 6593babf1b8cbb46ce095e4b2b68fac2dc9e07cd Mon Sep 17 00:00:00 2001
From: gubaidulinvadim <gubaidulinvadim@gmail.com>
Date: Wed, 23 Apr 2025 12:13:50 +0200
Subject: [PATCH] Added a test to check the tune shifts from FBT are correct.

---
 tests/physics/test_fbt_phys.py | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/tests/physics/test_fbt_phys.py b/tests/physics/test_fbt_phys.py
index 0a5283d..a44b650 100644
--- a/tests/physics/test_fbt_phys.py
+++ b/tests/physics/test_fbt_phys.py
@@ -1,5 +1,7 @@
+import h5py as hp
 import numpy as np
 import pytest
+from nafflib import get_tune
 from utility_test_growth_rate import get_growth_beam
 
 from mbtrack2 import (
@@ -40,10 +42,10 @@ class TestFBTPhys:
                      track_alive=False,
                      mpi=False)
         damping_time = [50, 100]
-        growth_rate = 1 / (damping_time[1] * demo_ring.T0)
+        phase_diff = [-45, -45]
         fbt = TransverseExponentialDamper(ring,
                                           damping_time=damping_time,
-                                          phase_diff=[-90, -90])
+                                          phase_diff=phase_diff)
 
         save_every = 1
         bbmon = BeamMonitor(h=ring.h,
@@ -62,6 +64,8 @@ class TestFBTPhys:
 
         bbmon.close()
 
+        growth_rate = (1 / (damping_time[1] * demo_ring.T0) *
+                       np.cos(np.deg2rad(phase_diff[1])))
         path = name + '.hdf5'
         gr, gr_std = get_growth_beam(ring, path, 1e3, 2e3)
         rel_error = np.abs(growth_rate - gr) * 100 / growth_rate
@@ -69,6 +73,17 @@ class TestFBTPhys:
         print(f"Relative error: {rel_error} % (std: {rel_error_std} %)")
         assert rel_error < 5
 
+        with hp.File(name + '.hdf5', 'r') as f:
+            x = f['Beam']['mean'][0, 0, :]
+        t = get_tune(x)
+
+        np.testing.assert_allclose(
+            (np.abs(t) - (demo_ring.tune[0] - int(demo_ring.tune[0]))),
+            np.abs(
+                np.sin(np.deg2rad(phase_diff[0])) /
+                (2 * np.pi * damping_time[0])),
+            rtol=5e-2)
+
     def test_firdamper_growth_rate_chroma0(self, demo_ring, tmp_path):
 
         ring = demo_ring
-- 
GitLab