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 "config.h"
0017 #include "g4app.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("simg4ox", "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 try
0054 {
0055 program.parse_args(argc, argv);
0056 }
0057 catch (const exception &err)
0058 {
0059 cerr << err.what() << endl;
0060 cerr << program;
0061 exit(EXIT_FAILURE);
0062 }
0063
0064 gphox::Config cfg(config_name);
0065
0066
0067
0068 G4VModularPhysicsList *physics = new FTFP_BERT;
0069 physics->RegisterPhysics(new G4OpticalPhysics);
0070
0071 G4RunManager run_mgr;
0072 run_mgr.SetUserInitialization(physics);
0073
0074 G4App *g4app = new G4App(cfg, gdml_file);
0075 run_mgr.SetUserInitialization(g4app->det_cons_);
0076 run_mgr.SetUserAction(g4app->prim_gen_);
0077 run_mgr.SetUserAction(g4app->event_act_);
0078 run_mgr.SetUserAction(g4app->tracking_);
0079 run_mgr.SetUserAction(g4app->stepping_);
0080 run_mgr.Initialize();
0081
0082 G4UIExecutive *uix = nullptr;
0083 G4VisManager *vis = nullptr;
0084
0085 if (interactive)
0086 {
0087 uix = new G4UIExecutive(argc, argv);
0088 vis = new G4VisExecutive;
0089 vis->Initialize();
0090 }
0091
0092 G4UImanager *ui = G4UImanager::GetUIpointer();
0093 ui->ApplyCommand("/control/execute " + macro_name);
0094
0095 if (interactive)
0096 {
0097 uix->SessionStart();
0098 }
0099
0100 delete uix;
0101
0102 return EXIT_SUCCESS;
0103 }