Skip to content
Merged
Show file tree
Hide file tree
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
23 changes: 0 additions & 23 deletions src/reboost/optmap/evt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import logging
from collections import OrderedDict
from collections.abc import Generator, Iterable
from pathlib import Path

import numpy as np
from lgdo import lh5
from lgdo.lh5 import LH5Iterator
from lgdo.types import Table

Expand Down Expand Up @@ -105,27 +103,6 @@ def _ensure_vert_df(vert_it: LH5Iterator, evtid: int) -> Generator[Table, None,
assert had_last_chunk, "did not reach last chunk in optmap-evt building"


def build_optmap_evt(
lh5_in_file: str, lh5_out_file: str, detectors: Iterable[str | int], buffer_len: int = int(5e6)
) -> None:
"""Create a faster map for lookup of the hits in each detector, for each primary event."""
lh5_out_file = Path(lh5_out_file)
lh5_out_file_tmp = lh5_out_file.with_stem(".evt-tmp." + lh5_out_file.stem)
if lh5_out_file_tmp.exists():
msg = f"temporary output file {lh5_out_file_tmp} already exists"
raise RuntimeError(msg)

for vert_it_count, chunk in enumerate(generate_optmap_evt(lh5_in_file, detectors, buffer_len)):
log.info("store evt file %s (%d)", lh5_out_file_tmp, vert_it_count - 1)
lh5.write(Table(chunk), name=EVT_TABLE_NAME, lh5_file=lh5_out_file_tmp, wo_mode="append")

# after finishing the output file, rename to the actual output file name.
if lh5_out_file.exists():
msg = f"output file {lh5_out_file_tmp} already exists after writing tmp output file"
raise RuntimeError(msg)
lh5_out_file_tmp.rename(lh5_out_file)


def get_optical_detectors_from_geom(geom_fn) -> dict[int, str]:
import pyg4ometry
import pygeomtools
Expand Down
11 changes: 0 additions & 11 deletions tests/test_optmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
merge_optical_maps,
rebin_optical_maps,
)
from reboost.optmap.evt import build_optmap_evt
from reboost.optmap.optmap import OpticalMap


Expand Down Expand Up @@ -53,16 +52,6 @@ def tbl_hits(tmptestdir):
return (str(hit_file),)


def test_optmap_evt(tbl_hits, tmptestdir):
evt_out_file = tmptestdir / "evt-out.lh5"
build_optmap_evt(
tbl_hits[0],
str(evt_out_file),
detectors=("1", "002", "003"),
buffer_len=20, # note: shorter window sizes (e.g. 10) do not work.
)


@pytest.fixture
def tbl_evt_fns(tmptestdir) -> tuple[str]:
evt_count = 100
Expand Down
Loading