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 // $Id: field06.cc 75572 2013-11-04 11:46:08Z gcosmo $ 26 // 27 // 27 /// \file field/field06/field06.cc 28 /// \file field/field06/field06.cc 28 /// \brief Main program of the field/field06 e 29 /// \brief Main program of the field/field06 example 29 // 30 // >> 31 // >> 32 // >> 33 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 34 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 35 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 36 33 #ifndef WIN32 37 #ifndef WIN32 34 # include <unistd.h> << 38 #include <unistd.h> 35 #endif 39 #endif 36 40 37 #include "F06ActionInitialization.hh" << 38 #include "F06DetectorConstruction.hh" << 39 #include "F06PhysicsList.hh" 41 #include "F06PhysicsList.hh" >> 42 #include "F06DetectorConstruction.hh" >> 43 #include "F06ActionInitialization.hh" >> 44 >> 45 #ifdef G4MULTITHREADED >> 46 #include "G4MTRunManager.hh" >> 47 #else >> 48 #include "G4RunManager.hh" >> 49 #endif 40 50 41 #include "G4RunManagerFactory.hh" << 42 #include "G4Transportation.hh" << 43 #include "G4Types.hh" << 44 #include "G4UIExecutive.hh" << 45 #include "G4UIcommand.hh" << 46 #include "G4UImanager.hh" 51 #include "G4UImanager.hh" 47 #include "G4VisExecutive.hh" << 52 #include "G4UIcommand.hh" >> 53 48 #include "Randomize.hh" 54 #include "Randomize.hh" 49 55 >> 56 #ifdef G4VIS_USE >> 57 #include "G4VisExecutive.hh" >> 58 #endif >> 59 >> 60 #ifdef G4UI_USE >> 61 #include "G4UIExecutive.hh" >> 62 #endif >> 63 50 //....oooOO0OOooo........oooOO0OOooo........oo 64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 51 namespace << 65 namespace { 52 { << 66 void PrintUsage() { 53 void PrintUsage() << 67 G4cerr << " Usage: " << G4endl; 54 { << 68 G4cerr << " field06 [-m macro ] [-u UIsession] [-t nThreads] [-r seed] " 55 G4cerr << " Usage: " << G4endl; << 69 << G4endl; 56 G4cerr << " field06 [-m macro ] [-u UIsessio << 70 G4cerr << " note: -t option is available only for multi-threaded mode." 57 G4cerr << " note: -t option is available o << 71 << G4endl; >> 72 } 58 } 73 } 59 } // namespace << 60 74 61 //....oooOO0OOooo........oooOO0OOooo........oo 75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 62 76 63 int main(int argc, char** argv) << 77 int main(int argc,char** argv) 64 { 78 { 65 // Evaluate arguments 79 // Evaluate arguments 66 // 80 // 67 if (argc > 9) { << 81 if ( argc > 9 ) { 68 PrintUsage(); 82 PrintUsage(); 69 return 1; 83 return 1; 70 } 84 } 71 85 72 G4String macro; 86 G4String macro; 73 G4String session; 87 G4String session; >> 88 #ifdef G4MULTITHREADED 74 G4int nThreads = 0; 89 G4int nThreads = 0; >> 90 #endif 75 91 76 G4long randomSeed = 1234; << 92 G4long myseed = 1234; 77 for (G4int i = 1; i < argc; i = i + 2) { << 93 for ( G4int i=1; i<argc; i=i+2 ) { 78 if (G4String(argv[i]) == "-m") << 94 if ( G4String(argv[i]) == "-m" ) macro = argv[i+1]; 79 macro = argv[i + 1]; << 95 else if ( G4String(argv[i]) == "-u" ) session = argv[i+1]; 80 else if (G4String(argv[i]) == "-u") << 96 else if ( G4String(argv[i]) == "-r" ) myseed = atoi(argv[i+1]); 81 session = argv[i + 1]; << 97 #ifdef G4MULTITHREADED 82 else if (G4String(argv[i]) == "-r") << 98 else if ( G4String(argv[i]) == "-t" ) { 83 randomSeed = atoi(argv[i + 1]); << 99 nThreads = G4UIcommand::ConvertToInt(argv[i+1]); 84 else if (G4String(argv[i]) == "-t") { << 85 nThreads = G4UIcommand::ConvertToInt(arg << 86 } 100 } >> 101 #endif 87 else { 102 else { 88 PrintUsage(); 103 PrintUsage(); 89 return 1; 104 return 1; 90 } 105 } 91 } 106 } 92 107 93 // Instantiate G4UIExecutive for interactive << 108 // Choose the Random engine 94 G4UIExecutive* ui = nullptr; << 109 // 95 if (macro.size() == 0) { << 110 G4Random::setTheEngine(new CLHEP::RanecuEngine); 96 ui = new G4UIExecutive(argc, argv, session << 97 } << 98 111 99 // Construct the default run manager 112 // Construct the default run manager 100 // 113 // 101 auto* runManager = G4RunManagerFactory::Crea << 114 #ifdef G4MULTITHREADED 102 if (nThreads > 0) runManager->SetNumberOfThr << 115 G4MTRunManager * runManager = new G4MTRunManager; >> 116 if ( nThreads > 0 ) runManager->SetNumberOfThreads(nThreads); >> 117 #else >> 118 G4RunManager * runManager = new G4RunManager; >> 119 #endif 103 120 104 // Seed the random number generator manually 121 // Seed the random number generator manually 105 G4Random::setTheSeed(randomSeed); << 122 G4Random::setTheSeed(myseed); 106 123 107 // Set mandatory initialization classes 124 // Set mandatory initialization classes 108 // 125 // 109 // Detector construction 126 // Detector construction 110 runManager->SetUserInitialization(new F06Det 127 runManager->SetUserInitialization(new F06DetectorConstruction()); 111 // Physics list 128 // Physics list 112 runManager->SetUserInitialization(new F06Phy 129 runManager->SetUserInitialization(new F06PhysicsList()); 113 << 114 // Ensure that Transportation considers grav << 115 G4Transportation::EnableGravity(true); << 116 << 117 // User action initialization 130 // User action initialization 118 runManager->SetUserInitialization(new F06Act 131 runManager->SetUserInitialization(new F06ActionInitialization()); 119 132 >> 133 // Initialize G4 kernel >> 134 // >> 135 runManager->Initialize(); >> 136 >> 137 #ifdef G4VIS_USE 120 // Initialize visualization 138 // Initialize visualization 121 // 139 // 122 G4VisManager* visManager = new G4VisExecutiv 140 G4VisManager* visManager = new G4VisExecutive; 123 // G4VisExecutive can take a verbosity argum 141 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance. 124 // G4VisManager* visManager = new G4VisExecu 142 // G4VisManager* visManager = new G4VisExecutive("Quiet"); 125 visManager->Initialize(); 143 visManager->Initialize(); >> 144 #endif 126 145 127 // Get the pointer to the User Interface man 146 // Get the pointer to the User Interface manager 128 // 147 // 129 G4UImanager* UImanager = G4UImanager::GetUIp 148 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 130 << 149 131 if (!ui) { << 150 if ( macro.size() ) { 132 // batch mode << 151 // batch mode 133 G4String command = "/control/execute "; << 152 G4String command = "/control/execute "; 134 UImanager->ApplyCommand(command + macro); << 153 UImanager->ApplyCommand(command+macro); 135 } 154 } 136 else { << 155 else 137 UImanager->ApplyCommand("/control/execute << 156 { // interactive mode : define UI session 138 if (ui->IsGUI()) UImanager->ApplyCommand(" << 157 #ifdef G4UI_USE 139 ui->SessionStart(); << 158 G4UIExecutive* ui = new G4UIExecutive(argc, argv, session); 140 delete ui; << 159 #ifdef G4VIS_USE >> 160 UImanager->ApplyCommand("/control/execute vis.mac"); >> 161 #else >> 162 UImanager->ApplyCommand("/control/execute field06.in"); >> 163 #endif >> 164 if (ui->IsGUI()) >> 165 UImanager->ApplyCommand("/control/execute gui.mac"); >> 166 ui->SessionStart(); >> 167 delete ui; >> 168 #endif 141 } 169 } 142 170 143 // Job termination 171 // Job termination 144 // Free the store: user actions, physics_lis 172 // Free the store: user actions, physics_list and detector_description are 145 // owned and deleted by the 173 // owned and deleted by the run manager, so they should not 146 // be deleted in the main() 174 // be deleted in the main() program ! 147 << 175 >> 176 #ifdef G4VIS_USE 148 delete visManager; 177 delete visManager; >> 178 #endif 149 delete runManager; 179 delete runManager; 150 180 151 return 0; 181 return 0; 152 } 182 } 153 183 154 //....oooOO0OOooo........oooOO0OOooo........oo 184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 155 185