File indexing completed on 2025-02-23 09:21:19
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
0034
0035
0036
0037
0038
0039
0040
0041 #ifndef WIN32
0042 # include <unistd.h>
0043 #endif
0044
0045 #include "G4Types.hh"
0046
0047 #ifdef G4MULTITHREADED
0048 # include "G4MTRunManager.hh"
0049 #else
0050 # include "F04SteppingVerbose.hh"
0051
0052 # include "G4RunManager.hh"
0053 #endif
0054
0055 #include "F04ActionInitialization.hh"
0056 #include "F04DetectorConstruction.hh"
0057 #include "F04PhysicsList.hh"
0058
0059 #include "G4UIExecutive.hh"
0060 #include "G4UImanager.hh"
0061 #include "G4VisExecutive.hh"
0062 #include "Randomize.hh"
0063
0064
0065
0066 namespace
0067 {
0068 void PrintUsage()
0069 {
0070 G4cerr << " Usage: " << G4endl;
0071 G4cerr << " field04 [-m macro ] [-p physicsList] [-r randomSeed] [-s preinit|idle]" << G4endl;
0072 }
0073 }
0074
0075
0076
0077 int main(int argc, char** argv)
0078 {
0079
0080
0081
0082
0083
0084
0085 if (argc > 7) {
0086 PrintUsage();
0087 return 1;
0088 }
0089
0090 G4String macro;
0091 G4String physicsList = "QGSP_BERT";
0092 G4int randomSeed = 1234;
0093 G4String startPhase = "idle";
0094 for (G4int i = 1; i < argc; i = i + 2) {
0095 if (G4String(argv[i]) == "-m")
0096 macro = argv[i + 1];
0097 else if (G4String(argv[i]) == "-r")
0098 randomSeed = atoi(argv[i + 1]);
0099 else if (G4String(argv[i]) == "-p")
0100 physicsList = argv[i + 1];
0101 else if (G4String(argv[i]) == "-s")
0102 startPhase = argv[i + 1];
0103 else {
0104 PrintUsage();
0105 return 1;
0106 }
0107 }
0108
0109
0110 G4UIExecutive* ui = nullptr;
0111 if (!macro.size()) {
0112 ui = new G4UIExecutive(argc, argv);
0113 }
0114
0115
0116
0117 G4Random::setTheEngine(new CLHEP::RanecuEngine);
0118
0119
0120
0121 #ifdef G4MULTITHREADED
0122 G4MTRunManager* runManager = new G4MTRunManager;
0123 #else
0124 G4VSteppingVerbose::SetInstance(new F04SteppingVerbose);
0125 auto runManager = new G4RunManager;
0126 #endif
0127
0128 G4Random::setTheSeed(randomSeed);
0129
0130
0131
0132
0133 auto detector = new F04DetectorConstruction();
0134 runManager->SetUserInitialization(detector);
0135
0136 runManager->SetUserInitialization(new F04PhysicsList(physicsList));
0137
0138 runManager->SetUserInitialization(new F04ActionInitialization(detector));
0139
0140
0141
0142
0143
0144
0145
0146 G4VisManager* visManager = new G4VisExecutive;
0147
0148
0149 visManager->Initialize();
0150
0151
0152
0153 G4UImanager* UImanager = G4UImanager::GetUIpointer();
0154
0155
0156
0157 if (macro.size()) {
0158
0159 G4String command = "/control/execute ";
0160 UImanager->ApplyCommand(command + macro);
0161 }
0162 else {
0163
0164 if (startPhase == "preinit") {
0165
0166 G4cout << "At the prompt, issue commands to set up detector & field, then:" << G4endl;
0167 G4cout << "/run/initialize" << G4endl;
0168 G4cout << "Then if you want a viewer:" << G4endl;
0169 G4cout << "/control/execute vis.mac" << G4endl;
0170 G4cout << "Then: " << G4endl;
0171 G4cout << "/run/beamOn … etc." << G4endl;
0172 }
0173 else {
0174
0175 UImanager->ApplyCommand("/control/execute init_vis.mac");
0176 }
0177 if (ui->IsGUI()) {
0178 UImanager->ApplyCommand("/control/execute gui.mac");
0179 }
0180 ui->SessionStart();
0181 delete ui;
0182 }
0183
0184
0185
0186
0187
0188
0189 delete visManager;
0190 delete runManager;
0191
0192 return 0;
0193 }
0194
0195