towards vis

This commit is contained in:
Jan Kieseler
2023-09-11 08:33:19 +02:00
parent b456e07018
commit 37d5b1eb3e
7 changed files with 212 additions and 109 deletions
+41
View File
@@ -0,0 +1,41 @@
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))
+9 -8
View File
@@ -4,7 +4,7 @@
#include <pybind11/operators.h>
#include "ConstructionWrapper.hh"
#include "SystemBuilder.hh"
#include "G4System.hh"
namespace py = pybind11;
@@ -17,16 +17,17 @@ void makeConstructionWrapper(M & m, std::string name){
}
template<class M>
void makeSystemBuilder(M& m, std::string name){
py::class_<SystemBuilder>(m, name.data()).def(py::init())
.def("init", &SystemBuilder::init, py::arg("cw"), py::arg("gui")=false)
.def("run_gui", &SystemBuilder::run_gui)
.def("run_batch", &SystemBuilder::run_batch, py::arg("nEvents"), py::arg("partSpecies"), py::arg("minEnergy"), py::arg("maxEnergy"))
.def("visualize", &SystemBuilder::visualize);
void makeG4System(M& m, std::string name){
py::class_<G4System>(m, name.data()).def(py::init())
.def("init", &G4System::init, py::arg("cw"), py::arg("gui")=false)
.def("run_gui", &G4System::run_gui)
.def("run_batch", &G4System::run_batch, py::arg("nEvents"), py::arg("partSpecies"), py::arg("minEnergy"), py::arg("maxEnergy"))
.def("run_visualize", &G4System::run_visualize, py::arg("partSpecies"), py::arg("minEnergy"), py::arg("maxEnergy"))
.def("applyUICommand", &G4System::applyUICommand, py::arg("command"));
}
PYBIND11_MODULE(minicalo, m) {
m.doc() = "pybind11 plugin"; // optional module docstring
makeConstructionWrapper(m, "ConstructionWrapper");
makeSystemBuilder(m, "SystemBuilder");
makeG4System(m, "G4System");
}
+7 -7
View File
@@ -1,11 +1,11 @@
from minicalo import ConstructionWrapper, SystemBuilder
from G4Calo import ConstructionWrapper, G4System
cw = ConstructionWrapper()
cw.addLayer(10,"G4_Si",True)
cw.addLayer(1,"G4_Pb",False)
cw.addLayer(10,"G4_Si",False)
cw = ConstructionWrapper()#the width of the calorimeter is 50 cm times 50 cm (also steerable, but I'd leave it)
cw.addLayer(10,"G4_Si",True) #10 cm of Silicon, active
cw.addLayer(1,"G4_Pb",False) #1 cm of Lead, passive
cw.addLayer(10,"G4_Si",True, 3) #10 cm of Silicon, active, 3x3 segmentation
sb = SystemBuilder()
sb = G4System()
sb.init(cw)
sb.run_batch(100, "gamma", 1000, 5000)
sb.run_batch(100, "gamma", 1000, 5000) #100 events, photons, 1000 MeV to 5000 MeV