File indexing completed on 2025-11-05 09:00:12
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
0030
0031
0032
0033 #ifndef WIN32
0034 # include <unistd.h>
0035 #endif
0036
0037 #include "F06ActionInitialization.hh"
0038 #include "F06DetectorConstruction.hh"
0039 #include "F06PhysicsList.hh"
0040
0041 #include "G4RunManagerFactory.hh"
0042 #include "G4Transportation.hh"
0043 #include "G4Types.hh"
0044 #include "G4UIExecutive.hh"
0045 #include "G4UIcommand.hh"
0046 #include "G4UImanager.hh"
0047 #include "G4VisExecutive.hh"
0048 #include "Randomize.hh"
0049
0050
0051 namespace
0052 {
0053 void PrintUsage()
0054 {
0055 G4cerr << " Usage: " << G4endl;
0056 G4cerr << " field06 [-m macro ] [-u UIsession] [-t nThreads] [-r randomSeed] " << G4endl;
0057 G4cerr << " note: -t option is available only for multi-threaded mode." << G4endl;
0058 }
0059 }
0060
0061
0062
0063 int main(int argc, char** argv)
0064 {
0065
0066
0067 if (argc > 9) {
0068 PrintUsage();
0069 return 1;
0070 }
0071
0072 G4String macro;
0073 G4String session;
0074 G4int nThreads = 0;
0075
0076 G4long randomSeed = 1234;
0077 for (G4int i = 1; i < argc; i = i + 2) {
0078 if (G4String(argv[i]) == "-m")
0079 macro = argv[i + 1];
0080 else if (G4String(argv[i]) == "-u")
0081 session = argv[i + 1];
0082 else if (G4String(argv[i]) == "-r")
0083 randomSeed = atoi(argv[i + 1]);
0084 else if (G4String(argv[i]) == "-t") {
0085 nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0086 }
0087 else {
0088 PrintUsage();
0089 return 1;
0090 }
0091 }
0092
0093
0094 G4UIExecutive* ui = nullptr;
0095 if (macro.size() == 0) {
0096 ui = new G4UIExecutive(argc, argv, session);
0097 }
0098
0099
0100
0101 auto* runManager = G4RunManagerFactory::CreateRunManager();
0102 if (nThreads > 0) runManager->SetNumberOfThreads(nThreads);
0103
0104
0105 G4Random::setTheSeed(randomSeed);
0106
0107
0108
0109
0110 runManager->SetUserInitialization(new F06DetectorConstruction());
0111
0112 runManager->SetUserInitialization(new F06PhysicsList());
0113
0114
0115 G4Transportation::EnableGravity(true);
0116
0117
0118 runManager->SetUserInitialization(new F06ActionInitialization());
0119
0120
0121
0122 G4VisManager* visManager = new G4VisExecutive;
0123
0124
0125 visManager->Initialize();
0126
0127
0128
0129 G4UImanager* UImanager = G4UImanager::GetUIpointer();
0130
0131 if (!ui) {
0132
0133 G4String command = "/control/execute ";
0134 UImanager->ApplyCommand(command + macro);
0135 }
0136 else {
0137 UImanager->ApplyCommand("/control/execute init_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