File indexing completed on 2025-02-23 09:22:39
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
0042
0043
0044
0045 #include "ActionInitialization.hh"
0046 #include "DetectorConstruction.hh"
0047 #include "PrimaryGeneratorAction.hh"
0048
0049 #include "G4PhysListFactory.hh"
0050 #include "G4RunManagerFactory.hh"
0051 #include "G4UIExecutive.hh"
0052 #include "G4UImanager.hh"
0053 #include "G4VModularPhysicsList.hh"
0054 #include "G4VisExecutive.hh"
0055 #include "Randomize.hh"
0056
0057
0058
0059 namespace
0060 {
0061 void PrintUsage()
0062 {
0063 G4cerr << " Usage: " << G4endl;
0064 G4cerr << " factory [-m macro ] [-p physList ] [-u UIsession] [-t nThreads]" << G4endl;
0065 G4cerr << " note: -t option is available only for multi-threaded mode." << G4endl;
0066 G4cerr << G4endl;
0067 }
0068 }
0069
0070
0071
0072 int main(int argc, char** argv)
0073 {
0074
0075
0076 if (argc > 9) {
0077 PrintUsage();
0078 return 1;
0079 }
0080
0081 G4String macro;
0082 G4String session;
0083 G4String physListName;
0084 G4String gdmlFileName;
0085 #ifdef G4MULTITHREADED
0086 G4int nofThreads = 0;
0087 #endif
0088 for (G4int i = 1; i < argc; i = i + 2) {
0089 if (G4String(argv[i]) == "-m")
0090 macro = argv[i + 1];
0091 else if (G4String(argv[i]) == "-u")
0092 session = argv[i + 1];
0093 else if (G4String(argv[i]) == "-p")
0094 physListName = argv[i + 1];
0095 #ifdef G4MULTITHREADED
0096 else if (G4String(argv[i]) == "-t") {
0097 nofThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0098 }
0099 #endif
0100 else {
0101 PrintUsage();
0102 return 1;
0103 }
0104 }
0105
0106
0107
0108 G4UIExecutive* ui = nullptr;
0109 if (!macro.size()) {
0110 ui = new G4UIExecutive(argc, argv, session);
0111 }
0112
0113
0114 G4Random::setTheEngine(new CLHEP::RanecuEngine());
0115
0116
0117 auto* runManager = G4RunManagerFactory::CreateRunManager();
0118 #ifdef G4MULTITHREADED
0119 if (nofThreads > 0) {
0120 runManager->SetNumberOfThreads(nofThreads);
0121 }
0122 #endif
0123
0124
0125 G4PhysListFactory factory;
0126 G4VModularPhysicsList* physList = nullptr;
0127
0128
0129 if (!physListName.size()) {
0130
0131 char* physListNameEnv = std::getenv("PHYSLIST");
0132 if (physListNameEnv) {
0133 physListName = G4String(physListNameEnv);
0134 }
0135 }
0136
0137
0138 if (physListName.size() && (!factory.IsReferencePhysList(physListName))) {
0139 G4cerr << "Physics list " << physListName << " is not available in PhysListFactory." << G4endl;
0140 physListName.clear();
0141 }
0142
0143
0144 if (!physListName.size()) {
0145 physListName = "FTFP_BERT";
0146 }
0147
0148
0149 physList = factory.GetReferencePhysList(physListName);
0150
0151
0152 runManager->SetUserInitialization(new DetectorConstruction());
0153 runManager->SetUserInitialization(physList);
0154
0155
0156 runManager->SetUserInitialization(new ActionInitialization("factory"));
0157
0158
0159 G4VisManager* visManager = new G4VisExecutive;
0160
0161
0162 visManager->Initialize();
0163
0164
0165 G4UImanager* UImanager = G4UImanager::GetUIpointer();
0166
0167 if (macro.size()) {
0168
0169 G4String command = "/control/execute ";
0170 UImanager->ApplyCommand(command + macro);
0171 }
0172 else {
0173
0174 UImanager->ApplyCommand("/control/execute init_vis.mac");
0175 ui->SessionStart();
0176 delete ui;
0177 }
0178
0179
0180
0181
0182
0183
0184 delete visManager;
0185 delete runManager;
0186 }
0187
0188