Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 /// \file exampleB4a.cc 27 /// \file exampleB4a.cc 28 /// \brief Main program of the B4a example 28 /// \brief Main program of the B4a example 29 29 30 #include "ActionInitialization.hh" << 30 #include "B4DetectorConstruction.hh" 31 #include "DetectorConstruction.hh" << 31 #include "B4aActionInitialization.hh" 32 #include "FTFP_BERT.hh" << 33 32 34 #include "G4RunManagerFactory.hh" 33 #include "G4RunManagerFactory.hh" 35 #include "G4SteppingVerbose.hh" << 34 36 #include "G4UIExecutive.hh" << 37 #include "G4UIcommand.hh" << 38 #include "G4UImanager.hh" 35 #include "G4UImanager.hh" >> 36 #include "G4UIcommand.hh" >> 37 #include "FTFP_BERT.hh" >> 38 >> 39 #include "Randomize.hh" >> 40 39 #include "G4VisExecutive.hh" 41 #include "G4VisExecutive.hh" 40 // #include "Randomize.hh" << 42 #include "G4UIExecutive.hh" 41 43 42 //....oooOO0OOooo........oooOO0OOooo........oo 44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 43 45 44 namespace << 46 namespace { 45 { << 47 void PrintUsage() { 46 void PrintUsage() << 48 G4cerr << " Usage: " << G4endl; 47 { << 49 G4cerr << " exampleB4a [-m macro ] [-u UIsession] [-t nThreads]" << G4endl; 48 G4cerr << " Usage: " << G4endl; << 50 G4cerr << " note: -t option is available only for multi-threaded mode." 49 G4cerr << " exampleB4a [-m macro ] [-u UIses << 51 << G4endl; 50 G4cerr << " note: -t option is available o << 52 } 51 } 53 } 52 } // namespace << 53 54 54 //....oooOO0OOooo........oooOO0OOooo........oo 55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 55 56 56 int main(int argc, char** argv) << 57 int main(int argc,char** argv) 57 { 58 { 58 // Evaluate arguments 59 // Evaluate arguments 59 // 60 // 60 if (argc > 7) { << 61 if ( argc > 7 ) { 61 PrintUsage(); 62 PrintUsage(); 62 return 1; 63 return 1; 63 } 64 } 64 << 65 65 G4String macro; 66 G4String macro; 66 G4String session; 67 G4String session; 67 G4bool verboseBestUnits = true; << 68 #ifdef G4MULTITHREADED 68 #ifdef G4MULTITHREADED 69 G4int nThreads = 0; 69 G4int nThreads = 0; 70 #endif 70 #endif 71 for (G4int i = 1; i < argc; i = i + 2) { << 71 for ( G4int i=1; i<argc; i=i+2 ) { 72 if (G4String(argv[i]) == "-m") << 72 if ( G4String(argv[i]) == "-m" ) macro = argv[i+1]; 73 macro = argv[i + 1]; << 73 else if ( G4String(argv[i]) == "-u" ) session = argv[i+1]; 74 else if (G4String(argv[i]) == "-u") << 75 session = argv[i + 1]; << 76 #ifdef G4MULTITHREADED 74 #ifdef G4MULTITHREADED 77 else if (G4String(argv[i]) == "-t") { << 75 else if ( G4String(argv[i]) == "-t" ) { 78 nThreads = G4UIcommand::ConvertToInt(arg << 76 nThreads = G4UIcommand::ConvertToInt(argv[i+1]); 79 } 77 } 80 #endif 78 #endif 81 else if (G4String(argv[i]) == "-vDefault") << 82 verboseBestUnits = false; << 83 --i; // this option is not followed wit << 84 } << 85 else { 79 else { 86 PrintUsage(); 80 PrintUsage(); 87 return 1; 81 return 1; 88 } 82 } 89 } << 83 } 90 << 84 91 // Detect interactive mode (if no macro prov 85 // Detect interactive mode (if no macro provided) and define UI session 92 // 86 // 93 G4UIExecutive* ui = nullptr; 87 G4UIExecutive* ui = nullptr; 94 if (!macro.size()) { << 88 if ( ! macro.size() ) { 95 ui = new G4UIExecutive(argc, argv, session 89 ui = new G4UIExecutive(argc, argv, session); 96 } 90 } 97 91 98 // Optionally: choose a different Random eng 92 // Optionally: choose a different Random engine... >> 93 // 99 // G4Random::setTheEngine(new CLHEP::MTwistE 94 // G4Random::setTheEngine(new CLHEP::MTwistEngine); 100 << 95 101 // Use G4SteppingVerboseWithUnits << 102 if (verboseBestUnits) { << 103 G4int precision = 4; << 104 G4SteppingVerbose::UseBestUnit(precision); << 105 } << 106 << 107 // Construct the default run manager 96 // Construct the default run manager 108 // 97 // 109 auto runManager = G4RunManagerFactory::Creat << 98 auto* runManager = >> 99 G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default); 110 #ifdef G4MULTITHREADED 100 #ifdef G4MULTITHREADED 111 if (nThreads > 0) { << 101 if ( nThreads > 0 ) { 112 runManager->SetNumberOfThreads(nThreads); 102 runManager->SetNumberOfThreads(nThreads); 113 } << 103 } 114 #endif 104 #endif 115 105 116 // Set mandatory initialization classes 106 // Set mandatory initialization classes 117 // 107 // 118 auto detConstruction = new B4::DetectorConst << 108 auto detConstruction = new B4DetectorConstruction(); 119 runManager->SetUserInitialization(detConstru 109 runManager->SetUserInitialization(detConstruction); 120 110 121 auto physicsList = new FTFP_BERT; 111 auto physicsList = new FTFP_BERT; 122 runManager->SetUserInitialization(physicsLis 112 runManager->SetUserInitialization(physicsList); 123 << 113 124 auto actionInitialization = new B4a::ActionI << 114 auto actionInitialization = new B4aActionInitialization(detConstruction); 125 runManager->SetUserInitialization(actionInit 115 runManager->SetUserInitialization(actionInitialization); 126 << 116 127 // Initialize visualization 117 // Initialize visualization 128 // 118 // 129 auto visManager = new G4VisExecutive; 119 auto visManager = new G4VisExecutive; 130 // G4VisExecutive can take a verbosity argum 120 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance. 131 // auto visManager = new G4VisExecutive("Qui << 121 // G4VisManager* visManager = new G4VisExecutive("Quiet"); 132 visManager->Initialize(); 122 visManager->Initialize(); 133 123 134 // Get the pointer to the User Interface man 124 // Get the pointer to the User Interface manager 135 auto UImanager = G4UImanager::GetUIpointer() 125 auto UImanager = G4UImanager::GetUIpointer(); 136 126 137 // Process macro or start UI session 127 // Process macro or start UI session 138 // 128 // 139 if (macro.size()) { << 129 if ( macro.size() ) { 140 // batch mode 130 // batch mode 141 G4String command = "/control/execute "; 131 G4String command = "/control/execute "; 142 UImanager->ApplyCommand(command + macro); << 132 UImanager->ApplyCommand(command+macro); 143 } 133 } 144 else { << 134 else { 145 // interactive mode : define UI session 135 // interactive mode : define UI session 146 UImanager->ApplyCommand("/control/execute 136 UImanager->ApplyCommand("/control/execute init_vis.mac"); 147 if (ui->IsGUI()) { 137 if (ui->IsGUI()) { 148 UImanager->ApplyCommand("/control/execut 138 UImanager->ApplyCommand("/control/execute gui.mac"); 149 } 139 } 150 ui->SessionStart(); 140 ui->SessionStart(); 151 delete ui; 141 delete ui; 152 } 142 } 153 143 154 // Job termination 144 // Job termination 155 // Free the store: user actions, physics_lis 145 // Free the store: user actions, physics_list and detector_description are 156 // owned and deleted by the run manager, so << 146 // owned and deleted by the run manager, so they should not be deleted 157 // in the main() program ! 147 // in the main() program ! 158 148 159 delete visManager; 149 delete visManager; 160 delete runManager; 150 delete runManager; 161 } 151 } 162 152 163 //....oooOO0OOooo........oooOO0OOooo........oo 153 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 164 154