Merge branch 'main' of gitlab.etp.kit.edu:jkiesele/minicalosim

This commit is contained in:
lars
2023-10-07 15:31:02 +02:00
15 changed files with 110 additions and 1059 deletions
+9 -14
View File
@@ -1,4 +1,4 @@
from minicalo import ConstructionWrapper
from minicalo import GeometryDescriptor
from minicalo import G4System as _G4System
import plotly.graph_objects as go
@@ -10,15 +10,8 @@ import uproot
from IPython.display import Image, display
class G4System(_G4System):
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
_G4System.run_visualize(self, particleSpec, minEnergy_GeV, maxEnergy_GeV)
self.displayEvent()
class __G4System(_G4System):
def run_batch(
self,
@@ -36,7 +29,7 @@ class G4System(_G4System):
df = ttree["Hits;1"].arrays(library="pd")
return df
def displayEvent(self, gd):
def displayEvent(self):
# for loop over all layers
to_plot = []
material_dict = {}
@@ -44,7 +37,7 @@ class G4System(_G4System):
# sum up total deposited energy
total_dep_energy = 0
for layer in gd.getLayers():
for layer in self.getGeometryDescriptor().getLayers():
for sensor in layer.sensors:
total_dep_energy += sensor.getEnergy()
@@ -53,7 +46,7 @@ class G4System(_G4System):
total_dep_energy = 10**-8 # to avoid division by zero
# loop over materials
for layer in gd.getLayers():
for layer in self.getGeometryDescriptor().getLayers():
layer_width = layer.nx * layer.sens_xwidth
@@ -245,4 +238,6 @@ col_dict = {
"G4_W": 'grey',
"G4_Cu": 'dimgray',
"G4_BRASS": 'slategrey',
}
}
G4System = __G4System()#singleton instance
+13 -11
View File
@@ -3,22 +3,23 @@
#include <pybind11/stl.h>
#include <pybind11/operators.h>
#include "ConstructionWrapper.hh"
#include "GeometryDescriptor.hh"
#include "G4System.hh"
namespace py = pybind11;
template<class M>
void makeConstructionWrapper(M & m, std::string name){
void makeGeometryDescriptor(M & m, std::string name){
py::class_<ConstructionWrapper>(m, name.data()).def(py::init())
.def("addLayer", &ConstructionWrapper::addLayer, py::arg("thickness"), py::arg("material"), py::arg("isActive")=true, py::arg("nx")=1, py::arg("ny")=-1)
.def("getXYWidth", &ConstructionWrapper::getXYWidth)
py::class_<GeometryDescriptor>(m, name.data()).def(py::init())
.def("addLayer", &GeometryDescriptor::addLayer, py::arg("thickness"), py::arg("material"), py::arg("isActive")=true, py::arg("nx")=1, py::arg("ny")=-1)
.def("getXYWidth", &GeometryDescriptor::getXYWidth)
// bind overloaded getLayers function
.def("getLayers", (std::vector<Layer> & (ConstructionWrapper::*)()) &ConstructionWrapper::getLayers)
.def("getLayers", (const std::vector<Layer> & (ConstructionWrapper::*)() const) &ConstructionWrapper::getLayers)
.def("getNSensors", &ConstructionWrapper::getNSensors);
.def("getLayers", (std::vector<Layer> & (GeometryDescriptor::*)()) &GeometryDescriptor::getLayers)
.def("getLayers", (const std::vector<Layer> & (GeometryDescriptor::*)() const) &GeometryDescriptor::getLayers)
.def("isAssigned", &GeometryDescriptor::isAssigned)
.def("getNSensors", &GeometryDescriptor::getNSensors);
}
@@ -31,8 +32,9 @@ void makeG4System(M &m, std::string name)
.def("run_gui", &G4System::run_gui).def("run_batch", &G4System::run_batch, py::arg("nEvents"), py::arg("partSpecies"), py::arg("minEnergy_GeV"), py::arg("maxEnergy_GeV"))
.def("applyUICommand", &G4System::applyUICommand, py::arg("command"))
.def("displayEvent", &G4System::displayEvent)
.def("printMaterial", &G4System::printMaterial, py::arg("name"))
.def("check", &G4System::check);
// .def("printMaterial", &G4System::printMaterial, py::arg("name"))
//.def("check", &G4System::check)
.def("getGeometryDescriptor", &G4System::getGeometryDescriptor);
}
// create bindings for Layer class
@@ -69,7 +71,7 @@ void makeSensor(M &m, std::string name){
PYBIND11_MODULE(minicalo, m)
{
m.doc() = "pybind11 plugin"; // optional module docstring
makeConstructionWrapper(m, "ConstructionWrapper");
makeGeometryDescriptor(m, "GeometryDescriptor");
makeG4System(m, "G4System");
makeSensor(m, "Sensor");
makeLayer(m, "Layer");
+7 -978
View File
File diff suppressed because one or more lines are too long
+6 -6
View File
@@ -1,14 +1,14 @@
from G4Calo import ConstructionWrapper, G4System
from G4Calo import GeometryDescriptor, G4System
cw = ConstructionWrapper()#the width of the calorimeter is 50 cm times 50 cm (also steerable, but I'd leave it)
cw = GeometryDescriptor()#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
G4s = G4System()
G4s.init(cw)
G4s.run_batch(100, "gamma", 1, 5) #100 events, photons, 1000 MeV to 5000 MeV
G4System = G4System
G4System.init(cw)
G4System.run_batch(100, "gamma", 1, 5) #100 events, photons, 1000 MeV to 5000 MeV
#G4s.run_visualize("gamma", 1, 5)
G4s.printMaterial("G4_Pb")
G4System.printMaterial("G4_Pb")