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