File indexing completed on 2026-05-01 07:38:35
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 #include "FTFP_BERT.hh"
0035 #include "VG01ActionInitialization.hh"
0036 #include "VG01DetectorConstruction.hh"
0037 #include "VG01SteppingVerboseWithDir.hh"
0038
0039 #include "G4RunManager.hh"
0040 #include "G4RunManagerFactory.hh"
0041 #include "G4StepLimiterPhysics.hh"
0042 #include "G4UImanager.hh"
0043 #include "G4UIsession.hh"
0044 #include "G4UIterminal.hh"
0045 #include "G4VModularPhysicsList.hh"
0046 #include "Randomize.hh"
0047
0048 #include <iomanip>
0049 #include <iostream>
0050
0051
0052 #include "G4UIExecutive.hh"
0053 #include "G4VisExecutive.hh"
0054
0055 static G4bool parUseVecGeom = true;
0056 static G4bool parCompareG4 = false;
0057 static G4bool parInteractive = false;
0058 static std::string parMacroFileName = "";
0059 static std::string parGDMLFile = "TestNTST.gdml";
0060
0061 void GetInputArguments(int argc, char** argv);
0062 void PrintUsage();
0063
0064 int main(int argc, char** argv)
0065 {
0066
0067
0068 GetInputArguments(argc, argv);
0069 G4cout << " ========== Running exampleVecGeomNav ================ " << G4endl
0070 << " GDML geometry file = " << parGDMLFile << G4endl
0071 << " Geant4 macro = " << parMacroFileName << G4endl
0072 << " Use VecGeom (VG) navigation = " << parUseVecGeom << G4endl
0073 << " Compare G4 vs VG navigation = " << parCompareG4 << G4endl
0074 << " ===================================================== " << G4endl;
0075
0076
0077 G4VSteppingVerbose::SetInstance(new VG01SteppingVerboseWithDir());
0078
0079
0080
0081 G4RunManager* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Serial);
0082
0083
0084
0085
0086
0087
0088 VG01DetectorConstruction* detector = new VG01DetectorConstruction;
0089 detector->SetGDMLFileName(parGDMLFile);
0090 detector->SetUseVecGeom(parUseVecGeom);
0091 runManager->SetUserInitialization(detector);
0092
0093
0094
0095 G4VModularPhysicsList* physicsList = new FTFP_BERT;
0096 physicsList->RegisterPhysics(new G4StepLimiterPhysics());
0097 runManager->SetUserInitialization(physicsList);
0098
0099
0100
0101 runManager->SetUserInitialization(new VG01ActionInitialization());
0102
0103
0104
0105 G4UImanager* UImgr = G4UImanager::GetUIpointer();
0106 G4String command = "/control/execute ";
0107 if (parMacroFileName != "-") UImgr->ApplyCommand(command + parMacroFileName);
0108
0109
0110
0111 if (parInteractive) {
0112 G4UIExecutive* uiExec = 0;
0113 uiExec = new G4UIExecutive(argc, argv);
0114
0115
0116
0117 G4VisManager* visManager = new G4VisExecutive;
0118
0119
0120 visManager->Initialize();
0121
0122
0123
0124
0125 uiExec->SessionStart();
0126
0127
0128 delete uiExec;
0129 delete visManager;
0130 }
0131 else {
0132
0133 G4cout << G4endl
0134 << " ================================================================= " << G4endl
0135 << " Final random number = " << G4UniformRand() << G4endl
0136 << " ================================================================= " << G4endl
0137 << G4endl;
0138 }
0139
0140
0141
0142 delete runManager;
0143 return 0;
0144 }
0145
0146 void horizontal_line(char c)
0147 {
0148 std::cout << "\n " << std::setw(100) << std::setfill(c) << "" << std::setfill(' ') << std::endl;
0149 }
0150
0151 void PrintUsage()
0152 {
0153 horizontal_line('=');
0154 std::cout << " Geant4 application to demonstrate interface to VecGeom Navigation. \n"
0155 << std::endl
0156 << " Two modes: \n\n"
0157 << " * 1 parameter this is treated as Geant4 macro file \n"
0158 << " \n"
0159 << " * Multiple Parameters: \n"
0160 << " at least one of the following: \n"
0161 << " -m : the standard Geant4 macro file \n"
0162 << " -i : interactive (after batch, if any) \n"
0163 << " optionally one of the following: \n"
0164 << " -v : flag ==> run using VecGeom navigation (default). \n"
0165 << " -o : flag ==> run using Geant4 navigation. \n"
0166 << " -c : flag ==> compare VecGeom and Geant4 navigation"
0167 << " (and report differences.) \n"
0168 << " and other(s): \n"
0169 << " -g : GDML file with geometry \n"
0170 << "\n"
0171 << std::endl;
0172 horizontal_line('=');
0173 }
0174
0175 void GetInputArguments(int argc, char** argv)
0176 {
0177
0178 if (argc == 1) {
0179 PrintUsage();
0180 exit(0);
0181 }
0182 if (argc == 2) {
0183 parMacroFileName = argv[1];
0184 G4cout << " argc = 2 -- Filename = " << parMacroFileName << G4endl;
0185 return;
0186 }
0187
0188
0189 for (G4int i = 1; i < argc; ++i) {
0190 if (G4String(argv[i]) == "-m") {
0191 if (++i < argc) {
0192 parMacroFileName = argv[i];
0193 G4cout << " arg-parsing: Macro file name= " << parMacroFileName << G4endl;
0194 }
0195 else {
0196 G4cerr << " Parse Error: '-m' cannot be last argument. Use it : -m <filename>" << G4endl;
0197 PrintUsage();
0198 exit(1);
0199 }
0200 }
0201 else if (G4String(argv[i]) == "-g") {
0202 if (++i < argc) {
0203 parGDMLFile = argv[i];
0204 G4cout << " arg-parsing: GDML file name= " << parGDMLFile << G4endl;
0205 }
0206 else {
0207 G4cerr << " Parse Error: '-m' cannot be last argument. Use it : -m <filename>" << G4endl;
0208 PrintUsage();
0209 exit(1);
0210 }
0211 }
0212 else if (G4String(argv[i]) == "-v") {
0213 parUseVecGeom = true;
0214 }
0215 else if (G4String(argv[i]) == "-o") {
0216 parUseVecGeom = false;
0217 }
0218 else if (G4String(argv[i]) == "-c") {
0219 parCompareG4 = true;
0220 parUseVecGeom = true;
0221 }
0222 else {
0223 G4cerr << " Unknown argument : " << argv[i] << G4endl;
0224 PrintUsage();
0225 exit(1);
0226 }
0227 }
0228
0229
0230 if (parMacroFileName == "" && !parInteractive) {
0231 G4cerr << " *** ERROR : either interactive mode or a Geant4 macro file is required. "
0232 << G4endl;
0233 PrintUsage();
0234 exit(-1);
0235 }
0236 }