unique filenames, circumvent Geant thread in filename, del root& save pkl
This commit is contained in:
+25
-2
@@ -5,8 +5,10 @@ import plotly.graph_objects as go
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import os
|
||||
import glob
|
||||
import subprocess
|
||||
import uproot
|
||||
import time
|
||||
|
||||
from IPython.display import Image, display
|
||||
|
||||
@@ -21,18 +23,39 @@ class __G4System(_G4System):
|
||||
minEnergy_GeV: float,
|
||||
maxEnergy_GeV: float = -1.0,
|
||||
):
|
||||
|
||||
if maxEnergy_GeV < 0:
|
||||
maxEnergy_GeV = minEnergy_GeV
|
||||
_G4System.run_batch(self, nEvents, particleSpec, minEnergy_GeV, maxEnergy_GeV)
|
||||
|
||||
# filename without file ending(!)
|
||||
filename = "_" + str(time.perf_counter_ns()) + ".root"
|
||||
_G4System.run_batch(self, nEvents, particleSpec, minEnergy_GeV, maxEnergy_GeV, filename=filename)
|
||||
|
||||
# TO FIX: Geant4 adds "t<threadnumber>" to the filename, circumvent this for one thread, but this is not a good solution
|
||||
file = glob.glob(filename.replace(".root", "*.root"))
|
||||
print(file)
|
||||
if len(file)>1:
|
||||
raise Exception("More than one file found! - Check mulithreading")
|
||||
else:
|
||||
filename = file[0]
|
||||
|
||||
# conversion from root to pandas dataframe
|
||||
ttree = uproot.open("_1234567890_Hits.root")
|
||||
|
||||
# TO FIX: circumvent index out of bounds error
|
||||
ttree = uproot.open(filename)
|
||||
try:
|
||||
df = ttree["Hits;1"].arrays(library="pd")
|
||||
except:
|
||||
df = index_out_of_bounds_workaround(ttree["Hits;1"])
|
||||
|
||||
# save to pickle and delete root file
|
||||
df.to_pickle(filename.replace(".root", ".pkl"))
|
||||
os.system("rm "+filename)
|
||||
|
||||
return df
|
||||
|
||||
|
||||
|
||||
def displayEvent(self, logE = False, renderer=None):
|
||||
# for loop over all layers
|
||||
to_plot = []
|
||||
|
||||
Reference in New Issue
Block a user