index out of bounds workaround

This commit is contained in:
lars
2023-10-08 10:21:06 +02:00
parent e7b26da63f
commit 48c0391978
+22 -1
View File
@@ -2,6 +2,7 @@ from minicalo import GeometryDescriptor
from minicalo import G4System as _G4System
import plotly.graph_objects as go
import pandas as pd
import numpy as np
import os
import subprocess
@@ -26,7 +27,10 @@ class __G4System(_G4System):
# conversion from root to pandas dataframe
ttree = uproot.open("_1234567890_Hits.root")
df = ttree["Hits;1"].arrays(library="pd")
try:
df = ttree["Hits;1"].arrays(library="pd")
except:
df = index_out_of_bounds_workaround(ttree["Hits;1"])
return df
def displayEvent(self):
@@ -240,4 +244,21 @@ col_dict = {
"G4_BRASS": 'slategrey',
}
def index_out_of_bounds_workaround(tbranch):
# ugly workaround for index out of bounds error
dfs = []
entries = tbranch['sensor_energy'].num_entries
# check each entry
for entry in range(entries):
try:
df = tbranch.arrays(entry_start=entry,entry_stop=entry+1, library='pd')
dfs.append(df)
except:
continue
df = pd.concat(dfs)
return df.reset_index(drop=True)
G4System = __G4System()#singleton instance