Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement interface and example script to get cable delays from the d… #86

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions examples/read_with_cable_delays.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import mattak.Dataset
import argparse

from NuRadioReco.detector import detector


if __name__ == "__main__":
argparser = argparse.ArgumentParser(description="")

argparser.add_argument('data_dir', type=str, default=None)
argparser.add_argument('--backend', type=str, help="Which backend to use", default='uproot')

args = argparser.parse_args()

d = mattak.Dataset.Dataset(0, 0, data_path=args.data_dir, backend=args.backend, verbose=True)

d.setEntries((1, 20))

det = detector.Detector(source="rnog_mongo", always_query_entire_description=False)

wfs = d.wfs(calibrated=False)
trace_start_times = d.tracesStartTime(det=det)

print(trace_start_times)
31 changes: 30 additions & 1 deletion py/mattak/Dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import logging
import warnings
import libconf
import datetime as dt


@dataclass
Expand Down Expand Up @@ -145,7 +146,6 @@ def is_calibration_run(self) -> Union[bool, None]:

return self.run_info.run_config["calib"]["enable_cal"]


@abstractmethod
def _iterate(self, start: int , stop : int , calibrated: bool, max_entries_in_mem: int,
selectors: Optional[Union[Callable[[EventInfo], bool],
Expand Down Expand Up @@ -199,6 +199,35 @@ def get_selected_wfs(self, selector: Callable[[EventInfo], bool], calibrated : b
return numpy.array([wf for _, wf in self.iterate(start=self.first, stop=self.last, selector=selector)])


def tracesStartTime(self, det) -> numpy.ndarray:
""" Get the relative (!) trace start times.

This includes possible readout delays as well as cable^* delays.

^*: Cable delays are used as a synonym for the entire delay between antenna and readout.

Parameters
----------

det : NuRadioMC.detector.detector.Detector
A NuRadioMC detector object

Returns
-------
trace_start_times : numpy.ndarray
Array of trace start times in ns. The values are to be considered relative
to each other but in no means absolute.
"""
readout_delays = numpy.array([ei.readoutDelay for ei in self.eventInfo()])

# this make the assumption that the detector will be valid/the same of all events
# within the selection ...
det.update(dt.datetime.fromtimestamp(self.eventInfo()[0].triggerTime))
cable_delays = numpy.array([det.get_cable_delay(self.station, ch) for ch in range(self.NUM_CHANNELS)])

return readout_delays + cable_delays


def Dataset(station : int = 0, run : int = 0, data_path : Optional[str] = None, backend : str= "auto",
verbose : bool = False, skip_incomplete : bool = True,
read_daq_status : bool = True, read_run_info : bool = True,
Expand Down