From 70351027962d92c93ec7c499451b35d9d538f334 Mon Sep 17 00:00:00 2001 From: Daniel Estrada <daniel.estrada.acevedo@cern.ch> Date: Thu, 18 May 2023 01:27:25 +0200 Subject: [PATCH] Add S-curve filter to identify noisy channels based on ENC value --- gemos/analysis/scurve_analysis.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/gemos/analysis/scurve_analysis.py b/gemos/analysis/scurve_analysis.py index cf7f923..f7bde75 100644 --- a/gemos/analysis/scurve_analysis.py +++ b/gemos/analysis/scurve_analysis.py @@ -7,6 +7,7 @@ from warnings import filterwarnings import gc import os +from matplotlib.cbook import boxplot_stats from matplotlib.colors import Normalize from mplhep import style from scipy.optimize import curve_fit @@ -63,6 +64,7 @@ def _show_report(report_info): print("{} - VFAT analyzed.".format(info["analyzed vfat"])) print("{} - empty channels found.".format(info["empty channels"])) print("{} - channels failed fitting.".format(info["fit-failed channels"])) + print("{} - noisy channels.".format(info["noisy channels"])) print("------------------------------------------------------------") @@ -121,12 +123,23 @@ def _analyze_vfat(vfat_dir): "threshold": mean, "enc": sigma, "empty": status == None, + "noisy": None, } ) return pd.DataFrame.from_records(values) +def _filter_noisy_channels(enc_data): + """Routine to filter noisy channels based on the outliers points defined by the interquartile range. + Only upper fliers are taken. + + :param pandas.core.series.Series enc_data: Pandas series with the noise of the channels for a VFAT + """ + stats = boxplot_stats(enc_data)[0] + return (enc_data.isin(stats["fliers"])) & (enc_data.gt(stats["med"])) + + def _scurve_summary_plots(oh_dirs, graph_name, units=Units.DAC_UNITS, calibration_df=None): """Routine to produce a summary 2D plots of the VFATs for an OH @@ -419,6 +432,7 @@ def create_configuration( "threshold": None, "enc": None, "empty": None, + "noisy": None, }, ) @@ -429,6 +443,7 @@ def create_configuration( analyzed_oh = 0 empty_channels = 0 fit_failed_channels = 0 + noisy_channels = 0 print("Analyzing", input_file_name) input_file = uproot.open(input_file_name) @@ -454,6 +469,11 @@ def create_configuration( # Merge results into a single DataFrame final_data = pd.concat([r.get() for r in results], ignore_index=True) + # Noisy channels are filtered + final_data["noisy"] = final_data.groupby(["fed", "slot", "oh", "vfat"])[ + "enc" + ].transform(_filter_noisy_channels) + # Data are changed to desired units calibration_df = None if units == Units.FC: @@ -583,6 +603,13 @@ def create_configuration( ].drop_duplicates(["fed", "slot", "oh", "vfat", "channel"]) ) + # To count how many noisy channels exist + noisy_channels = len( + final_data.loc[(final_data["noisy"] == True)].drop_duplicates( + ["fed", "slot", "oh", "vfat", "channel"] + ) + ) + report_info += [ { "filename": input_file_name, @@ -590,6 +617,7 @@ def create_configuration( "analyzed vfat": analyzed_vfat, "empty channels": empty_channels, "fit-failed channels": fit_failed_channels, + "noisy channels": noisy_channels, } ] -- GitLab