Files
minicalosim/bind/G4Calo.py
T
Jan Kieseler 37d5b1eb3e towards vis
2023-09-11 08:33:19 +02:00

42 lines
1.3 KiB
Python

from minicalo import ConstructionWrapper
from minicalo import G4System as _G4System
import os
import subprocess
from IPython.display import Image, display
class G4System(_G4System):
def run_visualize(self,particleSpec : str, minEnergy: float, maxEnergy:float = -1.):
if maxEnergy < 0:
maxEnergy = minEnergy
super(G4System).run_visualize(particleSpec, minEnergy, maxEnergy)
self.displayEvent()
def displayEvent(self):
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)
# 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"
])
display(Image("event.png", width=500))