From 00709f55cf7f0eae47bdd744791e32dfbbdd1b67 Mon Sep 17 00:00:00 2001
From: Camilla Galloni <camilla.galloni@cern.ch>
Date: Fri, 13 May 2022 18:36:09 +0200
Subject: [PATCH] Set the range of sbit plots as a function of max rate

---
 gemos/analysis/threshold_scan_analysis.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/gemos/analysis/threshold_scan_analysis.py b/gemos/analysis/threshold_scan_analysis.py
index 9200bb5..74f1c19 100644
--- a/gemos/analysis/threshold_scan_analysis.py
+++ b/gemos/analysis/threshold_scan_analysis.py
@@ -32,9 +32,12 @@ def create_configuration(input_filenames, output_directory, target_rate, plottin
     def plot_scan_oh(df):
         """Plot threshold scans for all VFATs in single OH"""
 
-        def plot_scan_vfat(vfat, df, ax):
+        def plot_scan_vfat(vfat, df, ax, time_interval):
             """Plot threshold scan for single VFAT"""
             ax.plot(df["dac-value"], df["rate"], "o")
+            # The axis limit is chosen to be twice the maximum rate aquired in the time interval of the scan
+            ax.set_ylim(1, time_interval * 40080000 * 2)
+            ax.set_xlim(0, 255)
             ax.title.set_text(f"VFAT {vfat}")
             ax.set_xlabel("THR_ARM_DAC")
             ax.set_ylabel("S-bt rate (Hz)")
@@ -44,6 +47,12 @@ def create_configuration(input_filenames, output_directory, target_rate, plottin
         slot = df.iloc[0]["slot"]
         oh = df.iloc[0]["oh"]
 
+        # The s-bit counters increase of maximum 1 per each bunch crossing;
+        # the bunch crissing rate in LHC is 40.07897 MHz approximated to 4008000 MHz
+        # giving a possible increase in the s-bit counters of maximum 4008000 per second.
+        # The time interval used for the scan can be estimated in second as:
+        time_interval = (df["rate"].max() // 40080000) + 1
+
         vfat_group = df.groupby(["vfat"])
 
         nrows, ncols = 3, int(np.ceil(len(vfat_group) / 3))  # Round-up the number of columns
@@ -51,7 +60,7 @@ def create_configuration(input_filenames, output_directory, target_rate, plottin
         thr_scan_axs = thr_scan_axs.flat
 
         for group_index, (vfat_index, vfat_df) in enumerate(vfat_group):
-            plot_scan_vfat(vfat_index, vfat_df, thr_scan_axs[group_index])
+            plot_scan_vfat(vfat_index, vfat_df, thr_scan_axs[group_index], time_interval)
 
         output_figure = "{}/plots/fed{}-slot{}-oh{}.png".format(output_directory, fed, slot, oh)
         thr_scan_fig.savefig(output_figure)
-- 
GitLab