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