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

Add option to merge lone_hits into data_start #908

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions strax/processing/peak_merging.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,26 @@ def _replace_merged(result, orig, merge, skip_windows):


@export
def add_lone_hits(peaks, lone_hits, to_pe, n_top_channels=0):
def add_lone_hits(peaks, lone_hits, to_pe, n_top_channels=0, waveform_start=False):
"""Function which adds information from lone hits to peaks if lone hit is inside a peak (e.g.
after merging.). Modifies peak area and data inplace.

:param peaks: Numpy array of peaks
:param lone_hits: Numpy array of lone_hits
:param to_pe: Gain values to convert lone hit area into PE.
:param n_top_channels: Number of top array channels.
:param waveform_start: Boolean indicating if a lone hit should be added to the data_start field
of peaks

"""
_fully_contained_in_sanity(lone_hits, peaks)
_add_lone_hits(peaks, lone_hits, to_pe, n_top_channels=n_top_channels)
_add_lone_hits(
peaks, lone_hits, to_pe, n_top_channels=n_top_channels, waveform_start=waveform_start
)


@numba.njit(cache=True, nogil=True)
def _add_lone_hits(peaks, lone_hits, to_pe, n_top_channels=0):
def _add_lone_hits(peaks, lone_hits, to_pe, n_top_channels=0, waveform_start=False):
"""The core function of add_lone_hits."""
fully_contained_index = _fully_contained_in(lone_hits, peaks)

Expand All @@ -218,3 +222,13 @@ def _add_lone_hits(peaks, lone_hits, to_pe, n_top_channels=0):
if n_top_channels > 0:
if lh_i["channel"] < n_top_channels:
p["data_top"][index] += lh_area

if waveform_start:
# Non-downsampled waveforms have a fixed dt of 10 ns
index_wf_start = (lh_i["time"] - p["time"]) // 10

if index_wf_start < 0:
raise ValueError("Hit outside of full containment!")

if index_wf_start < len(p["data_start"]):
p["data_start"][index_wf_start] += lh_area