def compute(self, peaklets): if not len(peaklets): return peaklets[:0] if self.config['s2_merge_max_gap'] < 0: # Do not merge at all merged_s2s = np.zeros(0, dtype=peaklets.dtype) else: # Find all groups of peaklets separated by < the gap cluster_starts, cluster_stops = strax.find_peak_groups( peaklets, self.config['s2_merge_max_gap']) start_merge_at, end_merge_at = self.get_merge_instructions( peaklets['time'], strax.endtime(peaklets), areas=peaklets['area'], types=peaklets['type'], cluster_starts=cluster_starts, cluster_stops=cluster_stops, max_duration=self.config['s2_merge_max_duration'], max_area=self.config['s2_merge_max_area']) merged_s2s = strax.merge_peaks( peaklets, start_merge_at, end_merge_at, max_buffer=int(self.config['s2_merge_max_duration'] // peaklets['dt'].min())) merged_s2s['type'] = 2 strax.compute_widths(merged_s2s) return merged_s2s
def compute(self, peaklets, lone_hits): if self.config['merge_without_s1']: peaklets = peaklets[peaklets['type'] != 1] if len(peaklets) <= 1: return np.zeros(0, dtype=peaklets.dtype) gap_thresholds = self.config['s2_merge_gap_thresholds'] max_gap = gap_thresholds[0][1] max_area = 10**gap_thresholds[-1][0] if max_gap < 0: # Do not merge at all return np.zeros(0, dtype=peaklets.dtype) else: # Max gap and area should be set by the gap thresholds # to avoid contradictions start_merge_at, end_merge_at = self.get_merge_instructions( peaklets['time'], strax.endtime(peaklets), areas=peaklets['area'], types=peaklets['type'], gap_thresholds=gap_thresholds, max_duration=self.config['s2_merge_max_duration'], max_gap=max_gap, max_area=max_area, ) merged_s2s = strax.merge_peaks( peaklets, start_merge_at, end_merge_at, max_buffer=int(self.config['s2_merge_max_duration'] // np.gcd.reduce(peaklets['dt'])), ) merged_s2s['type'] = 2 # Updated time and length of lone_hits and sort again: lh = np.copy(lone_hits) del lone_hits lh_time_shift = (lh['left'] - lh['left_integration']) * lh['dt'] lh['time'] = lh['time'] - lh_time_shift lh['length'] = (lh['right_integration'] - lh['left_integration']) lh = strax.sort_by_time(lh) strax.add_lone_hits(merged_s2s, lh, self.to_pe) strax.compute_widths(merged_s2s) return merged_s2s
def compute(self, peaklets): if not len(peaklets): return peaklets[:0] if self.config['s2_merge_max_gap'] < 0: # Do not merge at all merged_s2s = np.zeros(0, dtype=peaklets.dtype) else: # Find all groups of peaklets separated by < the gap cluster_starts, cluster_stops = strax.find_peak_groups( peaklets, self.config['s2_merge_max_gap']) start_merge_at, end_merge_at = self.get_merge_instructions( peaklets['time'], strax.endtime(peaklets), areas=peaklets['area'], types=peaklets['type'], cluster_starts=cluster_starts, cluster_stops=cluster_stops, max_duration=self.config['s2_merge_max_duration'], max_area=self.config['s2_merge_max_area']) merged_s2s = strax.merge_peaks( peaklets, start_merge_at, end_merge_at, max_buffer=int(self.config['s2_merge_max_duration'] // peaklets['dt'].min())) merged_s2s['type'] = 2 strax.compute_widths(merged_s2s) if len(merged_s2s) == 0: # Strax does not handle the case of no merged S2s well # If there are none in the entire dataset, it will just keep # waiting in Peaks forever. # Thus, this ugly hack of passing a single fake merged S2 # in the middle of the chunk, which is removed later merged_s2s = np.zeros(1, merged_s2s.dtype) q = merged_s2s[0] q['type'] = FAKE_MERGED_S2_TYPE q['time'] = (peaklets[0]['time'] + strax.endtime(peaklets[0])) / 2 q['dt'] = 1 return merged_s2s