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