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 /// \file electromagnetic/TestEm8/TestEm8.cc 26 /// \file electromagnetic/TestEm8/TestEm8.cc 27 /// \brief Main program of the electromagnetic 27 /// \brief Main program of the electromagnetic/TestEm8 example 28 // 28 // >> 29 // $Id: TestEm8.cc 67235 2013-02-08 16:34:49Z vnivanch $ 29 // 30 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 33 33 #include "ActionInitialization.hh" << 34 #include "G4RunManager.hh" >> 35 #include "G4UImanager.hh" >> 36 #include "Randomize.hh" >> 37 34 #include "DetectorConstruction.hh" 38 #include "DetectorConstruction.hh" 35 #include "PhysicsList.hh" 39 #include "PhysicsList.hh" >> 40 #include "PrimaryGeneratorAction.hh" >> 41 #include "RunAction.hh" >> 42 #include "EventAction.hh" >> 43 #include "StackingAction.hh" 36 44 37 #include "G4RunManagerFactory.hh" << 45 #ifdef G4VIS_USE 38 #include "G4UIExecutive.hh" << 39 #include "G4UIcommand.hh" << 40 #include "G4UImanager.hh" << 41 #include "G4VisExecutive.hh" 46 #include "G4VisExecutive.hh" >> 47 #endif >> 48 >> 49 #ifdef G4UI_USE >> 50 #include "G4UIExecutive.hh" >> 51 #endif 42 52 43 //....oooOO0OOooo........oooOO0OOooo........oo 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 44 54 45 int main(int argc, char** argv) << 55 int main(int argc,char** argv) 46 { 56 { 47 // detect interactive mode (if no arguments) << 57 //choose the Random engine 48 G4UIExecutive* ui = nullptr; << 58 CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine); 49 if (argc == 1) { << 59 50 ui = new G4UIExecutive(argc, argv); << 60 // Construct the default run manager 51 } << 61 G4RunManager * runManager = new G4RunManager; 52 << 53 auto* runManager = G4RunManagerFactory::Crea << 54 // Number of threads can be defined via 3rd << 55 G4int nThreads = 2; << 56 if (argc == 3) { << 57 if (G4String(argv[2]) == "NMAX") { << 58 nThreads = G4Threading::G4GetNumberOfCor << 59 } << 60 else { << 61 nThreads = G4UIcommand::ConvertToInt(arg << 62 } << 63 } << 64 else if (argc == 1) { << 65 nThreads = 1; << 66 } << 67 if (nThreads > 0) { << 68 runManager->SetNumberOfThreads(nThreads); << 69 } << 70 62 71 // set mandatory initialization classes 63 // set mandatory initialization classes 72 DetectorConstruction* det = new DetectorCons << 64 runManager->SetUserInitialization(new PhysicsList); 73 runManager->SetUserInitialization(det); << 65 PrimaryGeneratorAction* gun = new PrimaryGeneratorAction(); 74 runManager->SetUserInitialization(new Physic << 66 runManager->SetUserInitialization(new DetectorConstruction(gun)); 75 << 67 76 // set user action classes 68 // set user action classes 77 runManager->SetUserInitialization(new Action << 69 runManager->SetUserAction(gun); 78 << 70 runManager->SetUserAction(new RunAction()); 79 // initialize visualization << 71 runManager->SetUserAction(new EventAction()); 80 G4VisManager* visManager = nullptr; << 72 runManager->SetUserAction(new StackingAction()); 81 << 73 82 // get the pointer to the User Interface man << 74 G4UImanager* UI = G4UImanager::GetUIpointer(); 83 G4UImanager* UImanager = G4UImanager::GetUIp << 75 84 << 76 if (argc!=1) // batch mode 85 if (ui) { << 77 { 86 // interactive mode << 78 G4String command = "/control/execute "; 87 visManager = new G4VisExecutive(); << 79 G4String fileName = argv[1]; 88 visManager->Initialize(); << 80 UI->ApplyCommand(command+fileName); 89 ui->SessionStart(); << 81 } 90 delete ui; << 82 91 } << 83 else //define visualization and UI terminal for interactive mode 92 else { << 84 { 93 // batch mode << 85 #ifdef G4VIS_USE 94 G4String command = "/control/execute "; << 86 G4VisManager* visManager = new G4VisExecutive; 95 G4String fileName = argv[1]; << 87 visManager->Initialize(); 96 UImanager->ApplyCommand(command + fileName << 88 #endif 97 } << 89 98 << 90 #ifdef G4UI_USE >> 91 G4UIExecutive * ui = new G4UIExecutive(argc,argv); >> 92 ui->SessionStart(); >> 93 delete ui; >> 94 #endif >> 95 >> 96 #ifdef G4VIS_USE >> 97 delete visManager; >> 98 #endif >> 99 } >> 100 99 // job termination 101 // job termination 100 delete visManager; << 102 // 101 delete runManager; 103 delete runManager; >> 104 >> 105 return 0; 102 } 106 } 103 107 104 //....oooOO0OOooo........oooOO0OOooo........oo 108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 109 105 110