Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-15 07:41:50

0001 #include <cstdlib>
0002 #include <ctime>
0003 #include <iostream>
0004 #include <string>
0005 
0006 #include <argparse/argparse.hpp>
0007 
0008 #include "FTFP_BERT.hh"
0009 #include "G4OpticalPhysics.hh"
0010 #include "G4VModularPhysicsList.hh"
0011 
0012 #include "G4UImanager.hh"
0013 
0014 #include "eic-opticks/sysrap/OPTICKS_LOG.hh"
0015 
0016 #include "GPUMCTruth.h"
0017 
0018 #include "G4RunManager.hh"
0019 #include "G4RunManagerFactory.hh"
0020 #include "G4VUserActionInitialization.hh"
0021 
0022 using namespace std;
0023 
0024 struct ActionInitialization : public G4VUserActionInitialization
0025 {
0026     G4App* fG4App;
0027     ActionInitialization(G4App* app) :
0028         G4VUserActionInitialization(),
0029         fG4App(app)
0030     {
0031     }
0032 
0033     virtual void BuildForMaster() const override
0034     {
0035         SetUserAction(fG4App->run_act_);
0036     }
0037 
0038     virtual void Build() const override
0039     {
0040         SetUserAction(fG4App->prim_gen_);
0041         SetUserAction(fG4App->run_act_);
0042         SetUserAction(fG4App->event_act_);
0043         SetUserAction(fG4App->tracking_);
0044         SetUserAction(fG4App->stepping_);
0045     }
0046 };
0047 
0048 int main(int argc, char** argv)
0049 {
0050     OPTICKS_LOG(argc, argv);
0051 
0052     argparse::ArgumentParser program("GPUMCTruth", "0.0.0");
0053 
0054     string gdml_file, macro_name;
0055 
0056     program.add_argument("-g", "--gdml").help("path to GDML file").required().nargs(1).store_into(gdml_file);
0057 
0058     program.add_argument("-m", "--macro").help("path to G4 macro").required().nargs(1).store_into(macro_name);
0059 
0060     program.add_argument("-s", "--seed").help("fixed random seed (default: time-based)").scan<'i', long>();
0061 
0062     try
0063     {
0064         program.parse_args(argc, argv);
0065     }
0066     catch (const exception& err)
0067     {
0068         cerr << err.what() << endl;
0069         cerr << program;
0070         return EXIT_FAILURE;
0071     }
0072 
0073     long seed = program.is_used("--seed") ? program.get<long>("--seed") : static_cast<long>(time(nullptr));
0074     CLHEP::HepRandom::setTheSeed(seed);
0075     G4cout << "Random seed set to: " << seed << G4endl;
0076 
0077     G4VModularPhysicsList* physics = new FTFP_BERT;
0078     physics->RegisterPhysics(new G4OpticalPhysics);
0079 
0080     auto* run_mgr = G4RunManagerFactory::CreateRunManager();
0081     run_mgr->SetUserInitialization(physics);
0082 
0083     G4App* g4app = new G4App(gdml_file);
0084 
0085     ActionInitialization* actionInit = new ActionInitialization(g4app);
0086     run_mgr->SetUserInitialization(actionInit);
0087     run_mgr->SetUserInitialization(g4app->det_cons_);
0088 
0089     G4UImanager* ui = G4UImanager::GetUIpointer();
0090     ui->ApplyCommand("/control/execute " + macro_name);
0091 
0092     return EXIT_SUCCESS;
0093 }