Skip to content

Commit

Permalink
First and last channel inside peak(let)s (#1525)
Browse files Browse the repository at this point in the history
* First and last channel inside peak(let)s

* Debug

* Update Peaklets version
  • Loading branch information
dachengx authored Jan 17, 2025
1 parent 4c215d3 commit 6e0a79d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
27 changes: 26 additions & 1 deletion straxen/plugins/events/event_basics_vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ def infer_dtype(self):
np.int32,
f"Alternate S1 smallest time difference between apexes of hits [ns]",
),
(
f"s1_first_channel",
np.int16,
f"Main S1 first channel/PMT number (sorted by apexes of hits)",
),
(
f"alt_s1_first_channel",
np.int16,
f"Alternate S1 first channel/PMT number (sorted by apexes of hits)",
),
(
f"s1_last_channel",
np.int16,
f"Main S1 last channel/PMT number (sorted by apexes of hits)",
),
(
f"alt_s1_last_channel",
np.int16,
f"Alternate last channel/PMT number (sorted by apexes of hits)",
),
]

dtype += [
Expand Down Expand Up @@ -274,7 +294,12 @@ def fill_result_i(self, event, peaks):
for largest_index, main_or_alt in enumerate(["s", "alt_s"]):
peak_properties_to_save = [name for name, _, _ in self.peak_properties]
if s_i == 1:
peak_properties_to_save += ["max_diff", "min_diff"]
peak_properties_to_save += [
"max_diff",
"min_diff",
"first_channel",
"last_channel",
]
elif s_i == 2:
peak_properties_to_save += ["x", "y"]
peak_properties_to_save += self.posrec_save
Expand Down
16 changes: 10 additions & 6 deletions straxen/plugins/peaklets/peaklets.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Peaklets(strax.Plugin):
parallel = "process"
compressor = "zstd"

__version__ = "1.2.1"
__version__ = "1.2.2"

peaklet_gap_threshold = straxen.URLConfig(
default=700, infer_type=False, help="No hits for this many ns triggers a new peak"
Expand Down Expand Up @@ -417,14 +417,18 @@ def create_outside_peaks_region(peaklets, start, end):
def add_hit_features(hitlets, peaklets):
"""Create hits timing features."""
split_hits = strax.split_by_containment(hitlets, peaklets)
for peaklet, h_max in zip(peaklets, split_hits):
max_time_diff = np.diff(strax.stable_sort(h_max["max_time"]))
if len(max_time_diff) > 0:
peaklet["max_diff"] = max_time_diff.max()
peaklet["min_diff"] = max_time_diff.min()
for peaklet, _hitlets in zip(peaklets, split_hits):
argsort = strax.stable_argsort(_hitlets["max_time"])
sorted_hitlets = _hitlets[argsort]
time_diff = np.diff(sorted_hitlets["max_time"])
if len(time_diff) > 0:
peaklet["max_diff"] = time_diff.max()
peaklet["min_diff"] = time_diff.min()
else:
peaklet["max_diff"] = -1
peaklet["min_diff"] = -1
peaklet["first_channel"] = sorted_hitlets[0]["channel"]
peaklet["last_channel"] = sorted_hitlets[-1]["channel"]


def drop_data_field(peaklets, goal_dtype, _name_function="_drop_data_field"):
Expand Down
16 changes: 13 additions & 3 deletions straxen/plugins/peaks/peak_basics_vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,25 @@ def infer_dtype(self):
("Smallest time difference between apexes of hits inside peak [ns]", "min_diff"),
np.int32,
),
(
(
"First channel/PMT number inside peak (sorted by apexes of hits)",
"first_channel",
),
np.int16,
),
(
("Last channel/PMT number inside peak (sorted by apexes of hits)", "last_channel"),
np.int16,
),
]
return dtype

def compute(self, peaks):
p = peaks
r = np.zeros(len(p), self.dtype)
needed_fields = (
"time center_time length dt median_time area area_fraction_top type max_diff min_diff"
)
needed_fields = "time center_time length dt median_time area area_fraction_top type "
needed_fields += "max_diff min_diff first_channel last_channel"
for q in needed_fields.split():
r[q] = p[q]
r["endtime"] = p["time"] + p["dt"] * p["length"]
Expand Down

0 comments on commit 6e0a79d

Please sign in to comment.