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 "GPUPhotonFileSource.h"
0017
0018 using namespace std;
0019
0020 int main(int argc, char **argv)
0021 {
0022 OPTICKS_LOG(argc, argv);
0023
0024 argparse::ArgumentParser program("GPUPhotonFileSource", "0.0.0");
0025
0026 string gdml_file, macro_name, photon_file;
0027 bool interactive;
0028
0029 program.add_argument("-g", "--gdml")
0030 .help("path to GDML file")
0031 .default_value(string("geom.gdml"))
0032 .nargs(1)
0033 .store_into(gdml_file);
0034
0035 program.add_argument("-p", "--photons")
0036 .help("path to input photon text file (one photon per line: pos_x pos_y pos_z time mom_x mom_y mom_z pol_x "
0037 "pol_y pol_z wavelength)")
0038 .required()
0039 .nargs(1)
0040 .store_into(photon_file);
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
0079
0080 G4VModularPhysicsList *physics = new FTFP_BERT;
0081 physics->RegisterPhysics(new G4OpticalPhysics);
0082
0083 G4RunManager run_mgr;
0084 run_mgr.SetUserInitialization(physics);
0085
0086 G4App *g4app = new G4App(photon_file, gdml_file);
0087 run_mgr.SetUserInitialization(g4app->det_cons_);
0088 run_mgr.SetUserAction(g4app->prim_gen_);
0089 run_mgr.SetUserAction(g4app->run_act_);
0090 run_mgr.SetUserAction(g4app->event_act_);
0091 run_mgr.Initialize();
0092
0093 G4UIExecutive *uix = nullptr;
0094 G4VisManager *vis = nullptr;
0095
0096 if (interactive)
0097 {
0098 uix = new G4UIExecutive(argc, argv);
0099 vis = new G4VisExecutive;
0100 vis->Initialize();
0101 }
0102
0103 G4UImanager *ui = G4UImanager::GetUIpointer();
0104 ui->ApplyCommand("/control/execute " + macro_name);
0105
0106 if (interactive)
0107 {
0108 uix->SessionStart();
0109 }
0110
0111 delete uix;
0112
0113 return EXIT_SUCCESS;
0114 }