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" << 30 #include "B4dDetectorConstruction.hh" 31 #include "DetectorConstruction.hh" << 31 #include "B4dActionInitialization.hh" 32 #include "FTFP_BERT.hh" << 32 #include "B4Analysis.hh" 33 33 34 #include "G4AnalysisManager.hh" << 35 #include "G4RunManagerFactory.hh" 34 #include "G4RunManagerFactory.hh" 36 #include "G4SteppingVerbose.hh" << 35 37 #include "G4TScoreNtupleWriter.hh" << 38 #include "G4UIExecutive.hh" << 39 #include "G4UIcommand.hh" << 40 #include "G4UImanager.hh" 36 #include "G4UImanager.hh" >> 37 #include "FTFP_BERT.hh" 41 #include "G4VisExecutive.hh" 38 #include "G4VisExecutive.hh" 42 // #include "Randomize.hh" << 39 #include "G4UIExecutive.hh" >> 40 #include "Randomize.hh" >> 41 #include "G4TScoreNtupleWriter.hh" 43 42 44 //....oooOO0OOooo........oooOO0OOooo........oo 43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 45 44 46 namespace << 45 namespace { 47 { << 46 void PrintUsage() { 48 void PrintUsage() << 47 G4cerr << " Usage: " << G4endl; 49 { << 48 G4cerr << " exampleB4d [-m macro ] [-u UIsession] [-t nThreads]" << G4endl; 50 G4cerr << " Usage: " << G4endl; << 49 G4cerr << " note: -t option is available only for multi-threaded mode." 51 G4cerr << " exampleB4d [-m macro ] [-u UIses << 50 << G4endl; 52 G4cerr << " note: -t option is available o << 51 } 53 } 52 } 54 } // namespace << 55 53 56 //....oooOO0OOooo........oooOO0OOooo........oo 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 55 58 int main(int argc, char** argv) << 56 int main(int argc,char** argv) 59 { << 57 { 60 // Evaluate arguments 58 // Evaluate arguments 61 // 59 // 62 if (argc > 7) { << 60 if ( argc > 7 ) { 63 PrintUsage(); 61 PrintUsage(); 64 return 1; 62 return 1; 65 } 63 } 66 << 64 67 G4String macro; 65 G4String macro; 68 G4String session; 66 G4String session; 69 G4bool verboseBestUnits = true; << 70 #ifdef G4MULTITHREADED 67 #ifdef G4MULTITHREADED 71 G4int nThreads = 0; 68 G4int nThreads = 0; 72 #endif 69 #endif 73 for (G4int i = 1; i < argc; i = i + 2) { << 70 for ( G4int i=1; i<argc; i=i+2 ) { 74 if (G4String(argv[i]) == "-m") << 71 if ( G4String(argv[i]) == "-m" ) macro = argv[i+1]; 75 macro = argv[i + 1]; << 72 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 73 #ifdef G4MULTITHREADED 79 else if (G4String(argv[i]) == "-t") { << 74 else if ( G4String(argv[i]) == "-t" ) { 80 nThreads = G4UIcommand::ConvertToInt(arg << 75 nThreads = G4UIcommand::ConvertToInt(argv[i+1]); 81 } 76 } 82 #endif 77 #endif 83 else if (G4String(argv[i]) == "-vDefault") << 84 verboseBestUnits = false; << 85 --i; // this option is not followed wit << 86 } << 87 else { 78 else { 88 PrintUsage(); 79 PrintUsage(); 89 return 1; 80 return 1; 90 } 81 } 91 } << 82 } 92 << 83 93 // Detect interactive mode (if no macro prov 84 // Detect interactive mode (if no macro provided) and define UI session 94 // 85 // 95 G4UIExecutive* ui = nullptr; 86 G4UIExecutive* ui = nullptr; 96 if (!macro.size()) { << 87 if ( ! macro.size() ) { 97 ui = new G4UIExecutive(argc, argv, session 88 ui = new G4UIExecutive(argc, argv, session); 98 } 89 } 99 90 100 // Optionally: choose a different Random eng 91 // Optionally: choose a different Random engine... >> 92 // 101 // G4Random::setTheEngine(new CLHEP::MTwistE 93 // G4Random::setTheEngine(new CLHEP::MTwistEngine); 102 << 94 103 // Use G4SteppingVerboseWithUnits << 95 // Construct the MT run manager 104 if (verboseBestUnits) { << 105 G4int precision = 4; << 106 G4SteppingVerbose::UseBestUnit(precision); << 107 } << 108 << 109 // Construct the default run manager << 110 // 96 // 111 auto runManager = G4RunManagerFactory::Creat << 97 >> 98 auto* runManager = >> 99 G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default); 112 #ifdef G4MULTITHREADED 100 #ifdef G4MULTITHREADED 113 if (nThreads > 0) { << 101 if ( nThreads > 0 ) { 114 runManager->SetNumberOfThreads(nThreads); 102 runManager->SetNumberOfThreads(nThreads); 115 } 103 } 116 #endif 104 #endif 117 105 118 // Set mandatory initialization classes 106 // Set mandatory initialization classes 119 // 107 // 120 auto detConstruction = new B4d::DetectorCons << 108 auto detConstruction = new B4dDetectorConstruction(); 121 runManager->SetUserInitialization(detConstru 109 runManager->SetUserInitialization(detConstruction); 122 110 123 auto physicsList = new FTFP_BERT; 111 auto physicsList = new FTFP_BERT; 124 runManager->SetUserInitialization(physicsLis 112 runManager->SetUserInitialization(physicsList); 125 113 126 auto actionInitialization = new B4d::ActionI << 114 auto actionInitialization = new B4dActionInitialization(); 127 runManager->SetUserInitialization(actionInit 115 runManager->SetUserInitialization(actionInitialization); 128 << 116 129 // Initialize visualization 117 // Initialize visualization 130 auto visManager = new G4VisExecutive; 118 auto visManager = new G4VisExecutive; 131 // G4VisExecutive can take a verbosity argum 119 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance. 132 // auto visManager = new G4VisExecutive("Qui << 120 // G4VisManager* visManager = new G4VisExecutive("Quiet"); 133 visManager->Initialize(); 121 visManager->Initialize(); 134 122 135 // Get the pointer to the User Interface man 123 // Get the pointer to the User Interface manager 136 auto UImanager = G4UImanager::GetUIpointer() 124 auto UImanager = G4UImanager::GetUIpointer(); 137 125 138 // Activate score ntuple writer 126 // Activate score ntuple writer 139 // The verbose level can be also set via UI << 127 // The Root output type (Root) is selected in B3Analysis.hh. 140 // /score/ntuple/writerVerbose level << 141 // The default file type ("root") can be cha << 142 // scoreNtupleWriter.SetDefaultFileType("xml << 143 G4TScoreNtupleWriter<G4AnalysisManager> scor 128 G4TScoreNtupleWriter<G4AnalysisManager> scoreNtupleWriter; 144 scoreNtupleWriter.SetVerboseLevel(1); << 129 // The verbose level can be set via UI commands 145 scoreNtupleWriter.SetNtupleMerging(true); << 130 // /score/ntuple/writerVerbose level 146 // Note: merging ntuples is available only w << 131 // or via the score ntuple writer function: 147 // (the default in G4TScoreNtupleWriter) << 132 // scoreNtupleWriter.SetVerboseLevel(1); 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