Skip to content

Commit fba43a5

Browse files
committed
Catching MuonGun error
1 parent 9cc3a70 commit fba43a5

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/graphnet/data/extractors/icecube/i3calorimetry.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def __call__(self, frame: "icetray.I3Frame") -> Dict[str, Any]:
138138
)
139139

140140
# Check only in the case that there were primaries
141-
if not len(primaries) == 0:
141+
if not len(primaries) == 0 and (not np.isnan(e_total)):
142142

143143
# total energy should always be less than the primary energy
144144
assert e_total <= (
@@ -220,8 +220,25 @@ def get_energies(
220220
track.pos, track.dir
221221
)
222222
# Get the corresponding energies
223-
e0 = track.get_energy(intersections.first)
224-
e1 = track.get_energy(intersections.second)
223+
try:
224+
e0 = track.get_energy(intersections.first)
225+
e1 = track.get_energy(intersections.second)
226+
227+
# Catch MuonGun errors
228+
except RuntimeError as e:
229+
if (
230+
"sum of losses is smaller than "
231+
"energy at last checkpoint" in str(e)
232+
):
233+
hdr = frame["I3EventHeader"]
234+
e.add_note(f"Error in MuonGun track in event {hdr}")
235+
print(f"Skipping bad event {hdr}: {e}")
236+
e0 = np.nan
237+
e1 = np.nan
238+
e_dep_cascade = np.nan
239+
continue # skip this frame
240+
else:
241+
raise # re-raise unexpected errors
225242

226243
e_dep_track += e0 - e1
227244
e_ent_track += e0

0 commit comments

Comments
 (0)