From 14cfc18369c7606f79309eb4997f2866c3059fd7 Mon Sep 17 00:00:00 2001 From: Lars Bogner Date: Mon, 13 Jul 2026 13:58:54 +0200 Subject: [PATCH] Add optional primary particle energy argument to dataset scripts run_pbwo4 and run_sampling previously hardcoded 1 GeV mono-energetic e- primaries. Both now accept a trailing energy_GeV CLI argument (default 1.0, unchanged) so datasets at other energies can be produced without recompiling. --- run_pbwo4.cc | 18 ++++++++++++++---- run_sampling.cc | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/run_pbwo4.cc b/run_pbwo4.cc index 22e3895..c6b11e6 100644 --- a/run_pbwo4.cc +++ b/run_pbwo4.cc @@ -8,6 +8,7 @@ int main(int argc, char** argv) { int nEvents = 10; + double energy_GeV = 1.0; int seed = -1; if (const char* seedEnv = std::getenv("MINICALOSIM_SEED")) { @@ -21,11 +22,11 @@ int main(int argc, char** argv) { } } - if (argc > 2) { - std::cerr << "Usage: run_pbwo4 [nEvents]" << std::endl; + if (argc > 3) { + std::cerr << "Usage: run_pbwo4 [nEvents] [energy_GeV]" << std::endl; return 1; } - if (argc == 2) { + if (argc >= 2) { try { nEvents = std::stoi(argv[1]); if (nEvents <= 0) throw std::invalid_argument("must be positive"); @@ -34,6 +35,15 @@ int main(int argc, char** argv) { return 1; } } + if (argc == 3) { + try { + energy_GeV = std::stod(argv[2]); + if (energy_GeV <= 0) throw std::invalid_argument("must be positive"); + } catch (const std::exception& e) { + std::cerr << "Invalid energy_GeV '" << argv[2] << "': " << e.what() << std::endl; + return 1; + } + } std::string outfile = "pbwo4_" + std::to_string(nEvents) + "events_hits.root"; @@ -42,7 +52,7 @@ int main(int argc, char** argv) { G4System g4; g4.init(gd, seed); - g4.run_batch(nEvents, {"e-"}, 1.0, 1.0, outfile); + g4.run_batch(nEvents, {"e-"}, energy_GeV, energy_GeV, outfile); std::cout << "Saved " << nEvents << " events to " << outfile << std::endl; return 0; diff --git a/run_sampling.cc b/run_sampling.cc index b2da2b1..53c1c7b 100644 --- a/run_sampling.cc +++ b/run_sampling.cc @@ -57,7 +57,7 @@ const std::vector> kConfigs = { }; void printUsage() { - std::cerr << "Usage: run_sampling [configName|configIndex] [nEvents]" << std::endl; + std::cerr << "Usage: run_sampling [configName|configIndex] [nEvents] [energy_GeV]" << std::endl; std::cerr << "Available configs:" << std::endl; for (std::size_t i = 0; i < kConfigs.size(); ++i) { std::cerr << " " << (i + 1) << ": " << kConfigs[i].first << std::endl; @@ -69,15 +69,16 @@ void printUsage() { int main(int argc, char** argv) { std::string configName = kConfigs.front().first; int nEvents = 10; + double energy_GeV = 1.0; - if (argc > 3) { + if (argc > 4) { printUsage(); return 1; } if (argc >= 2) { configName = argv[1]; } - if (argc == 3) { + if (argc >= 3) { try { nEvents = std::stoi(argv[2]); if (nEvents <= 0) throw std::invalid_argument("must be positive"); @@ -86,6 +87,15 @@ int main(int argc, char** argv) { return 1; } } + if (argc == 4) { + try { + energy_GeV = std::stod(argv[3]); + if (energy_GeV <= 0) throw std::invalid_argument("must be positive"); + } catch (const std::exception& e) { + std::cerr << "Invalid energy_GeV '" << argv[3] << "': " << e.what() << std::endl; + return 1; + } + } GeometryDescriptor (*builder)() = nullptr; try { @@ -130,7 +140,7 @@ int main(int argc, char** argv) { G4System g4; g4.init(gd, seed); - g4.run_batch(nEvents, {"e-"}, 1.0, 1.0, outfile); + g4.run_batch(nEvents, {"e-"}, energy_GeV, energy_GeV, outfile); std::cout << "Saved " << nEvents << " events to " << outfile << std::endl; return 0;