Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // Author: J. Apostolakis, S. Wenzel, 2018-2021 27 // 28 // Started from FullCMS Geant4 application by Mihaly Novak (2017) 29 //--------------------------------------------------------------------- 30 31 #include "FTFP_BERT.hh" 32 #include "VG01ActionInitialization.hh" 33 #include "VG01DetectorConstruction.hh" 34 #include "VG01SteppingVerboseWithDir.hh" 35 36 #include "G4RunManager.hh" 37 #include "G4RunManagerFactory.hh" 38 #include "G4StepLimiterPhysics.hh" 39 #include "G4UImanager.hh" 40 #include "G4UIsession.hh" 41 #include "G4UIterminal.hh" 42 #include "G4VModularPhysicsList.hh" 43 #include "Randomize.hh" 44 45 #include <iomanip> 46 #include <iostream> 47 48 // For interactivity 49 #include "G4UIExecutive.hh" 50 #include "G4VisExecutive.hh" 51 52 static G4bool parUseVecGeom = true; 53 static G4bool parCompareG4 = false; 54 static G4bool parInteractive = false; 55 static std::string parMacroFileName = ""; 56 static std::string parGDMLFile = "TestNTST.gdml"; 57 58 void GetInputArguments(int argc, char** argv); 59 void PrintUsage(); 60 61 int main(int argc, char** argv) 62 { 63 // 64 // get input arguments 65 GetInputArguments(argc, argv); 66 G4cout << " ========== Running exampleVecGeomNav ================ " << G4endl 67 << " GDML geometry file = " << parGDMLFile << G4endl 68 << " Geant4 macro = " << parMacroFileName << G4endl 69 << " Use VecGeom (VG) navigation = " << parUseVecGeom << G4endl 70 << " Compare G4 vs VG navigation = " << parCompareG4 << G4endl 71 << " ===================================================== " << G4endl; 72 73 // Use custom stepping verbosity 74 G4VSteppingVerbose::SetInstance(new VG01SteppingVerboseWithDir()); 75 76 // Construct the run manager 77 // 78 G4RunManager* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Serial); 79 // or G4RunManagerType::Default to get Task or Multithreading 80 81 // set mandatory initialization classes 82 // 83 // 1. Detector construction 84 // 85 VG01DetectorConstruction* detector = new VG01DetectorConstruction; 86 detector->SetGDMLFileName(parGDMLFile); 87 detector->SetUseVecGeom(parUseVecGeom); 88 runManager->SetUserInitialization(detector); 89 90 // 2. Physics list 91 // 92 G4VModularPhysicsList* physicsList = new FTFP_BERT; 93 physicsList->RegisterPhysics(new G4StepLimiterPhysics()); 94 runManager->SetUserInitialization(physicsList); 95 96 // 3. User action 97 // 98 runManager->SetUserInitialization(new VG01ActionInitialization()); 99 100 // 4. Run the simulation in batch mode, except if macroFile == "-" 101 // 102 G4UImanager* UImgr = G4UImanager::GetUIpointer(); 103 G4String command = "/control/execute "; 104 if (parMacroFileName != "-") UImgr->ApplyCommand(command + parMacroFileName); 105 106 // 5. Run the simulation in Interactive mode if requested ( flag: -i ) 107 // 108 if (parInteractive) { 109 G4UIExecutive* uiExec = 0; 110 uiExec = new G4UIExecutive(argc, argv); 111 112 // Initialize visualization 113 // 114 G4VisManager* visManager = new G4VisExecutive; 115 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance. 116 // G4VisManager* visManager = new G4VisExecutive("Quiet"); 117 visManager->Initialize(); 118 119 // UImgr->ApplyCommand("/control/execute init_vis.mac"); 120 121 // interactive mode 122 uiExec->SessionStart(); 123 124 // Cleanup 125 delete uiExec; 126 delete visManager; 127 } 128 else { 129 // Print out the final random number - for batch only runs 130 G4cout << G4endl 131 << " ================================================================= " << G4endl 132 << " Final random number = " << G4UniformRand() << G4endl 133 << " ================================================================= " << G4endl 134 << G4endl; 135 } 136 // 137 138 // Delete the RunManager 139 delete runManager; 140 return 0; 141 } 142 143 void horizontal_line(char c) 144 { 145 std::cout << "\n " << std::setw(100) << std::setfill(c) << "" << std::setfill(' ') << std::endl; 146 } 147 148 void PrintUsage() 149 { 150 horizontal_line('='); 151 std::cout << " Geant4 application to demonstrate interface to VecGeom Navigation. \n" 152 << std::endl 153 << " Two modes: \n\n" 154 << " * 1 parameter this is treated as Geant4 macro file \n" 155 << " \n" 156 << " * Multiple Parameters: \n" 157 << " at least one of the following: \n" 158 << " -m : the standard Geant4 macro file \n" 159 << " -i : interactive (after batch, if any) \n" 160 << " optionally one of the following: \n" 161 << " -v : flag ==> run using VecGeom navigation (default). \n" 162 << " -o : flag ==> run using Geant4 navigation. \n" 163 << " -c : flag ==> compare VecGeom and Geant4 navigation" 164 << " (and report differences.) \n" 165 << " and other(s): \n" 166 << " -g : GDML file with geometry \n" 167 << "\n" 168 << std::endl; 169 horizontal_line('='); 170 } 171 172 void GetInputArguments(int argc, char** argv) 173 { 174 // process arguments 175 if (argc == 1) { 176 PrintUsage(); 177 exit(0); 178 } 179 if (argc == 2) { 180 parMacroFileName = argv[1]; 181 G4cout << " argc = 2 -- Filename = " << parMacroFileName << G4endl; 182 return; 183 } 184 185 // Adapted from examples/basic/B4/exampleB4a.cc 186 for (G4int i = 1; i < argc; ++i) { 187 if (G4String(argv[i]) == "-m") { 188 if (++i < argc) { 189 parMacroFileName = argv[i]; 190 G4cout << " arg-parsing: Macro file name= " << parMacroFileName << G4endl; 191 } 192 else { 193 G4cerr << " Parse Error: '-m' cannot be last argument. Use it : -m <filename>" << G4endl; 194 PrintUsage(); 195 exit(1); 196 } 197 } 198 else if (G4String(argv[i]) == "-g") { 199 if (++i < argc) { 200 parGDMLFile = argv[i]; 201 G4cout << " arg-parsing: GDML file name= " << parGDMLFile << G4endl; 202 } 203 else { 204 G4cerr << " Parse Error: '-m' cannot be last argument. Use it : -m <filename>" << G4endl; 205 PrintUsage(); 206 exit(1); 207 } 208 } 209 else if (G4String(argv[i]) == "-v") { 210 parUseVecGeom = true; 211 } 212 else if (G4String(argv[i]) == "-o") { 213 parUseVecGeom = false; 214 } 215 else if (G4String(argv[i]) == "-c") { 216 parCompareG4 = true; 217 parUseVecGeom = true; 218 } 219 else { 220 G4cerr << " Unknown argument : " << argv[i] << G4endl; 221 PrintUsage(); 222 exit(1); 223 } 224 } 225 226 // check if mandatory Geant4 macro file was provided 227 if (parMacroFileName == "" && !parInteractive) { 228 G4cerr << " *** ERROR : either interactive mode or a Geant4 macro file is required. " 229 << G4endl; 230 PrintUsage(); 231 exit(-1); 232 } 233 } 234