From 34a030560165154530d16978da3ece905f34e003 Mon Sep 17 00:00:00 2001 From: Jan Kieseler Date: Sat, 7 Oct 2023 11:10:57 +0200 Subject: [PATCH 1/3] fixed a few little things --- bind/G4Calo.py | 8 +++++--- bind/bindings.cpp | 7 ++++--- bind/example.py | 8 ++++---- include/ConstructionWrapper.hh | 11 +++++++++++ include/G4System.hh | 12 ++++++++++-- src/G4System.cc | 9 +++++---- 6 files changed, 39 insertions(+), 16 deletions(-) diff --git a/bind/G4Calo.py b/bind/G4Calo.py index 3907630..c85d654 100644 --- a/bind/G4Calo.py +++ b/bind/G4Calo.py @@ -10,7 +10,7 @@ import uproot from IPython.display import Image, display -class G4System(_G4System): +class __G4System(_G4System): def run_visualize( self, particleSpec: str, minEnergy_GeV: float, maxEnergy_GeV: float = -1.0 ): @@ -47,7 +47,7 @@ class G4System(_G4System): z0=0 # loop over materials - for layer_i, layer in enumerate(self.cw.getLayers()): + for layer_i, layer in enumerate(self.getConstructionWrapper().getLayers()): #layer_i = len(self.cw.getLayers()) - layer_i -1 print(layer_i) @@ -241,4 +241,6 @@ col_dict = { "G4_W": 'grey', "G4_Cu": 'dimgray', "G4_BRASS": 'slategrey', -} \ No newline at end of file +} + +G4System = __G4System()#singleton instance \ No newline at end of file diff --git a/bind/bindings.cpp b/bind/bindings.cpp index 304eaa3..1e8784d 100644 --- a/bind/bindings.cpp +++ b/bind/bindings.cpp @@ -18,6 +18,7 @@ void makeConstructionWrapper(M & m, std::string name){ // bind overloaded getLayers function .def("getLayers", (std::vector & (ConstructionWrapper::*)()) &ConstructionWrapper::getLayers) .def("getLayers", (const std::vector & (ConstructionWrapper::*)() const) &ConstructionWrapper::getLayers) + .def("isAssigned", &ConstructionWrapper::isAssigned) .def("getNSensors", &ConstructionWrapper::getNSensors); } @@ -31,9 +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_readwrite("cw", &G4System::cw); + // .def("printMaterial", &G4System::printMaterial, py::arg("name")) + //.def("check", &G4System::check) + .def("getConstructionWrapper", &G4System::getConstructionWrapper); } diff --git a/bind/example.py b/bind/example.py index cf3e907..26d9176 100644 --- a/bind/example.py +++ b/bind/example.py @@ -6,9 +6,9 @@ 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") \ No newline at end of file +G4System.printMaterial("G4_Pb") \ No newline at end of file diff --git a/include/ConstructionWrapper.hh b/include/ConstructionWrapper.hh index 0ad2378..067d374 100644 --- a/include/ConstructionWrapper.hh +++ b/include/ConstructionWrapper.hh @@ -43,6 +43,11 @@ public: void setIsActive(bool isActive); void assignPhysicalVolume(G4VPhysicalVolume* physicalVolume); + void unAssign(){ + physicalVolume = nullptr; + sensors.clear(); + } + double thickness; double sens_xwidth; double sens_ywidth; @@ -99,6 +104,12 @@ public: } } + void unAssign(){ + for(auto& layer: layers){ + layer.unAssign(); + } + } + private: double xywidth; diff --git a/include/G4System.hh b/include/G4System.hh index 9f59b67..aa34389 100644 --- a/include/G4System.hh +++ b/include/G4System.hh @@ -28,6 +28,7 @@ G4System(bool Gui=false):gui(Gui){}; delete runManager; delete ui; } + }; @@ -43,15 +44,22 @@ void applyUICommand(const std::string& command){ UImanager->ApplyCommand(command); } -ConstructionWrapper cw; - void displayEvent()const{}; //just a placeholder, this will be implemented in python void printMaterial(const std::string& name)const; +ConstructionWrapper& getConstructionWrapper(){ + check(); + if ( assigned_cw == nullptr ){ + throw std::runtime_error("ConstructionWrapper not assigned"); + } + return *assigned_cw; +} + private: void check()const; +ConstructionWrapper * assigned_cw=nullptr; bool gui; diff --git a/src/G4System.cc b/src/G4System.cc index 2e82f0b..b86d2e4 100644 --- a/src/G4System.cc +++ b/src/G4System.cc @@ -9,6 +9,11 @@ void G4System::init(ConstructionWrapper &CW){ if(CW.isAssigned()){ throw std::runtime_error("ConstructionWrapper already assigned"); } + if(assigned_cw != nullptr){ + //reassign + assigned_cw->unAssign(); + } + assigned_cw = &CW; char* argv[]={(char*)"dummy"}; @@ -33,10 +38,6 @@ void G4System::init(ConstructionWrapper &CW){ //delete actionInitialization; } - // save layers of CW to G4System class - G4System::cw = CW; - - G4String session; ui = nullptr; if ( gui ) { From 51001d1b592cef72bf3624ba82be624a5ff9ae23 Mon Sep 17 00:00:00 2001 From: Jan Kieseler Date: Sat, 7 Oct 2023 11:14:45 +0200 Subject: [PATCH 2/3] renamed --- bind/G4Calo.py | 4 ++-- bind/bindings.cpp | 22 ++++++++--------- bind/example.ipynb | 4 ++-- bind/example.py | 4 ++-- exampleB4a.cc | 12 +++++----- include/DetectorConstruction.hh | 12 +++++----- include/EventAction.hh | 2 +- include/G4System.hh | 14 +++++------ ...uctionWrapper.hh => GeometryDescriptor.hh} | 10 ++++---- include/SteppingAction.hh | 2 +- src/DetectorConstruction.cc | 2 +- src/EventAction.cc | 10 ++++---- src/G4System.cc | 6 ++--- ...uctionWrapper.cc => GeometryDescriptor.cc} | 24 +++++++++---------- src/SteppingAction.cc | 10 ++++---- 15 files changed, 69 insertions(+), 69 deletions(-) rename include/{ConstructionWrapper.hh => GeometryDescriptor.hh} (92%) rename src/{ConstructionWrapper.cc => GeometryDescriptor.cc} (73%) diff --git a/bind/G4Calo.py b/bind/G4Calo.py index c85d654..fe193fa 100644 --- a/bind/G4Calo.py +++ b/bind/G4Calo.py @@ -1,4 +1,4 @@ -from minicalo import ConstructionWrapper +from minicalo import GeometryDescriptor from minicalo import G4System as _G4System import plotly.graph_objects as go @@ -47,7 +47,7 @@ class __G4System(_G4System): z0=0 # loop over materials - for layer_i, layer in enumerate(self.getConstructionWrapper().getLayers()): + for layer_i, layer in enumerate(self.getGeometryDescriptor().getLayers()): #layer_i = len(self.cw.getLayers()) - layer_i -1 print(layer_i) diff --git a/bind/bindings.cpp b/bind/bindings.cpp index 1e8784d..1b7f927 100644 --- a/bind/bindings.cpp +++ b/bind/bindings.cpp @@ -3,23 +3,23 @@ #include #include -#include "ConstructionWrapper.hh" +#include "GeometryDescriptor.hh" #include "G4System.hh" namespace py = pybind11; template -void makeConstructionWrapper(M & m, std::string name){ +void makeGeometryDescriptor(M & m, std::string name){ - py::class_(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_(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 & (ConstructionWrapper::*)()) &ConstructionWrapper::getLayers) - .def("getLayers", (const std::vector & (ConstructionWrapper::*)() const) &ConstructionWrapper::getLayers) - .def("isAssigned", &ConstructionWrapper::isAssigned) - .def("getNSensors", &ConstructionWrapper::getNSensors); + .def("getLayers", (std::vector & (GeometryDescriptor::*)()) &GeometryDescriptor::getLayers) + .def("getLayers", (const std::vector & (GeometryDescriptor::*)() const) &GeometryDescriptor::getLayers) + .def("isAssigned", &GeometryDescriptor::isAssigned) + .def("getNSensors", &GeometryDescriptor::getNSensors); } @@ -34,7 +34,7 @@ void makeG4System(M &m, std::string name) .def("displayEvent", &G4System::displayEvent) // .def("printMaterial", &G4System::printMaterial, py::arg("name")) //.def("check", &G4System::check) - .def("getConstructionWrapper", &G4System::getConstructionWrapper); + .def("getGeometryDescriptor", &G4System::getGeometryDescriptor); } @@ -66,7 +66,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"); diff --git a/bind/example.ipynb b/bind/example.ipynb index ebc324e..3ddf57c 100644 --- a/bind/example.ipynb +++ b/bind/example.ipynb @@ -977,9 +977,9 @@ } ], "source": [ - "from G4Calo import ConstructionWrapper, G4System\n", + "from G4Calo import GeometryDescriptor, G4System\n", "\n", - "cw = ConstructionWrapper() #the width of the calorimeter is 50 cm times 50 cm (also steerable, but I'd leave it)\n", + "cw = GeometryDescriptor() #the width of the calorimeter is 50 cm times 50 cm (also steerable, but I'd leave it)\n", "\n", "cw.addLayer(3,\"G4_Si\",True, 7)\n", "cw.addLayer(4,\"G4_Pb\",False) \n", diff --git a/bind/example.py b/bind/example.py index 26d9176..aa373b1 100644 --- a/bind/example.py +++ b/bind/example.py @@ -1,7 +1,7 @@ -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 diff --git a/exampleB4a.cc b/exampleB4a.cc index 0cec81f..c9f4cf8 100644 --- a/exampleB4a.cc +++ b/exampleB4a.cc @@ -39,7 +39,7 @@ #include "FTFP_BERT.hh" #include "Randomize.hh" -#include "ConstructionWrapper.hh" +#include "GeometryDescriptor.hh" #include "G4System.hh" @@ -121,7 +121,7 @@ int main2(int argc,char** argv) } #endif - ConstructionWrapper * cw = new ConstructionWrapper(); + GeometryDescriptor * cw = new GeometryDescriptor(); cw->addLayer(1, "G4_Pb", false); cw->addLayer(10, "G4_Si", true, 9); cw->addLayer(1, "G4_Pb", false); @@ -185,11 +185,11 @@ int main2(int argc,char** argv) //later //class Runner { //public: -// void initialize(ConstructionWrapper CW, bool gui=false); +// void initialize(GeometryDescriptor CW, bool gui=false); // void run(int nEvents, std::string partSpecies, double minEnergy, double maxEnergy); //} -void run(ConstructionWrapper CW, int nEvents, std::string partSpecies, double minEnergy, double maxEnergy, bool gui=false){ +void run(GeometryDescriptor CW, int nEvents, std::string partSpecies, double minEnergy, double maxEnergy, bool gui=false){ char* argv[]={(char*)"dummy"}; @@ -199,7 +199,7 @@ void run(ConstructionWrapper CW, int nEvents, std::string partSpecies, double mi G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default); runManager->SetNumberOfThreads(1); - ConstructionWrapper * cw = &CW; + GeometryDescriptor * cw = &CW; G4String session; G4UIExecutive* ui = nullptr; if ( gui ) { @@ -261,7 +261,7 @@ void run(ConstructionWrapper CW, int nEvents, std::string partSpecies, double mi int main(){ - ConstructionWrapper cw; + GeometryDescriptor cw; //to be moved cw.addLayer(1, "G4_Pb", false); cw.addLayer(10, "G4_Si", true, 9); diff --git a/include/DetectorConstruction.hh b/include/DetectorConstruction.hh index 082aba8..640c044 100644 --- a/include/DetectorConstruction.hh +++ b/include/DetectorConstruction.hh @@ -35,7 +35,7 @@ class G4VPhysicalVolume; class G4GlobalMagFieldMessenger; -class ConstructionWrapper; +class GeometryDescriptor; namespace B4 { @@ -67,7 +67,7 @@ class DetectorConstruction : public G4VUserDetectorConstruction return _global_detector_construction; } - DetectorConstruction( ConstructionWrapper* Cw): G4VUserDetectorConstruction(), cw(Cw){ + DetectorConstruction( GeometryDescriptor* Cw): G4VUserDetectorConstruction(), cw(Cw){ _global_detector_construction=this; } ~DetectorConstruction() override = default; @@ -76,14 +76,14 @@ class DetectorConstruction : public G4VUserDetectorConstruction G4VPhysicalVolume* Construct() override; void ConstructSDandField() override; - void setConstructionWrapper(ConstructionWrapper* Cw){ + void setGeometryDescriptor(GeometryDescriptor* Cw){ this->cw = Cw; } - ConstructionWrapper* getConstructionWrapper(){ + GeometryDescriptor* getGeometryDescriptor(){ return cw; } - const ConstructionWrapper* getConstructionWrapper()const{ + const GeometryDescriptor* getGeometryDescriptor()const{ return cw; } @@ -100,7 +100,7 @@ class DetectorConstruction : public G4VUserDetectorConstruction G4bool fCheckOverlaps = true; // option to activate checking of volumes overlaps - ConstructionWrapper* cw=nullptr; + GeometryDescriptor* cw=nullptr; }; diff --git a/include/EventAction.hh b/include/EventAction.hh index caa531d..43a4e14 100644 --- a/include/EventAction.hh +++ b/include/EventAction.hh @@ -34,7 +34,7 @@ #include "RunAction.hh" #include "PrimaryGeneratorAction.hh" #include "globals.hh" -class ConstructionWrapper; +class GeometryDescriptor; namespace B4a { diff --git a/include/G4System.hh b/include/G4System.hh index aa34389..d9274fe 100644 --- a/include/G4System.hh +++ b/include/G4System.hh @@ -2,7 +2,7 @@ #ifndef G4SYSTEM_HH #define G4SYSTEM_HH -#include "ConstructionWrapper.hh" +#include "GeometryDescriptor.hh" #include #include "G4RunManagerFactory.hh" #include "DetectorConstruction.hh" @@ -32,7 +32,7 @@ G4System(bool Gui=false):gui(Gui){}; }; -void init(ConstructionWrapper &cw); +void init(GeometryDescriptor &cw); //will use dawn for visualization, also wrap more in python void run_visualize(const std::string& partSpecies, double minEnergy_GeV, double maxEnergy_GeV); //runs the whole gui if available @@ -48,10 +48,10 @@ void displayEvent()const{}; //just a placeholder, this will be implemented in py void printMaterial(const std::string& name)const; -ConstructionWrapper& getConstructionWrapper(){ +GeometryDescriptor& getGeometryDescriptor(){ check(); if ( assigned_cw == nullptr ){ - throw std::runtime_error("ConstructionWrapper not assigned"); + throw std::runtime_error("GeometryDescriptor not assigned"); } return *assigned_cw; } @@ -59,7 +59,7 @@ ConstructionWrapper& getConstructionWrapper(){ private: void check()const; -ConstructionWrapper * assigned_cw=nullptr; +GeometryDescriptor * assigned_cw=nullptr; bool gui; @@ -77,7 +77,7 @@ G4UIExecutive * ui=nullptr; /* -void run(ConstructionWrapper CW, int nEvents, std::string partSpecies, double minEnergy, double maxEnergy, bool gui=false){ +void run(GeometryDescriptor CW, int nEvents, std::string partSpecies, double minEnergy, double maxEnergy, bool gui=false){ char* argv[]={(char*)"dummy"}; @@ -87,7 +87,7 @@ void run(ConstructionWrapper CW, int nEvents, std::string partSpecies, double mi G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default); runManager->SetNumberOfThreads(1); - ConstructionWrapper * cw = &CW; + GeometryDescriptor * cw = &CW; G4String session; G4UIExecutive* ui = nullptr; if ( gui ) { diff --git a/include/ConstructionWrapper.hh b/include/GeometryDescriptor.hh similarity index 92% rename from include/ConstructionWrapper.hh rename to include/GeometryDescriptor.hh index 067d374..6e60feb 100644 --- a/include/ConstructionWrapper.hh +++ b/include/GeometryDescriptor.hh @@ -1,6 +1,6 @@ -#ifndef CONSTRUCTIONWRAPPER_HH -#define CONSTRUCTIONWRAPPER_HH +#ifndef GeometryDescriptor_HH +#define GeometryDescriptor_HH #include "G4ThreeVector.hh" #include @@ -62,11 +62,11 @@ public: }; -class ConstructionWrapper{ +class GeometryDescriptor{ public: - ConstructionWrapper(double xy_width=50); - ~ConstructionWrapper() {}; + GeometryDescriptor(double xy_width=50); + ~GeometryDescriptor() {}; void addLayer(double thickness_cm, std::string material, bool isActive=true, int nx=1, int ny=-1); diff --git a/include/SteppingAction.hh b/include/SteppingAction.hh index d52869d..85cdd0f 100644 --- a/include/SteppingAction.hh +++ b/include/SteppingAction.hh @@ -31,7 +31,7 @@ #define B4aSteppingAction_h 1 #include "G4UserSteppingAction.hh" -#include "ConstructionWrapper.hh" +#include "GeometryDescriptor.hh" #include "DetectorConstruction.hh" diff --git a/src/DetectorConstruction.cc b/src/DetectorConstruction.cc index 5b1259e..f9bd893 100644 --- a/src/DetectorConstruction.cc +++ b/src/DetectorConstruction.cc @@ -28,7 +28,7 @@ /// \brief Implementation of the B4::DetectorConstruction class #include "DetectorConstruction.hh" -#include "ConstructionWrapper.hh" +#include "GeometryDescriptor.hh" #include "G4Material.hh" #include "G4NistManager.hh" diff --git a/src/EventAction.cc b/src/EventAction.cc index fc04b43..ce5ff3d 100644 --- a/src/EventAction.cc +++ b/src/EventAction.cc @@ -27,7 +27,7 @@ /// \file B4/B4a/src/EventAction.cc /// \brief Implementation of the B4a::EventAction class -#include "ConstructionWrapper.hh" +#include "GeometryDescriptor.hh" #include "EventAction.hh" #include "RunAction.hh" @@ -49,11 +49,11 @@ namespace B4a void EventAction::BeginOfEventAction(const G4Event* /*event*/) { - auto cw = B4::DetectorConstruction::getDetectorConstruction()->getConstructionWrapper(); + auto cw = B4::DetectorConstruction::getDetectorConstruction()->getGeometryDescriptor(); // initialisation per event if(cw == nullptr){ - G4cout << "ConstructionWrapper not found" << G4endl; - throw std::runtime_error("ConstructionWrapper not found"); + G4cout << "GeometryDescriptor not found" << G4endl; + throw std::runtime_error("GeometryDescriptor not found"); } if(gen == nullptr){ G4cout << "PrimaryGeneratorAction not found" << G4endl; @@ -84,7 +84,7 @@ void EventAction::EndOfEventAction(const G4Event* event) // get analysis manager auto analysisManager = G4AnalysisManager::Instance(); - auto cw = B4::DetectorConstruction::getDetectorConstruction()->getConstructionWrapper(); + auto cw = B4::DetectorConstruction::getDetectorConstruction()->getGeometryDescriptor(); //cw->printSensorEnergies();//DEBUG diff --git a/src/G4System.cc b/src/G4System.cc index b86d2e4..c71eb59 100644 --- a/src/G4System.cc +++ b/src/G4System.cc @@ -4,10 +4,10 @@ #include #include -void G4System::init(ConstructionWrapper &CW){ +void G4System::init(GeometryDescriptor &CW){ if(CW.isAssigned()){ - throw std::runtime_error("ConstructionWrapper already assigned"); + throw std::runtime_error("GeometryDescriptor already assigned"); } if(assigned_cw != nullptr){ //reassign @@ -58,7 +58,7 @@ void G4System::init(ConstructionWrapper &CW){ runManager->SetUserInitialization(actionInitialization); } else{ - detConstruction->setConstructionWrapper(&CW); + detConstruction->setGeometryDescriptor(&CW); runManager->ReinitializeGeometry(true); } diff --git a/src/ConstructionWrapper.cc b/src/GeometryDescriptor.cc similarity index 73% rename from src/ConstructionWrapper.cc rename to src/GeometryDescriptor.cc index 7f2b2a1..6f9bd82 100644 --- a/src/ConstructionWrapper.cc +++ b/src/GeometryDescriptor.cc @@ -1,6 +1,6 @@ -#include "ConstructionWrapper.hh" +#include "GeometryDescriptor.hh" #include "G4VPhysicalVolume.hh" Layer::Layer(){ @@ -36,11 +36,11 @@ void Layer::assignPhysicalVolume(G4VPhysicalVolume* physicalVolume){ this->physicalVolume = physicalVolume; } -ConstructionWrapper::ConstructionWrapper(double xy_width){ +GeometryDescriptor::GeometryDescriptor(double xy_width){ xywidth = xy_width; } -void ConstructionWrapper::addLayer(double thickness, std::string material, bool isActive, int nx, int ny){ +void GeometryDescriptor::addLayer(double thickness, std::string material, bool isActive, int nx, int ny){ if(ny<0){ ny = nx; } @@ -60,20 +60,20 @@ void ConstructionWrapper::addLayer(double thickness, std::string material, bool layers.push_back(layer); } -const std::vector & ConstructionWrapper::getLayers() const{ +const std::vector & GeometryDescriptor::getLayers() const{ return layers; } -std::vector & ConstructionWrapper::getLayers(){ +std::vector & GeometryDescriptor::getLayers(){ return layers; } -double ConstructionWrapper::getXYWidth() const{ +double GeometryDescriptor::getXYWidth() const{ return xywidth; } -void ConstructionWrapper::resetSensorEnergies()const { +void GeometryDescriptor::resetSensorEnergies()const { for(const auto & layer : layers){ for(const auto & sensor : layer.sensors){ sensor.energy = 0; @@ -81,7 +81,7 @@ void ConstructionWrapper::resetSensorEnergies()const { } } -Layer* ConstructionWrapper::getLayerByVolume(G4VPhysicalVolume* volume){ +Layer* GeometryDescriptor::getLayerByVolume(G4VPhysicalVolume* volume){ for(auto & layer : layers){ if(layer.physicalVolume == volume){ return &layer; @@ -90,7 +90,7 @@ Layer* ConstructionWrapper::getLayerByVolume(G4VPhysicalVolume* volume){ return nullptr; } -const Layer* ConstructionWrapper::getLayerByVolume(G4VPhysicalVolume* volume)const{ +const Layer* GeometryDescriptor::getLayerByVolume(G4VPhysicalVolume* volume)const{ for(auto & layer : layers){ if(layer.physicalVolume == volume){ return &layer; @@ -99,7 +99,7 @@ const Layer* ConstructionWrapper::getLayerByVolume(G4VPhysicalVolume* volume)con return nullptr; } -Sensor* ConstructionWrapper::getSensorByVolume(G4VPhysicalVolume* volume){ +Sensor* GeometryDescriptor::getSensorByVolume(G4VPhysicalVolume* volume){ int copyNo = volume->GetCopyNo(); auto layer = getLayerByVolume(volume); if(layer == nullptr){ @@ -111,7 +111,7 @@ Sensor* ConstructionWrapper::getSensorByVolume(G4VPhysicalVolume* volume){ return &layer->sensors[copyNo]; } -const Sensor* ConstructionWrapper::getSensorByVolume(G4VPhysicalVolume* volume)const{ +const Sensor* GeometryDescriptor::getSensorByVolume(G4VPhysicalVolume* volume)const{ int copyNo = volume->GetCopyNo(); auto layer = getLayerByVolume(volume); if(layer == nullptr){ @@ -124,7 +124,7 @@ const Sensor* ConstructionWrapper::getSensorByVolume(G4VPhysicalVolume* volume)c } -void ConstructionWrapper::printSensorEnergies()const{ +void GeometryDescriptor::printSensorEnergies()const{ for(const auto& layer: layers){ for(const auto& sensor: layer.sensors){ G4cout << sensor.energy << " "; diff --git a/src/SteppingAction.cc b/src/SteppingAction.cc index e1f1b17..ec80e5d 100644 --- a/src/SteppingAction.cc +++ b/src/SteppingAction.cc @@ -59,15 +59,15 @@ void SteppingAction::UserSteppingAction(const G4Step* step) //return; - //find the layer through the constructionwrapper that corresponds to the volume - auto cw = DetectorConstruction::getDetectorConstruction()->getConstructionWrapper(); + //find the layer through the GeometryDescriptor that corresponds to the volume + auto cw = DetectorConstruction::getDetectorConstruction()->getGeometryDescriptor(); if(cw == nullptr){ - G4cout << "ConstructionWrapper not found" << G4endl; - throw std::runtime_error("ConstructionWrapper not found"); + G4cout << "GeometryDescriptor not found" << G4endl; + throw std::runtime_error("GeometryDescriptor not found"); } - auto sensor = DetectorConstruction::getDetectorConstruction()->getConstructionWrapper()->getSensorByVolume(volume); + auto sensor = DetectorConstruction::getDetectorConstruction()->getGeometryDescriptor()->getSensorByVolume(volume); if(sensor == nullptr){ //can simply be not an active volume, so no need to throw an error //G4cout << "Sensor not found in" << volume->GetName() << G4endl; //DEBUG From 6e591c6255f3d273d75a2768cd369a1a059ed7a0 Mon Sep 17 00:00:00 2001 From: Jan Kieseler Date: Sat, 7 Oct 2023 11:16:41 +0200 Subject: [PATCH 3/3] clean up --- bind/G4Calo.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/bind/G4Calo.py b/bind/G4Calo.py index fe193fa..540db2e 100644 --- a/bind/G4Calo.py +++ b/bind/G4Calo.py @@ -11,14 +11,7 @@ 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() + def run_batch( self,