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