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