Skip to content
Snippets Groups Projects
Commit 3acece82 authored by Stefan Reck's avatar Stefan Reck
Browse files

- change default output file name suffix from _hist to _dl

- remove correct_timeslew (this is part of kp.calib now)
- subtract t0 from mchit times for now
parent ee7c9ba0
No related branches found
No related tags found
Loading
...@@ -58,6 +58,7 @@ class BaseProcessor: ...@@ -58,6 +58,7 @@ class BaseProcessor:
If False, throw an error instead. If False, throw an error instead.
mc_info_to_float64 : bool mc_info_to_float64 : bool
Convert everything in the mcinfo array to float 64 (Default: True). Convert everything in the mcinfo array to float 64 (Default: True).
Hint: int dtypes can not store nan!
Attributes Attributes
---------- ----------
...@@ -86,7 +87,6 @@ class BaseProcessor: ...@@ -86,7 +87,6 @@ class BaseProcessor:
det_file=None, det_file=None,
center_time=True, center_time=True,
add_t0=False, add_t0=False,
correct_timeslew=False,
event_skipper=None, event_skipper=None,
chunksize=32, chunksize=32,
keep_event_info=True, keep_event_info=True,
...@@ -97,7 +97,6 @@ class BaseProcessor: ...@@ -97,7 +97,6 @@ class BaseProcessor:
self.det_file = det_file self.det_file = det_file
self.center_time = center_time self.center_time = center_time
self.add_t0 = add_t0 self.add_t0 = add_t0
self.correct_timeslew = correct_timeslew
self.event_skipper = event_skipper self.event_skipper = event_skipper
self.chunksize = chunksize self.chunksize = chunksize
self.keep_event_info = keep_event_info self.keep_event_info = keep_event_info
...@@ -126,7 +125,7 @@ class BaseProcessor: ...@@ -126,7 +125,7 @@ class BaseProcessor:
""" """
if outfile is None: if outfile is None:
outfile = os.path.join(os.getcwd(), "{}_hist.h5".format( outfile = os.path.join(os.getcwd(), "{}_dl.h5".format(
os.path.splitext(os.path.basename(infile))[0])) os.path.splitext(os.path.basename(infile))[0]))
if not self.overwrite: if not self.overwrite:
if os.path.isfile(outfile): if os.path.isfile(outfile):
...@@ -155,7 +154,7 @@ class BaseProcessor: ...@@ -155,7 +154,7 @@ class BaseProcessor:
for infile in infiles: for infile in infiles:
outfile = os.path.join( outfile = os.path.join(
outfolder, outfolder,
f"{os.path.splitext(os.path.basename(infile))[0]}_hist.h5") f"{os.path.splitext(os.path.basename(infile))[0]}_dl.h5")
outfiles.append(outfile) outfiles.append(outfile)
self.run(infile, outfile) self.run(infile, outfile)
return outfiles return outfiles
...@@ -183,11 +182,10 @@ class BaseProcessor: ...@@ -183,11 +182,10 @@ class BaseProcessor:
if self.det_file: if self.det_file:
cmpts.append((modules.DetApplier, {"det_file": self.det_file})) cmpts.append((modules.DetApplier, {"det_file": self.det_file}))
if any((self.center_time, self.add_t0, self.correct_timeslew)): if any((self.center_time, self.add_t0)):
cmpts.append((modules.TimePreproc, { cmpts.append((modules.TimePreproc, {
"add_t0": self.add_t0, "add_t0": self.add_t0,
"center_time": self.center_time, "center_time": self.center_time}))
"correct_timeslew": self.correct_timeslew}))
return cmpts return cmpts
@abstractmethod @abstractmethod
......
...@@ -59,22 +59,15 @@ class TimePreproc(kp.Module): ...@@ -59,22 +59,15 @@ class TimePreproc(kp.Module):
---------- ----------
add_t0 : bool add_t0 : bool
If true, t0 will be added to times of hits and mchits. If true, t0 will be added to times of hits and mchits.
correct_timeslew : bool
If true, the time slewing of hits depending on their tot
will be corrected.
center_time : bool center_time : bool
If true, center hit and mchit times with the time of the first If true, center hit and mchit times with the time of the first
triggered hit. triggered hit.
subtract_t0_mchits : bool
It True, subtract t0 from the times of mchits.
""" """
def configure(self): def configure(self):
self.add_t0 = self.get('add_t0', default=False) self.add_t0 = self.get('add_t0', default=False)
self.correct_timeslew = self.get("correct_timeslew", default=False)
self.center_time = self.get('center_time', default=True) self.center_time = self.get('center_time', default=True)
self.subtract_t0_mchits = self.get('subtract_t0_mchits', default=False)
self._has_mchits = None self._has_mchits = None
self._print_flags = set() self._print_flags = set()
...@@ -82,23 +75,13 @@ class TimePreproc(kp.Module): ...@@ -82,23 +75,13 @@ class TimePreproc(kp.Module):
def process(self, blob): def process(self, blob):
if self._has_mchits is None: if self._has_mchits is None:
self._has_mchits = "McHits" in blob self._has_mchits = "McHits" in blob
if self.add_t0: if self.add_t0:
blob = self.add_t0_time(blob) blob = self.add_t0_time(blob)
if self.correct_timeslew:
blob = self.timeslew(blob)
if self.subtract_t0_mchits and self._has_mchits:
blob = self.subtract_t0_mctime(blob)
if self.center_time: if self.center_time:
blob = self.center_hittime(blob) blob = self.center_hittime(blob)
return blob return blob
def timeslew(self, blob):
self._print_once("Subtracting time slew of hit times")
blob["Hits"]["time"] -= km.mc.slew(blob["Hits"]["tot"])
return blob
def add_t0_time(self, blob): def add_t0_time(self, blob):
self._print_once("Adding t0 to hit times") self._print_once("Adding t0 to hit times")
blob["Hits"].time = np.add(blob["Hits"].time, blob["Hits"].t0) blob["Hits"].time = np.add(blob["Hits"].time, blob["Hits"].t0)
...@@ -109,12 +92,6 @@ class TimePreproc(kp.Module): ...@@ -109,12 +92,6 @@ class TimePreproc(kp.Module):
return blob return blob
def subtract_t0_mctime(self, blob):
self._print_once("Subtracting t0 from mchits")
blob["McHits"].time = np.subtract(
blob["McHits"].time, blob["McHits"].t0)
return blob
def center_hittime(self, blob): def center_hittime(self, blob):
hits_time = blob["Hits"].time hits_time = blob["Hits"].time
hits_triggered = blob["Hits"].triggered hits_triggered = blob["Hits"].triggered
...@@ -459,11 +436,17 @@ class DetApplier(kp.Module): ...@@ -459,11 +436,17 @@ class DetApplier(kp.Module):
"errors with t0." "errors with t0."
) )
self._calib_checked = True self._calib_checked = True
# TODO use built-in time slewing of km3pipe 9 once released blob["Hits"] = self.calib.apply(blob["Hits"], correct_slewing=True)
blob = self.calib.process(blob, key="Hits", outkey="Hits")
if "McHits" in blob: if "McHits" in blob:
blob = self.calib.process(blob, key="McHits", outkey="McHits") blob["McHits"] = self.calib.apply(blob["McHits"])
# TODO remove once https://git.km3net.de/km3py/km3pipe/-/issues/239 is solved
self.subtract_t0_mctime(blob)
return blob
def subtract_t0_mctime(self, blob):
blob["McHits"].time = np.subtract(
blob["McHits"].time, blob["McHits"].t0)
return blob return blob
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment