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