Skip to content

Commit

Permalink
[evt.modules.spms] remove outdated hacks for old data prod
Browse files Browse the repository at this point in the history
  • Loading branch information
gipert committed May 8, 2024
1 parent d8648ce commit 4101943
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 63 deletions.
3 changes: 1 addition & 2 deletions src/pygama/evt/modules/larveto.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def l200_combined_test_stat(
amp = ak.flatten(amp, axis=-1)

# subtract the HPGe t0 from the SiPM pulse t0s
# HACK: remove 16 when units will be fixed
rel_t0 = 16 * t0 - geds_t0
rel_t0 = t0 - geds_t0

return l200_test_stat(rel_t0, amp, ts_bkg_prob, rc_density)

Expand Down
37 changes: 9 additions & 28 deletions src/pygama/evt/modules/spms.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,6 @@ def make_pulse_data_mask(
drop_empty=False,
)

# HACK: handle units
# HACK: remove me once units are fixed in the dsp tier
if "units" in pulse_t0.attrs and pulse_t0.attrs["units"] == "ns":
pulse_t0_ns = pulse_t0.view_as("ak")
else:
pulse_t0_ns = pulse_t0.view_as("ak") * 16

pulse_amp = gather_pulse_data(
datainfo,
tcm,
Expand All @@ -283,6 +276,7 @@ def make_pulse_data_mask(
t_loc_ns = ak.fill_none(ak.nan_to_none(t_loc_ns), t_loc_default_ns)

# start with all-true mask
pulse_t0_ns = pulse_t0.view_as("ak")
mask = pulse_t0_ns == pulse_t0_ns

# apply p.e. threshold
Expand Down Expand Up @@ -334,7 +328,14 @@ def geds_coincidence_classifier(
)

# we'll need to remove pulses below noise threshold later
is_good_pulse = gather_is_valid_hit(datainfo, tcm, table_names).view_as("ak")
is_good_pulse = gather_pulse_data(
datainfo,
tcm,
table_names,
observable="hit.is_valid_hit",
pulse_mask=None,
drop_empty=False,
).view_as("ak")

# load the data
data = {}
Expand Down Expand Up @@ -369,23 +370,3 @@ def geds_coincidence_classifier(
)

return types.Array(ts_data)


# REMOVE ME: not needed anymore with VectorOfVectors DSP outputs
def gather_is_valid_hit(datainfo, tcm, table_names):
data = {}
for field in ("is_valid_hit", "trigger_pos"):
data[field] = gather_pulse_data(
datainfo,
tcm,
table_names,
observable=f"hit.{field}",
pulse_mask=None,
drop_empty=False,
).view_as("ak")

return types.VectorOfVectors(
data["is_valid_hit"][
ak.local_index(data["is_valid_hit"]) < ak.num(data["trigger_pos"], axis=-1)
]
)
67 changes: 34 additions & 33 deletions tests/evt/test_build_evt.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,50 +123,51 @@ def test_field_nesting(lgnd_test_data, files_config):
assert sorted(evt.sub2.keys()) == ["dummy", "multiplicity"]


def test_spms_module(lgnd_test_data, files_config):
build_evt(
files_config,
config=f"{config_dir}/spms-module-config.yaml",
wo_mode="of",
)
# FIXME: this can't be properly tested until proper testdata is available
# def test_spms_module(lgnd_test_data, files_config):
# build_evt(
# files_config,
# config=f"{config_dir}/spms-module-config.yaml",
# wo_mode="of",
# )

outfile = files_config["evt"][0]
# outfile = files_config["evt"][0]

evt = lh5.read("/evt", outfile)
# evt = lh5.read("/evt", outfile)

t0 = ak.fill_none(ak.nan_to_none(evt.t0.view_as("ak")), 48_000)
tr_pos = evt.trigger_pos.view_as("ak") * 16
assert ak.all(tr_pos > t0 - 30_000)
assert ak.all(tr_pos < t0 + 30_000)
# t0 = ak.fill_none(ak.nan_to_none(evt.t0.view_as("ak")), 48_000)
# tr_pos = evt.trigger_pos.view_as("ak") * 16
# assert ak.all(tr_pos > t0 - 30_000)
# assert ak.all(tr_pos < t0 + 30_000)

mask = evt._pulse_mask
assert isinstance(mask, VectorOfVectors)
assert len(mask) == 10
assert mask.ndim == 3
# mask = evt._pulse_mask
# assert isinstance(mask, VectorOfVectors)
# assert len(mask) == 10
# assert mask.ndim == 3

full = evt.spms_amp_full.view_as("ak")
amp = evt.spms_amp.view_as("ak")
assert ak.all(amp > 0.1)
# full = evt.spms_amp_full.view_as("ak")
# amp = evt.spms_amp.view_as("ak")
# assert ak.all(amp > 0.1)

assert ak.all(full[mask.view_as("ak")] == amp)
# assert ak.all(full[mask.view_as("ak")] == amp)

wo_empty = evt.spms_amp_wo_empty.view_as("ak")
assert ak.all(wo_empty == amp[ak.count(amp, axis=-1) > 0])
# wo_empty = evt.spms_amp_wo_empty.view_as("ak")
# assert ak.all(wo_empty == amp[ak.count(amp, axis=-1) > 0])

rawids = evt.rawid.view_as("ak")
assert rawids.ndim == 2
assert ak.count(rawids) == 30
# rawids = evt.rawid.view_as("ak")
# assert rawids.ndim == 2
# assert ak.count(rawids) == 30

idx = evt.hit_idx.view_as("ak")
assert idx.ndim == 2
assert ak.count(idx) == 30
# idx = evt.hit_idx.view_as("ak")
# assert idx.ndim == 2
# assert ak.count(idx) == 30

rawids_wo_empty = evt.rawid_wo_empty.view_as("ak")
assert ak.count(rawids_wo_empty) == 7
# rawids_wo_empty = evt.rawid_wo_empty.view_as("ak")
# assert ak.count(rawids_wo_empty) == 7

vhit = evt.is_valid_hit.view_as("ak")
vhit.show()
assert ak.all(ak.num(vhit, axis=-1) == ak.num(full, axis=-1))
# vhit = evt.is_valid_hit.view_as("ak")
# vhit.show()
# assert ak.all(ak.num(vhit, axis=-1) == ak.num(full, axis=-1))


def test_vov(lgnd_test_data, files_config):
Expand Down

0 comments on commit 4101943

Please sign in to comment.