Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed delta peak timestamp problem #702

Merged
merged 4 commits into from Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion strax/processing/peak_merging.py
Expand Up @@ -161,5 +161,7 @@ def add_lone_hits(peaks, lone_hits, to_pe):
p['area_per_channel'][lh_i['channel']] += lh_area

# Add lone hit as delta pulse to waveform:
index = (p['time'] - lh_i['time'])//p['dt']
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
16 changes: 11 additions & 5 deletions tests/test_peak_merging.py
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WenzDaniel if we had realized this - the test would have worked. Now it always added zeros.

peak['dt'] = dt

to_pe = np.ones(10000)
strax.add_lone_hits(peak, hits, to_pe)
Expand All @@ -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)