Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // 27 /// \file exampleB4d.cc 28 /// \brief Main program of the B4d example 29 30 #include "ActionInitialization.hh" 31 #include "DetectorConstruction.hh" 32 #include "FTFP_BERT.hh" 33 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" 41 #include "G4VisExecutive.hh" 42 // #include "Randomize.hh" 43 44 //....oooOO0OOooo........oooOO0OOooo........oo 45 46 namespace 47 { 48 void PrintUsage() 49 { 50 G4cerr << " Usage: " << G4endl; 51 G4cerr << " exampleB4d [-m macro ] [-u UIses 52 G4cerr << " note: -t option is available o 53 } 54 } // namespace 55 56 //....oooOO0OOooo........oooOO0OOooo........oo 57 58 int main(int argc, char** argv) 59 { 60 // Evaluate arguments 61 // 62 if (argc > 7) { 63 PrintUsage(); 64 return 1; 65 } 66 67 G4String macro; 68 G4String session; 69 G4bool verboseBestUnits = true; 70 #ifdef G4MULTITHREADED 71 G4int nThreads = 0; 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 { 88 PrintUsage(); 89 return 1; 90 } 91 } 92 93 // Detect interactive mode (if no macro prov 94 // 95 G4UIExecutive* ui = nullptr; 96 if (!macro.size()) { 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 110 // 111 auto runManager = G4RunManagerFactory::Creat 112 #ifdef G4MULTITHREADED 113 if (nThreads > 0) { 114 runManager->SetNumberOfThreads(nThreads); 115 } 116 #endif 117 118 // Set mandatory initialization classes 119 // 120 auto detConstruction = new B4d::DetectorCons 121 runManager->SetUserInitialization(detConstru 122 123 auto physicsList = new FTFP_BERT; 124 runManager->SetUserInitialization(physicsLis 125 126 auto actionInitialization = new B4d::ActionI 127 runManager->SetUserInitialization(actionInit 128 129 // Initialize visualization 130 auto visManager = new G4VisExecutive; 131 // G4VisExecutive can take a verbosity argum 132 // auto visManager = new G4VisExecutive("Qui 133 visManager->Initialize(); 134 135 // Get the pointer to the User Interface man 136 auto 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 149 // Process macro or start UI session 150 // 151 if (macro.size()) { 152 // batch mode 153 G4String command = "/control/execute "; 154 UImanager->ApplyCommand(command + macro); 155 } 156 else { 157 // interactive mode : define UI session 158 UImanager->ApplyCommand("/control/execute 159 if (ui->IsGUI()) { 160 UImanager->ApplyCommand("/control/execut 161 } 162 ui->SessionStart(); 163 delete ui; 164 } 165 166 // Job termination 167 // Free the store: user actions, physics_lis 168 // owned and deleted by the run manager, so 169 // in the main() program ! 170 171 delete visManager; 172 delete runManager; 173 } 174 175 //....oooOO0OOooo........oooOO0OOooo........oo 176