Skip to content

Commit

Permalink
Load whole run for VetoIntervals regardless the run length (#1399)
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx authored Jul 11, 2024
1 parent 58a78b7 commit 4d6c2b7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 48 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ docutils==0.18.1
mistune==0.8.4
pymongo
requests
strax>=1.5.0
strax>=1.6.4
utilix>=0.5.3
xedocs
35 changes: 11 additions & 24 deletions straxen/plugins/events/veto_proximity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import numba

export, __all__ = strax.exporter()
__all__.extend(["DTYPE_VETO_INTERVALS"])


DTYPE_VETO_INTERVALS = np.int64


@export
class VetoProximity(strax.OverlapWindowPlugin):
class VetoProximity(strax.ExhaustPlugin):
"""Find the closest next/previous veto start w.r.t.
the event time or when a busy happens during an event.
Expand All @@ -30,20 +34,6 @@ class VetoProximity(strax.OverlapWindowPlugin):
),
)

veto_proximity_window = straxen.URLConfig(
default=int(300e9), help="Maximum separation between veto stop and start pulses [ns]"
)
time_no_aqmon_veto_found = straxen.URLConfig(
default=int(3.6e12),
track=True,
type=int,
help=(
"If no next/previous veto is found, we will fill the fields "
"time_to_previous_XX with this time. Set to a large number "
"such that one will never cut events that are < YY ns."
),
)

veto_names = ["busy", "busy_he", "hev", "straxen_deadtime"]

def infer_dtype(self):
Expand All @@ -57,7 +47,7 @@ def infer_dtype(self):
f'Duration of event overlapping with "{name}"-veto [ns]',
f"veto_{name}_overlap",
),
np.int64,
DTYPE_VETO_INTERVALS,
),
(
(
Expand All @@ -67,7 +57,7 @@ def infer_dtype(self):
),
f"time_to_previous_{name}",
),
np.int64,
DTYPE_VETO_INTERVALS,
),
(
(
Expand All @@ -77,15 +67,12 @@ def infer_dtype(self):
),
f"time_to_next_{name}",
),
np.int64,
DTYPE_VETO_INTERVALS,
),
]

return dtype

def get_window_size(self):
return self.veto_proximity_window

def set_result_for_veto(
self,
result_buffer: np.ndarray,
Expand All @@ -105,8 +92,8 @@ def set_result_for_veto(
"""
# Set defaults to be some very long time
result_buffer[f"time_to_previous_{veto_name}"] = self.time_no_aqmon_veto_found
result_buffer[f"time_to_next_{veto_name}"] = self.time_no_aqmon_veto_found
result_buffer[f"time_to_previous_{veto_name}"] = np.iinfo(DTYPE_VETO_INTERVALS).max
result_buffer[f"time_to_next_{veto_name}"] = np.iinfo(DTYPE_VETO_INTERVALS).max

selected_intervals = veto_intervals[veto_intervals["veto_type"] == f"{veto_name}_veto"]
if not len(selected_intervals):
Expand Down Expand Up @@ -136,7 +123,7 @@ def get_overlapping_window_time(
vetos_during_event, selected_intervals, event_window, result_buffer
):
"""Computes total time each event overlaps with the corresponding veto."""
res = np.zeros(len(vetos_during_event), np.int64)
res = np.zeros(len(vetos_during_event), DTYPE_VETO_INTERVALS)

for event_i, veto_window in enumerate(vetos_during_event):
if veto_window[1] - veto_window[0]:
Expand Down
23 changes: 1 addition & 22 deletions straxen/plugins/veto_intervals/veto_intervals.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import typing
import numpy as np
import strax
import straxen

from straxen.plugins.aqmon_hits.aqmon_hits import AqmonChannels

Expand All @@ -21,7 +20,7 @@


@export
class VetoIntervals(strax.OverlapWindowPlugin):
class VetoIntervals(strax.ExhaustPlugin):
"""Find pairs of veto start and veto stop signals and the veto.
duration between them:
Expand All @@ -38,22 +37,6 @@ class VetoIntervals(strax.OverlapWindowPlugin):
provides = "veto_intervals"
data_kind = "veto_intervals"

# This option is just showing where the OverlapWindowPlugin fails.
# We need to buffer the entire run in order not to run into chunking
# issues. A better solution would be using
# github.com/AxFoundation/strax/pull/654
max_veto_window = straxen.URLConfig(
default=int(7.2e12),
track=True,
type=int,
help=(
"Maximum separation between veto stop and start pulses [ns]. "
"Set to be >> than the max duration of the run to be able to "
"fully store one run into buffer since aqmon-hits are not "
"sorted by endtime"
),
)

def infer_dtype(self):
dtype = [
(("veto interval [ns]", "veto_interval"), np.int64),
Expand All @@ -66,10 +49,6 @@ def setup(self):
self.veto_names = ["busy_", "busy_he_", "hev_"]
self.channel_map = {aq_ch.name.lower(): int(aq_ch) for aq_ch in AqmonChannels}

def get_window_size(self):
# Give a very wide window
return self.max_veto_window

def compute(self, aqmon_hits, start, end):
# Allocate a nice big buffer and throw away the part we don't need later
result = np.zeros(len(aqmon_hits) * len(self.veto_names), self.dtype)
Expand Down
1 change: 0 additions & 1 deletion tests/test_aqmon.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ def setUp(self) -> None:
st.set_context_config({"free_options": list(st.config.keys())})
st._plugin_class_registry = {}

st.set_config(dict(veto_proximity_window=10**99))
self.TOTAL_DEADTIME: List = []
self.TOTAL_SIGNALS: List = []

Expand Down

0 comments on commit 4d6c2b7

Please sign in to comment.