Skip to content

Commit

Permalink
Merge branch 'master' into merged_s2s_avg_pos
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx authored Dec 16, 2024
2 parents c954cff + 7138149 commit 5ac47f5
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion straxen/analyses/posrec_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def load_corrected_positions(
alt_s1=False,
alt_s2=False,
cmt_version=None,
posrec_algos=("mlp"), # TODO: https://github.com/XENONnT/straxen/issues/1454
posrec_algos=("mlp", "cnf"), # TODO: https://github.com/XENONnT/straxen/issues/1454
):
"""Returns the corrected position for each position algorithm available, without the need to
reprocess event_basics, as the needed information is already stored in event_basics.
Expand Down
16 changes: 13 additions & 3 deletions straxen/corrections_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
export, __all__ = strax.exporter()

corrections_w_file = [
"mlp_model",
"mlp_model", # there is no cnf_model because CNF is using another jax protocol
"s2_xy_map_mlp",
"s2_xy_map",
"s2_xy_map_cnf",
"s1_xyz_map_mlp",
"s1_xyz_map_cnf",
"fdc_map_mlp",
"fdc_map_cnf",
"s1_aft_xyz_map",
]

Expand Down Expand Up @@ -168,7 +170,15 @@ def _get_correction(self, run_id, correction, version):
df = self.interface.interpolate(df, when)
values.append(df.loc[df.index == when, version].values[0])
else:
df = self.interface.read_at(correction, when)
# TODO: remove this hack when fdc_map_cnf is available
if correction == "fdc_map_cnf":
df = self.interface.read_at("fdc_map_mlp", when)
elif correction == "s1_xyz_map_cnf":
df = self.interface.read_at("s1_xyz_map_mlp", when)
elif correction == "s2_xy_map_cnf":
df = self.interface.read_at("s2_xy_map_mlp", when)
else:
df = self.interface.read_at(correction, when)
if df[version].isnull().values.any():
raise CMTnanValueError(
f"For {correction} there are NaN values, this means no correction available"
Expand Down
2 changes: 1 addition & 1 deletion straxen/plugins/defaults.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Some shared defaults."""

DEFAULT_POSREC_ALGO = "mlp"
DEFAULT_POSREC_ALGO = "cnf"

HE_PREAMBLE = """High energy channels: attenuated signals of the top PMT-array\n"""

Expand Down
12 changes: 1 addition & 11 deletions straxen/plugins/events/event_basics_vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,9 @@ def _get_posrec_dtypes(self):

return posrec_dtpye

@staticmethod
def set_nan_defaults(buffer):
"""When constructing the dtype, take extra care to set values to np.Nan / -1 (for ints) as 0
might have a meaning."""
for field in buffer.dtype.names:
if np.issubdtype(buffer.dtype[field], np.integer):
buffer[field][:] = -1
else:
buffer[field][:] = np.nan

def compute(self, events, peaks):
result = np.zeros(len(events), dtype=self.dtype)
self.set_nan_defaults(result)
strax.set_nan_defaults(result)

split_peaks = strax.split_by_containment(peaks, events)

Expand Down
3 changes: 1 addition & 2 deletions straxen/plugins/events/event_nearest_triggering.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import strax
import straxen

export, __all__ = strax.exporter()

Expand Down Expand Up @@ -77,7 +76,7 @@ def compute(self, events, peaks):
split_peaks = strax.split_by_containment(peaks, events)
result = np.zeros(len(events), self.dtype)

straxen.EventBasicsVanilla.set_nan_defaults(result)
strax.set_nan_defaults(result)

# 1. Assign peaks features to main S1 and main S2 in the event
for event_i, (event, sp) in enumerate(zip(events, split_peaks)):
Expand Down
4 changes: 1 addition & 3 deletions straxen/plugins/events/event_shadow.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import numpy as np
import strax

import straxen

export, __all__ = strax.exporter()


Expand Down Expand Up @@ -108,7 +106,7 @@ def compute(self, events, peaks):
split_peaks = strax.split_by_containment(peaks, events)
result = np.zeros(len(events), self.dtype)

straxen.EventBasicsVanilla.set_nan_defaults(result)
strax.set_nan_defaults(result)

# 1. Assign peaks features to main S1 and main S2 in the event
for event_i, (event, sp) in enumerate(zip(events, split_peaks)):
Expand Down
2 changes: 1 addition & 1 deletion straxen/plugins/peaks/peak_nearest_triggering.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def compute_triggering(self, peaks, current_peak):
_peaks = _peaks[_is_triggering]
# init result
result = np.zeros(len(current_peak), self.dtype)
straxen.EventBasicsVanilla.set_nan_defaults(result)
strax.set_nan_defaults(result)

# use center_time as the anchor of things
things = np.zeros(len(_peaks), dtype=strax.time_fields)
Expand Down
3 changes: 1 addition & 2 deletions straxen/plugins/peaks/peak_per_event.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import strax
import straxen

export, __all__ = strax.exporter()

Expand Down Expand Up @@ -30,7 +29,7 @@ def compute(self, events, peaks):
split_peaks = strax.split_by_containment(peaks, events)
split_peaks_ind = strax.fully_contained_in(peaks, events)
result = np.zeros(len(peaks), self.dtype)
straxen.EventBasicsVanilla.set_nan_defaults(result)
strax.set_nan_defaults(result)

# Assign peaks features to main S1 and main S2 in the event
for event_i, (event, sp) in enumerate(zip(events, split_peaks)):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ def test_cmt_versions():
)

test = unittest.TestCase()
# We should always work for one offline and the online version
test.assertTrue(len(success_for) >= 2)
# We should always work for the online version
test.assertTrue(len(success_for) >= 1)

0 comments on commit 5ac47f5

Please sign in to comment.