-
Notifications
You must be signed in to change notification settings - Fork 1
/
peaks.py
93 lines (76 loc) · 3.39 KB
/
peaks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import numba
import numpy as np
import strax
export, __all__ = strax.exporter()
# These are also needed in peaklets, since hitfinding is repeated
HITFINDER_OPTIONS = tuple([
strax.Option(
'hit_min_amplitude',
default='pmt_commissioning_initial',
help='Minimum hit amplitude in ADC counts above baseline. '
'See straxen.hit_min_amplitude for options.'
)])
@export
@strax.takes_config(
strax.Option('peak_gap_threshold', default=300,
help="No hits for this many ns triggers a new peak"),
strax.Option('peak_left_extension', default=10,
help="Include this many ns left of hits in peaks"),
strax.Option('peak_right_extension', default=10,
help="Include this many ns right of hits in peaks"),
strax.Option('peak_min_area', default=10,
help="Minimum contributing PMTs needed to define a peak"),
strax.Option('peak_min_pmts', default=1,
help="Minimum contributing PMTs needed to define a peak"),
strax.Option('single_channel_peaks', default=False,
help='Whether single-channel peaks should be reported'),
strax.Option('peak_split_min_height', default=25,
help="Minimum height in PE above a local sum waveform"
"minimum, on either side, to trigger a split"),
strax.Option('peak_split_min_ratio', default=4,
help="Minimum ratio between local sum waveform"
"minimum and maxima on either side, to trigger a split"),
strax.Option('diagnose_sorting', track=False, default=False,
help="Enable runtime checks for sorting and disjointness"),
strax.Option('n_tpc_pmts', track=False, default=False,
help="Number of channels"),
strax.Option('gain_to_pe_array', default=None,
help="Gain to pe array"),
)
class Peaks(strax.Plugin):
depends_on = ('records',)
data_kind = 'peaks'
parallel = 'process'
provides = ('peaks')
rechunk_on_save = True
__version__ = '0.1.50'
def infer_dtype(self):
return strax.peak_dtype(n_channels=self.config['n_tpc_pmts'])
def compute(self, records, start, end):
r = records
if self.config['gain_to_pe_array'] is None:
self.to_pe = np.ones(self.config['n_tpc_pmts'])
else:
self.to_pe = self.config['gain_to_pe_array']
hits = strax.find_hits(r)
hits = strax.sort_by_time(hits)
rlinks = strax.record_links(r)
# Rewrite to just peaks/hits
peaks = strax.find_peaks(
hits, self.to_pe,
gap_threshold=self.config['peak_gap_threshold'],
left_extension=self.config['peak_left_extension'],
right_extension=self.config['peak_right_extension'],
min_area=self.config['peak_min_area'],
min_channels=self.config['peak_min_pmts'],
# min_channels=1,
result_dtype=strax.peak_dtype(n_channels=self.config['n_tpc_pmts'])
# result_dtype=self.dtype
)
strax.sum_waveform(peaks, hits, r, rlinks, self.to_pe)
peaks = strax.split_peaks(
peaks, hits, r, rlinks, self.to_pe,
min_height=self.config['peak_split_min_height'],
min_ratio=self.config['peak_split_min_ratio'])
strax.compute_widths(peaks)
return peaks