Skip to content

Commit

Permalink
Merge pull request #57 from cta-observatory/use_tib
Browse files Browse the repository at this point in the history
Use tib trigger if available by default
  • Loading branch information
maxnoe authored Feb 3, 2021
2 parents e9a8cfa + e61a88c commit 7633427
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
48 changes: 44 additions & 4 deletions ctapipe_io_lst/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from ctapipe.io import EventSource
from ctapipe.io.datalevels import DataLevel
from ctapipe.core.traits import Int, Bool, List, Float
from ctapipe.core.traits import Int, Bool, List, Float, Enum
from ctapipe.containers import PixelStatusContainer, EventType

from .containers import LSTArrayEventContainer, LSTServiceContainer
Expand Down Expand Up @@ -164,6 +164,17 @@ class LSTEventSource(EventSource):
),
).tag(config=True)

default_trigger_type = Enum(
['ucts', 'tib'], default_value='ucts',
help=(
'Default source for trigger type information.'
' For older data, tib might be the better choice but for data newer'
' than 2020-06-25, ucts is the preferred option. The source will still'
' fallback to the other device if the chosen default device is not '
' available'
)
).tag(config=True)

classes = [PointingSource, EventTimeCalculator, LSTR0Corrections]

def __init__(self, input_url=None, **kwargs):
Expand Down Expand Up @@ -314,7 +325,7 @@ def _generator(self):
self.fill_lst_event_container(array_event, zfits_event)

# fill trigger info (needs r0 and lst specifics)
self.fill_trigger_info(array_event, zfits_event)
self.fill_trigger_info(array_event)

# fill general monitoring data
self.fill_mon_container(array_event, zfits_event)
Expand Down Expand Up @@ -469,15 +480,44 @@ def fill_lst_event_container(self, array_event, zfits_event):
lst_evt.drs_tag_status = zfits_event.lstcam.drs_tag_status
lst_evt.drs_tag = zfits_event.lstcam.drs_tag

def fill_trigger_info(self, array_event, zfits_event):
def fill_trigger_info(self, array_event):
tel_id = self.tel_id

trigger = array_event.trigger
trigger.time = self.time_calculator(tel_id, array_event)
trigger.tels_with_trigger = [tel_id]
trigger.tel[tel_id].time = trigger.time

trigger_bits = array_event.lst.tel[tel_id].evt.ucts_trigger_type
lst = array_event.lst.tel[tel_id]
tib_available = lst.evt.extdevices_presence & 1
ucts_available = lst.evt.extdevices_presence & 2

# decide which source to use, if both are available,
# the option decides, if not, fallback to the avilable source
# if no source available, warn and do not fill trigger info
if tib_available and ucts_available:
if self.default_trigger_type == 'ucts':
trigger_bits = lst.evt.ucts_trigger_type
else:
trigger_bits = lst.evt.tib_masked_trigger

elif tib_available:
trigger_bits = lst.evt.tib_masked_trigger

elif ucts_available:
trigger_bits = lst.evt.ucts_trigger_type

else:
self.log.warning('No trigger info available.')
return

if ucts_available and lst.evt.ucts_trigger_type == 42:
self.log.warning(
'Event with UCTS trigger_type 42 found.'
' Probably means unreliable or shifted UCTS data.'
' Consider switching to TIB using `default_trigger_type="tib"`'
)

# first bit mono trigger, second stereo.
# If *only* those two are set, we assume it's a physics event
# for all other we only check if the flag is present
Expand Down
11 changes: 6 additions & 5 deletions ctapipe_io_lst/event_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ def __call__(self, tel_id, event):
# data comes in random module order, svc contains actual order
central_module_index = np.where(lst.svc.module_ids == CENTRAL_MODULE)[0][0]

tib_available = lst.evt.extdevices_presence & 1
ucts_available = lst.evt.extdevices_presence & 2

if self._has_reference[tel_id]:
# Dragon/TIB timestamps based on a valid absolute reference UCTS timestamp
dragon_time = calc_dragon_time(
Expand All @@ -168,8 +171,7 @@ def __call__(self, tel_id, event):
reference=1e-9 * (self._ucts_t0_tib[tel_id] - self._tib_counter0[tel_id])
)

if lst.evt.extdevices_presence & 2:
# UCTS presence flag is OK
if ucts_available:
ucts_timestamp = lst.evt.ucts_timestamp
ucts_time = ucts_timestamp * 1e-9
else:
Expand All @@ -178,7 +180,7 @@ def __call__(self, tel_id, event):

# first event and values not passed
else:
if not lst.evt.extdevices_presence & 2:
if not ucts_available:
raise ValueError(
'Timestamp reference should be extracted from first event'
' but UCTS not available'
Expand All @@ -198,7 +200,7 @@ def __call__(self, tel_id, event):
f' dragon_counter: {initial_dragon_counter}'
)

if not lst.evt.extdevices_presence & 1 and self.timestamp == 'tib':
if not tib_available and self.timestamp == 'tib':
raise ValueError(
'TIB is selected for timestamp, no external reference given'
' and first event has not TIB info'
Expand Down Expand Up @@ -254,7 +256,6 @@ def __call__(self, tel_id, event):
ucts_trigger_type = self.previous_ucts_trigger_types[tel_id].popleft()
ucts_time = ucts_timestamp * 1e-9


lst.evt.ucts_trigger_type = ucts_trigger_type
lst.evt.ucts_timestamp = ucts_timestamp

Expand Down
2 changes: 1 addition & 1 deletion ctapipe_io_lst/tests/test_stage1.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_stage1(tmpdir):
'dragon_counter0': int(run_info['dragon_counter0']),
'ucts_t0_tib': int(run_info['ucts_t0_tib']),
'tib_counter0': int(run_info['tib_counter0']),
}
},
},
"CameraCalibrator": {
"image_extractor_type": "LocalPeakWindowSum",
Expand Down

0 comments on commit 7633427

Please sign in to comment.