From fef74fc7a22e09477a84cee0cbfdc4a6ee896781 Mon Sep 17 00:00:00 2001
From: Gamelin Alexis <alexis.gamelin@synchrotron-soleil.fr>
Date: Wed, 19 May 2021 16:27:38 +0200
Subject: [PATCH] [Fix] CavityResonator with mpi with non-uniform beams

---
 tracking/rf.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tracking/rf.py b/tracking/rf.py
index 49a743b..f34958b 100644
--- a/tracking/rf.py
+++ b/tracking/rf.py
@@ -215,11 +215,13 @@ class CavityResonator():
             if beam.filling_pattern[index]:
                 
                 if beam.mpi_switch:
+                    # get rank of bunch n° index
+                    rank = beam.mpi.bunch_to_rank(index)
                     # mpi -> get shared bunch profile for current bunch
-                    center = beam.mpi.tau_center[index]
-                    profile = beam.mpi.tau_profile[index]
+                    center = beam.mpi.tau_center[rank]
+                    profile = beam.mpi.tau_profile[rank]
                     bin_length = center[1]-center[0]
-                    charge_per_mp = beam.mpi.charge_per_mp_all[index]
+                    charge_per_mp = beam.mpi.charge_per_mp_all[rank]
                     if index == self.bunch_index:
                         sorted_index = beam.mpi.tau_sorted_index
                 else:
-- 
GitLab