Skip to content

Commit

Permalink
Add software basic trigger structure and test
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Nov 25, 2022
1 parent 758e137 commit 603d00d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
52 changes: 52 additions & 0 deletions ctapipe/instrument/tests/test_trigger.py
Original file line number Diff line number Diff line change
@@ -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]
28 changes: 28 additions & 0 deletions ctapipe/instrument/trigger.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 603d00d

Please sign in to comment.