From 6b8b1ec0c7aea8032e665066bce9511045664220 Mon Sep 17 00:00:00 2001
From: Gamelin Alexis <gamelin@synchrotron-soleil.fr>
Date: Fri, 12 Jun 2020 19:57:18 +0200
Subject: [PATCH] Add synchrotron_tune method to Synchrotron class

---
 tracking/synchrotron.py | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/tracking/synchrotron.py b/tracking/synchrotron.py
index a622c04..a12122c 100644
--- a/tracking/synchrotron.py
+++ b/tracking/synchrotron.py
@@ -69,6 +69,11 @@ class Synchrotron:
         Momentum compaction.
     sigma : array of shape (4,)
         RMS beam size at equilibrium in [m].
+        
+    Methods
+    -------
+    synchrotron_tune(Vrf)
+        Compute synchrotron tune from RF voltage.
     """
     def __init__(self, h, optics, particle, **kwargs):
         self._h = h
@@ -230,4 +235,23 @@ class Synchrotron:
                     self.optics.local_dispersion[2]**2*self.sigma_delta)**0.5
         sigma[3] = (self.emit[1]*self.optics.local_alpha[1] +
                     self.optics.local_dispersion[3]**2*self.sigma_delta)**0.5
-        return sigma
\ No newline at end of file
+        return sigma
+    
+    def synchrotron_tune(Vrf):
+        """
+        Compute synchrotron tune from RF voltage
+        
+        Parameters
+        ----------
+        Vrf : float
+            Main RF voltage in [V].
+            
+        Returns
+        -------
+        tuneS : float
+            Synchrotron tune.
+        """
+        phase = np.pi - np.arcsin(ring.U0 / Vrf)
+        tuneS = np.sqrt( - (Vrf / ring.E0) * (ring.h * ring.ac) / (2*np.pi) 
+                        * np.cos(phase) )
+        return tuneS
\ No newline at end of file
-- 
GitLab