diff --git a/strax/processing/peak_merging.py b/strax/processing/peak_merging.py index c91b9d163..c36548ddd 100644 --- a/strax/processing/peak_merging.py +++ b/strax/processing/peak_merging.py @@ -174,8 +174,10 @@ def add_lone_hits(peaks, lone_hits, to_pe, n_top_channels=0): p['area'] += lh_area p['area_per_channel'][lh_i['channel']] += lh_area - # Add lone hit as delta pulse to waveforms: - index = (p['time'] - lh_i['time'])//p['dt'] + # Add lone hit as delta pulse to waveform: + index = (lh_i['time'] - p['time'])//p['dt'] + if index < 0 or index > len(p['data']): + raise ValueError('Hit outside of full containment!') p['data'][index] += lh_area if n_top_channels > 0: diff --git a/tests/test_peak_merging.py b/tests/test_peak_merging.py index 2c2eed935..32e82eee7 100644 --- a/tests/test_peak_merging.py +++ b/tests/test_peak_merging.py @@ -51,12 +51,18 @@ def test_replace_merged(intervals, merge_instructions): @hypothesis.given(fake_hits, - hypothesis.strategies.integers(min_value=0, max_value=100)) + hypothesis.strategies.integers(min_value=0, max_value=int(1e18)), + hypothesis.strategies.integers(min_value=0, max_value=100), + hypothesis.strategies.integers(min_value=1, max_value=2), + ) @hypothesis.settings(deadline=None) -def test_add_lone_hits(hits, peak_length): +def test_add_lone_hits(hits, time_offset, peak_length, dt): peak = np.zeros(1, dtype=strax.peak_dtype()) + peak['time'] = time_offset + hits['time'] += time_offset peak['length'] = peak_length - peak['dt'] = 1 + hits['area'] = 1 + peak['dt'] = dt to_pe = np.ones(10000) strax.add_lone_hits(peak, hits, to_pe) @@ -70,7 +76,7 @@ def test_add_lone_hits(hits, peak_length): dummy_peak = np.zeros(peak_length) for h in split_hits: - dummy_peak[h['time']] += h['area'] + dummy_peak[(h['time']-time_offset)//dt] += h['area'] peak = peak[0] assert peak['area'] == np.sum(split_hits['area']) - assert np.all(peak['data'][:peak['length']] == dummy_peak) + assert np.all(peak['data'][:peak_length] == dummy_peak)