diff --git a/ctapipe/instrument/tests/test_trigger.py b/ctapipe/instrument/tests/test_trigger.py new file mode 100644 index 00000000000..354502413de --- /dev/null +++ b/ctapipe/instrument/tests/test_trigger.py @@ -0,0 +1,52 @@ +from ctapipe.containers import ArrayEventContainer + + +def test_softare_trigger(subarray_prod5_paranal): + from ctapipe.instrument.trigger import SoftwareTrigger + + subarray = subarray_prod5_paranal + trigger = SoftwareTrigger( + subarray=subarray, + min_telescopes=2, + min_telescopes_by_type=[ + ("type", "*", 1), + ("type", "LST*", 2), + ], + ) + + # only one telescope, no SWAT + event = ArrayEventContainer() + event.trigger.tels_with_trigger = [5] + assert trigger(event) == False + assert event.trigger.tels_with_trigger == [] + + # 1 LST + 1 MST, 1 LST would not have triggered LST hardware trigger + # and after LST is removed, we only have 1 telescope, so no SWAT either + event = ArrayEventContainer() + event.trigger.tels_with_trigger = [1, 6] + assert trigger(event) == False + assert event.trigger.tels_with_trigger == [] + + # two MSTs and 1 LST, -> remove single LST + event = ArrayEventContainer() + event.trigger.tels_with_trigger = [1, 5, 6] + assert trigger(event) == True + assert event.trigger.tels_with_trigger == [5, 6] + + # two MSTs, nothing to change + event = ArrayEventContainer() + event.trigger.tels_with_trigger = [5, 6] + assert trigger(event) == True + assert event.trigger.tels_with_trigger == [5, 6] + + # three LSTs, nothing to change + event = ArrayEventContainer() + event.trigger.tels_with_trigger = [1, 2, 3] + assert trigger(event) == True + assert event.trigger.tels_with_trigger == [1, 2, 3] + + # thee LSTs, plus MSTs, nothing to change + event = ArrayEventContainer() + event.trigger.tels_with_trigger = [1, 2, 3, 5, 6, 7] + assert trigger(event) == True + assert event.trigger.tels_with_trigger == [1, 2, 3, 5, 6, 7] diff --git a/ctapipe/instrument/trigger.py b/ctapipe/instrument/trigger.py new file mode 100644 index 00000000000..5a93687436b --- /dev/null +++ b/ctapipe/instrument/trigger.py @@ -0,0 +1,28 @@ +from ctapipe.containers import ArrayEventContainer +from ctapipe.core import TelescopeComponent +from ctapipe.core.traits import Integer, IntTelescopeParameter + + +class SoftwareTrigger(TelescopeComponent): + + min_telescopes = Integer( + default_value=1, + help=( + "Minimum number of telescopes required globally." + " Events with fewer telescopes will be filtered out completely." + ), + ).tag(config=True) + + min_telescopes_by_type = IntTelescopeParameter( + default_value=1, + help=( + "Minimum number of telescopes required for a specific type." + " In events with fewer telescopes of a given type" + " , those telescopes will be removed from the array event." + " This might result in the event not fullfilling ``min_telescopes`` anymore" + " and thus being filtered completely." + ), + ).tag(config=True) + + def __call__(self, event: ArrayEventContainer) -> bool: + return True