Back to home page

EIC code displayed by LXR

 
 

    


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 "G4VModularPhysicsList.hh"
0008 
0009 #include "G4UIExecutive.hh"
0010 #include "G4UImanager.hh"
0011 #include "G4VisExecutive.hh"
0012 
0013 #include "sysrap/OPTICKS_LOG.hh"
0014 
0015 #include "GPUCerenkov.h"
0016 
0017 #include "G4RunManager.hh"
0018 #include "G4RunManagerFactory.hh"
0019 #include "G4VUserActionInitialization.hh"
0020 
0021 using namespace std;
0022 
0023 struct ActionInitialization : public G4VUserActionInitialization
0024 {
0025   private:
0026     G4App *fG4App; // Store the pointer to G4App
0027 
0028   public:
0029     // Note the signature: now we take a pointer to the G4App itself
0030     ActionInitialization(G4App *app) : G4VUserActionInitialization(), fG4App(app)
0031     {
0032     }
0033 
0034     virtual void BuildForMaster() const override
0035     {
0036         SetUserAction(fG4App->run_act_);
0037     }
0038 
0039     virtual void Build() const override
0040     {
0041         SetUserAction(fG4App->prim_gen_);
0042         SetUserAction(fG4App->run_act_);
0043         SetUserAction(fG4App->event_act_);
0044         SetUserAction(fG4App->tracking_);
0045         SetUserAction(fG4App->stepping_);
0046     }
0047 };
0048 
0049 int main(int argc, char **argv)
0050 {
0051 
0052     long seed = static_cast<long>(time(nullptr));
0053     CLHEP::HepRandom::setTheSeed(seed);
0054     G4cout << "Random seed set to: " << seed << G4endl;
0055     OPTICKS_LOG(argc, argv);
0056 
0057     argparse::ArgumentParser program("GPUCerenkov", "0.0.0");
0058 
0059     string gdml_file, macro_name;
0060     bool interactive;
0061 
0062     program.add_argument("-g", "--gdml")
0063         .help("path to GDML file")
0064         .default_value(string("geom.gdml"))
0065         .nargs(1)
0066         .store_into(gdml_file);
0067 
0068     program.add_argument("-m", "--macro")
0069         .help("path to G4 macro")
0070         .default_value(string("run.mac"))
0071         .nargs(1)
0072         .store_into(macro_name);
0073 
0074     program.add_argument("-i", "--interactive")
0075         .help("whether to open an interactive window with a viewer")
0076         .flag()
0077         .store_into(interactive);
0078 
0079     try
0080     {
0081         program.parse_args(argc, argv);
0082     }
0083     catch (const exception &err)
0084     {
0085         cerr << err.what() << endl;
0086         cerr << program;
0087         exit(EXIT_FAILURE);
0088     }
0089 
0090     // Configure Geant4
0091     // The physics list must be instantiated before other user actions
0092     G4VModularPhysicsList *physics = new FTFP_BERT;
0093     physics->RegisterPhysics(new G4OpticalPhysics);
0094 
0095     auto *run_mgr = G4RunManagerFactory::CreateRunManager();
0096     run_mgr->SetUserInitialization(physics);
0097 
0098     G4App *g4app = new G4App(gdml_file);
0099 
0100     ActionInitialization *actionInit = new ActionInitialization(g4app);
0101     run_mgr->SetUserInitialization(actionInit);
0102     run_mgr->SetUserInitialization(g4app->det_cons_);
0103 
0104     G4UIExecutive *uix = nullptr;
0105     G4VisManager *vis = nullptr;
0106 
0107     if (interactive)
0108     {
0109         uix = new G4UIExecutive(argc, argv);
0110         vis = new G4VisExecutive;
0111         vis->Initialize();
0112     }
0113 
0114     G4UImanager *ui = G4UImanager::GetUIpointer();
0115     ui->ApplyCommand("/control/execute " + macro_name);
0116 
0117     if (interactive)
0118     {
0119         uix->SessionStart();
0120     }
0121 
0122     delete uix;
0123 
0124     return EXIT_SUCCESS;
0125 }