From 82e0eea78cdf4736d84eb1c845421f4737141717 Mon Sep 17 00:00:00 2001
From: Gamelin Alexis <gamelin@synchrotron-soleil.fr>
Date: Thu, 18 Mar 2021 11:46:43 +0100
Subject: [PATCH] Correct case when where is no mp in the bin

Correct case when where is no mp in the bin
Remove useless test
---
 tracking/rf.py | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/tracking/rf.py b/tracking/rf.py
index d1c2401..9ed3b00 100644
--- a/tracking/rf.py
+++ b/tracking/rf.py
@@ -219,13 +219,16 @@ class CavityResonator():
                 for i, center0 in enumerate(center):
                     mp_per_bin = profile[i]
                     
-                    if index == self.bunch_index:
-                        ind = (sorted_index == i)
-                        Vgene = self.Vg*np.cos(self.m*self.ring.omega1*bunch["tau"][ind] + self.theta_g)
-                        Vbeam = np.real(self.beam_phasor)
-                        Vtot = Vgene + Vbeam - charge_per_mp*self.loss_factor*mp_per_bin
-                        energy_change[ind] = Vtot / self.ring.E0
-                        
+                    if mp_per_bin == 0:
+                        self.phasor_decay(bin_length)
+                        continue
+                    
+                    ind = (sorted_index == i)
+                    Vgene = self.Vg*np.cos(self.m*self.ring.omega1*bunch["tau"][ind] + self.theta_g)
+                    Vbeam = np.real(self.beam_phasor)
+                    Vtot = Vgene + Vbeam - charge_per_mp*self.loss_factor*mp_per_bin
+                    energy_change[ind] = Vtot / self.ring.E0
+
                     self.phasor_decay(bin_length)
                     
                     self.beam_phasor -= 2*charge_per_mp*self.loss_factor*mp_per_bin
-- 
GitLab