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 hadronic/Hadr00/Hadr00.cc 26 /// \file hadronic/Hadr00/Hadr00.cc 27 /// \brief Main program of the hadronic/Hadr00 27 /// \brief Main program of the hadronic/Hadr00 example 28 // 28 // 29 // 29 // >> 30 // $Id$ 30 // 31 // 31 // ------------------------------------------- 32 // ------------------------------------------------------------- 32 // GEANT4 Hadr00 33 // GEANT4 Hadr00 33 // 34 // 34 // Application demonstrating Geant4 hadronic 35 // Application demonstrating Geant4 hadronic cross sections 35 // 36 // 36 // Author: V.Ivanchenko 20 June 2008 37 // Author: V.Ivanchenko 20 June 2008 37 // 38 // 38 // Modified: << 39 // Modified: 39 // 40 // 40 // ------------------------------------------- 41 // ------------------------------------------------------------- 41 // 42 // 42 // 43 // 43 //....oooOO0OOooo........oooOO0OOooo........oo 44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 44 //....oooOO0OOooo........oooOO0OOooo........oo 45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 45 46 46 #include "ActionInitialization.hh" << 47 #include "G4RunManager.hh" 47 #include "DetectorConstruction.hh" << 48 #include "G4UImanager.hh" 48 #include "PrimaryGeneratorAction.hh" << 49 #include "Randomize.hh" 49 50 >> 51 #include "DetectorConstruction.hh" 50 #include "G4PhysListFactory.hh" 52 #include "G4PhysListFactory.hh" 51 #include "G4RunManagerFactory.hh" << 52 #include "G4UIExecutive.hh" << 53 #include "G4UImanager.hh" << 54 #include "G4VModularPhysicsList.hh" 53 #include "G4VModularPhysicsList.hh" >> 54 #include "PrimaryGeneratorAction.hh" >> 55 >> 56 #include "RunAction.hh" >> 57 #include "EventAction.hh" >> 58 >> 59 #ifdef G4VIS_USE 55 #include "G4VisExecutive.hh" 60 #include "G4VisExecutive.hh" 56 #include "Randomize.hh" << 61 #endif >> 62 >> 63 #ifdef G4UI_USE >> 64 #include "G4UIExecutive.hh" >> 65 #endif 57 66 58 //....oooOO0OOooo........oooOO0OOooo........oo 67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 59 68 60 int main(int argc, char** argv) << 69 int main(int argc,char** argv) { 61 { << 62 // detect interactive mode (if no arguments) << 63 G4UIExecutive* ui = nullptr; << 64 if (argc == 1) { << 65 ui = new G4UIExecutive(argc, argv); << 66 } << 67 70 68 auto* runManager = G4RunManagerFactory::Crea << 71 //choose the Random engine >> 72 CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine()); 69 73 70 // Number of threads can be defined via 3rd << 74 //Construct the default run manager 71 if (argc == 4) { << 75 G4RunManager * runManager = new G4RunManager(); 72 G4int nThreads = G4UIcommand::ConvertToInt << 73 runManager->SetNumberOfThreads(nThreads); << 74 } << 75 G4cout << "##### Hadr00 started for " << run << 76 << " #####" << G4endl; << 77 76 78 // set mandatory initialization classes << 77 //set mandatory initialization classes 79 DetectorConstruction* det = new DetectorCons << 78 runManager->SetUserInitialization(new DetectorConstruction()); 80 runManager->SetUserInitialization(det); << 81 79 82 G4PhysListFactory factory; 80 G4PhysListFactory factory; 83 G4VModularPhysicsList* phys = nullptr; << 81 G4VModularPhysicsList* phys = 0; 84 G4String physName = ""; 82 G4String physName = ""; 85 83 86 // Physics List name defined via 3nd argumen 84 // Physics List name defined via 3nd argument 87 if (argc >= 3) { << 85 if (argc==3) { physName = argv[2]; } 88 physName = argv[2]; << 89 } << 90 86 91 // Physics List is defined via environment v 87 // Physics List is defined via environment variable PHYSLIST 92 if ("" == physName) { << 88 if("" == physName) { 93 char* path = std::getenv("PHYSLIST"); << 89 char* path = getenv("PHYSLIST"); 94 if (path) { << 90 if (path) { physName = G4String(path); } 95 physName = G4String(path); << 96 } << 97 } 91 } 98 92 99 // if name is not known to the factory use F 93 // if name is not known to the factory use FTFP_BERT 100 if ("" == physName || !factory.IsReferencePh << 94 if("" == physName || !factory.IsReferencePhysList(physName)) { 101 physName = "FTFP_BERT"; << 95 physName = "FTFP_BERT"; 102 } 96 } 103 97 104 // reference PhysicsList via its name 98 // reference PhysicsList via its name 105 phys = factory.GetReferencePhysList(physName 99 phys = factory.GetReferencePhysList(physName); 106 100 107 runManager->SetUserInitialization(phys); 101 runManager->SetUserInitialization(phys); 108 det->SetPhysicsList(phys); << 109 102 110 // set user action classes << 103 runManager->SetUserAction(new PrimaryGeneratorAction()); 111 runManager->SetUserInitialization(new Action << 112 104 113 // initialize visualization << 105 //set user action classes 114 G4VisManager* visManager = nullptr; << 106 runManager->SetUserAction(new RunAction()); >> 107 runManager->SetUserAction(new EventAction()); 115 108 116 // get the pointer to the User Interface man << 109 //get the pointer to the User Interface manager 117 G4UImanager* UImanager = G4UImanager::GetUIp 110 G4UImanager* UImanager = G4UImanager::GetUIpointer(); >> 111 #ifdef G4VIS_USE >> 112 G4VisManager* visManager = 0; >> 113 #endif >> 114 >> 115 if (argc==1) // Define UI terminal for interactive mode >> 116 { >> 117 #ifdef G4VIS_USE >> 118 //visualization manager >> 119 visManager = new G4VisExecutive; >> 120 visManager->Initialize(); >> 121 #endif >> 122 #ifdef G4UI_USE >> 123 G4UIExecutive* ui = new G4UIExecutive(argc, argv); >> 124 ui->SessionStart(); >> 125 delete ui; >> 126 #endif >> 127 } >> 128 else // Batch mode >> 129 { >> 130 G4String command = "/control/execute "; >> 131 G4String fileName = argv[1]; >> 132 UImanager->ApplyCommand(command+fileName); >> 133 } 118 134 119 if (ui) { << 135 //job termination 120 // interactive mode << 136 #ifdef G4VIS_USE 121 visManager = new G4VisExecutive; << 122 visManager->Initialize(); << 123 ui->SessionStart(); << 124 delete ui; << 125 } << 126 else { << 127 // batch mode << 128 G4String command = "/control/execute "; << 129 G4String fileName = argv[1]; << 130 UImanager->ApplyCommand(command + fileName << 131 } << 132 << 133 // job termination << 134 delete visManager; 137 delete visManager; >> 138 #endif 135 delete runManager; 139 delete runManager; >> 140 >> 141 return 0; 136 } 142 } 137 143 138 //....oooOO0OOooo........oooOO0OOooo........oo 144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 139 145