Skip to content

Commit

Permalink
Change naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
WenzDaniel committed Aug 20, 2021
1 parent 0ebadcf commit bc7df5e
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions straxen/plugins/peaklet_processing.py
Expand Up @@ -175,22 +175,28 @@ 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)

# 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, hits, r, rlinks, self.to_pe,
peaklets, hitlets, r, rlinks, self.to_pe,
algorithm='natural_breaks',
threshold=self.natural_breaks_threshold,
split_low=True,
Expand All @@ -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'])

Expand All @@ -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']
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit bc7df5e

Please sign in to comment.