From 950e49c707aec043604dae7269bc1a85fca11771 Mon Sep 17 00:00:00 2001
From: Alexis Gamelin <alexis.gamelin@synchrotron-soleil.fr>
Date: Mon, 23 Sep 2024 17:47:07 +0200
Subject: [PATCH] [Fix] Quadrupolar wake potential sign

The Q wake potential should be of the same sign as the Q wake function. A positive Q wake function/potential is defocusing i.e. a positive angular kick is felt by the test particle (for positive test particule position).
Also fix WakePotential.plot_last_wake for negative wake function.
---
 mbtrack2/tracking/wakepotential.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/mbtrack2/tracking/wakepotential.py b/mbtrack2/tracking/wakepotential.py
index 3fdb19b..951e979 100644
--- a/mbtrack2/tracking/wakepotential.py
+++ b/mbtrack2/tracking/wakepotential.py
@@ -271,7 +271,7 @@ class WakePotential(Element):
 
         profile0 = np.interp(tau0, self.tau, self.rho, 0, 0)
 
-        if wake_type == "Wlong" or wake_type == "Wxquad" or wake_type == "Wyquad" or wake_type == "Wxcst" or wake_type == "Wycst":
+        if wake_type == "Wlong" or wake_type == "Wxcst" or wake_type == "Wycst":
             Wp = signal.convolve(profile0, W0 * -1, mode='same') * dtau0
         elif wake_type == "Wxdip":
             dipole0 = self.dipole_moment(bunch, "x", tau0)
@@ -279,6 +279,8 @@ class WakePotential(Element):
         elif wake_type == "Wydip":
             dipole0 = self.dipole_moment(bunch, "y", tau0)
             Wp = signal.convolve(profile0 * dipole0, W0, mode='same') * dtau0
+        elif wake_type == "Wxquad" or wake_type == "Wyquad":
+            Wp = signal.convolve(profile0, W0, mode='same') * dtau0
         else:
             raise ValueError("This type of wake is not taken into account.")
 
@@ -386,7 +388,7 @@ class WakePotential(Element):
 
         if plot_wake_function is True:
             W0 = getattr(self, "W0_" + wake_type)
-            W0_rescaled = W0 / max(W0) * max(np.abs(Wp))
+            W0_rescaled = W0 / max(np.abs(W0)) * max(np.abs(Wp))
             ax.plot(tau0 * 1e12,
                     W0_rescaled * 1e-12,
                     label=r"$W_{function}$ (a.u.)")
-- 
GitLab