Skip to content

Commit

Permalink
Merge pull request #134 from cta-observatory/negative_jumps
Browse files Browse the repository at this point in the history
Do not treat negative differences of ucts - dragon time as jump, fixes #133
  • Loading branch information
maxnoe authored Dec 21, 2021
2 parents 4f7d966 + 6e199a8 commit bf82b2f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions ctapipe_io_lst/event_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ def module_id_to_index(expected_module_ids, module_id):
return np.where(expected_module_ids == module_id)[0][0]


def abs_diff(a, b):
return max(a, b) - min(a, b)
def uint64_diff(a, b):
'''Calculate the diff of two uint64 numbers without risking underflow'''
if a > b:
return (a - b).astype(np.int64)
else:
return -(b - a).astype(np.int64)


class EventTimeCalculator(TelescopeComponent):
Expand Down Expand Up @@ -359,11 +363,20 @@ def __call__(self, tel_id, event):
# event rate), and set its ucts_trigger_type to -1,
# which will tell us a jump happened and hence this
# event does not have proper UCTS info.
delta = abs_diff(ucts_timestamp, dragon_timestamp)
delta = uint64_diff(ucts_timestamp, dragon_timestamp)
if delta < -1e3:
self.log.warning(
f'Found dragon time much ahead of ucts time in event {event.index.event_id}'
f', dragon time: {dragon_timestamp:d}'
f', ucts time: {ucts_timestamp:d}'
f', delta: {delta / 1000:.0f} µs'
)

if delta > 1e3:
self.log.warning(
f'Found UCTS jump in event {event.index.event_id}'
f', dragon time: {dragon_timestamp:d}'
f', ucts time: {ucts_timestamp:d}'
f', delta: {delta / 1000:.0f} µs'
)
self.previous_ucts_timestamps[tel_id].appendleft(ucts_timestamp)
Expand Down

0 comments on commit bf82b2f

Please sign in to comment.