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: exampleB4d.cc 86065 2014-11-07 08:51:15Z gcosmo $ 26 // 27 // 27 /// \file exampleB4d.cc 28 /// \file exampleB4d.cc 28 /// \brief Main program of the B4d example 29 /// \brief Main program of the B4d example 29 30 30 #include "ActionInitialization.hh" << 31 #include "B4dDetectorConstruction.hh" 31 #include "DetectorConstruction.hh" << 32 #include "B4dActionInitialization.hh" 32 #include "FTFP_BERT.hh" << 33 >> 34 #ifdef G4MULTITHREADED >> 35 #include "G4MTRunManager.hh" >> 36 #else >> 37 #include "G4RunManager.hh" >> 38 #endif 33 39 34 #include "G4AnalysisManager.hh" << 35 #include "G4RunManagerFactory.hh" << 36 #include "G4SteppingVerbose.hh" << 37 #include "G4TScoreNtupleWriter.hh" << 38 #include "G4UIExecutive.hh" << 39 #include "G4UIcommand.hh" << 40 #include "G4UImanager.hh" 40 #include "G4UImanager.hh" >> 41 #include "G4UIcommand.hh" >> 42 #include "FTFP_BERT.hh" >> 43 >> 44 #include "Randomize.hh" >> 45 41 #include "G4VisExecutive.hh" 46 #include "G4VisExecutive.hh" 42 // #include "Randomize.hh" << 47 >> 48 #include "G4UIExecutive.hh" 43 49 44 //....oooOO0OOooo........oooOO0OOooo........oo 50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 45 51 46 namespace << 52 namespace { 47 { << 53 void PrintUsage() { 48 void PrintUsage() << 54 G4cerr << " Usage: " << G4endl; 49 { << 55 G4cerr << " exampleB4d [-m macro ] [-u UIsession] [-t nThreads]" << G4endl; 50 G4cerr << " Usage: " << G4endl; << 56 G4cerr << " note: -t option is available only for multi-threaded mode." 51 G4cerr << " exampleB4d [-m macro ] [-u UIses << 57 << G4endl; 52 G4cerr << " note: -t option is available o << 58 } 53 } 59 } 54 } // namespace << 55 60 56 //....oooOO0OOooo........oooOO0OOooo........oo 61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 62 58 int main(int argc, char** argv) << 63 int main(int argc,char** argv) 59 { << 64 { 60 // Evaluate arguments 65 // Evaluate arguments 61 // 66 // 62 if (argc > 7) { << 67 if ( argc > 7 ) { 63 PrintUsage(); 68 PrintUsage(); 64 return 1; 69 return 1; 65 } 70 } 66 << 71 67 G4String macro; 72 G4String macro; 68 G4String session; 73 G4String session; 69 G4bool verboseBestUnits = true; << 70 #ifdef G4MULTITHREADED 74 #ifdef G4MULTITHREADED 71 G4int nThreads = 0; 75 G4int nThreads = 0; 72 #endif 76 #endif 73 for (G4int i = 1; i < argc; i = i + 2) { << 77 for ( G4int i=1; i<argc; i=i+2 ) { 74 if (G4String(argv[i]) == "-m") << 78 if ( G4String(argv[i]) == "-m" ) macro = argv[i+1]; 75 macro = argv[i + 1]; << 79 else if ( G4String(argv[i]) == "-u" ) session = argv[i+1]; 76 else if (G4String(argv[i]) == "-u") << 77 session = argv[i + 1]; << 78 #ifdef G4MULTITHREADED 80 #ifdef G4MULTITHREADED 79 else if (G4String(argv[i]) == "-t") { << 81 else if ( G4String(argv[i]) == "-t" ) { 80 nThreads = G4UIcommand::ConvertToInt(arg << 82 nThreads = G4UIcommand::ConvertToInt(argv[i+1]); 81 } 83 } 82 #endif 84 #endif 83 else if (G4String(argv[i]) == "-vDefault") << 84 verboseBestUnits = false; << 85 --i; // this option is not followed wit << 86 } << 87 else { 85 else { 88 PrintUsage(); 86 PrintUsage(); 89 return 1; 87 return 1; 90 } 88 } 91 } << 89 } 92 << 90 93 // Detect interactive mode (if no macro prov 91 // Detect interactive mode (if no macro provided) and define UI session 94 // 92 // 95 G4UIExecutive* ui = nullptr; << 93 G4UIExecutive* ui = 0; 96 if (!macro.size()) { << 94 if ( ! macro.size() ) { 97 ui = new G4UIExecutive(argc, argv, session << 95 ui = new G4UIExecutive(argc, argv); 98 } << 99 << 100 // Optionally: choose a different Random eng << 101 // G4Random::setTheEngine(new CLHEP::MTwistE << 102 << 103 // Use G4SteppingVerboseWithUnits << 104 if (verboseBestUnits) { << 105 G4int precision = 4; << 106 G4SteppingVerbose::UseBestUnit(precision); << 107 } 96 } 108 97 109 // Construct the default run manager << 98 // Choose the Random engine >> 99 // >> 100 G4Random::setTheEngine(new CLHEP::RanecuEngine); >> 101 >> 102 // Construct the MT run manager 110 // 103 // 111 auto runManager = G4RunManagerFactory::Creat << 112 #ifdef G4MULTITHREADED 104 #ifdef G4MULTITHREADED 113 if (nThreads > 0) { << 105 G4MTRunManager * runManager = new G4MTRunManager; >> 106 if ( nThreads > 0 ) { 114 runManager->SetNumberOfThreads(nThreads); 107 runManager->SetNumberOfThreads(nThreads); 115 } << 108 } >> 109 #else >> 110 G4RunManager * runManager = new G4RunManager; 116 #endif 111 #endif 117 112 118 // Set mandatory initialization classes 113 // Set mandatory initialization classes 119 // 114 // 120 auto detConstruction = new B4d::DetectorCons << 115 B4dDetectorConstruction* detConstruction = new B4dDetectorConstruction(); 121 runManager->SetUserInitialization(detConstru 116 runManager->SetUserInitialization(detConstruction); 122 117 123 auto physicsList = new FTFP_BERT; << 118 G4VModularPhysicsList* physicsList = new FTFP_BERT; 124 runManager->SetUserInitialization(physicsLis 119 runManager->SetUserInitialization(physicsList); 125 120 126 auto actionInitialization = new B4d::ActionI << 121 B4dActionInitialization* actionInitialization >> 122 = new B4dActionInitialization(); 127 runManager->SetUserInitialization(actionInit 123 runManager->SetUserInitialization(actionInitialization); 128 << 124 129 // Initialize visualization 125 // Initialize visualization 130 auto visManager = new G4VisExecutive; << 126 G4VisManager* visManager = new G4VisExecutive; 131 // G4VisExecutive can take a verbosity argum 127 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance. 132 // auto visManager = new G4VisExecutive("Qui << 128 // G4VisManager* visManager = new G4VisExecutive("Quiet"); 133 visManager->Initialize(); 129 visManager->Initialize(); 134 130 135 // Get the pointer to the User Interface man 131 // Get the pointer to the User Interface manager 136 auto UImanager = G4UImanager::GetUIpointer() << 132 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 137 << 138 // Activate score ntuple writer << 139 // The verbose level can be also set via UI << 140 // /score/ntuple/writerVerbose level << 141 // The default file type ("root") can be cha << 142 // scoreNtupleWriter.SetDefaultFileType("xml << 143 G4TScoreNtupleWriter<G4AnalysisManager> scor << 144 scoreNtupleWriter.SetVerboseLevel(1); << 145 scoreNtupleWriter.SetNtupleMerging(true); << 146 // Note: merging ntuples is available only w << 147 // (the default in G4TScoreNtupleWriter) << 148 133 149 // Process macro or start UI session 134 // Process macro or start UI session 150 // 135 // 151 if (macro.size()) { << 136 if ( macro.size() ) { 152 // batch mode 137 // batch mode 153 G4String command = "/control/execute "; 138 G4String command = "/control/execute "; 154 UImanager->ApplyCommand(command + macro); << 139 UImanager->ApplyCommand(command+macro); 155 } 140 } 156 else { << 141 else { 157 // interactive mode : define UI session 142 // interactive mode : define UI session 158 UImanager->ApplyCommand("/control/execute 143 UImanager->ApplyCommand("/control/execute init_vis.mac"); 159 if (ui->IsGUI()) { 144 if (ui->IsGUI()) { 160 UImanager->ApplyCommand("/control/execut 145 UImanager->ApplyCommand("/control/execute gui.mac"); 161 } 146 } 162 ui->SessionStart(); 147 ui->SessionStart(); 163 delete ui; 148 delete ui; 164 } 149 } 165 150 166 // Job termination 151 // Job termination 167 // Free the store: user actions, physics_lis 152 // Free the store: user actions, physics_list and detector_description are 168 // owned and deleted by the run manager, so << 153 // owned and deleted by the run manager, so they should not be deleted 169 // in the main() program ! 154 // in the main() program ! 170 155 171 delete visManager; 156 delete visManager; 172 delete runManager; 157 delete runManager; 173 } 158 } 174 159 175 //....oooOO0OOooo........oooOO0OOooo........oo 160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 176 161