File indexing completed on 2025-01-18 09:17:15
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 #include "ActionInitialization.hh"
0031 #include "DetectorConstruction.hh"
0032 #include "FTFP_BERT.hh"
0033
0034 #include "G4RunManagerFactory.hh"
0035 #include "G4SteppingVerbose.hh"
0036 #include "G4UIExecutive.hh"
0037 #include "G4UIcommand.hh"
0038 #include "G4UImanager.hh"
0039 #include "G4VisExecutive.hh"
0040
0041
0042
0043
0044 namespace
0045 {
0046 void PrintUsage()
0047 {
0048 G4cerr << " Usage: " << G4endl;
0049 G4cerr << " exampleB4a [-m macro ] [-u UIsession] [-t nThreads] [-vDefault]" << G4endl;
0050 G4cerr << " note: -t option is available only for multi-threaded mode." << G4endl;
0051 }
0052 }
0053
0054
0055
0056 int main(int argc, char** argv)
0057 {
0058
0059
0060 if (argc > 7) {
0061 PrintUsage();
0062 return 1;
0063 }
0064
0065 G4String macro;
0066 G4String session;
0067 G4bool verboseBestUnits = true;
0068 #ifdef G4MULTITHREADED
0069 G4int nThreads = 0;
0070 #endif
0071 for (G4int i = 1; i < argc; i = i + 2) {
0072 if (G4String(argv[i]) == "-m")
0073 macro = argv[i + 1];
0074 else if (G4String(argv[i]) == "-u")
0075 session = argv[i + 1];
0076 #ifdef G4MULTITHREADED
0077 else if (G4String(argv[i]) == "-t") {
0078 nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0079 }
0080 #endif
0081 else if (G4String(argv[i]) == "-vDefault") {
0082 verboseBestUnits = false;
0083 --i;
0084 }
0085 else {
0086 PrintUsage();
0087 return 1;
0088 }
0089 }
0090
0091
0092
0093 G4UIExecutive* ui = nullptr;
0094 if (!macro.size()) {
0095 ui = new G4UIExecutive(argc, argv, session);
0096 }
0097
0098
0099
0100
0101
0102 if (verboseBestUnits) {
0103 G4int precision = 4;
0104 G4SteppingVerbose::UseBestUnit(precision);
0105 }
0106
0107
0108
0109 auto runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
0110 #ifdef G4MULTITHREADED
0111 if (nThreads > 0) {
0112 runManager->SetNumberOfThreads(nThreads);
0113 }
0114 #endif
0115
0116
0117
0118 auto detConstruction = new B4::DetectorConstruction();
0119 runManager->SetUserInitialization(detConstruction);
0120
0121 auto physicsList = new FTFP_BERT;
0122 runManager->SetUserInitialization(physicsList);
0123
0124 auto actionInitialization = new B4a::ActionInitialization(detConstruction);
0125 runManager->SetUserInitialization(actionInitialization);
0126
0127
0128
0129 auto visManager = new G4VisExecutive;
0130
0131
0132 visManager->Initialize();
0133
0134
0135 auto UImanager = G4UImanager::GetUIpointer();
0136
0137
0138
0139 if (macro.size()) {
0140
0141 G4String command = "/control/execute ";
0142 UImanager->ApplyCommand(command + macro);
0143 }
0144 else {
0145
0146 UImanager->ApplyCommand("/control/execute init_vis.mac");
0147 if (ui->IsGUI()) {
0148 UImanager->ApplyCommand("/control/execute gui.mac");
0149 }
0150 ui->SessionStart();
0151 delete ui;
0152 }
0153
0154
0155
0156
0157
0158
0159 delete visManager;
0160 delete runManager;
0161 }
0162
0163