File indexing completed on 2026-09-22 08:08:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifndef WIN32
0030 # include <unistd.h>
0031 #endif
0032
0033 #include "ExUCNActionInitialization.hh"
0034 #include "ExUCNDetectorConstruction.hh"
0035 #include "ExUCNPhysicsList.hh"
0036
0037 #include "G4RunManagerFactory.hh"
0038 #include "G4Types.hh"
0039 #include "G4UIExecutive.hh"
0040 #include "G4UIcommand.hh"
0041 #include "G4UImanager.hh"
0042 #include "G4VisExecutive.hh"
0043 #include "Randomize.hh"
0044
0045
0046
0047 namespace
0048 {
0049 void PrintUsage()
0050 {
0051 G4cerr << " Usage: " << G4endl;
0052 G4cerr << " ExUCN [-m macro ] [-u UIsession] [-t nThreads] [-r seed] " << G4endl;
0053 G4cerr << " note: -t option is available only for multi-threaded mode." << G4endl;
0054 }
0055 }
0056
0057
0058
0059 int main(int argc, char** argv)
0060 {
0061
0062
0063 if (argc > 9) {
0064 PrintUsage();
0065 return 1;
0066 }
0067
0068 G4String macro;
0069 G4String session;
0070 G4int nThreads = 0;
0071
0072 G4long myseed = 1234;
0073 for (G4int i = 1; i < argc; i = i + 2) {
0074 if (G4String(argv[i]) == "-m")
0075 macro = argv[i + 1];
0076 else if (G4String(argv[i]) == "-u")
0077 session = argv[i + 1];
0078 else if (G4String(argv[i]) == "-r")
0079 myseed = atoi(argv[i + 1]);
0080 else if (G4String(argv[i]) == "-t") {
0081 nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0082 }
0083 else {
0084 PrintUsage();
0085 return 1;
0086 }
0087 }
0088
0089
0090 G4UIExecutive* ui = nullptr;
0091 if (argc == 1) {
0092 ui = new G4UIExecutive(argc, argv);
0093 }
0094
0095
0096
0097 G4Random::setTheEngine(new CLHEP::RanecuEngine);
0098
0099
0100
0101 auto* runManager = G4RunManagerFactory::CreateRunManager();
0102 if (nThreads > 0) runManager->SetNumberOfThreads(nThreads);
0103
0104
0105 G4Random::setTheSeed(myseed);
0106
0107
0108
0109
0110 runManager->SetUserInitialization(new ExUCNDetectorConstruction());
0111
0112 runManager->SetUserInitialization(new ExUCNPhysicsList());
0113
0114 runManager->SetUserInitialization(new ExUCNActionInitialization());
0115
0116
0117
0118 runManager->Initialize();
0119
0120
0121
0122 G4VisManager* visManager = new G4VisExecutive;
0123
0124
0125 visManager->Initialize();
0126
0127
0128
0129 G4UImanager* UImanager = G4UImanager::GetUIpointer();
0130
0131 if (macro.size()) {
0132
0133 G4String command = "/control/execute ";
0134 UImanager->ApplyCommand(command + macro);
0135 }
0136 else {
0137 UImanager->ApplyCommand("/control/execute vis.mac");
0138 if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
0139 ui->SessionStart();
0140 delete ui;
0141 }
0142
0143
0144
0145
0146
0147
0148 delete visManager;
0149 delete runManager;
0150
0151 return 0;
0152 }
0153
0154