diff --git a/ctapipe/io/simteleventsource.py b/ctapipe/io/simteleventsource.py index e62e4211e00..a040cc04b2f 100644 --- a/ctapipe/io/simteleventsource.py +++ b/ctapipe/io/simteleventsource.py @@ -429,6 +429,14 @@ class SimTelEventSource(EventSource): config=True ) + skip_non_triggered_events = Bool( + True, + help=( + "If False, also yield events where no telescope has triggered", + " meaning only shower information will be available.", + ), + ).tag(config=True) + focal_length_choice = UseEnum( FocalLengthKind, default_value=FocalLengthKind.EFFECTIVE, @@ -499,6 +507,7 @@ def __init__(self, input_url=Undefined, config=None, parent=None, **kwargs): self.input_url.expanduser(), allowed_telescopes=self.allowed_tels, skip_calibration=self.skip_calibration_events, + skip_non_triggered=self.skip_non_triggered_events, ) self._subarray_info = self.prepare_subarray_info( @@ -732,8 +741,9 @@ def _generate_events(self): data.meta["input_url"] = self.input_url data.meta["max_events"] = self.max_events - telescope_events = array_event["telescope_events"] - tracking_positions = array_event["tracking_positions"] + if trigger is None: + yield data + continue photoelectron_sums = array_event.get("photoelectron_sums") if photoelectron_sums is not None: @@ -751,6 +761,9 @@ def _generate_events(self): else: impact_distances = np.full(len(self.subarray), np.nan) * u.m + telescope_events = array_event["telescope_events"] + tracking_positions = array_event["tracking_positions"] + for tel_id, telescope_event in telescope_events.items(): adc_samples = telescope_event.get("adc_samples") if adc_samples is None: @@ -891,7 +904,9 @@ def _fill_event_pointing(tracking_position): return TelescopePointingContainer(azimuth=azimuth, altitude=altitude) def _fill_trigger_info(self, array_event): - trigger = array_event["trigger_information"] + trigger = array_event.get("trigger_information") + if trigger is None: + return None if array_event["type"] == "data": event_type = EventType.SUBARRAY diff --git a/ctapipe/io/tests/test_simteleventsource.py b/ctapipe/io/tests/test_simteleventsource.py index 11904e29e7c..3444eb5dafa 100644 --- a/ctapipe/io/tests/test_simteleventsource.py +++ b/ctapipe/io/tests/test_simteleventsource.py @@ -592,3 +592,26 @@ def test_starting_grammage(): with SimTelEventSource(path, focal_length_choice="EQUIVALENT") as source: e = next(iter(source)) assert e.simulation.shower.starting_grammage == 580 * u.g / u.cm**2 + + +def test_all_events(): + path = "dataset://gamma_prod5.simtel.zst" + + with SimTelEventSource(path, skip_non_triggered_events=False) as source: + reuse = source.simulation_config[1].shower_reuse + n_showers = source.simulation_config[1].n_showers + + shower = 0 + event = 0 + total = 0 + for e in source: + if total % reuse == 0: + event = 0 + shower += 1 + else: + event += 1 + + assert e.index.event_id == shower * 100 + event + total += 1 + + assert total == n_showers * reuse