From 95d7c92ef141503a552ddddd81a791bcca8f6409 Mon Sep 17 00:00:00 2001 From: Gonzalo Date: Sat, 9 Jun 2018 19:11:07 +0200 Subject: [PATCH 1/5] Combine S1 and S2 times correctly to compute the correct z and dt --- invisible_cities/cities/base_cities.py | 8 ++++---- invisible_cities/evm/event_model.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/invisible_cities/cities/base_cities.py b/invisible_cities/cities/base_cities.py index c58a1608bf..2ea381f9c7 100644 --- a/invisible_cities/cities/base_cities.py +++ b/invisible_cities/cities/base_cities.py @@ -784,15 +784,15 @@ def compute_xy_position(self, sr): msipm = self.conf.msipm, masked_sipm = self.pos_sipm_masked) - def compute_z_and_dt(self, ts2, ts1): + def compute_z_and_dt(self, ts2, ts1s): """ Computes dt & z dt = ts2 - ts1 (in mus) z = dt * v_drift (i natural units) """ - dt = ts2 - ts1 - z = dt * self.drift_v + dt = ts2 - np.array(ts1s) + z = dt * self.drift_v dt *= units.ns / units.mus #in mus return z, dt @@ -848,7 +848,7 @@ def create_kr_event(self, pmapVectors, filter_output): c = clusters[loc_elem_1d(cQ, c_closest)] print('c_chosen = {}'.format(c)) - Z, DT = self.compute_z_and_dt(evt.S2t[-1], evt.S1t[0]) + Z, DT = self.compute_z_and_dt(evt.S2t[-1], evt.S1t) Zrms = peak.rms / units.mus evt.Nsipm.append(c.nsipm) diff --git a/invisible_cities/evm/event_model.py b/invisible_cities/evm/event_model.py index cf63f6e82a..cc3dd04d24 100644 --- a/invisible_cities/evm/event_model.py +++ b/invisible_cities/evm/event_model.py @@ -396,15 +396,15 @@ def __init__(self, event_number, event_time): self.S2t = [] # time self.Nsipm = [] # number of SiPMs in S2Si - self.DT = [] # drift time (wrt S1[0]) + self.DT = [] # drift time self.Z = [] # Position (x,y,z,R,phi) - self.Zrms = [] self.X = [] self.Y = [] self.R = [] self.Phi = [] self.Xrms = [] # error in position self.Yrms = [] + self.Zrms = [] def store(self, table): row = table.row From 323e79f637585a21d41f5f1002230f71b7fa3344 Mon Sep 17 00:00:00 2001 From: Gonzalo Date: Sat, 9 Jun 2018 19:11:39 +0200 Subject: [PATCH 2/5] Save nan for z and dt when no S1 is found in the event --- invisible_cities/evm/event_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/invisible_cities/evm/event_model.py b/invisible_cities/evm/event_model.py index cc3dd04d24..f0d93f1a47 100644 --- a/invisible_cities/evm/event_model.py +++ b/invisible_cities/evm/event_model.py @@ -429,8 +429,8 @@ def store(self, table): row["S2t" ] = self.S2t [j] row["Nsipm" ] = self.Nsipm[j] - row["DT" ] = self.DT [j] - row["Z" ] = self.Z [j] + row["DT" ] = self.DT [j][i] if self.nS1 else np.nan + row["Z" ] = self.Z [j][i] if self.nS1 else np.nan row["Zrms" ] = self.Zrms [j] row["X" ] = self.X [j] row["Y" ] = self.Y [j] From 9cab7adad82e9fef9e4a2ffc263a8e272aa5e41c Mon Sep 17 00:00:00 2001 From: Gonzalo Date: Sat, 9 Jun 2018 19:15:02 +0200 Subject: [PATCH 3/5] Remove empty s1/s2 filter --- invisible_cities/cities/base_cities.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/invisible_cities/cities/base_cities.py b/invisible_cities/cities/base_cities.py index 2ea381f9c7..c1c5abd81e 100644 --- a/invisible_cities/cities/base_cities.py +++ b/invisible_cities/cities/base_cities.py @@ -649,8 +649,6 @@ def __init__(self, **kwds): self.cnt.init(n_events_tot = 0, n_empty_pmaps = 0, - n_events_not_s1 = 0, - n_events_not_s2 = 0, n_events_not_s2si = 0, n_events_not_s1s2_filter = 0, n_events_not_s2si_filter = 0, @@ -746,12 +744,6 @@ def filter_event(self, pmap): """Filter the event in terms of s1, s2, s2si""" # loop event away if any signal (s1, s2 or s2si) not present empty = S12SelectorOutput(False, [], []) - if not pmap.s1s: - self.cnt.n_events_not_s1 += 1 - return empty - elif not pmap.s2s: - self.cnt.n_events_not_s2 += 1 - return empty # filters in s12 and s2si f = pmap_filter(self.s1s2_selector, pmap) From 32ae527abefa41a015e1f5028567c26837974d9b Mon Sep 17 00:00:00 2001 From: Gonzalo Date: Sat, 9 Jun 2018 20:10:30 +0200 Subject: [PATCH 4/5] Fill default values in case of an empty S1 or S2 --- invisible_cities/evm/event_model.py | 31 +++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/invisible_cities/evm/event_model.py b/invisible_cities/evm/event_model.py index f0d93f1a47..e4429f588f 100644 --- a/invisible_cities/evm/event_model.py +++ b/invisible_cities/evm/event_model.py @@ -406,10 +406,33 @@ def __init__(self, event_number, event_time): self.Yrms = [] self.Zrms = [] + def fill_defaults(self): + if self.nS1 == 0: + for attribute in ["w", "h", "e", "t"]: + setattr(self, "S1" + attribute, [np.nan]) + + if self.nS2 == 0: + for attribute in ["w", "h", "e", "t", "q"]: + setattr(self, "S2" + attribute, [np.nan]) + + self.Nsipm = 0 + for attribute in ["X", "Y", "R", "Phi", "Xrms", "Yrms", "Zrms"]: + setattr(self, attribute, [np.nan]) + + if not self.nS1 or not self.nS2: + for attribute in ["Z", "DT"]: + setattr(self, attribute, [[np.nan] * max(self.nS1, 1)] * max(self.nS2, 1)) + def store(self, table): row = table.row - for i in range(int(self.nS1)): - for j in range(int(self.nS2)): + + s1_peaks = range(int(self.nS1)) if self.nS1 else [-1] + s2_peaks = range(int(self.nS2)) if self.nS2 else [-1] + self.fill_defaults() + + print(self) + for i in s1_peaks: + for j in s2_peaks: row["event" ] = self.event row["time" ] = self.time row["s1_peak"] = i @@ -429,8 +452,8 @@ def store(self, table): row["S2t" ] = self.S2t [j] row["Nsipm" ] = self.Nsipm[j] - row["DT" ] = self.DT [j][i] if self.nS1 else np.nan - row["Z" ] = self.Z [j][i] if self.nS1 else np.nan + row["DT" ] = self.DT [j][i] + row["Z" ] = self.Z [j][i] row["Zrms" ] = self.Zrms [j] row["X" ] = self.X [j] row["Y" ] = self.Y [j] From a5f42151a3f20e7374586c5b743581cad7491712 Mon Sep 17 00:00:00 2001 From: Gonzalo Date: Sun, 10 Jun 2018 13:04:27 +0200 Subject: [PATCH 5/5] Update test --- .../Kr83_nexus_v5_03_00_ACTIVE_7bar_10evts_KDST.h5 | 4 ++-- invisible_cities/io/kdst_io_test.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/invisible_cities/database/test_data/Kr83_nexus_v5_03_00_ACTIVE_7bar_10evts_KDST.h5 b/invisible_cities/database/test_data/Kr83_nexus_v5_03_00_ACTIVE_7bar_10evts_KDST.h5 index ca06c16d6c..293ed8b03a 100644 --- a/invisible_cities/database/test_data/Kr83_nexus_v5_03_00_ACTIVE_7bar_10evts_KDST.h5 +++ b/invisible_cities/database/test_data/Kr83_nexus_v5_03_00_ACTIVE_7bar_10evts_KDST.h5 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6c9f536250d066c46740bd980947051073aca34dc81d3ba0945696f2159a16b6 -size 22900 +oid sha256:0edd8cb2336802cfa6a40d4fb71fd07ce10d17d214682f6b8b8bad369b6cb20d +size 22870 diff --git a/invisible_cities/io/kdst_io_test.py b/invisible_cities/io/kdst_io_test.py index eb22a56e25..513ac2636e 100644 --- a/invisible_cities/io/kdst_io_test.py +++ b/invisible_cities/io/kdst_io_test.py @@ -29,6 +29,16 @@ def dump_df(write, df): getattr(evt, col).append(value) except AttributeError: setattr(evt, col, value) + + evt.nS1 = int(evt.nS1) + evt.nS2 = int(evt.nS2) + for col in ("Z", "DT"): + column = list(getattr(evt, col)) + setattr(evt, col, []) + for i in range(evt.nS2): + s1_data = column[:evt.nS1 ] + column = column[ evt.nS1:] + getattr(evt, col).append(s1_data) write(evt) with tb.open_file(filename, 'w') as h5out: