File indexing completed on 2026-09-19 08:37:32
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
0032 #include "G4MonopolePhysics.hh"
0033 #include "G4PhysListFactory.hh"
0034 #include "G4RunManagerFactory.hh"
0035 #include "G4Types.hh"
0036 #include "G4UIExecutive.hh"
0037 #include "G4UImanager.hh"
0038 #include "G4VModularPhysicsList.hh"
0039 #include "G4VisExecutive.hh"
0040 #include "Randomize.hh"
0041 #include "globals.hh"
0042
0043
0044
0045 namespace
0046 {
0047 void PrintUsage()
0048 {
0049 G4cerr << " Usage: " << G4endl << " monopole [-m macro ] [-s setupMonopole] [-t nThreads]"
0050 << G4endl << " Note: " << G4endl
0051 << " -s should be followed by a composed string, eg. \'1 0 100 GeV\'" << G4endl
0052 << " -t option is for multi-threaded mode." << G4endl << G4endl;
0053 }
0054 }
0055
0056
0057
0058 int main(int argc, char** argv)
0059 {
0060
0061
0062 if (argc > 7) {
0063 PrintUsage();
0064 return 1;
0065 }
0066
0067 G4String macro;
0068 G4String setupMonopole;
0069 G4int nThreads = 1;
0070 for (G4int i = 1; i < argc; i = i + 2) {
0071 if (G4String(argv[i]) == "-m")
0072 macro = argv[i + 1];
0073 else if (G4String(argv[i]) == "-s")
0074 setupMonopole = argv[i + 1];
0075 else if (G4String(argv[i]) == "-t") {
0076 nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0077 }
0078 else {
0079 PrintUsage();
0080 return 1;
0081 }
0082 }
0083
0084
0085 auto* runManager = G4RunManagerFactory::CreateRunManager();
0086 if (nThreads > 0) {
0087 runManager->SetNumberOfThreads(nThreads);
0088 }
0089 G4cout << "===== Example is started with " << runManager->GetNumberOfThreads()
0090 << " threads =====" << G4endl;
0091
0092
0093 G4UIExecutive* ui = nullptr;
0094 if (macro.empty()) {
0095 ui = new G4UIExecutive(argc, argv);
0096 }
0097
0098
0099 G4UImanager* UImanager = G4UImanager::GetUIpointer();
0100
0101
0102
0103 G4PhysListFactory factory;
0104 G4VModularPhysicsList* phys = factory.GetReferencePhysList("FTFP_BERT");
0105
0106
0107 G4MonopolePhysics* theMonopole = new G4MonopolePhysics();
0108
0109
0110 if (setupMonopole.size()) {
0111 UImanager->ApplyCommand("/control/verbose 1");
0112 UImanager->ApplyCommand("/monopole/setup " + setupMonopole);
0113 }
0114
0115
0116 phys->RegisterPhysics(theMonopole);
0117
0118 runManager->SetUserInitialization(phys);
0119
0120
0121 G4VisManager* visManager = nullptr;
0122
0123
0124 DetectorConstruction* det = new DetectorConstruction();
0125 runManager->SetUserInitialization(det);
0126
0127
0128 runManager->SetUserInitialization(new ActionInitialization(det));
0129
0130
0131
0132 if (macro.size()) {
0133
0134 G4String command = "/control/execute ";
0135 UImanager->ApplyCommand(command + macro);
0136 }
0137 else {
0138
0139 visManager = new G4VisExecutive();
0140 visManager->Initialize();
0141 UImanager->ApplyCommand("/control/execute init_vis.mac");
0142 ui->SessionStart();
0143 delete ui;
0144 }
0145
0146 delete visManager;
0147
0148
0149 delete runManager;
0150
0151 return 0;
0152 }
0153
0154