From 355275f6aa182ce639ce55f09cc75fe6964254c3 Mon Sep 17 00:00:00 2001 From: Abelardo Moralejo Date: Fri, 9 Jun 2023 14:31:50 +0200 Subject: [PATCH 1/7] Check # of gains in FF events. Don't apply heuristic tag on 1-gain events. --- src/ctapipe_io_lst/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ctapipe_io_lst/__init__.py b/src/ctapipe_io_lst/__init__.py index 9a7113ed..fba4b744 100644 --- a/src/ctapipe_io_lst/__init__.py +++ b/src/ctapipe_io_lst/__init__.py @@ -686,6 +686,12 @@ def fill_trigger_info(self, array_event): ) trigger.event_type = self._event_type_from_trigger_bits(trigger_bits) + + if trigger.event_type == EventType.FLATFIELD: + waveform = array_event.r1.tel[tel_id].waveform + if waveform.ndim == 2: + self.log.warning(f'Event {array_event.index.event_id} tagged as FLATFIELD, but has only one gain!') + if trigger.event_type == EventType.UNKNOWN: self.log.warning(f'Event {array_event.index.event_id} has unknown event type, trigger: {trigger_bits:08b}') @@ -703,11 +709,11 @@ def tag_flatfield_events(self, array_event): tel_id = self.tel_id waveform = array_event.r1.tel[tel_id].waveform - # needs to work for gain already selected or not + # Tag only events with 2-gains waveforms: both gains are needed for calibration if waveform.ndim == 3: image = waveform[HIGH_GAIN].sum(axis=1) else: - image = waveform.sum(axis=1) + return; in_range = (image >= self.min_flatfield_adc) & (image <= self.max_flatfield_adc) n_in_range = np.count_nonzero(in_range) From b56f23ce61248a8be15207b5e1beb116ff9b01a7 Mon Sep 17 00:00:00 2001 From: Abelardo Moralejo Date: Fri, 9 Jun 2023 16:35:27 +0200 Subject: [PATCH 2/7] Check both r0 and r1 in FF check --- src/ctapipe_io_lst/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ctapipe_io_lst/__init__.py b/src/ctapipe_io_lst/__init__.py index fba4b744..c5abf942 100644 --- a/src/ctapipe_io_lst/__init__.py +++ b/src/ctapipe_io_lst/__init__.py @@ -688,7 +688,9 @@ def fill_trigger_info(self, array_event): trigger.event_type = self._event_type_from_trigger_bits(trigger_bits) if trigger.event_type == EventType.FLATFIELD: - waveform = array_event.r1.tel[tel_id].waveform + waveform = array_event.r0.tel[tel_id].waveform + if waveform is None: + waveform = array_event.r1.tel[tel_id].waveform if waveform.ndim == 2: self.log.warning(f'Event {array_event.index.event_id} tagged as FLATFIELD, but has only one gain!') From a61c9df6e3709f475f0c5ba19e04535081ee0593 Mon Sep 17 00:00:00 2001 From: Maximilian Linhoff Date: Fri, 9 Jun 2023 16:47:29 +0200 Subject: [PATCH 3/7] Simplify gain selection check --- src/ctapipe_io_lst/__init__.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ctapipe_io_lst/__init__.py b/src/ctapipe_io_lst/__init__.py index c5abf942..c0ec48b8 100644 --- a/src/ctapipe_io_lst/__init__.py +++ b/src/ctapipe_io_lst/__init__.py @@ -686,14 +686,12 @@ def fill_trigger_info(self, array_event): ) trigger.event_type = self._event_type_from_trigger_bits(trigger_bits) - + if trigger.event_type == EventType.FLATFIELD: - waveform = array_event.r0.tel[tel_id].waveform - if waveform is None: - waveform = array_event.r1.tel[tel_id].waveform - if waveform.ndim == 2: + waveform = array_event.r1.tel[tel_id].waveform + if waveform is not None and waveform.ndim == 2: self.log.warning(f'Event {array_event.index.event_id} tagged as FLATFIELD, but has only one gain!') - + if trigger.event_type == EventType.UNKNOWN: self.log.warning(f'Event {array_event.index.event_id} has unknown event type, trigger: {trigger_bits:08b}') From d0e5845f20fd32885ff54de333d806967f92e2dd Mon Sep 17 00:00:00 2001 From: Maximilian Linhoff Date: Fri, 9 Jun 2023 16:48:25 +0200 Subject: [PATCH 4/7] Remove unneeded semicolon --- src/ctapipe_io_lst/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ctapipe_io_lst/__init__.py b/src/ctapipe_io_lst/__init__.py index c0ec48b8..31516761 100644 --- a/src/ctapipe_io_lst/__init__.py +++ b/src/ctapipe_io_lst/__init__.py @@ -713,7 +713,7 @@ def tag_flatfield_events(self, array_event): if waveform.ndim == 3: image = waveform[HIGH_GAIN].sum(axis=1) else: - return; + return in_range = (image >= self.min_flatfield_adc) & (image <= self.max_flatfield_adc) n_in_range = np.count_nonzero(in_range) From f08e0109f5bb536a90f8497ef46c971e6d8ed8ae Mon Sep 17 00:00:00 2001 From: Abelardo Moralejo Date: Sat, 10 Jun 2023 10:54:03 +0200 Subject: [PATCH 5/7] Set to UNKNOWN event type of 1-gain FF candidates --- src/ctapipe_io_lst/__init__.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/ctapipe_io_lst/__init__.py b/src/ctapipe_io_lst/__init__.py index 31516761..228c6889 100644 --- a/src/ctapipe_io_lst/__init__.py +++ b/src/ctapipe_io_lst/__init__.py @@ -708,27 +708,35 @@ def tag_flatfield_events(self, array_event): ''' tel_id = self.tel_id waveform = array_event.r1.tel[tel_id].waveform - - # Tag only events with 2-gains waveforms: both gains are needed for calibration + if waveform.ndim == 3: image = waveform[HIGH_GAIN].sum(axis=1) else: - return + image = waveform.sum(axis=1) in_range = (image >= self.min_flatfield_adc) & (image <= self.max_flatfield_adc) n_in_range = np.count_nonzero(in_range) looks_like_ff = n_in_range >= self.min_flatfield_pixel_fraction * image.size + if looks_like_ff: - array_event.trigger.event_type = EventType.FLATFIELD - self.log.debug( - 'Setting event type of event' - f' {array_event.index.event_id} to FLATFIELD' - ) + # Tag as FF only events with 2-gains waveforms: both gains are needed for calibration + if waveform.ndim == 3: + array_event.trigger.event_type = EventType.FLATFIELD + self.log.debug( + 'Setting event type of event' + f' {array_event.index.event_id} to FLATFIELD' + ) + else: + array_event.trigger.event_type = EventType.UNKNOWN + self.log.warning( + 'Found FF-looking event that has just one gain: %d', + array_event.index.event_id, 'Setting event type to UNKNOWN' + ) elif array_event.trigger.event_type == EventType.FLATFIELD: self.log.warning( 'Found FF event that does not fulfill FF criteria: %d', - array_event.index.event_id, + array_event.index.event_id, 'Setting event type to UNKNOWN' ) array_event.trigger.event_type = EventType.UNKNOWN From b964edfa0da407b41fdff956d038188bdb930aec Mon Sep 17 00:00:00 2001 From: Abelardo Moralejo Date: Sat, 10 Jun 2023 10:59:55 +0200 Subject: [PATCH 6/7] Fixed log messages --- src/ctapipe_io_lst/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ctapipe_io_lst/__init__.py b/src/ctapipe_io_lst/__init__.py index 228c6889..a9134ffd 100644 --- a/src/ctapipe_io_lst/__init__.py +++ b/src/ctapipe_io_lst/__init__.py @@ -730,13 +730,13 @@ def tag_flatfield_events(self, array_event): else: array_event.trigger.event_type = EventType.UNKNOWN self.log.warning( - 'Found FF-looking event that has just one gain: %d', - array_event.index.event_id, 'Setting event type to UNKNOWN' + 'Found FF-looking event that has just one gain:', + f'{array_event.index.event_id}. Setting event type to UNKNOWN' ) elif array_event.trigger.event_type == EventType.FLATFIELD: self.log.warning( - 'Found FF event that does not fulfill FF criteria: %d', - array_event.index.event_id, 'Setting event type to UNKNOWN' + 'Found FF event that does not fulfill FF criteria:', + f'{array_event.index.event_id}. Setting event type to UNKNOWN' ) array_event.trigger.event_type = EventType.UNKNOWN From 3308418c8f9efc0851077fc7fcd468cb4cbd4d60 Mon Sep 17 00:00:00 2001 From: Abelardo Moralejo Date: Sat, 10 Jun 2023 11:06:59 +0200 Subject: [PATCH 7/7] Second try at fixing log messages... --- src/ctapipe_io_lst/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ctapipe_io_lst/__init__.py b/src/ctapipe_io_lst/__init__.py index a9134ffd..0b1e05d0 100644 --- a/src/ctapipe_io_lst/__init__.py +++ b/src/ctapipe_io_lst/__init__.py @@ -730,12 +730,12 @@ def tag_flatfield_events(self, array_event): else: array_event.trigger.event_type = EventType.UNKNOWN self.log.warning( - 'Found FF-looking event that has just one gain:', - f'{array_event.index.event_id}. Setting event type to UNKNOWN' + 'Found FF-looking event that has just one gain:' + f'{array_event.index.event_id}. Setting event type to UNKNOWN' ) elif array_event.trigger.event_type == EventType.FLATFIELD: self.log.warning( - 'Found FF event that does not fulfill FF criteria:', + 'Found FF event that does not fulfill FF criteria:' f'{array_event.index.event_id}. Setting event type to UNKNOWN' ) array_event.trigger.event_type = EventType.UNKNOWN