File indexing completed on 2026-03-30 07:51:00
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 #include "OpNoviceDetectorConstruction.hh"
0041 #ifdef GEANT4_USE_GDML
0042 # include "OpNoviceGDMLDetectorConstruction.hh"
0043 #endif
0044 #include "FTFP_BERT.hh"
0045 #include "OpNoviceActionInitialization.hh"
0046
0047 #include "G4EmStandardPhysics_option4.hh"
0048 #include "G4OpticalPhysics.hh"
0049 #include "G4RunManagerFactory.hh"
0050 #include "G4Types.hh"
0051 #include "G4UIExecutive.hh"
0052 #include "G4UImanager.hh"
0053 #include "G4VisExecutive.hh"
0054
0055
0056 namespace
0057 {
0058 void PrintUsage()
0059 {
0060 G4cerr << " Usage: " << G4endl;
0061 #ifdef GEANT4_USE_GDML
0062 G4cerr << " OpNovice [-g gdmlfile] [-m macro ] [-u UIsession] [-t "
0063 "nThreads] [-r seed] "
0064 << G4endl;
0065 #else
0066 G4cerr << " OpNovice [-m macro ] [-u UIsession] [-t nThreads] [-r seed] " << G4endl;
0067 #endif
0068 G4cerr << " note: -t option is available only for multi-threaded mode." << G4endl;
0069 }
0070 }
0071
0072
0073
0074 int main(int argc, char** argv)
0075 {
0076
0077
0078 if (argc > 9) {
0079 PrintUsage();
0080 return 1;
0081 }
0082 G4String gdmlfile;
0083 G4String macro;
0084 G4String session;
0085 #ifdef G4MULTITHREADED
0086 G4int nThreads = 0;
0087 #endif
0088
0089 G4long myseed = 345354;
0090 for (G4int i = 1; i < argc; i = i + 2) {
0091 if (G4String(argv[i]) == "-g")
0092 gdmlfile = argv[i + 1];
0093 else if (G4String(argv[i]) == "-m")
0094 macro = argv[i + 1];
0095 else if (G4String(argv[i]) == "-u")
0096 session = argv[i + 1];
0097 else if (G4String(argv[i]) == "-r")
0098 myseed = atoi(argv[i + 1]);
0099 #ifdef G4MULTITHREADED
0100 else if (G4String(argv[i]) == "-t") {
0101 nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0102 }
0103 #endif
0104 else {
0105 PrintUsage();
0106 return 1;
0107 }
0108 }
0109
0110
0111 G4UIExecutive* ui = nullptr;
0112 if (macro.size() == 0) {
0113 ui = new G4UIExecutive(argc, argv);
0114 }
0115
0116
0117 auto runManager = G4RunManagerFactory::CreateRunManager();
0118 #ifdef G4MULTITHREADED
0119 if (nThreads > 0) runManager->SetNumberOfThreads(nThreads);
0120 #endif
0121
0122
0123 G4Random::setTheSeed(myseed);
0124
0125
0126
0127
0128 if (gdmlfile != "") {
0129 #ifdef GEANT4_USE_GDML
0130 runManager->SetUserInitialization(new OpNoviceGDMLDetectorConstruction(gdmlfile));
0131 #else
0132 G4cout << "Error! Input gdml file specified, but Geant4 wasn't" << G4endl
0133 << "built with gdml support." << G4endl;
0134 return 1;
0135 #endif
0136 }
0137 else {
0138 runManager->SetUserInitialization(new OpNoviceDetectorConstruction());
0139 }
0140
0141 G4VModularPhysicsList* physicsList = new FTFP_BERT;
0142 physicsList->ReplacePhysics(new G4EmStandardPhysics_option4());
0143 auto opticalPhysics = new G4OpticalPhysics();
0144 physicsList->RegisterPhysics(opticalPhysics);
0145 runManager->SetUserInitialization(physicsList);
0146
0147 runManager->SetUserInitialization(new OpNoviceActionInitialization());
0148
0149 G4VisManager* visManager = new G4VisExecutive("Quiet");
0150 visManager->Initialize();
0151
0152 G4UImanager* UImanager = G4UImanager::GetUIpointer();
0153
0154 if (macro.size()) {
0155 G4String command = "/control/execute ";
0156 UImanager->ApplyCommand(command + macro);
0157 }
0158 else
0159 {
0160 UImanager->ApplyCommand("/control/execute vis.mac");
0161 if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
0162 ui->SessionStart();
0163 delete ui;
0164 }
0165
0166 delete visManager;
0167 delete runManager;
0168
0169 return 0;
0170 }
0171
0172