From f4d40fe665857e1c32d4bce7110278a91eeb3faf Mon Sep 17 00:00:00 2001 From: Daniel Wenz Date: Tue, 13 Jul 2021 10:46:25 -0500 Subject: [PATCH 01/17] Modified peaklet building to remove baseline bias --- straxen/plugins/peaklet_processing.py | 39 ++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/straxen/plugins/peaklet_processing.py b/straxen/plugins/peaklet_processing.py index e26b86fb6..6038a171d 100644 --- a/straxen/plugins/peaklet_processing.py +++ b/straxen/plugins/peaklet_processing.py @@ -92,7 +92,7 @@ class Peaklets(strax.Plugin): parallel = 'process' compressor = 'zstd' - __version__ = '0.3.10' + __version__ = '0.4.0' def infer_dtype(self): return dict(peaklets=strax.peak_dtype( @@ -153,7 +153,8 @@ def compute(self, records, start, end): # Get hits outside peaklets, and store them separately. # fully_contained is OK provided gap_threshold > extension, # which is asserted inside strax.find_peaks. - lone_hits = hits[strax.fully_contained_in(hits, peaklets) == -1] + is_lone_hit = strax.fully_contained_in(hits, peaklets) == -1 + lone_hits = hits[is_lone_hit] strax.integrate_lone_hits( lone_hits, records, peaklets, save_outside_hits=(self.config['peak_left_extension'], @@ -161,14 +162,29 @@ def compute(self, records, start, end): n_channels=len(self.to_pe)) # Compute basic peak properties -- needed before natural breaks - strax.sum_waveform(peaklets, r, self.to_pe) + hits = hits[~is_lone_hit] + # Define regions outside of peaks such that _find_hit_integration_bounds + # is not extended beyond a peak. + outside_peaks = self.create_outside_peaks_region(peaklets, start, end) + strax.processing.peak_building._find_hit_integration_bounds(hits, + outside_peaks, + records, + (self.config['peak_left_extension'], + self.config['peak_right_extension']), + len(self.to_pe)) + + + hits = np.sort(hits, order='record_i') + + strax.sum_waveform(peaklets, hits, r, self.to_pe) + strax.compute_widths(peaklets) # Split peaks using low-split natural breaks; # see https://github.com/XENONnT/straxen/pull/45 # and https://github.com/AxFoundation/strax/pull/225 peaklets = strax.split_peaks( - peaklets, r, self.to_pe, + peaklets, hits, r, self.to_pe, algorithm='natural_breaks', threshold=self.natural_breaks_threshold, split_low=True, @@ -187,7 +203,7 @@ def compute(self, records, start, end): if self.config['saturation_correction_on']: peak_list = peak_saturation_correction( - r, peaklets, self.to_pe, + r, peaklets, hits, self.to_pe, reference_length=self.config['saturation_reference_length'], min_reference_length=self.config['saturation_min_reference_length']) @@ -253,7 +269,18 @@ def clip_peaklet_times(peaklets, start, end): p['time'] = start if strax.endtime(p) > end: p['length'] = (end - p['time']) // p['dt'] - + + @staticmethod + def create_outside_peaks_region(peaklets, start, end): + outside_peaks = np.zeros(len(peaklets) + 1, + dtype=strax.time_fields) + outside_peaks[0]['time'] = start + outside_peaks[0]['endtime'] = peaklets[0]['time'] + outside_peaks[1:-1]['time'] = strax.endtime(peaklets[:-1]) + outside_peaks[1:-1]['endtime'] = peaklets['time'][1:] + outside_peaks[-1]['time'] = strax.endtime(peaklets[-1]) + outside_peaks[-1]['endtime'] = end + return outside_peaks @numba.jit(nopython=True, nogil=True, cache=True) def peak_saturation_correction(records, peaks, to_pe, From 766d0b605d54eb3de954c1f5f846472129deca17 Mon Sep 17 00:00:00 2001 From: Daniel Wenz Date: Tue, 13 Jul 2021 11:10:23 -0500 Subject: [PATCH 02/17] Forgot to updated desaturation --- straxen/plugins/peaklet_processing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/straxen/plugins/peaklet_processing.py b/straxen/plugins/peaklet_processing.py index 6038a171d..5f4bba308 100644 --- a/straxen/plugins/peaklet_processing.py +++ b/straxen/plugins/peaklet_processing.py @@ -283,7 +283,7 @@ def create_outside_peaks_region(peaklets, start, end): return outside_peaks @numba.jit(nopython=True, nogil=True, cache=True) -def peak_saturation_correction(records, peaks, to_pe, +def peak_saturation_correction(records, peaks, hits, to_pe, reference_length=100, min_reference_length=20, use_classification=False, @@ -362,7 +362,7 @@ def peak_saturation_correction(records, peaks, to_pe, peaks[peak_i]['length'] = p['length'] * p['dt'] / dt peaks[peak_i]['dt'] = dt - strax.sum_waveform(peaks, records, to_pe, peak_list) + strax.sum_waveform(peaks, hits, records, to_pe, peak_list) return peak_list From f1ed3503298f4989543b23a3c785f120a27418b2 Mon Sep 17 00:00:00 2001 From: Daniel Wenz Date: Mon, 19 Jul 2021 06:47:53 -0500 Subject: [PATCH 03/17] test --- straxen/plugins/peaklet_processing.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/straxen/plugins/peaklet_processing.py b/straxen/plugins/peaklet_processing.py index 6b4dfdfa9..98cc179e9 100644 --- a/straxen/plugins/peaklet_processing.py +++ b/straxen/plugins/peaklet_processing.py @@ -92,7 +92,7 @@ class Peaklets(strax.Plugin): parallel = 'process' compressor = 'zstd' - __version__ = '0.4.0' + __version__ = '0.4.4' def infer_dtype(self): return dict(peaklets=strax.peak_dtype( @@ -174,8 +174,6 @@ def compute(self, records, start, end): len(self.to_pe)) - hits = np.sort(hits, order='record_i') - strax.sum_waveform(peaklets, hits, r, self.to_pe) strax.compute_widths(peaklets) From 4f07070eebdf773201526542b325b2dd92befefb Mon Sep 17 00:00:00 2001 From: Daniel Wenz Date: Mon, 19 Jul 2021 09:45:31 -0500 Subject: [PATCH 04/17] Fix record_i in overlapping peaks --- straxen/plugins/peaklet_processing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/straxen/plugins/peaklet_processing.py b/straxen/plugins/peaklet_processing.py index 98cc179e9..71b7a8048 100644 --- a/straxen/plugins/peaklet_processing.py +++ b/straxen/plugins/peaklet_processing.py @@ -92,7 +92,7 @@ class Peaklets(strax.Plugin): parallel = 'process' compressor = 'zstd' - __version__ = '0.4.4' + __version__ = '0.4.0' def infer_dtype(self): return dict(peaklets=strax.peak_dtype( @@ -173,7 +173,7 @@ def compute(self, records, start, end): self.config['peak_right_extension']), len(self.to_pe)) - + hits = np.sort(hits, order=('record_i', 'time')) strax.sum_waveform(peaklets, hits, r, self.to_pe) strax.compute_widths(peaklets) From 8c57443ce9eabdd469a07ffe8e6a23d7c5616be8 Mon Sep 17 00:00:00 2001 From: Daniel Wenz Date: Fri, 23 Jul 2021 10:29:14 +0200 Subject: [PATCH 05/17] Updated peaklets building according to change in strax --- straxen/plugins/peaklet_processing.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/straxen/plugins/peaklet_processing.py b/straxen/plugins/peaklet_processing.py index 71b7a8048..f8aa3b9c4 100644 --- a/straxen/plugins/peaklet_processing.py +++ b/straxen/plugins/peaklet_processing.py @@ -166,15 +166,22 @@ def compute(self, records, start, end): # Define regions outside of peaks such that _find_hit_integration_bounds # is not extended beyond a peak. outside_peaks = self.create_outside_peaks_region(peaklets, start, end) - strax.processing.peak_building._find_hit_integration_bounds(hits, - outside_peaks, - records, - (self.config['peak_left_extension'], - self.config['peak_right_extension']), - len(self.to_pe)) + strax.find_hit_integration_bounds(hits, + outside_peaks, + records, + (self.config['peak_left_extension'], + self.config['peak_right_extension']), + len(self.to_pe), + allow_bounds_beyond_records=True, + ) + + # Updated time and length of hits and sort again: + hits['time'] = hits['time'] - (hits['left_integration'] - hits['left']) * hits['dt'] + hits['length'] = (hits['right_integration'] - hits['left_integration']) + hits = strax.sort_by_time(hits) + rlinks = strax.record_links(records) - hits = np.sort(hits, order=('record_i', 'time')) - strax.sum_waveform(peaklets, hits, r, self.to_pe) + strax.sum_waveform(peaklets, hits, r, rlinks, self.to_pe) strax.compute_widths(peaklets) @@ -182,7 +189,7 @@ def compute(self, records, start, end): # see https://github.com/XENONnT/straxen/pull/45 # and https://github.com/AxFoundation/strax/pull/225 peaklets = strax.split_peaks( - peaklets, hits, r, self.to_pe, + peaklets, hits, r, rlinks, self.to_pe, algorithm='natural_breaks', threshold=self.natural_breaks_threshold, split_low=True, From 0c30951f6aba6728f4ba164e51063dd9755db3c9 Mon Sep 17 00:00:00 2001 From: Daniel Wenz Date: Fri, 23 Jul 2021 04:43:56 -0500 Subject: [PATCH 06/17] Minor fixes --- straxen/plugins/peaklet_processing.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/straxen/plugins/peaklet_processing.py b/straxen/plugins/peaklet_processing.py index f8aa3b9c4..17536888f 100644 --- a/straxen/plugins/peaklet_processing.py +++ b/straxen/plugins/peaklet_processing.py @@ -176,7 +176,7 @@ def compute(self, records, start, end): ) # Updated time and length of hits and sort again: - hits['time'] = hits['time'] - (hits['left_integration'] - hits['left']) * hits['dt'] + hits['time'] = hits['time'] - (hits['left'] - hits['left_integration']) * hits['dt'] hits['length'] = (hits['right_integration'] - hits['left_integration']) hits = strax.sort_by_time(hits) rlinks = strax.record_links(records) @@ -208,7 +208,7 @@ def compute(self, records, start, end): if self.config['saturation_correction_on']: peak_list = peak_saturation_correction( - r, peaklets, hits, self.to_pe, + r, rlinks, peaklets, hits, self.to_pe, reference_length=self.config['saturation_reference_length'], min_reference_length=self.config['saturation_min_reference_length']) @@ -287,13 +287,14 @@ def create_outside_peaks_region(peaklets, start, end): return outside_peaks @numba.jit(nopython=True, nogil=True, cache=True) -def peak_saturation_correction(records, peaks, hits, to_pe, +def peak_saturation_correction(records, rlinks, peaks, hits, to_pe, reference_length=100, min_reference_length=20, use_classification=False, ): """Correct the area and per pmt area of peaks from saturation :param records: Records + :param rlinks: strax.record_links of corresponding records. :param peaks: Peaklets / Peaks :param to_pe: adc to PE conversion (length should equal number of PMTs) :param reference_length: Maximum number of reference sample used @@ -366,7 +367,7 @@ def peak_saturation_correction(records, peaks, hits, to_pe, peaks[peak_i]['length'] = p['length'] * p['dt'] / dt peaks[peak_i]['dt'] = dt - strax.sum_waveform(peaks, hits, records, to_pe, peak_list) + strax.sum_waveform(peaks, hits, records, rlinks, to_pe, peak_list) return peak_list From 053cad38430a868e4350d1d423eac6b34fcf938b Mon Sep 17 00:00:00 2001 From: Daniel Wenz Date: Mon, 26 Jul 2021 18:27:57 +0200 Subject: [PATCH 07/17] Addressed some review dog comments. --- straxen/plugins/peaklet_processing.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/straxen/plugins/peaklet_processing.py b/straxen/plugins/peaklet_processing.py index 17536888f..a5cecb1d8 100644 --- a/straxen/plugins/peaklet_processing.py +++ b/straxen/plugins/peaklet_processing.py @@ -273,19 +273,28 @@ def clip_peaklet_times(peaklets, start, end): p['time'] = start if strax.endtime(p) > end: p['length'] = (end - p['time']) // p['dt'] - + @staticmethod def create_outside_peaks_region(peaklets, start, end): - outside_peaks = np.zeros(len(peaklets) + 1, + """ + Creates time intervals which are outside peaks. + + :param peaklets: Peaklets for which intervals should be computed. + :param start: Chunk start + :param end: Chunk end + :return: array of strax.time_fields dtype. + """ + outside_peaks = np.zeros(len(peaklets) + 1, dtype=strax.time_fields) outside_peaks[0]['time'] = start outside_peaks[0]['endtime'] = peaklets[0]['time'] outside_peaks[1:-1]['time'] = strax.endtime(peaklets[:-1]) outside_peaks[1:-1]['endtime'] = peaklets['time'][1:] outside_peaks[-1]['time'] = strax.endtime(peaklets[-1]) - outside_peaks[-1]['endtime'] = end + outside_peaks[-1]['endtime'] = end return outside_peaks + @numba.jit(nopython=True, nogil=True, cache=True) def peak_saturation_correction(records, rlinks, peaks, hits, to_pe, reference_length=100, From 58ab841c9fa16a9c4a86ad3a566bd2f8b6ddf50c Mon Sep 17 00:00:00 2001 From: Daniel Wenz Date: Mon, 26 Jul 2021 18:51:22 +0200 Subject: [PATCH 08/17] Added test for new function --- tests/test_peaklet_processing.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/test_peaklet_processing.py diff --git a/tests/test_peaklet_processing.py b/tests/test_peaklet_processing.py new file mode 100644 index 000000000..3dbbf346f --- /dev/null +++ b/tests/test_peaklet_processing.py @@ -0,0 +1,25 @@ +import numpy as np +from hypothesis import given, settings +import hypothesis.strategies as st + +import strax +import straxen + + +@settings(deadline=None) +@given(st.integers(min_value=0, max_value=100, size=20),) +def test_create_outside_peaks_region(time): + time = np.sort(time) + time_intervals = np.zeros(len(time), strax.time_dt_fields) + time_intervals['time'] = time[::2] + time_intervals['length'] = time[1::2] - time[::2] + time_intervals['dt'] = 1 + + st = straxen.contexts.demo() + p = st.get_single_plugin('0', 'peaklets') + outside = p.create_outside_peaks_region(time_intervals) + + touching = strax.touching_windows(outside, time_intervals, window=0) + + for tw in touching: + assert np.diff(tw) == 0, 'Intervals overlap although they should not!' From 33aa3af5419f822a1c1072a5cf9cbf5acc208583 Mon Sep 17 00:00:00 2001 From: Daniel Wenz Date: Mon, 26 Jul 2021 12:18:07 -0500 Subject: [PATCH 09/17] Fixed test --- tests/test_peaklet_processing.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_peaklet_processing.py b/tests/test_peaklet_processing.py index 3dbbf346f..3e8a19641 100644 --- a/tests/test_peaklet_processing.py +++ b/tests/test_peaklet_processing.py @@ -7,19 +7,20 @@ @settings(deadline=None) -@given(st.integers(min_value=0, max_value=100, size=20),) +@given(st.lists(st.integers(min_value=0, max_value=10), min_size=8, max_size=8, unique=True),) def test_create_outside_peaks_region(time): time = np.sort(time) - time_intervals = np.zeros(len(time), strax.time_dt_fields) + time_intervals = np.zeros(len(time)//2, strax.time_dt_fields) time_intervals['time'] = time[::2] time_intervals['length'] = time[1::2] - time[::2] time_intervals['dt'] = 1 st = straxen.contexts.demo() p = st.get_single_plugin('0', 'peaklets') - outside = p.create_outside_peaks_region(time_intervals) + outside = p.create_outside_peaks_region(time_intervals, 0, np.max(time)) touching = strax.touching_windows(outside, time_intervals, window=0) for tw in touching: + print(tw) assert np.diff(tw) == 0, 'Intervals overlap although they should not!' From 20c268156e1c45538230ca0eec145ccbd9290b72 Mon Sep 17 00:00:00 2001 From: Daniel Wenz Date: Wed, 11 Aug 2021 09:57:15 -0500 Subject: [PATCH 10/17] Add empty peaklets support --- straxen/plugins/peaklet_processing.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/straxen/plugins/peaklet_processing.py b/straxen/plugins/peaklet_processing.py index a5cecb1d8..c4ba665f3 100644 --- a/straxen/plugins/peaklet_processing.py +++ b/straxen/plugins/peaklet_processing.py @@ -284,8 +284,12 @@ def create_outside_peaks_region(peaklets, start, end): :param end: Chunk end :return: array of strax.time_fields dtype. """ + if not len(peaklets): + return np.zeros(0, dtype=strax.time_fields) + outside_peaks = np.zeros(len(peaklets) + 1, dtype=strax.time_fields) + outside_peaks[0]['time'] = start outside_peaks[0]['endtime'] = peaklets[0]['time'] outside_peaks[1:-1]['time'] = strax.endtime(peaklets[:-1]) From 42d982de936847eb06da1e32c249de24efdf14ca Mon Sep 17 00:00:00 2001 From: Daniel Wenz Date: Wed, 11 Aug 2021 09:58:39 -0500 Subject: [PATCH 11/17] Update splitting inputs in veto plugins --- straxen/plugins/veto_hitlets.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/straxen/plugins/veto_hitlets.py b/straxen/plugins/veto_hitlets.py index d83dc1ff8..ff09ba3e9 100644 --- a/straxen/plugins/veto_hitlets.py +++ b/straxen/plugins/veto_hitlets.py @@ -126,7 +126,9 @@ def compute(self, records_nv, start, end): min_hitlet_sample=600) temp_hitlets = strax.split_peaks(temp_hitlets, + None, # Only needed for peak splitting records_nv, + None, # Only needed for peak splitting self.to_pe, data_type='hitlets', algorithm='local_minimum', From 0bbad6c5f1f079ad8005d9c25897c7ba8dceeb78 Mon Sep 17 00:00:00 2001 From: Daniel Wenz Date: Thu, 19 Aug 2021 18:56:04 +0200 Subject: [PATCH 12/17] Add time shift to get correct maximum --- straxen/plugins/peaklet_processing.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/straxen/plugins/peaklet_processing.py b/straxen/plugins/peaklet_processing.py index c4ba665f3..1b48009a0 100644 --- a/straxen/plugins/peaklet_processing.py +++ b/straxen/plugins/peaklet_processing.py @@ -176,7 +176,8 @@ def compute(self, records, start, end): ) # Updated time and length of hits and sort again: - hits['time'] = hits['time'] - (hits['left'] - hits['left_integration']) * hits['dt'] + hits_time_shift = (hits['left'] - hits['left_integration']) * hits['dt'] + hits['time'] = hits['time'] - hits_time_shift hits['length'] = (hits['right_integration'] - hits['left_integration']) hits = strax.sort_by_time(hits) rlinks = strax.record_links(records) @@ -222,7 +223,9 @@ def compute(self, records, start, end): # possibly due to its currently primitive scheduling. hit_max_times = np.sort( hits['time'] - + hits['dt'] * hit_max_sample(records, hits)) + + hits['dt'] * hit_max_sample(records, hits) + + hits_time_shift # add time shift again to get correct maximum + ) peaklet_max_times = ( peaklets['time'] + np.argmax(peaklets['data'], axis=1) * peaklets['dt']) From 0a97e4fd78633e4d5da9ca1c7465fb10fa2a813b Mon Sep 17 00:00:00 2001 From: Joran Angevaare Date: Fri, 20 Aug 2021 07:55:21 +0200 Subject: [PATCH 13/17] Update peaklet_processing.py --- straxen/plugins/peaklet_processing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/straxen/plugins/peaklet_processing.py b/straxen/plugins/peaklet_processing.py index 1b48009a0..0358278a7 100644 --- a/straxen/plugins/peaklet_processing.py +++ b/straxen/plugins/peaklet_processing.py @@ -92,7 +92,7 @@ class Peaklets(strax.Plugin): parallel = 'process' compressor = 'zstd' - __version__ = '0.4.0' + __version__ = '0.4.1' def infer_dtype(self): return dict(peaklets=strax.peak_dtype( From 0ebadcf554098aba094534d876fd6a73c08765ed Mon Sep 17 00:00:00 2001 From: Daniel Wenz Date: Fri, 20 Aug 2021 10:40:37 +0200 Subject: [PATCH 14/17] Rename startegy alias --- tests/test_peaklet_processing.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_peaklet_processing.py b/tests/test_peaklet_processing.py index 3e8a19641..06fdd45e1 100644 --- a/tests/test_peaklet_processing.py +++ b/tests/test_peaklet_processing.py @@ -1,13 +1,15 @@ import numpy as np from hypothesis import given, settings -import hypothesis.strategies as st +import hypothesis.strategies as strat import strax import straxen @settings(deadline=None) -@given(st.lists(st.integers(min_value=0, max_value=10), min_size=8, max_size=8, unique=True),) +@given(strat.lists(strat.integers(min_value=0, max_value=10), + min_size=8, max_size=8, unique=True), + ) def test_create_outside_peaks_region(time): time = np.sort(time) time_intervals = np.zeros(len(time)//2, strax.time_dt_fields) From 6dddbb54d1d7cdc2e825dc8e846889fe22563e65 Mon Sep 17 00:00:00 2001 From: Daniel Wenz <43881800+WenzDaniel@users.noreply.github.com> Date: Fri, 20 Aug 2021 10:51:00 +0200 Subject: [PATCH 15/17] Update straxen/plugins/peaklet_processing.py Co-authored-by: Joran Angevaare --- straxen/plugins/peaklet_processing.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/straxen/plugins/peaklet_processing.py b/straxen/plugins/peaklet_processing.py index 0358278a7..26cf5c7f7 100644 --- a/straxen/plugins/peaklet_processing.py +++ b/straxen/plugins/peaklet_processing.py @@ -166,14 +166,13 @@ def compute(self, records, start, end): # Define regions outside of peaks such that _find_hit_integration_bounds # is not extended beyond a peak. outside_peaks = self.create_outside_peaks_region(peaklets, start, end) - strax.find_hit_integration_bounds(hits, - outside_peaks, - records, - (self.config['peak_left_extension'], - self.config['peak_right_extension']), - len(self.to_pe), - allow_bounds_beyond_records=True, - ) + strax.find_hit_integration_bounds( + hits, outside_peaks, records, + save_outside_hits=(self.config['peak_left_extension'], + self.config['peak_right_extension']), + n_channels=len(self.to_pe), + allow_bounds_beyond_records=True, + ) # Updated time and length of hits and sort again: hits_time_shift = (hits['left'] - hits['left_integration']) * hits['dt'] From bc7df5e15275fc0e2a908951de578d2260055b6e Mon Sep 17 00:00:00 2001 From: Daniel Wenz Date: Fri, 20 Aug 2021 11:19:48 +0200 Subject: [PATCH 16/17] Change naming conventions --- straxen/plugins/peaklet_processing.py | 38 ++++++++++++++++----------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/straxen/plugins/peaklet_processing.py b/straxen/plugins/peaklet_processing.py index 0358278a7..1a70b319f 100644 --- a/straxen/plugins/peaklet_processing.py +++ b/straxen/plugins/peaklet_processing.py @@ -175,14 +175,20 @@ def compute(self, records, start, end): allow_bounds_beyond_records=True, ) - # Updated time and length of hits and sort again: - hits_time_shift = (hits['left'] - hits['left_integration']) * hits['dt'] - hits['time'] = hits['time'] - hits_time_shift - hits['length'] = (hits['right_integration'] - hits['left_integration']) - hits = strax.sort_by_time(hits) + # Transform hits to hitlets for naming conventions. A hit refers + # to the central part above threshold a hitlet to the entire signal + # including the left and right extension. + # (We are not going to use the actual hitlet data_type here.) + hitlets = hits + del hits + + hitlet_time_shift = (hitlets['left'] - hitlets['left_integration']) * hitlets['dt'] + hitlets['time'] = hitlets['time'] - hitlet_time_shift + hitlets['length'] = (hitlets['right_integration'] - hitlets['left_integration']) + hitlets = strax.sort_by_time(hitlets) rlinks = strax.record_links(records) - strax.sum_waveform(peaklets, hits, r, rlinks, self.to_pe) + strax.sum_waveform(peaklets, hitlets, r, rlinks, self.to_pe) strax.compute_widths(peaklets) @@ -190,7 +196,7 @@ def compute(self, records, start, end): # see https://github.com/XENONnT/straxen/pull/45 # and https://github.com/AxFoundation/strax/pull/225 peaklets = strax.split_peaks( - peaklets, hits, r, rlinks, self.to_pe, + peaklets, hitlets, r, rlinks, self.to_pe, algorithm='natural_breaks', threshold=self.natural_breaks_threshold, split_low=True, @@ -209,7 +215,7 @@ def compute(self, records, start, end): if self.config['saturation_correction_on']: peak_list = peak_saturation_correction( - r, rlinks, peaklets, hits, self.to_pe, + r, rlinks, peaklets, hitlets, self.to_pe, reference_length=self.config['saturation_reference_length'], min_reference_length=self.config['saturation_min_reference_length']) @@ -222,9 +228,9 @@ def compute(self, records, start, end): # (b) increase strax memory usage / max_messages, # possibly due to its currently primitive scheduling. hit_max_times = np.sort( - hits['time'] - + hits['dt'] * hit_max_sample(records, hits) - + hits_time_shift # add time shift again to get correct maximum + hitlets['time'] + + hitlets['dt'] * hit_max_sample(records, hitlets) + + hitlet_time_shift # add time shift again to get correct maximum ) peaklet_max_times = ( peaklets['time'] @@ -237,12 +243,12 @@ def compute(self, records, start, end): if self.config['diagnose_sorting'] and len(r): assert np.diff(r['time']).min(initial=1) >= 0, "Records not sorted" - assert np.diff(hits['time']).min(initial=1) >= 0, "Hits not sorted" + assert np.diff(hitlets['time']).min(initial=1) >= 0, "Hits/Hitlets not sorted" assert np.all(peaklets['time'][1:] >= strax.endtime(peaklets)[:-1]), "Peaks not disjoint" # Update nhits of peaklets: - counts = strax.touching_windows(hits, peaklets) + counts = strax.touching_windows(hitlets, peaklets) counts = np.diff(counts, axis=1).flatten() counts += 1 peaklets['n_hits'] = counts @@ -303,7 +309,7 @@ def create_outside_peaks_region(peaklets, start, end): @numba.jit(nopython=True, nogil=True, cache=True) -def peak_saturation_correction(records, rlinks, peaks, hits, to_pe, +def peak_saturation_correction(records, rlinks, peaks, hitlets, to_pe, reference_length=100, min_reference_length=20, use_classification=False, @@ -312,6 +318,8 @@ def peak_saturation_correction(records, rlinks, peaks, hits, to_pe, :param records: Records :param rlinks: strax.record_links of corresponding records. :param peaks: Peaklets / Peaks + :param hitlets: Hitlets found in records to build peaks. + (Hitlets are hits including the left/right extension) :param to_pe: adc to PE conversion (length should equal number of PMTs) :param reference_length: Maximum number of reference sample used to correct saturated samples @@ -383,7 +391,7 @@ def peak_saturation_correction(records, rlinks, peaks, hits, to_pe, peaks[peak_i]['length'] = p['length'] * p['dt'] / dt peaks[peak_i]['dt'] = dt - strax.sum_waveform(peaks, hits, records, rlinks, to_pe, peak_list) + strax.sum_waveform(peaks, hitlets, records, rlinks, to_pe, peak_list) return peak_list From 0c6e71b3a4b63205c8966e770abe271a065eb0b3 Mon Sep 17 00:00:00 2001 From: Joran Angevaare Date: Wed, 25 Aug 2021 08:44:37 +0200 Subject: [PATCH 17/17] fix test --- tests/test_several.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_several.py b/tests/test_several.py index 0f5bcac6f..c5cb29566 100644 --- a/tests/test_several.py +++ b/tests/test_several.py @@ -40,7 +40,7 @@ def test_secret(): # They were added on 27/11/2020 and may be outdated by now EXPECTED_OUTCOMES_TEST_SEVERAL = { 'n_peaks': 128, - 'n_s1': 6, + 'n_s1': 8, 'run_live_time': 0.17933107, 'n_events': 2, }