From 417053a583dcfa7f5593ca0391fee9c17f33fcdd Mon Sep 17 00:00:00 2001 From: lars Date: Thu, 28 Sep 2023 11:06:41 +0200 Subject: [PATCH] return dataframe in run_batch function --- Dockerfile | 6 +++-- bind/G4Calo.py | 62 ++++++++++++++++++++++++++++---------------------- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/Dockerfile b/Dockerfile index 436042d..0c28078 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,7 @@ RUN apt-get install -y dpkg-dev cmake g++ gcc binutils libx11-dev libxpm-dev lib #RUN python3 --version && python3 -m ensurepip RUN python3 -m pip install --upgrade pip -RUN python3 -m pip install pandas numpy matplotlib MarkupSafe wandb uproot setuptools +RUN python3 -m pip install pandas numpy matplotlib MarkupSafe wandb uproot setuptools awkward-pandas RUN python3 -m pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 # # # # GEANT @@ -82,5 +82,7 @@ RUN ln -s /usr/bin/python3 /usr/bin/python #finally the package ARG INCUBATOR_VER ADD minicalosim /root/minicalosim -RUN cd && cd minicalosim && mkdir build && cd build && cmake ../ && make -j4 &&\ +RUN cd && cd minicalosim && mkdir -p build && cd build && cmake ../ && make -j4 &&\ cp minicalo* ../bind/G4Calo.py /usr/local/lib/python3.8/dist-packages/ + + diff --git a/bind/G4Calo.py b/bind/G4Calo.py index 0c94120..3473b48 100644 --- a/bind/G4Calo.py +++ b/bind/G4Calo.py @@ -1,50 +1,58 @@ - from minicalo import ConstructionWrapper from minicalo import G4System as _G4System import os import subprocess +import uproot + from IPython.display import Image, display class G4System(_G4System): - - def run_visualize(self,particleSpec : str, minEnergy_GeV: float, maxEnergy_GeV:float = -1.): + def run_visualize( + self, particleSpec: str, minEnergy_GeV: float, maxEnergy_GeV: float = -1.0 + ): if maxEnergy_GeV < 0: maxEnergy_GeV = minEnergy_GeV - #anpassen: run 1 event and get stuff from construction wrapper + # anpassen: run 1 event and get stuff from construction wrapper _G4System.run_visualize(self, particleSpec, minEnergy_GeV, maxEnergy_GeV) self.displayEvent() - def run_batch(self, nEvents: int, particleSpec : str, minEnergy_GeV: float, - maxEnergy_GeV:float = -1., outputFile:str = "dataframe.df"): + def run_batch( + self, + nEvents: int, + particleSpec: str, + 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) - # here conversion from root to pandas dataframe + # conversion from root to pandas dataframe + ttree = uproot.open("_1234567890_Hits.root") + df = ttree["Hits;1"].arrays(library="pd") + return df def displayEvent(self): - f_to_conv = max(filter(lambda x: x.endswith(".prim"), os.listdir()), - key=os.path.getctime) + f_to_conv = max( + filter(lambda x: x.endswith(".prim"), os.listdir()), key=os.path.getctime + ) # Convert the .prim file to an eps graphic. - subprocess.run(["dawn", - "-d", - f_to_conv], - stderr=subprocess.DEVNULL) + subprocess.run(["dawn", "-d", f_to_conv], stderr=subprocess.DEVNULL) # Convert the eps graphic to png graphic. - subprocess.run(["gs", - "-DEPSCrop", "-dSAFER", "-sDEVICE=png256", - "-r600", - "-o", - "event_raw.png", - f_to_conv.replace(".prim", ".eps")], - stdout=subprocess.DEVNULL) - subprocess.run(["convert", - "event_raw.png", - "-trim", - "event.png" - ]) + subprocess.run( + [ + "gs", + "-DEPSCrop", + "-dSAFER", + "-sDEVICE=png256", + "-r600", + "-o", + "event_raw.png", + f_to_conv.replace(".prim", ".eps"), + ], + stdout=subprocess.DEVNULL, + ) + subprocess.run(["convert", "event_raw.png", "-trim", "event.png"]) display(Image("event.png", width=500)) - -