From f67c4c930f348df7d048147c5b7d5ee1ebc41f04 Mon Sep 17 00:00:00 2001
From: Alexis Gamelin <alexis.gamelin@synchrotron-soleil.fr>
Date: Mon, 22 Apr 2024 18:38:56 +0200
Subject: [PATCH] Add R_factor calculation to BeamLoadingEquilibrium

---
 mbtrack2/utilities/beamloading.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mbtrack2/utilities/beamloading.py b/mbtrack2/utilities/beamloading.py
index cfd3548..d8d64b1 100644
--- a/mbtrack2/utilities/beamloading.py
+++ b/mbtrack2/utilities/beamloading.py
@@ -69,7 +69,7 @@ class BeamLoadingEquilibrium():
         self.N = N
         self.z0 = np.linspace(self.B1, self.B2, self.N)
         self.tau0 = self.z0/c
-        self.rho0 = gaussian_bunch(self.tau0, self.ring.sigma_0)
+        self.rho0 = gaussian_bunch(self.tau0, self.ring.sigma_0)/c
 
         # Define constants for scaled potential u(z)
         self.u0 = self.ring.U0 / (self.ring.ac * self.ring.sigma_delta**2 *
@@ -394,3 +394,9 @@ class BeamLoadingEquilibrium():
                 (2 * np.pi * HC.m**2 * self.F[1] * self.ring.h * I0 * f))
 
         return (eta, RQth, f)
+    
+    @property
+    def R_factor(self):
+        rho0 = gaussian_bunch(self.tau0, self.ring.sigma_0)/c
+        R = trapz(rho0**2, self.tau0)/trapz(self.rho0**2, self.tau0)
+        return R
-- 
GitLab