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: electronScattering2.cc 75702 2013-11-05 13:08:48Z gcosmo $ 26 // 27 // 27 /// \file medical/electronScattering2/electron 28 /// \file medical/electronScattering2/electronScattering2.cc 28 /// \brief Main program of the medical/electro 29 /// \brief Main program of the medical/electronScattering2 example 29 #include "ElectronActionInitialization.hh" << 30 #include "ElectronBenchmarkDetector.hh" << 31 #include "PhysicsList.hh" << 32 30 33 #include "G4RunManagerFactory.hh" << 31 #ifdef G4MULTITHREADED 34 #include "G4Types.hh" << 32 #include "G4MTRunManager.hh" 35 #include "G4UIExecutive.hh" << 33 #else 36 #include "G4UImanager.hh" << 34 #include "G4RunManager.hh" 37 #include "G4VisExecutive.hh" << 35 #endif >> 36 38 #include "Randomize.hh" 37 #include "Randomize.hh" >> 38 #include "G4ScoringManager.hh" >> 39 >> 40 #ifdef G4VIS_USE >> 41 #include "G4VisExecutive.hh" >> 42 #endif >> 43 >> 44 #include "G4UImanager.hh" >> 45 #ifdef G4UI_USE >> 46 #include "G4UIExecutive.hh" >> 47 #endif >> 48 >> 49 #include "ElectronBenchmarkDetector.hh" >> 50 #include "PhysicsList.hh" >> 51 #include "ElectronActionInitialization.hh" 39 52 40 //....oooOO0OOooo........oooOO0OOooo........oo 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 41 54 42 int main(int argc, char** argv) << 55 int main(int argc,char** argv) { 43 { << 56 44 // detect interactive mode (if no arguments) << 57 // Parse the arguments 45 G4UIExecutive* ui = nullptr; << 58 G4String outputFile = "output.csv"; 46 if (argc == 1) ui = new G4UIExecutive(argc, << 59 G4String startingSeed = "1"; 47 << 60 G4String macroFile = "None"; 48 // Parse the arguments << 61 if (argc > 1) macroFile = argv[1]; 49 G4String outputFile = "output.csv"; << 62 if (argc > 2) startingSeed = argv[2]; 50 G4String startingSeed = "1"; << 63 if (argc > 3) outputFile = argv[3]; 51 G4String macroFile = "None"; << 64 G4cout << "Starting run with" << G4endl; 52 if (argc > 1) macroFile = argv[1]; << 65 G4cout << "Macro File : " << macroFile << G4endl; 53 if (argc > 2) startingSeed = argv[2]; << 66 G4cout << "Starting Seed : " << startingSeed << G4endl; 54 if (argc > 3) outputFile = argv[3]; << 67 G4cout << "Output File : " << outputFile << G4endl; 55 G4cout << "Starting run with" << G4endl; << 68 56 G4cout << "Macro File : " << macroFile << << 69 // Instantiate the run manager 57 G4cout << "Starting Seed : " << startingSeed << 70 #ifdef G4MULTITHREADED 58 G4cout << "Output File : " << outputFile < << 71 G4MTRunManager* runManager = new G4MTRunManager; 59 << 72 #else 60 // Instantiate the run manager << 73 G4RunManager* runManager = new G4RunManager; 61 auto* runManager = G4RunManagerFactory::Crea << 74 #endif 62 << 75 63 // Instantiate the random engine << 76 // Instantiate the random engine 64 G4Random::setTheEngine(new CLHEP::MTwistEngi << 77 G4Random::setTheEngine(new CLHEP::MTwistEngine); 65 << 78 66 // Convert the starting seed to integer and << 79 // Convert the starting seed to integer and feed it to the random engine 67 unsigned startingSeedInt; << 80 unsigned startingSeedInt; 68 std::istringstream is(startingSeed); << 81 std::istringstream is(startingSeed); 69 is >> startingSeedInt; << 82 is >> startingSeedInt; 70 G4Random::setTheSeed(startingSeedInt); << 83 G4Random::setTheSeed(startingSeedInt); 71 << 84 72 // Instantiate the geometry << 85 // Instantiate the scoring manager 73 runManager->SetUserInitialization(new Electr << 86 G4ScoringManager::GetScoringManager(); 74 << 87 75 // Instantiate the physics list (in turn cal << 88 // Instantiate the geometry 76 // physics list) << 89 runManager->SetUserInitialization(new ElectronBenchmarkDetector); 77 runManager->SetUserInitialization(new Physic << 90 78 << 91 // Instantiate the physics list (in turn calls one of four choices of physics list) 79 // set user action classes << 92 runManager->SetUserInitialization(new PhysicsList); 80 runManager->SetUserInitialization(new Electr << 93 81 << 94 // set user action classes 82 // initialize visualization << 95 runManager->SetUserInitialization(new ElectronActionInitialization(outputFile)); 83 G4VisManager* visManager = nullptr; << 96 84 << 97 // Instantiate the visualization System 85 // get the pointer to the User Interface man << 98 #ifdef G4VIS_USE 86 G4UImanager* UImanager = G4UImanager::GetUIp << 99 G4VisManager* visManager = new G4VisExecutive; 87 << 88 if (ui) { << 89 // interactive mode << 90 visManager = new G4VisExecutive; << 91 visManager->Initialize(); 100 visManager->Initialize(); 92 ui->SessionStart(); << 101 #endif 93 delete ui; << 102 94 } << 103 if (argc == 1) 95 else { << 104 { 96 // batch mode << 105 // Since no macro was specified, instantiate an interactive session (exact 97 G4String command = "/control/execute "; << 106 // (session type depends on user preference expressed in environment variables). 98 G4String fileName = argv[1]; << 107 #ifdef G4UI_USE 99 UImanager->ApplyCommand(command + fileName << 108 G4UIExecutive* ui = new G4UIExecutive(argc, argv); 100 } << 109 ui->SessionStart(); 101 << 110 delete ui; 102 // job termination << 111 #endif 103 delete visManager; << 112 } 104 delete runManager; << 113 else >> 114 { >> 115 // A macro was specified. Execute it. >> 116 G4UImanager* UImanager = G4UImanager::GetUIpointer(); >> 117 G4String command = "/control/execute "; >> 118 UImanager->ApplyCommand(command+macroFile); >> 119 } >> 120 >> 121 #ifdef G4VIS_USE >> 122 delete visManager; >> 123 #endif >> 124 delete runManager; >> 125 >> 126 return 0; 105 } 127 } 106 128 107 //....oooOO0OOooo........oooOO0OOooo........oo 129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 108 130