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