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.
This commit is contained in:
2026-07-13 13:58:54 +02:00
parent 068cf93604
commit 14cfc18369
2 changed files with 28 additions and 8 deletions
+14 -4
View File
@@ -57,7 +57,7 @@ const std::vector<std::pair<std::string, GeometryDescriptor (*)()>> 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;