File indexing completed on 2026-04-09 07:49:12
0001 #include <string>
0002
0003 #include <argparse/argparse.hpp>
0004
0005 #include "FTFP_BERT.hh"
0006 #include "G4OpticalPhysics.hh"
0007 #include "G4RunManager.hh"
0008 #include "G4VModularPhysicsList.hh"
0009
0010 #include "G4UIExecutive.hh"
0011 #include "G4UImanager.hh"
0012 #include "G4VisExecutive.hh"
0013
0014 #include "sysrap/OPTICKS_LOG.hh"
0015
0016 #include "GPUPhotonSourceMinimal.h"
0017 #include "config.h"
0018
0019 using namespace std;
0020
0021 int main(int argc, char **argv)
0022 {
0023 OPTICKS_LOG(argc, argv);
0024
0025 argparse::ArgumentParser program("GPUPhotonSourceMinimal", "0.0.0");
0026
0027 string gdml_file, config_name, macro_name;
0028 bool interactive;
0029
0030 program.add_argument("-g", "--gdml")
0031 .help("path to GDML file")
0032 .default_value(string("geom.gdml"))
0033 .nargs(1)
0034 .store_into(gdml_file);
0035
0036 program.add_argument("-c", "--config")
0037 .help("the name of a config file")
0038 .default_value(string("dev"))
0039 .nargs(1)
0040 .store_into(config_name);
0041
0042 program.add_argument("-m", "--macro")
0043 .help("path to G4 macro")
0044 .default_value(string("run.mac"))
0045 .nargs(1)
0046 .store_into(macro_name);
0047
0048 program.add_argument("-i", "--interactive")
0049 .help("whether to open an interactive window with a viewer")
0050 .flag()
0051 .store_into(interactive);
0052
0053 program.add_argument("-s", "--seed").help("fixed random seed (default: time-based)").scan<'i', long>();
0054
0055 try
0056 {
0057 program.parse_args(argc, argv);
0058 }
0059 catch (const exception &err)
0060 {
0061 cerr << err.what() << endl;
0062 cerr << program;
0063 exit(EXIT_FAILURE);
0064 }
0065
0066 long seed;
0067 if (program.is_used("--seed"))
0068 {
0069 seed = program.get<long>("--seed");
0070 }
0071 else
0072 {
0073 seed = static_cast<long>(time(nullptr));
0074 }
0075 CLHEP::HepRandom::setTheSeed(seed);
0076 G4cout << "Random seed set to: " << seed << G4endl;
0077
0078 gphox::Config cfg(config_name);
0079
0080
0081
0082 G4VModularPhysicsList *physics = new FTFP_BERT;
0083 physics->RegisterPhysics(new G4OpticalPhysics);
0084
0085 G4RunManager run_mgr;
0086 run_mgr.SetUserInitialization(physics);
0087
0088 G4App *g4app = new G4App(cfg, gdml_file);
0089 run_mgr.SetUserInitialization(g4app->det_cons_);
0090 run_mgr.SetUserAction(g4app->prim_gen_);
0091 run_mgr.SetUserAction(g4app->run_act_);
0092 run_mgr.SetUserAction(g4app->event_act_);
0093 run_mgr.Initialize();
0094
0095 G4UIExecutive *uix = nullptr;
0096 G4VisManager *vis = nullptr;
0097
0098 if (interactive)
0099 {
0100 uix = new G4UIExecutive(argc, argv);
0101 vis = new G4VisExecutive;
0102 vis->Initialize();
0103 }
0104
0105 G4UImanager *ui = G4UImanager::GetUIpointer();
0106 ui->ApplyCommand("/control/execute " + macro_name);
0107
0108 if (interactive)
0109 {
0110 uix->SessionStart();
0111 }
0112
0113 delete uix;
0114
0115 return EXIT_SUCCESS;
0116 }