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