From 761f211fe85648320e73c0f004d708632bb5f6e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henning=20Schulze=20Ei=C3=9Fing?= Date: Thu, 16 May 2024 09:12:53 +0200 Subject: [PATCH 1/8] Add MultiPeakData plugin --- straxen/plugins/events/peaks_of_event.py | 77 ++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 straxen/plugins/events/peaks_of_event.py diff --git a/straxen/plugins/events/peaks_of_event.py b/straxen/plugins/events/peaks_of_event.py new file mode 100644 index 000000000..18d0c2b69 --- /dev/null +++ b/straxen/plugins/events/peaks_of_event.py @@ -0,0 +1,77 @@ +import strax +import straxen +import numpy as np + + +MAX_NUMBER_OF_PEAKS_PER_EVENT = 10 +PEAK_WAVEFORM_LENGTH = 200 + +class MultiPeakData(strax.Plugin): + + """ + Plugin that extracts information of multiple peaks in an event. + """ + + __version__ = "0.0.1" + + depends_on = ("peaks", "peak_per_event", "events", "peak_positions", 'peak_basics') + provides = "multi_peak_data" + data_kind = 'events' + save_when = strax.SaveWhen.TARGET + + + dtype = [ + (('time difference to the first peak in the event in ns', + 'delta_time_i'), np.int64, MAX_NUMBER_OF_PEAKS_PER_EVENT), + (('sample width in ns of the corresponding waveform', + 'peak_dt_i'), np.int32, MAX_NUMBER_OF_PEAKS_PER_EVENT), + (('peak type of the corresponding waveform', + 'peak_type_i'), np.int8, MAX_NUMBER_OF_PEAKS_PER_EVENT), + (('peak area of the corresponding waveform', + 'peak_area_i'), np.float32, MAX_NUMBER_OF_PEAKS_PER_EVENT), + (('x position of peak i', + 'peak_x_position_i'), np.float32, MAX_NUMBER_OF_PEAKS_PER_EVENT), + (('y position of peak i', + 'peak_y_position_i'), np.float32, MAX_NUMBER_OF_PEAKS_PER_EVENT), + (('area fraction top of peak i', + 'peak_aft_i'), np.float32, MAX_NUMBER_OF_PEAKS_PER_EVENT), + (('Sum Waveforms of all peaks in the event', + 'peak_waveform_i'), np.int16, (MAX_NUMBER_OF_PEAKS_PER_EVENT, PEAK_WAVEFORM_LENGTH)), + (('Top Waveforms of all peaks in the event', + 'peak_waveform_i_top'), np.int16, (MAX_NUMBER_OF_PEAKS_PER_EVENT, PEAK_WAVEFORM_LENGTH)), + (('PMT hitpattern of all peaks in the event', + 'peak_area_per_channel_i'), np.float32, (MAX_NUMBER_OF_PEAKS_PER_EVENT, straxen.n_tpc_pmts)), + *strax.time_fields] + + def compute(self, peaks, events): + + # Just interested in S1 or S2 peaks. Here would be the place to apply further peak quality cuts. + peaks = peaks[peaks["type"] != 0] + + peaks_per_event = strax.split_by_containment(peaks, events) + + result = np.zeros(len(events), dtype=self.dtype) + + for i, peaks_in_event in enumerate(peaks_per_event): + + n_peaks_in_event = len(peaks_in_event) + + if n_peaks_in_event == 0: + continue + + else: + result[i]["delta_time_i"][0:n_peaks_in_event] = peaks_in_event["time"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT]-peaks_in_event["time"][0] + result[i]["peak_dt_i"][0:n_peaks_in_event] = peaks_in_event["dt"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] + result[i]["peak_area_per_channel_i"][0:n_peaks_in_event] = peaks_in_event["area_per_channel"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] + result[i]["peak_waveform_i"][0:n_peaks_in_event] = peaks_in_event["data"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] + result[i]["peak_waveform_i_top"][0:n_peaks_in_event] = peaks_in_event["data_top"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] + result[i]["peak_type_i"][0:n_peaks_in_event] = peaks_in_event["type"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] + result[i]["peak_area_i"][0:n_peaks_in_event] = peaks_in_event["area"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] + result[i]["peak_x_position_i"][0:n_peaks_in_event] = peaks_in_event["x"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] + result[i]["peak_y_position_i"][0:n_peaks_in_event] = peaks_in_event["y"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] + result[i]["peak_aft_i"][0:n_peaks_in_event] = peaks_in_event["area_fraction_top"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] + + result["time"] = events["time"] + result["endtime"] = events["endtime"] + + return result \ No newline at end of file From e5eae05c6c852a94f39fc75a2dd5a1b5a7ba61e0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 16 May 2024 07:15:18 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- straxen/plugins/events/peaks_of_event.py | 173 ++++++++++++++--------- 1 file changed, 105 insertions(+), 68 deletions(-) diff --git a/straxen/plugins/events/peaks_of_event.py b/straxen/plugins/events/peaks_of_event.py index 18d0c2b69..0a6cad460 100644 --- a/straxen/plugins/events/peaks_of_event.py +++ b/straxen/plugins/events/peaks_of_event.py @@ -6,72 +6,109 @@ MAX_NUMBER_OF_PEAKS_PER_EVENT = 10 PEAK_WAVEFORM_LENGTH = 200 -class MultiPeakData(strax.Plugin): - """ - Plugin that extracts information of multiple peaks in an event. - """ - - __version__ = "0.0.1" - - depends_on = ("peaks", "peak_per_event", "events", "peak_positions", 'peak_basics') - provides = "multi_peak_data" - data_kind = 'events' - save_when = strax.SaveWhen.TARGET - - - dtype = [ - (('time difference to the first peak in the event in ns', - 'delta_time_i'), np.int64, MAX_NUMBER_OF_PEAKS_PER_EVENT), - (('sample width in ns of the corresponding waveform', - 'peak_dt_i'), np.int32, MAX_NUMBER_OF_PEAKS_PER_EVENT), - (('peak type of the corresponding waveform', - 'peak_type_i'), np.int8, MAX_NUMBER_OF_PEAKS_PER_EVENT), - (('peak area of the corresponding waveform', - 'peak_area_i'), np.float32, MAX_NUMBER_OF_PEAKS_PER_EVENT), - (('x position of peak i', - 'peak_x_position_i'), np.float32, MAX_NUMBER_OF_PEAKS_PER_EVENT), - (('y position of peak i', - 'peak_y_position_i'), np.float32, MAX_NUMBER_OF_PEAKS_PER_EVENT), - (('area fraction top of peak i', - 'peak_aft_i'), np.float32, MAX_NUMBER_OF_PEAKS_PER_EVENT), - (('Sum Waveforms of all peaks in the event', - 'peak_waveform_i'), np.int16, (MAX_NUMBER_OF_PEAKS_PER_EVENT, PEAK_WAVEFORM_LENGTH)), - (('Top Waveforms of all peaks in the event', - 'peak_waveform_i_top'), np.int16, (MAX_NUMBER_OF_PEAKS_PER_EVENT, PEAK_WAVEFORM_LENGTH)), - (('PMT hitpattern of all peaks in the event', - 'peak_area_per_channel_i'), np.float32, (MAX_NUMBER_OF_PEAKS_PER_EVENT, straxen.n_tpc_pmts)), - *strax.time_fields] - - def compute(self, peaks, events): - - # Just interested in S1 or S2 peaks. Here would be the place to apply further peak quality cuts. - peaks = peaks[peaks["type"] != 0] - - peaks_per_event = strax.split_by_containment(peaks, events) - - result = np.zeros(len(events), dtype=self.dtype) - - for i, peaks_in_event in enumerate(peaks_per_event): - - n_peaks_in_event = len(peaks_in_event) - - if n_peaks_in_event == 0: - continue - - else: - result[i]["delta_time_i"][0:n_peaks_in_event] = peaks_in_event["time"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT]-peaks_in_event["time"][0] - result[i]["peak_dt_i"][0:n_peaks_in_event] = peaks_in_event["dt"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] - result[i]["peak_area_per_channel_i"][0:n_peaks_in_event] = peaks_in_event["area_per_channel"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] - result[i]["peak_waveform_i"][0:n_peaks_in_event] = peaks_in_event["data"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] - result[i]["peak_waveform_i_top"][0:n_peaks_in_event] = peaks_in_event["data_top"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] - result[i]["peak_type_i"][0:n_peaks_in_event] = peaks_in_event["type"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] - result[i]["peak_area_i"][0:n_peaks_in_event] = peaks_in_event["area"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] - result[i]["peak_x_position_i"][0:n_peaks_in_event] = peaks_in_event["x"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] - result[i]["peak_y_position_i"][0:n_peaks_in_event] = peaks_in_event["y"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] - result[i]["peak_aft_i"][0:n_peaks_in_event] = peaks_in_event["area_fraction_top"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] - - result["time"] = events["time"] - result["endtime"] = events["endtime"] - - return result \ No newline at end of file +class MultiPeakData(strax.Plugin): + """Plugin that extracts information of multiple peaks in an event.""" + + __version__ = "0.0.1" + + depends_on = ("peaks", "peak_per_event", "events", "peak_positions", "peak_basics") + provides = "multi_peak_data" + data_kind = "events" + save_when = strax.SaveWhen.TARGET + + dtype = [ + ( + ("time difference to the first peak in the event in ns", "delta_time_i"), + np.int64, + MAX_NUMBER_OF_PEAKS_PER_EVENT, + ), + ( + ("sample width in ns of the corresponding waveform", "peak_dt_i"), + np.int32, + MAX_NUMBER_OF_PEAKS_PER_EVENT, + ), + ( + ("peak type of the corresponding waveform", "peak_type_i"), + np.int8, + MAX_NUMBER_OF_PEAKS_PER_EVENT, + ), + ( + ("peak area of the corresponding waveform", "peak_area_i"), + np.float32, + MAX_NUMBER_OF_PEAKS_PER_EVENT, + ), + (("x position of peak i", "peak_x_position_i"), np.float32, MAX_NUMBER_OF_PEAKS_PER_EVENT), + (("y position of peak i", "peak_y_position_i"), np.float32, MAX_NUMBER_OF_PEAKS_PER_EVENT), + (("area fraction top of peak i", "peak_aft_i"), np.float32, MAX_NUMBER_OF_PEAKS_PER_EVENT), + ( + ("Sum Waveforms of all peaks in the event", "peak_waveform_i"), + np.int16, + (MAX_NUMBER_OF_PEAKS_PER_EVENT, PEAK_WAVEFORM_LENGTH), + ), + ( + ("Top Waveforms of all peaks in the event", "peak_waveform_i_top"), + np.int16, + (MAX_NUMBER_OF_PEAKS_PER_EVENT, PEAK_WAVEFORM_LENGTH), + ), + ( + ("PMT hitpattern of all peaks in the event", "peak_area_per_channel_i"), + np.float32, + (MAX_NUMBER_OF_PEAKS_PER_EVENT, straxen.n_tpc_pmts), + ), + *strax.time_fields, + ] + + def compute(self, peaks, events): + + # Just interested in S1 or S2 peaks. Here would be the place to apply further peak quality cuts. + peaks = peaks[peaks["type"] != 0] + + peaks_per_event = strax.split_by_containment(peaks, events) + + result = np.zeros(len(events), dtype=self.dtype) + + for i, peaks_in_event in enumerate(peaks_per_event): + + n_peaks_in_event = len(peaks_in_event) + + if n_peaks_in_event == 0: + continue + + else: + result[i]["delta_time_i"][0:n_peaks_in_event] = ( + peaks_in_event["time"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] + - peaks_in_event["time"][0] + ) + result[i]["peak_dt_i"][0:n_peaks_in_event] = peaks_in_event["dt"][ + 0:MAX_NUMBER_OF_PEAKS_PER_EVENT + ] + result[i]["peak_area_per_channel_i"][0:n_peaks_in_event] = peaks_in_event[ + "area_per_channel" + ][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] + result[i]["peak_waveform_i"][0:n_peaks_in_event] = peaks_in_event["data"][ + 0:MAX_NUMBER_OF_PEAKS_PER_EVENT + ] + result[i]["peak_waveform_i_top"][0:n_peaks_in_event] = peaks_in_event["data_top"][ + 0:MAX_NUMBER_OF_PEAKS_PER_EVENT + ] + result[i]["peak_type_i"][0:n_peaks_in_event] = peaks_in_event["type"][ + 0:MAX_NUMBER_OF_PEAKS_PER_EVENT + ] + result[i]["peak_area_i"][0:n_peaks_in_event] = peaks_in_event["area"][ + 0:MAX_NUMBER_OF_PEAKS_PER_EVENT + ] + result[i]["peak_x_position_i"][0:n_peaks_in_event] = peaks_in_event["x"][ + 0:MAX_NUMBER_OF_PEAKS_PER_EVENT + ] + result[i]["peak_y_position_i"][0:n_peaks_in_event] = peaks_in_event["y"][ + 0:MAX_NUMBER_OF_PEAKS_PER_EVENT + ] + result[i]["peak_aft_i"][0:n_peaks_in_event] = peaks_in_event["area_fraction_top"][ + 0:MAX_NUMBER_OF_PEAKS_PER_EVENT + ] + + result["time"] = events["time"] + result["endtime"] = events["endtime"] + + return result From f2c1dd4fa54d197fb5d9d5b255c8cc5d59bbe102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henning=20Schulze=20Ei=C3=9Fing?= Date: Tue, 17 Sep 2024 11:00:08 +0200 Subject: [PATCH 3/8] Get the 5 largest S1s and S2s not the 10 first peaks. --- straxen/plugins/events/peaks_of_event.py | 118 ++++++++++++----------- 1 file changed, 61 insertions(+), 57 deletions(-) diff --git a/straxen/plugins/events/peaks_of_event.py b/straxen/plugins/events/peaks_of_event.py index 0a6cad460..9f52e1a44 100644 --- a/straxen/plugins/events/peaks_of_event.py +++ b/straxen/plugins/events/peaks_of_event.py @@ -2,15 +2,14 @@ import straxen import numpy as np - -MAX_NUMBER_OF_PEAKS_PER_EVENT = 10 +MAX_NUMBER_OF_S1_PEAKS_PER_EVENT = 5 +MAX_NUMBER_OF_S2_PEAKS_PER_EVENT = 5 PEAK_WAVEFORM_LENGTH = 200 - class MultiPeakData(strax.Plugin): """Plugin that extracts information of multiple peaks in an event.""" - __version__ = "0.0.1" + __version__ = "0.0.2" depends_on = ("peaks", "peak_per_event", "events", "peak_positions", "peak_basics") provides = "multi_peak_data" @@ -19,42 +18,43 @@ class MultiPeakData(strax.Plugin): dtype = [ ( - ("time difference to the first peak in the event in ns", "delta_time_i"), + ("time difference of S1 peaks to event start time", "s1_delta_time_i"), np.int64, - MAX_NUMBER_OF_PEAKS_PER_EVENT, + MAX_NUMBER_OF_S1_PEAKS_PER_EVENT, ), ( - ("sample width in ns of the corresponding waveform", "peak_dt_i"), - np.int32, - MAX_NUMBER_OF_PEAKS_PER_EVENT, + ("time difference of S2 peaks to event start time", "s2_delta_time_i"), + np.int64, + MAX_NUMBER_OF_S2_PEAKS_PER_EVENT, ), ( - ("peak type of the corresponding waveform", "peak_type_i"), - np.int8, - MAX_NUMBER_OF_PEAKS_PER_EVENT, + ("sample width in ns of the S1 waveform", "s1_peak_dt_i"), + np.int32, + MAX_NUMBER_OF_S1_PEAKS_PER_EVENT, ), ( - ("peak area of the corresponding waveform", "peak_area_i"), - np.float32, - MAX_NUMBER_OF_PEAKS_PER_EVENT, + ("sample width in ns of the S2 waveform", "s2_peak_dt_i"), + np.int32, + MAX_NUMBER_OF_S2_PEAKS_PER_EVENT, ), - (("x position of peak i", "peak_x_position_i"), np.float32, MAX_NUMBER_OF_PEAKS_PER_EVENT), - (("y position of peak i", "peak_y_position_i"), np.float32, MAX_NUMBER_OF_PEAKS_PER_EVENT), - (("area fraction top of peak i", "peak_aft_i"), np.float32, MAX_NUMBER_OF_PEAKS_PER_EVENT), + (("x position of S2 i", "s2_x_position_i"), np.float32, MAX_NUMBER_OF_S2_PEAKS_PER_EVENT), + (("y position of S2 i", "s2_y_position_i"), np.float32, MAX_NUMBER_OF_S2_PEAKS_PER_EVENT), + (("area fraction top of S2 i", "s2_aft_i"), np.float32, MAX_NUMBER_OF_S2_PEAKS_PER_EVENT), + (("area fraction top of S1 i", "s1_aft_i"), np.float32, MAX_NUMBER_OF_S1_PEAKS_PER_EVENT), ( - ("Sum Waveforms of all peaks in the event", "peak_waveform_i"), - np.int16, - (MAX_NUMBER_OF_PEAKS_PER_EVENT, PEAK_WAVEFORM_LENGTH), + ("Sum Waveform of S1 peaks", "s1_waveform_i"), + np.float32, + (MAX_NUMBER_OF_S1_PEAKS_PER_EVENT, PEAK_WAVEFORM_LENGTH), ), ( - ("Top Waveforms of all peaks in the event", "peak_waveform_i_top"), - np.int16, - (MAX_NUMBER_OF_PEAKS_PER_EVENT, PEAK_WAVEFORM_LENGTH), + ("Sum Waveform of S2 peaks", "s2_waveform_i"), + np.float32, + (MAX_NUMBER_OF_S2_PEAKS_PER_EVENT, PEAK_WAVEFORM_LENGTH), ), ( - ("PMT hitpattern of all peaks in the event", "peak_area_per_channel_i"), + ("Start of S1 waverforms", "s1_waveform_start_i"), np.float32, - (MAX_NUMBER_OF_PEAKS_PER_EVENT, straxen.n_tpc_pmts), + (MAX_NUMBER_OF_S1_PEAKS_PER_EVENT, PEAK_WAVEFORM_LENGTH), ), *strax.time_fields, ] @@ -74,39 +74,43 @@ def compute(self, peaks, events): if n_peaks_in_event == 0: continue - else: - result[i]["delta_time_i"][0:n_peaks_in_event] = ( - peaks_in_event["time"][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] - - peaks_in_event["time"][0] + + # Get the largest S1s and S2s + s1_peaks = peaks_in_event[peaks_in_event["type"] == 1] + s2_peaks = peaks_in_event[peaks_in_event["type"] == 2] + + s1_peaks = s1_peaks[np.argsort(s1_peaks["area"])[::-1]] + s2_peaks = s2_peaks[np.argsort(s2_peaks["area"])[::-1]] + + n_s1_peaks_in_event = len(s1_peaks) + n_s2_peaks_in_event = len(s2_peaks) + + # Save the data of the n largest peaks + result[i]["s1_delta_time_i"][0:n_s1_peaks_in_event] = ( + s1_peaks["time"][0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT] - peaks_in_event["time"][0] ) - result[i]["peak_dt_i"][0:n_peaks_in_event] = peaks_in_event["dt"][ - 0:MAX_NUMBER_OF_PEAKS_PER_EVENT - ] - result[i]["peak_area_per_channel_i"][0:n_peaks_in_event] = peaks_in_event[ - "area_per_channel" - ][0:MAX_NUMBER_OF_PEAKS_PER_EVENT] - result[i]["peak_waveform_i"][0:n_peaks_in_event] = peaks_in_event["data"][ - 0:MAX_NUMBER_OF_PEAKS_PER_EVENT - ] - result[i]["peak_waveform_i_top"][0:n_peaks_in_event] = peaks_in_event["data_top"][ - 0:MAX_NUMBER_OF_PEAKS_PER_EVENT - ] - result[i]["peak_type_i"][0:n_peaks_in_event] = peaks_in_event["type"][ - 0:MAX_NUMBER_OF_PEAKS_PER_EVENT - ] - result[i]["peak_area_i"][0:n_peaks_in_event] = peaks_in_event["area"][ - 0:MAX_NUMBER_OF_PEAKS_PER_EVENT - ] - result[i]["peak_x_position_i"][0:n_peaks_in_event] = peaks_in_event["x"][ - 0:MAX_NUMBER_OF_PEAKS_PER_EVENT - ] - result[i]["peak_y_position_i"][0:n_peaks_in_event] = peaks_in_event["y"][ - 0:MAX_NUMBER_OF_PEAKS_PER_EVENT - ] - result[i]["peak_aft_i"][0:n_peaks_in_event] = peaks_in_event["area_fraction_top"][ - 0:MAX_NUMBER_OF_PEAKS_PER_EVENT - ] + result[i]["s2_delta_time_i"][0:n_s2_peaks_in_event] = ( + s2_peaks["time"][0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT]- peaks_in_event["time"][0] + ) + + result[i]["s1_peak_dt_i"][0:n_s1_peaks_in_event] = s1_peaks["dt"][0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT] + result[i]["s2_peak_dt_i"][0:n_s2_peaks_in_event] = s2_peaks["dt"][0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT] + + result[i]["s2_x_position_i"][0:n_s2_peaks_in_event] = s2_peaks["x"][0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT] + result[i]["s2_y_position_i"][0:n_s2_peaks_in_event] = s2_peaks["y"][0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT] + result[i]["s2_aft_i"][0:n_s2_peaks_in_event] = s2_peaks["area_fraction_top"][0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT] + + result[i]["s1_aft_i"][0:n_s1_peaks_in_event] = s1_peaks["area_fraction_top"][0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT] + + result[i]["s1_waveform_i"][0:n_s1_peaks_in_event] = s1_peaks["data"][0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT] + result[i]["s2_waveform_i"][0:n_s2_peaks_in_event] = s2_peaks["data"][0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT] + + result[i]["s1_waveform_start_i"][0:n_s1_peaks_in_event] = s1_peaks["data_start"][:, :PEAK_WAVEFORM_START_LENGTH][0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT] + + # If waveform_start was not explicitly saved, we can take it from the regular waveform + mask = result["s1_peak_dt_i"] == 10 + result["s1_waveform_start_i"][mask] = result["s1_waveform_i"][mask] result["time"] = events["time"] result["endtime"] = events["endtime"] From 136e8a023c348df52687715c64628c470c7f1ca6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 17 Sep 2024 09:00:32 +0000 Subject: [PATCH 4/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- straxen/plugins/events/peaks_of_event.py | 47 +++++++++++++++++------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/straxen/plugins/events/peaks_of_event.py b/straxen/plugins/events/peaks_of_event.py index 9f52e1a44..c82b9c7b8 100644 --- a/straxen/plugins/events/peaks_of_event.py +++ b/straxen/plugins/events/peaks_of_event.py @@ -6,6 +6,7 @@ MAX_NUMBER_OF_S2_PEAKS_PER_EVENT = 5 PEAK_WAVEFORM_LENGTH = 200 + class MultiPeakData(strax.Plugin): """Plugin that extracts information of multiple peaks in an event.""" @@ -91,22 +92,40 @@ def compute(self, peaks, events): s1_peaks["time"][0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT] - peaks_in_event["time"][0] ) result[i]["s2_delta_time_i"][0:n_s2_peaks_in_event] = ( - s2_peaks["time"][0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT]- peaks_in_event["time"][0] + s2_peaks["time"][0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT] - peaks_in_event["time"][0] ) - result[i]["s1_peak_dt_i"][0:n_s1_peaks_in_event] = s1_peaks["dt"][0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT] - result[i]["s2_peak_dt_i"][0:n_s2_peaks_in_event] = s2_peaks["dt"][0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT] - - result[i]["s2_x_position_i"][0:n_s2_peaks_in_event] = s2_peaks["x"][0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT] - result[i]["s2_y_position_i"][0:n_s2_peaks_in_event] = s2_peaks["y"][0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT] - result[i]["s2_aft_i"][0:n_s2_peaks_in_event] = s2_peaks["area_fraction_top"][0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT] - - result[i]["s1_aft_i"][0:n_s1_peaks_in_event] = s1_peaks["area_fraction_top"][0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT] - - result[i]["s1_waveform_i"][0:n_s1_peaks_in_event] = s1_peaks["data"][0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT] - result[i]["s2_waveform_i"][0:n_s2_peaks_in_event] = s2_peaks["data"][0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT] - - result[i]["s1_waveform_start_i"][0:n_s1_peaks_in_event] = s1_peaks["data_start"][:, :PEAK_WAVEFORM_START_LENGTH][0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT] + result[i]["s1_peak_dt_i"][0:n_s1_peaks_in_event] = s1_peaks["dt"][ + 0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT + ] + result[i]["s2_peak_dt_i"][0:n_s2_peaks_in_event] = s2_peaks["dt"][ + 0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT + ] + + result[i]["s2_x_position_i"][0:n_s2_peaks_in_event] = s2_peaks["x"][ + 0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT + ] + result[i]["s2_y_position_i"][0:n_s2_peaks_in_event] = s2_peaks["y"][ + 0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT + ] + result[i]["s2_aft_i"][0:n_s2_peaks_in_event] = s2_peaks["area_fraction_top"][ + 0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT + ] + + result[i]["s1_aft_i"][0:n_s1_peaks_in_event] = s1_peaks["area_fraction_top"][ + 0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT + ] + + result[i]["s1_waveform_i"][0:n_s1_peaks_in_event] = s1_peaks["data"][ + 0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT + ] + result[i]["s2_waveform_i"][0:n_s2_peaks_in_event] = s2_peaks["data"][ + 0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT + ] + + result[i]["s1_waveform_start_i"][0:n_s1_peaks_in_event] = s1_peaks["data_start"][ + :, :PEAK_WAVEFORM_START_LENGTH + ][0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT] # If waveform_start was not explicitly saved, we can take it from the regular waveform mask = result["s1_peak_dt_i"] == 10 From 3f24414e18f01c400781fd73fbad1dc8c0ae3d3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henning=20Schulze=20Ei=C3=9Fing?= Date: Tue, 17 Sep 2024 11:44:23 +0200 Subject: [PATCH 5/8] Bugfixing --- straxen/plugins/events/peaks_of_event.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/straxen/plugins/events/peaks_of_event.py b/straxen/plugins/events/peaks_of_event.py index c82b9c7b8..a0da71926 100644 --- a/straxen/plugins/events/peaks_of_event.py +++ b/straxen/plugins/events/peaks_of_event.py @@ -123,9 +123,7 @@ def compute(self, peaks, events): 0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT ] - result[i]["s1_waveform_start_i"][0:n_s1_peaks_in_event] = s1_peaks["data_start"][ - :, :PEAK_WAVEFORM_START_LENGTH - ][0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT] + result[i]["s1_waveform_start_i"][0:n_s1_peaks_in_event] = s1_peaks["data_start"][0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT] # If waveform_start was not explicitly saved, we can take it from the regular waveform mask = result["s1_peak_dt_i"] == 10 From 29fbeb8be653d4988f46d86128c72cb790f80ebc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 17 Sep 2024 09:45:06 +0000 Subject: [PATCH 6/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- straxen/plugins/events/peaks_of_event.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/straxen/plugins/events/peaks_of_event.py b/straxen/plugins/events/peaks_of_event.py index a0da71926..406ff92f7 100644 --- a/straxen/plugins/events/peaks_of_event.py +++ b/straxen/plugins/events/peaks_of_event.py @@ -123,7 +123,9 @@ def compute(self, peaks, events): 0:MAX_NUMBER_OF_S2_PEAKS_PER_EVENT ] - result[i]["s1_waveform_start_i"][0:n_s1_peaks_in_event] = s1_peaks["data_start"][0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT] + result[i]["s1_waveform_start_i"][0:n_s1_peaks_in_event] = s1_peaks["data_start"][ + 0:MAX_NUMBER_OF_S1_PEAKS_PER_EVENT + ] # If waveform_start was not explicitly saved, we can take it from the regular waveform mask = result["s1_peak_dt_i"] == 10 From 697c68910f131a3c9e24520829667f2b6d88397b Mon Sep 17 00:00:00 2001 From: yuema137 <3124558229@qq.com> Date: Thu, 17 Oct 2024 15:18:11 -0500 Subject: [PATCH 7/8] fix flake8 errors --- straxen/plugins/events/peaks_of_event.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/straxen/plugins/events/peaks_of_event.py b/straxen/plugins/events/peaks_of_event.py index 406ff92f7..e39466c9b 100644 --- a/straxen/plugins/events/peaks_of_event.py +++ b/straxen/plugins/events/peaks_of_event.py @@ -1,5 +1,4 @@ import strax -import straxen import numpy as np MAX_NUMBER_OF_S1_PEAKS_PER_EVENT = 5 @@ -62,7 +61,8 @@ class MultiPeakData(strax.Plugin): def compute(self, peaks, events): - # Just interested in S1 or S2 peaks. Here would be the place to apply further peak quality cuts. + # Just interested in S1 or S2 peaks. + # Here would be the place to apply further peak quality cuts. peaks = peaks[peaks["type"] != 0] peaks_per_event = strax.split_by_containment(peaks, events) From 7e49388474736fbcfab75190fae91d29aad4f11e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 17 Oct 2024 20:18:58 +0000 Subject: [PATCH 8/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- straxen/plugins/events/peaks_of_event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/straxen/plugins/events/peaks_of_event.py b/straxen/plugins/events/peaks_of_event.py index e39466c9b..b265f3320 100644 --- a/straxen/plugins/events/peaks_of_event.py +++ b/straxen/plugins/events/peaks_of_event.py @@ -61,7 +61,7 @@ class MultiPeakData(strax.Plugin): def compute(self, peaks, events): - # Just interested in S1 or S2 peaks. + # Just interested in S1 or S2 peaks. # Here would be the place to apply further peak quality cuts. peaks = peaks[peaks["type"] != 0]