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/TestEm1/TestEm1.cc 26 /// \file electromagnetic/TestEm1/TestEm1.cc 27 /// \brief Main program of the electromagnetic 27 /// \brief Main program of the electromagnetic/TestEm1 example 28 // 28 // 29 // 29 // 30 // << 30 // $Id$ 31 //....oooOO0OOooo........oooOO0OOooo........oo << 31 // 32 //....oooOO0OOooo........oooOO0OOooo........oo 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 34 >> 35 #include "G4RunManager.hh" >> 36 #include "G4UImanager.hh" >> 37 #include "Randomize.hh" 33 38 34 #include "ActionInitialization.hh" << 35 #include "DetectorConstruction.hh" 39 #include "DetectorConstruction.hh" 36 #include "PhysicsList.hh" 40 #include "PhysicsList.hh" >> 41 #include "PrimaryGeneratorAction.hh" >> 42 #include "SteppingVerbose.hh" 37 43 38 #include "G4RunManagerFactory.hh" << 44 #include "RunAction.hh" 39 #include "G4SteppingVerbose.hh" << 45 #include "EventAction.hh" 40 #include "G4Types.hh" << 46 #include "TrackingAction.hh" >> 47 #include "SteppingAction.hh" >> 48 #include "StackingAction.hh" >> 49 >> 50 #ifdef G4VIS_USE >> 51 #include "G4VisExecutive.hh" >> 52 #endif >> 53 >> 54 #ifdef G4UI_USE 41 #include "G4UIExecutive.hh" 55 #include "G4UIExecutive.hh" 42 #include "G4UImanager.hh" << 56 #endif 43 #include "G4VisExecutive.hh" << 44 #include "Randomize.hh" << 45 57 46 //....oooOO0OOooo........oooOO0OOooo........oo 58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 47 << 59 48 int main(int argc, char** argv) << 60 int main(int argc,char** argv) { 49 { << 61 50 // detect interactive mode (if no arguments) << 62 //choose the Random engine 51 G4UIExecutive* ui = nullptr; << 63 CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine); 52 if (argc == 1) { << 64 53 ui = new G4UIExecutive(argc, argv); << 65 //my Verbose output class 54 } << 66 G4VSteppingVerbose::SetInstance(new SteppingVerbose); 55 << 67 56 // use G4SteppingVerboseWithUnits << 68 // Construct the default run manager 57 G4int precision = 4; << 69 G4RunManager * runManager = new G4RunManager; 58 G4SteppingVerbose::UseBestUnit(precision); << 59 << 60 // construct the run manager << 61 auto runManager = G4RunManagerFactory::Creat << 62 if (argc == 3) { << 63 G4int nThreads = G4UIcommand::ConvertToInt << 64 runManager->SetNumberOfThreads(nThreads); << 65 } << 66 70 67 // set mandatory initialization classes 71 // set mandatory initialization classes 68 DetectorConstruction* det = new DetectorCons << 72 DetectorConstruction* det; 69 runManager->SetUserInitialization(det); << 73 PrimaryGeneratorAction* prim; 70 << 74 runManager->SetUserInitialization(det = new DetectorConstruction); 71 PhysicsList* phys = new PhysicsList(det); << 75 runManager->SetUserInitialization(new PhysicsList(det)); 72 runManager->SetUserInitialization(phys); << 76 runManager->SetUserAction(prim = new PrimaryGeneratorAction(det)); 73 << 77 74 // set user action classes 78 // set user action classes 75 runManager->SetUserInitialization(new Action << 79 RunAction* run; 76 << 80 EventAction* event; 77 // initialize visualization << 81 78 G4VisManager* visManager = nullptr; << 82 runManager->SetUserAction(run = new RunAction(det,prim)); 79 << 83 runManager->SetUserAction(event = new EventAction()); 80 // get the pointer to the User Interface man << 84 runManager->SetUserAction(new TrackingAction(prim,run)); 81 G4UImanager* UImanager = G4UImanager::GetUIp << 85 runManager->SetUserAction(new SteppingAction(run,event)); >> 86 runManager->SetUserAction(new StackingAction()); >> 87 >> 88 // get the pointer to the User Interface manager >> 89 G4UImanager* UI = G4UImanager::GetUIpointer(); >> 90 >> 91 if (argc!=1) // batch mode >> 92 { >> 93 G4String command = "/control/execute "; >> 94 G4String fileName = argv[1]; >> 95 UI->ApplyCommand(command+fileName); >> 96 } >> 97 >> 98 else //define visualization and UI terminal for interactive mode >> 99 { >> 100 #ifdef G4VIS_USE >> 101 G4VisManager* visManager = new G4VisExecutive; >> 102 visManager->Initialize(); >> 103 #endif >> 104 >> 105 #ifdef G4UI_USE >> 106 G4UIExecutive * ui = new G4UIExecutive(argc,argv); >> 107 ui->SessionStart(); >> 108 delete ui; >> 109 #endif >> 110 >> 111 #ifdef G4VIS_USE >> 112 delete visManager; >> 113 #endif >> 114 } 82 115 83 if (ui) { << 116 // job termination 84 // interactive mode << 117 // 85 visManager = new G4VisExecutive; << 86 visManager->Initialize(); << 87 ui->SessionStart(); << 88 delete ui; << 89 } << 90 else { << 91 // batch mode << 92 G4String command = "/control/execute "; << 93 G4String fileName = argv[1]; << 94 UImanager->ApplyCommand(command + fileName << 95 } << 96 << 97 // job termination << 98 delete visManager; << 99 delete runManager; 118 delete runManager; >> 119 >> 120 return 0; 100 } 121 } 101 122 102 //....oooOO0OOooo........oooOO0OOooo........oo << 123 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 103 124