From 14ac2edc094955fb1d6c6ef74bfd739d17217163 Mon Sep 17 00:00:00 2001
From: Alexis Gamelin <alexis.gamelin@synchrotron-soleil.fr>
Date: Mon, 3 Jun 2024 15:21:58 +0200
Subject: [PATCH] Add form factor contribution to lcbi_growth_rate_mode

---
 mbtrack2/instability/instabilities.py | 39 ++++++++++++++++++++++-----
 1 file changed, 32 insertions(+), 7 deletions(-)

diff --git a/mbtrack2/instability/instabilities.py b/mbtrack2/instability/instabilities.py
index 692c465..ec4425e 100644
--- a/mbtrack2/instability/instabilities.py
+++ b/mbtrack2/instability/instabilities.py
@@ -103,10 +103,11 @@ def lcbi_growth_rate_mode(ring,
                           fr=None,
                           RL=None,
                           QL=None,
-                          Z=None):
+                          Z=None,
+                          bunch_length=None):
     """
     Compute the longitudinal coupled bunch instability growth rate driven by
-    an impedance for a given coupled bunch mode mu [1].
+    an impedance for a given coupled bunch mode mu [1-2].
     
     Use either a list of resonators (fr, RL, QL) or an Impedance object (Z).
 
@@ -131,6 +132,10 @@ def lcbi_growth_rate_mode(ring,
         Loaded quality factor of the resonator.
     Z : Impedance, optional
         Longitunial impedance to consider.
+    bunch_length : float, optional
+        Bunch length in [s].
+        Used to computed the form factor for a resonator impedance if given.
+        Default is None.
 
     Returns
     -------
@@ -142,9 +147,12 @@ def lcbi_growth_rate_mode(ring,
     [1] : Eq. 51 p139 of Akai, Kazunori. "RF System for Electron Storage 
     Rings." Physics And Engineering Of High Performance Electron Storage Rings 
     And Application Of Superconducting Technology. 2002. 118-149.
+    
+    [2] : Tavares, P. F., et al. "Beam-based characterization of higher-order-mode 
+    driven coupled-bunch instabilities in a fourth-generation storage ring." 
+    NIM A (2022): 165945.
 
     """
-
     if synchrotron_tune is None and Vrf is None:
         raise ValueError("Either synchrotron_tune or Vrf is needed.")
     if synchrotron_tune is None:
@@ -188,8 +196,15 @@ def lcbi_growth_rate_mode(ring,
     n1 = np.arange(1, n_max)
     omega_p = ring.omega0 * (n0*M + mu + nu_s)
     omega_m = ring.omega0 * (n1*M - mu - nu_s)
+    
+    if bunch_length is None:
+        FFp = 1
+        FFm = 1
+    else:
+        FFp = np.exp(-(omega_p * bunch_length)**2)
+        FFm = np.exp(-(omega_m * bunch_length)**2)
 
-    sum_val = np.sum(omega_p * Zr(omega_p)) - np.sum(omega_m * Zr(omega_m))
+    sum_val = np.sum(omega_p * Zr(omega_p) * FFp) - np.sum(omega_m * Zr(omega_m) * FFm)
 
     return factor * sum_val
 
@@ -202,10 +217,11 @@ def lcbi_growth_rate(ring,
                      fr=None,
                      RL=None,
                      QL=None,
-                     Z=None):
+                     Z=None,
+                     bunch_length=None):
     """
     Compute the maximum growth rate for longitudinal coupled bunch instability 
-    driven an impedance [1].
+    driven an impedance [1-2].
     
     Use either a list of resonators (fr, RL, QL) or an Impedance object (Z).
 
@@ -228,6 +244,10 @@ def lcbi_growth_rate(ring,
         Loaded quality factor of the HOM.
     Z : Impedance, optional
         Longitunial impedance to consider.
+    bunch_length : float, optional
+        Bunch length in [s].
+        Used to computed the form factor for a resonator impedance if given.
+        Default is None.
 
     Returns
     -------
@@ -245,6 +265,10 @@ def lcbi_growth_rate(ring,
     [1] : Eq. 51 p139 of Akai, Kazunori. "RF System for Electron Storage 
     Rings." Physics And Engineering Of High Performance Electron Storage Rings 
     And Application Of Superconducting Technology. 2002. 118-149.
+    
+    [2] : Tavares, P. F., et al. "Beam-based characterization of higher-order-mode 
+    driven coupled-bunch instabilities in a fourth-generation storage ring." 
+    NIM A (2022): 165945.
 
     """
     growth_rates = np.zeros(M)
@@ -259,7 +283,8 @@ def lcbi_growth_rate(ring,
             fr=fr,
             RL=RL,
             QL=QL,
-            Z=Z)
+            Z=Z,
+            bunch_length=bunch_length)
 
     growth_rate = np.max(growth_rates)
     mu = np.argmax(growth_rates)
-- 
GitLab