Skip to content

Commit

Permalink
Merge pull request #193 from cta-observatory/event_head_trigger_v3
Browse files Browse the repository at this point in the history
Event head and trigger v3
  • Loading branch information
maxnoe authored Oct 1, 2019
2 parents 2ed9da5 + 46082f1 commit dac1150
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
2 changes: 1 addition & 1 deletion eventio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .histograms import Histograms


__version__ = '0.21.3'
__version__ = '0.21.4'

__all__ = [
'EventIOFile',
Expand Down
23 changes: 19 additions & 4 deletions eventio/simtel/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,8 @@ def __str__(self):
)

def parse(self):
assert_max_version(self, 2)
assert_max_version(self, 3)

self.seek(0)
byte_stream = BytesIO(self.read())

Expand All @@ -544,7 +545,8 @@ def parse(self):
event_info['trigger_pattern'] = read_int(byte_stream)
event_info['data_pattern'] = read_int(byte_stream)

if self.header.version >= 1:
version = self.header.version
if version >= 1:
tels_trigger = read_short(byte_stream)
event_info['n_triggered_telescopes'] = tels_trigger

Expand All @@ -560,7 +562,7 @@ def parse(self):
byte_stream, count=tels_data, dtype='<i2'
)

if self.header.version >= 2:
if version >= 2:
# konrad saves the trigger mask as crazy int, but it uses only 4 bits
# so it should be indentical to a normal unsigned int with 1 byte
event_info['teltrg_type_mask'] = read_array(
Expand All @@ -579,6 +581,14 @@ def parse(self):
t = read_float(byte_stream)
event_info['teltrg_time_by_type'][tel_id][trigger] = t

if version >= 3:
# information about "plane wavefront compensation"
comp = {}
comp['az'] = read_float(byte_stream)
comp['alt'] = read_float(byte_stream)
comp['speed_of_light'] = read_float(byte_stream)
event_info['plane_wavefront_compensation'] = comp

return event_info


Expand Down Expand Up @@ -698,7 +708,7 @@ def __str__(self):
)

def parse(self):
assert_max_version(self, 2)
assert_max_version(self, 3)
self.seek(0)
byte_stream = BytesIO(self.read())

Expand Down Expand Up @@ -749,6 +759,11 @@ def parse(self):
)
pos += length

if self.header.version >= 3:
times = struct.unpack('ff', data[pos:pos + 8])
pos += 8
event_head['readout_time'], event_head['relative_trigger_time'] = times

event_head['telescope_id'] = self.header.id
return event_head

Expand Down
23 changes: 20 additions & 3 deletions tests/simtel/test_simtel_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_2003_v2():
# print(pixel_id, sector)


def test_2004_3_objects():
def test_2004():
from eventio.simtel.objects import PixelSettings

with EventIOFile(prod2_file) as f:
Expand Down Expand Up @@ -245,7 +245,7 @@ def test_2008_3_objects():
assert tracking_info['range_high_alt'] == approx(2 * np.pi)


def test_2009_3_objects():
def test_2009():
from eventio.simtel.objects import TriggerInformation

with EventIOFile(prod2_file) as f:
Expand All @@ -255,6 +255,17 @@ def test_2009_3_objects():
assert 'gps_time' in data
assert 'teltrg_time_by_type' in data

with EventIOFile('tests/resources/prod4_pixelsettings_v3.gz') as f:
for o in yield_n_and_assert(f, TriggerInformation, n=10):
assert o.header.version == 3

data = parse_and_assert_consumption(o, limit=3)
assert 'plane_wavefront_compensation' in data
comp = data['plane_wavefront_compensation']
assert comp['az'] == 0
assert comp['alt'] == np.float32(np.pi / 2)
assert comp['speed_of_light'] == approx(29.97, abs=0.01)


def test_2100_3_objects():
from eventio.simtel.objects import TrackingPosition
Expand Down Expand Up @@ -288,7 +299,7 @@ def test_2010():
assert n_events > 0


def test_2011_3_objects():
def test_2011():
from eventio.simtel.objects import TelescopeEventHeader

with EventIOFile(prod2_file) as f:
Expand Down Expand Up @@ -358,6 +369,12 @@ def test_2011_3_objects():
}
'''

with EventIOFile('tests/resources/prod4_pixelsettings_v3.gz') as f:
for i, o in enumerate(yield_n_and_assert(f, TelescopeEventHeader, n=10)):
o = parse_and_assert_consumption(o, limit=3)
assert 'relative_trigger_time' in o
assert 'readout_time' in o


def test_2012_3_objects():
from eventio.simtel.objects import ADCSums
Expand Down
8 changes: 8 additions & 0 deletions tests/simtel/test_simtelfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,11 @@ def test_skip_calibration_events():
def test_frankenstein():
with SimTelFile(frankenstein_path) as f:
assert len(f.telescope_descriptions) == f.n_telescopes


def test_new_prod4():
with SimTelFile('tests/resources/prod4_pixelsettings_v3.gz') as f:
i = 0
for e in f:
i += 1
assert i == 10

0 comments on commit dac1150

Please sign in to comment.