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 /// \file GB02/exampleGB02.cc 26 /// \file GB02/exampleGB02.cc 27 /// \brief Main program of the GB02 example 27 /// \brief Main program of the GB02 example 28 // 28 // >> 29 // $Id: $ 29 // 30 // 30 31 31 #include "FTFP_BERT.hh" << 32 #ifdef G4MULTITHREADED >> 33 #include "G4MTRunManager.hh" >> 34 #else >> 35 #include "G4RunManager.hh" >> 36 #endif 32 #include "GB02ActionInitialization.hh" 37 #include "GB02ActionInitialization.hh" >> 38 >> 39 #include "G4UImanager.hh" >> 40 33 #include "GB02DetectorConstruction.hh" 41 #include "GB02DetectorConstruction.hh" 34 #include "GB02PrimaryGeneratorAction.hh" 42 #include "GB02PrimaryGeneratorAction.hh" 35 43 >> 44 #include "FTFP_BERT.hh" 36 #include "G4GenericBiasingPhysics.hh" 45 #include "G4GenericBiasingPhysics.hh" 37 #include "G4RunManagerFactory.hh" << 46 38 #include "G4Types.hh" << 47 #ifdef G4VIS_USE 39 #include "G4UIExecutive.hh" << 40 #include "G4UImanager.hh" << 41 #include "G4VisExecutive.hh" 48 #include "G4VisExecutive.hh" >> 49 #endif >> 50 >> 51 #ifdef G4UI_USE >> 52 #include "G4UIExecutive.hh" >> 53 #endif 42 54 43 //....oooOO0OOooo........oooOO0OOooo........oo 55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 44 56 45 namespace << 57 namespace { 46 { << 58 void PrintUsage() { 47 void PrintUsage() << 59 G4cerr << " Usage: " << G4endl; 48 { << 60 G4cerr << " ./exampleGB02 [-m macro ] " 49 G4cerr << " Usage: " << G4endl; << 61 << " [-b biasing {'on','off'}]" 50 G4cerr << " ./exampleGB02 [-m macro ] " << 62 << "\n or\n ./exampleGB02 [macro.mac]" 51 << " [-b biasing {'on','off'}]" << 63 << G4endl; 52 << "\n or\n ./exampleGB02 [macro.mac] << 64 } 53 } 65 } 54 } // namespace << 55 66 56 //....oooOO0OOooo........oooOO0OOooo........oo 67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 68 58 int main(int argc, char** argv) << 69 int main(int argc,char** argv) 59 { 70 { 60 // Evaluate arguments 71 // Evaluate arguments 61 // 72 // 62 if (argc > 5) { << 73 if ( argc > 5 ) { 63 PrintUsage(); 74 PrintUsage(); 64 return 1; 75 return 1; 65 } 76 } 66 << 77 67 G4String macro(""); 78 G4String macro(""); 68 G4String onOffBiasing(""); 79 G4String onOffBiasing(""); 69 if (argc == 2) << 80 if ( argc == 2 ) macro = argv[1]; 70 macro = argv[1]; << 81 else 71 else { << 82 { 72 for (G4int i = 1; i < argc; i = i + 2) { << 83 for ( G4int i=1; i<argc; i=i+2 ) 73 if (G4String(argv[i]) == "-m") << 84 { 74 macro = argv[i + 1]; << 85 if ( G4String(argv[i]) == "-m" ) macro = argv[i+1]; 75 else if (G4String(argv[i]) == "-b") << 86 else if ( G4String(argv[i]) == "-b" ) onOffBiasing = argv[i+1]; 76 onOffBiasing = argv[i + 1]; << 87 else 77 else { << 88 { 78 PrintUsage(); << 89 PrintUsage(); 79 return 1; << 90 return 1; 80 } << 91 } >> 92 } 81 } 93 } 82 } << 94 83 << 95 if ( onOffBiasing == "" ) onOffBiasing = "on"; 84 if (onOffBiasing == "") onOffBiasing = "on"; << 85 << 86 // Instantiate G4UIExecutive if interactive << 87 G4UIExecutive* ui = nullptr; << 88 if (macro == "") { << 89 ui = new G4UIExecutive(argc, argv); << 90 } << 91 96 92 // -- Construct the run manager : MT or sequ 97 // -- Construct the run manager : MT or sequential one 93 auto* runManager = G4RunManagerFactory::Crea << 98 #ifdef G4MULTITHREADED >> 99 G4MTRunManager * runManager = new G4MTRunManager; >> 100 G4cout << " ********** Run Manager constructed in MT mode ************ " << G4endl; >> 101 // -- Choose 4 threads: 94 runManager->SetNumberOfThreads(4); 102 runManager->SetNumberOfThreads(4); >> 103 #else >> 104 G4RunManager * runManager = new G4RunManager; >> 105 G4cout << " ********** Run Manager constructed in sequential mode ************ " << G4endl; >> 106 #endif 95 107 96 // -- Set mandatory initialization classes 108 // -- Set mandatory initialization classes 97 GB02DetectorConstruction* detector = new GB0 109 GB02DetectorConstruction* detector = new GB02DetectorConstruction(); 98 runManager->SetUserInitialization(detector); 110 runManager->SetUserInitialization(detector); 99 // -- Select a physics list 111 // -- Select a physics list 100 FTFP_BERT* physicsList = new FTFP_BERT; 112 FTFP_BERT* physicsList = new FTFP_BERT; 101 // -- And augment it with biasing facilities 113 // -- And augment it with biasing facilities: 102 G4GenericBiasingPhysics* biasingPhysics = ne 114 G4GenericBiasingPhysics* biasingPhysics = new G4GenericBiasingPhysics(); 103 if (onOffBiasing == "on") { << 115 if ( onOffBiasing == "on" ) 104 biasingPhysics->Bias("gamma"); << 116 { 105 biasingPhysics->Bias("neutron"); << 117 biasingPhysics->Bias("gamma"); 106 physicsList->RegisterPhysics(biasingPhysic << 118 biasingPhysics->Bias("neutron"); 107 G4cout << " ************************* << 119 physicsList->RegisterPhysics(biasingPhysics); 108 G4cout << " ********** processes are << 120 G4cout << " ********************************************************* " << G4endl; 109 G4cout << " ************************* << 121 G4cout << " ********** processes are wrapped for biasing ************ " << G4endl; 110 } << 122 G4cout << " ********************************************************* " << G4endl; 111 else { << 123 } 112 G4cout << " ************************* << 124 else 113 G4cout << " ********** processes are << 125 { 114 G4cout << " ************************* << 126 G4cout << " ************************************************* " << G4endl; 115 } << 127 G4cout << " ********** processes are not wrapped ************ " << G4endl; >> 128 G4cout << " ************************************************* " << G4endl; >> 129 } 116 runManager->SetUserInitialization(physicsLis 130 runManager->SetUserInitialization(physicsList); 117 // -- Action initialization: 131 // -- Action initialization: 118 runManager->SetUserInitialization(new GB02Ac 132 runManager->SetUserInitialization(new GB02ActionInitialization); 119 133 120 // Initialize G4 kernel 134 // Initialize G4 kernel 121 runManager->Initialize(); 135 runManager->Initialize(); >> 136 122 137 >> 138 #ifdef G4VIS_USE 123 // Initialize visualization 139 // Initialize visualization 124 G4VisManager* visManager = new G4VisExecutiv 140 G4VisManager* visManager = new G4VisExecutive; 125 // G4VisExecutive can take a verbosity argum 141 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance. 126 visManager->Initialize(); 142 visManager->Initialize(); >> 143 #endif 127 144 128 // Get the pointer to the User Interface man 145 // Get the pointer to the User Interface manager 129 G4UImanager* UImanager = G4UImanager::GetUIp 146 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 130 147 131 if (macro != "") // batch mode << 148 if ( macro != "" ) // batch mode 132 { << 149 { 133 G4String command = "/control/execute "; << 150 G4String command = "/control/execute "; 134 UImanager->ApplyCommand(command + macro); << 151 UImanager->ApplyCommand(command+macro); 135 } << 152 } 136 else { // interactive mode : define UI sess << 153 else 137 // UImanager->ApplyCommand("/control/ << 154 { // interactive mode : define UI session 138 // if (ui->IsGUI()) << 155 #ifdef G4UI_USE 139 // UImanager->ApplyCommand("/contro << 156 G4UIExecutive* ui = new G4UIExecutive(argc, argv); 140 ui->SessionStart(); << 157 #ifdef G4VIS_USE 141 delete ui; << 158 // UImanager->ApplyCommand("/control/execute vis.mac"); 142 } << 159 #endif >> 160 // if (ui->IsGUI()) >> 161 // UImanager->ApplyCommand("/control/execute gui.mac"); >> 162 ui->SessionStart(); >> 163 delete ui; >> 164 #endif >> 165 } 143 166 >> 167 #ifdef G4VIS_USE 144 delete visManager; 168 delete visManager; >> 169 #endif 145 delete runManager; 170 delete runManager; >> 171 146 172 147 return 0; 173 return 0; 148 } 174 } 149 175 150 //....oooOO0OOooo........oooOO0OOooo........oo 176 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 151 177