diff --git a/examples/read_with_cable_delays.py b/examples/read_with_cable_delays.py new file mode 100644 index 0000000..0bf1eab --- /dev/null +++ b/examples/read_with_cable_delays.py @@ -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) \ No newline at end of file diff --git a/py/mattak/Dataset.py b/py/mattak/Dataset.py index 01927e8..51132ac 100644 --- a/py/mattak/Dataset.py +++ b/py/mattak/Dataset.py @@ -9,6 +9,7 @@ import logging import warnings import libconf +import datetime as dt @dataclass @@ -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], @@ -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,