From 01df646aa9ddc2877da07322ac9d8adb9bbb8291 Mon Sep 17 00:00:00 2001 From: Lars Bogner Date: Wed, 10 Jun 2026 09:19:55 +0200 Subject: [PATCH] add run_pbwo4 C++ executable; fix missing std headers for Geant4 11.4 Co-Authored-By: Claude Sonnet 4.6 --- CMakeLists.txt | 3 +++ include/PrimaryGeneratorAction.hh | 2 ++ include/RunAction.hh | 1 + run_pbwo4.cc | 36 +++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 run_pbwo4.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index fb75b02..642a1a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,9 @@ target_link_libraries(minicalo PUBLIC ${Geant4_LIBRARIES} ${Python3_LIBRARIES}) add_executable(exampleB4a exampleB4a.cc ${sources} ${headers}) target_link_libraries(exampleB4a ${Geant4_LIBRARIES} ${Python3_LIBRARIES}) +add_executable(run_pbwo4 run_pbwo4.cc ${sources} ${headers}) +target_link_libraries(run_pbwo4 ${Geant4_LIBRARIES} ${Python3_LIBRARIES}) + #---------------------------------------------------------------------------- # Copy all scripts to the build directory, i.e. the directory in which we # build B4a. This is so that we can run the executable directly because it diff --git a/include/PrimaryGeneratorAction.hh b/include/PrimaryGeneratorAction.hh index 0366a7f..3cc9219 100644 --- a/include/PrimaryGeneratorAction.hh +++ b/include/PrimaryGeneratorAction.hh @@ -32,6 +32,8 @@ #include "G4VUserPrimaryGeneratorAction.hh" #include "globals.hh" +#include +#include class G4ParticleGun; class G4Event; diff --git a/include/RunAction.hh b/include/RunAction.hh index 6c89fc2..854bb55 100644 --- a/include/RunAction.hh +++ b/include/RunAction.hh @@ -32,6 +32,7 @@ #include "G4UserRunAction.hh" #include "globals.hh" +#include class G4Run; diff --git a/run_pbwo4.cc b/run_pbwo4.cc new file mode 100644 index 0000000..1754eb1 --- /dev/null +++ b/run_pbwo4.cc @@ -0,0 +1,36 @@ +#include "GeometryDescriptor.hh" +#include "G4System.hh" + +#include +#include +#include + +int main(int argc, char** argv) { + int nEvents = 10; + + if (argc > 2) { + std::cerr << "Usage: run_pbwo4 [nEvents]" << std::endl; + return 1; + } + if (argc == 2) { + try { + nEvents = std::stoi(argv[1]); + if (nEvents <= 0) throw std::invalid_argument("must be positive"); + } catch (const std::exception& e) { + std::cerr << "Invalid nEvents '" << argv[1] << "': " << e.what() << std::endl; + return 1; + } + } + + std::string outfile = "pbwo4_" + std::to_string(nEvents) + "events_hits.root"; + + GeometryDescriptor gd; + gd.addLayer(20.0, "G4_PbWO4", true, 10, 10); + + G4System g4; + g4.init(gd, -1); + g4.run_batch(nEvents, {"e-"}, 1.0, 1.0, outfile); + + std::cout << "Saved " << nEvents << " events to " << outfile << std::endl; + return 0; +}