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