Skip to content

Add DL0 telescope event type, add missing types #2769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/ctapipe/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,15 @@ class CoordinateFrameType(enum.Enum):


class EventType(enum.Enum):
"""Enum of EventTypes as defined in :cite:p:`ctao-r1-event-data-model`"""
"""R1/DL0 EventType

Defined in :cite:p:`ctao-r1-event-data-model`.

This enum currently has additional values that are not defined
in the data model:
- the data model does not distinguish between types of pedestals
- the data model does not define the RANDOM_MONO type
"""

# calibrations are 0-15
FLATFIELD = 0
Expand All @@ -159,15 +167,21 @@ class EventType(enum.Enum):
ELECTRONIC_PEDESTAL = 4
OTHER_CALIBRATION = 15

#: For mono-telescope triggers (not used in MC)
#: Muon event candidate
MUON = 16
#: (LST) hardware-stereo trigger
HARDWARE_STEREO = 17
#: Random mono trigger, used in simulations to force storage
#: of event regardless of subarray trigger for certain studies.
RANDOM_MONO = 18

#: ACADA (DAQ) software trigger
DAQ = 24

#: Standard Physics stereo trigger
#: Standard Physics trigger
SUBARRAY = 32
#: Standard Physics trigger with extended readout window
LONG_EVENT = 33

UNKNOWN = 255

Expand Down Expand Up @@ -919,6 +933,8 @@ class SimulationConfigContainer(Container):
class TelescopeTriggerContainer(Container):
default_prefix = ""
time = Field(NAN_TIME, description="Telescope trigger time")
event_type = Field(EventType.UNKNOWN, description="Event type")

n_trigger_pixels = Field(
-1, description="Number of trigger groups (sectors) listed"
)
Expand Down
40 changes: 37 additions & 3 deletions src/ctapipe/io/simteleventsource.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import enum
import warnings
from contextlib import nullcontext
from enum import Enum, auto, unique
from enum import Enum, IntFlag, auto, unique
from gzip import GzipFile
from io import BufferedReader
from pathlib import Path
Expand Down Expand Up @@ -103,6 +103,37 @@
_float32_nan = np.float32(np.nan)


class SimTelTriggerMask(IntFlag):
"""sim_telarray trigger type mask (teltrg_type_mask)."""

ANALOG_MAJORITY = auto()
ANALOG_SUM = auto()
DIGITAL_SUM = auto()
DIGITAL_MAJORITY = auto()
RESERVED4 = auto()
RESERVED5 = auto()
RESERVED6 = auto()
RESERVED7 = auto()
LONG_EVENT = auto()
MUON = auto()
RANDOM_MONO = auto()


def _trigger_mask_to_event_type(trigger_mask):
trigger_mask = SimTelTriggerMask(int(trigger_mask))

if SimTelTriggerMask.RANDOM_MONO in trigger_mask:
return EventType.RANDOM_MONO

if SimTelTriggerMask.MUON in trigger_mask:
return EventType.MUON

if SimTelTriggerMask.LONG_EVENT in trigger_mask:
return EventType.LONG_EVENT

return EventType.SUBARRAY


def _clip_altitude_if_close(altitude):
"""
Round absolute values slightly larger than pi/2 in float64 to pi/2
Expand Down Expand Up @@ -1143,8 +1174,10 @@ def _fill_trigger_info(self, array_event):
central_time = parse_simtel_time(trigger["gps_time"])

tel = Map(TelescopeTriggerContainer)
for tel_id, time in zip(
trigger["triggered_telescopes"], trigger["trigger_times"]
for tel_id, time, trigger_mask in zip(
trigger["triggered_telescopes"],
trigger["trigger_times"],
trigger["teltrg_type_mask"],
):
if self.allowed_tels and tel_id not in self.allowed_tels:
continue
Expand All @@ -1171,6 +1204,7 @@ def _fill_trigger_info(self, array_event):

tel[tel_id] = TelescopeTriggerContainer(
time=time,
event_type=_trigger_mask_to_event_type(trigger_mask),
n_trigger_pixels=n_trigger_pixels,
trigger_pixels=trigger_pixels,
)
Expand Down
Loading