Skip to content

Commit ddfed5d

Browse files
authored
Merge pull request #295 from zhipzhang/split_always_mode
Add support for split-always mode event handling in IACTFile
2 parents 213d821 + 6c4c557 commit ddfed5d

File tree

4 files changed

+59
-12
lines changed

4 files changed

+59
-12
lines changed

src/eventio/iact/__init__.py

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
RunEnd,
1919
Longitudinal,
2020
InputCard,
21+
TelescopeArrayHead,
22+
TelescopeArrayEnd,
2123
AtmosphericProfile,
2224
)
2325

@@ -43,6 +45,8 @@
4345
'RunEnd',
4446
'Longitudinal',
4547
'InputCard',
48+
'TelescopeArrayHead',
49+
'TelescopeArrayEnd',
4650
'AtmosphericProfile',
4751
]
4852

@@ -80,6 +84,18 @@ class IACTFile(EventIOFile):
8084
EventEnd
8185
8286
RunEnd
87+
88+
For Split-Always mode, the structure is slightly different:
89+
For each Event:
90+
EventHeader
91+
ArrayOffsets
92+
Longitudinal (optional)
93+
For each reuse:
94+
TelescopeArrayHead
95+
For each Telescopes:
96+
Photons
97+
TelescopeArrayEnd
98+
EventEnd
8399
'''
84100

85101
def __init__(self, path, zcat=True):
@@ -140,7 +156,7 @@ def __iter__(self):
140156

141157
obj = next(self)
142158

143-
while not isinstance(obj, TelescopeData):
159+
while not isinstance(obj, (TelescopeData, TelescopeArrayHead)):
144160
if isinstance(obj, Longitudinal):
145161
longitudinal = obj.parse()
146162

@@ -152,22 +168,34 @@ def __iter__(self):
152168

153169
obj = next(self)
154170

155-
for reuse in range(n_reuses):
156-
157-
check_type(obj, TelescopeData)
158-
telescope_data_obj = obj
171+
split_always = isinstance(obj, TelescopeArrayHead)
172+
if split_always:
173+
obj = next(self)
159174

175+
for reuse in range(n_reuses):
160176
photon_bunches = {}
161177
emitter_bunches = {}
162178
n_photons = {}
163179
n_bunches = {}
164-
for data in telescope_data_obj:
165-
if isinstance(data, Photons):
166-
photons, emitter = data.parse()
167-
photon_bunches[data.telescope] = photons
168-
emitter_bunches[data.telescope] = emitter
169-
n_photons[data.telescope] = data.n_photons
170-
n_bunches[data.telescope] = data.n_bunches
180+
if split_always:
181+
while not isinstance(obj, TelescopeArrayEnd):
182+
check_type(obj, Photons)
183+
photons, emitter = obj.parse()
184+
photon_bunches[obj.telescope] = photons
185+
emitter_bunches[obj.telescope] = emitter
186+
n_photons[obj.telescope] = obj.n_photons
187+
n_bunches[obj.telescope] = obj.n_bunches
188+
obj = next(self)
189+
else:
190+
check_type(obj, TelescopeData)
191+
telescope_data_obj = obj
192+
for data in telescope_data_obj:
193+
if isinstance(data, Photons):
194+
photons, emitter = data.parse()
195+
photon_bunches[data.telescope] = photons
196+
emitter_bunches[data.telescope] = emitter
197+
n_photons[data.telescope] = data.n_photons
198+
n_bunches[data.telescope] = data.n_bunches
171199

172200
if len(array_offsets.dtype) == 3:
173201
weight = array_offsets[reuse]['weight']

src/eventio/iact/objects.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
'RunEnd',
3333
'Longitudinal',
3434
'InputCard',
35+
'MarkersBegin',
36+
'MakersEnd',
3537
]
3638

3739

@@ -412,6 +414,13 @@ def parse(self):
412414
input_card += b'\n'
413415
return input_card
414416

417+
class TelescopeArrayHead(EventIOObject):
418+
"""This Object is just a marker to indcate the beginning of separate telescope data."""
419+
eventio_type = 1213
420+
421+
class TelescopeArrayEnd(EventIOObject):
422+
"""This Object is just a marker to indcate the end of separate telescope data."""
423+
eventio_type = 1214
415424

416425
class AtmosphericProfile(EventIOObject):
417426
''' This Object contains the CORSIKA/atmext atmospheric profile '''

tests/iact/test_iact_file.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
testfile_reuse = 'tests/resources/3_gammas_reuse_5.dat'
88
testfile_two_telescopes = 'tests/resources/two_telescopes.dat'
99
testfile_zstd = 'tests/resources/run102_gamma_za20deg_azm0deg-paranal-sst.corsika.zst'
10+
testfile_split_always = 'tests/resources/5_gamma_2_telescopes_split_always.zst'
1011

1112

1213
def test_file_open():
@@ -135,3 +136,12 @@ def test_event_with_reuse():
135136
for i, e in enumerate(f):
136137
assert e.event_number == i // 5 + 1
137138
assert e.reuse == (i % 5) + 1
139+
140+
141+
def test_event_split_always():
142+
with eventio.IACTFile(testfile_split_always) as f:
143+
event = next(iter(f))
144+
assert event.header['zenith'] == approx(20.0/ 180 * 3.14159)
145+
assert event.header['azimuth'] == approx(0.0)
146+
assert event.header['total_energy'] == approx(50)
147+
assert len(event.photon_bunches) == 2
Binary file not shown.

0 commit comments

Comments
 (0)