From bdcd83e63f150578335fe5b98797f7b69f5f9027 Mon Sep 17 00:00:00 2001 From: Jan Kieseler Date: Wed, 20 Sep 2023 22:51:37 +0200 Subject: [PATCH] detector change might work - might --- bind/bindings.cpp | 2 +- exampleB4a.cc | 4 ++-- include/ConstructionWrapper.hh | 9 +++++++++ include/G4System.hh | 5 +++-- src/G4System.cc | 34 ++++++++++++++++++++-------------- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/bind/bindings.cpp b/bind/bindings.cpp index 130f8a0..782d2c1 100644 --- a/bind/bindings.cpp +++ b/bind/bindings.cpp @@ -19,7 +19,7 @@ void makeConstructionWrapper(M & m, std::string name){ template void makeG4System(M& m, std::string name){ py::class_(m, name.data()).def(py::init()) - .def("init", &G4System::init, py::arg("cw"), py::arg("gui")=false) + .def("init", &G4System::init, py::arg("cw")) .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("run_visualize", &G4System::run_visualize, py::arg("partSpecies"), py::arg("minEnergy_GeV"), py::arg("maxEnergy_GeV")) diff --git a/exampleB4a.cc b/exampleB4a.cc index 979f3fb..0cec81f 100644 --- a/exampleB4a.cc +++ b/exampleB4a.cc @@ -270,8 +270,8 @@ int main(){ cw.addLayer(4, "G4_Pb", false); cw.addLayer(3, "G4_Si", true, 23); - G4System builder; - builder.init(cw, true); + G4System builder(true); + builder.init(cw); //builder.run_gui(); builder.run_batch(10000, ((std::string)"e-").data(), 1, 100); diff --git a/include/ConstructionWrapper.hh b/include/ConstructionWrapper.hh index ba716ee..477d9d6 100644 --- a/include/ConstructionWrapper.hh +++ b/include/ConstructionWrapper.hh @@ -90,6 +90,15 @@ public: void printSensorEnergies()const; + bool isAssigned()const{ + if(layers.size() == 0){ + return false; + } + else{ + return layers[0].physicalVolume != nullptr; + } + } + private: double xywidth; diff --git a/include/G4System.hh b/include/G4System.hh index ac8e01a..effe9c8 100644 --- a/include/G4System.hh +++ b/include/G4System.hh @@ -21,7 +21,7 @@ class G4System{ public: -G4System(){}; +G4System(bool Gui=false):gui(Gui){}; ~G4System(){ if(visManager != nullptr){ delete visManager; @@ -31,7 +31,7 @@ G4System(){}; }; -void init(ConstructionWrapper &cw, bool gui=false); +void init(ConstructionWrapper &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 @@ -50,6 +50,7 @@ private: void check()const; +bool gui; G4RunManager * runManager=nullptr; B4::DetectorConstruction * detConstruction=nullptr; diff --git a/src/G4System.cc b/src/G4System.cc index 9d05e19..2e59ae8 100644 --- a/src/G4System.cc +++ b/src/G4System.cc @@ -1,7 +1,11 @@ #include "G4System.hh" -void G4System::init(ConstructionWrapper &CW, bool gui){ +void G4System::init(ConstructionWrapper &CW){ + + if(CW.isAssigned()){ + throw std::runtime_error("ConstructionWrapper already assigned"); + } char* argv[]={(char*)"dummy"}; @@ -16,12 +20,11 @@ void G4System::init(ConstructionWrapper &CW, bool gui){ } else{ // Abort the current run - runManager->AbortRun(true); - - // Clear any pending events - runManager->Clear(); + G4RunManager::GetRunManager()->AbortRun(true); first_init = false; - + //delete actionInitialization; + //delete detConstruction; + //delete actionInitialization; } @@ -37,24 +40,27 @@ void G4System::init(ConstructionWrapper &CW, bool gui){ runManager->SetUserInitialization(detConstruction); - auto physicsList = new FTFP_BERT; - runManager->SetUserInitialization(physicsList); + if(first_init){ + auto physicsList = new FTFP_BERT; + runManager->SetUserInitialization(physicsList); + actionInitialization = new B4a::ActionInitialization(detConstruction); runManager->SetUserInitialization(actionInitialization); - +} if(! first_init){ - runManager->GeometryHasBeenModified(); - runManager->ReinitializeGeometry(); - runManager->PhysicsHasBeenModified(); - runManager->ReinitializePhysics(); + G4RunManager::GetRunManager()->GeometryHasBeenModified(); + G4RunManager::GetRunManager()->ReinitializeGeometry(); } - // Initialize visualization + if(visManager == nullptr){ + // Initialize visualization // visManager = new G4VisExecutive; // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance. // G4VisManager* visManager = new G4VisExecutive("Quiet"); + + } visManager->Initialize(); // Get the pointer to the User Interface manager