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:
+14
-4
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
int nEvents = 10;
|
int nEvents = 10;
|
||||||
|
double energy_GeV = 1.0;
|
||||||
|
|
||||||
int seed = -1;
|
int seed = -1;
|
||||||
if (const char* seedEnv = std::getenv("MINICALOSIM_SEED")) {
|
if (const char* seedEnv = std::getenv("MINICALOSIM_SEED")) {
|
||||||
@@ -21,11 +22,11 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc > 2) {
|
if (argc > 3) {
|
||||||
std::cerr << "Usage: run_pbwo4 [nEvents]" << std::endl;
|
std::cerr << "Usage: run_pbwo4 [nEvents] [energy_GeV]" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (argc == 2) {
|
if (argc >= 2) {
|
||||||
try {
|
try {
|
||||||
nEvents = std::stoi(argv[1]);
|
nEvents = std::stoi(argv[1]);
|
||||||
if (nEvents <= 0) throw std::invalid_argument("must be positive");
|
if (nEvents <= 0) throw std::invalid_argument("must be positive");
|
||||||
@@ -34,6 +35,15 @@ int main(int argc, char** argv) {
|
|||||||
return 1;
|
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";
|
std::string outfile = "pbwo4_" + std::to_string(nEvents) + "events_hits.root";
|
||||||
|
|
||||||
@@ -42,7 +52,7 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
G4System g4;
|
G4System g4;
|
||||||
g4.init(gd, seed);
|
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;
|
std::cout << "Saved " << nEvents << " events to " << outfile << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+14
-4
@@ -57,7 +57,7 @@ const std::vector<std::pair<std::string, GeometryDescriptor (*)()>> kConfigs = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void printUsage() {
|
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;
|
std::cerr << "Available configs:" << std::endl;
|
||||||
for (std::size_t i = 0; i < kConfigs.size(); ++i) {
|
for (std::size_t i = 0; i < kConfigs.size(); ++i) {
|
||||||
std::cerr << " " << (i + 1) << ": " << kConfigs[i].first << std::endl;
|
std::cerr << " " << (i + 1) << ": " << kConfigs[i].first << std::endl;
|
||||||
@@ -69,15 +69,16 @@ void printUsage() {
|
|||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
std::string configName = kConfigs.front().first;
|
std::string configName = kConfigs.front().first;
|
||||||
int nEvents = 10;
|
int nEvents = 10;
|
||||||
|
double energy_GeV = 1.0;
|
||||||
|
|
||||||
if (argc > 3) {
|
if (argc > 4) {
|
||||||
printUsage();
|
printUsage();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (argc >= 2) {
|
if (argc >= 2) {
|
||||||
configName = argv[1];
|
configName = argv[1];
|
||||||
}
|
}
|
||||||
if (argc == 3) {
|
if (argc >= 3) {
|
||||||
try {
|
try {
|
||||||
nEvents = std::stoi(argv[2]);
|
nEvents = std::stoi(argv[2]);
|
||||||
if (nEvents <= 0) throw std::invalid_argument("must be positive");
|
if (nEvents <= 0) throw std::invalid_argument("must be positive");
|
||||||
@@ -86,6 +87,15 @@ int main(int argc, char** argv) {
|
|||||||
return 1;
|
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;
|
GeometryDescriptor (*builder)() = nullptr;
|
||||||
try {
|
try {
|
||||||
@@ -130,7 +140,7 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
G4System g4;
|
G4System g4;
|
||||||
g4.init(gd, seed);
|
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;
|
std::cout << "Saved " << nEvents << " events to " << outfile << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user