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: field04.cc 78551 2014-01-07 09:45:08Z gcosmo $ 26 // 27 // 27 /// \file field/field04/field04.cc 28 /// \file field/field04/field04.cc 28 /// \brief Main program of the field/field04 e 29 /// \brief Main program of the field/field04 example 29 // 30 // 30 //....oooOO0OOooo........oooOO0OOooo........oo << 31 // 31 //....oooOO0OOooo........oooOO0OOooo........oo << 32 // -------------------------------------------------------------- >> 33 // >> 34 // GEANT 4 - Example F04 >> 35 // >> 36 // -------------------------------------------------------------- >> 37 // Comments >> 38 // >> 39 // >> 40 // -------------------------------------------------------------- 32 41 33 #ifndef WIN32 42 #ifndef WIN32 34 # include <unistd.h> << 43 #include <unistd.h> 35 #endif 44 #endif 36 45 37 #include "G4Types.hh" << 46 #ifdef G4MULTITHREADED 38 << 47 #include "G4MTRunManager.hh" 39 #include "G4RunManagerFactory.hh" << 48 #else 40 #include "F04SteppingVerbose.hh" 49 #include "F04SteppingVerbose.hh" >> 50 #include "G4RunManager.hh" >> 51 #endif 41 52 42 #include "F04ActionInitialization.hh" << 43 #include "F04DetectorConstruction.hh" << 44 #include "F04PhysicsList.hh" 53 #include "F04PhysicsList.hh" >> 54 #include "F04DetectorConstruction.hh" >> 55 >> 56 #include "F04ActionInitialization.hh" 45 57 46 #include "G4UIExecutive.hh" << 47 #include "G4UImanager.hh" 58 #include "G4UImanager.hh" 48 #include "G4VisExecutive.hh" << 59 49 #include "Randomize.hh" 60 #include "Randomize.hh" 50 61 51 //....oooOO0OOooo........oooOO0OOooo........oo << 62 #ifdef G4VIS_USE >> 63 #include "G4VisExecutive.hh" >> 64 #endif 52 65 53 namespace << 66 #ifdef G4UI_USE 54 { << 67 #include "G4UIExecutive.hh" 55 void PrintUsage() << 68 #endif 56 { << 69 57 G4cerr << " Usage: " << G4endl; << 70 // argc holds the number of arguments (including the name) on the command line 58 G4cerr << " field04 [-m macro ] [-p physicsL << 71 // -> it is ONE when only the name is given !!! 59 } << 72 // argv[0] is always the name of the program 60 } // namespace << 73 // argv[1] points to the first argument, and so on 61 74 62 //....oooOO0OOooo........oooOO0OOooo........oo 75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 63 76 64 int main(int argc, char** argv) << 77 int main(int argc,char** argv) 65 { 78 { 66 // Evaluate arguments << 79 // Choose the Random engine 67 // argc holds the number of arguments (inclu << 68 // -> it is ONE when only the name is given << 69 // argv[0] is always the name of the program << 70 // argv[1] points to the first argument, and << 71 // << 72 if (argc > 7) { << 73 PrintUsage(); << 74 return 1; << 75 } << 76 << 77 G4String macro; << 78 G4String physicsList = "QGSP_BERT"; << 79 G4int randomSeed = 1234; << 80 G4String startPhase = "idle"; << 81 for (G4int i = 1; i < argc; i = i + 2) { << 82 if (G4String(argv[i]) == "-m") << 83 macro = argv[i + 1]; << 84 else if (G4String(argv[i]) == "-r") << 85 randomSeed = atoi(argv[i + 1]); << 86 else if (G4String(argv[i]) == "-p") << 87 physicsList = argv[i + 1]; << 88 else if (G4String(argv[i]) == "-s") << 89 startPhase = argv[i + 1]; << 90 else { << 91 PrintUsage(); << 92 return 1; << 93 } << 94 } << 95 << 96 // Instantiate G4UIExecutive if there are no << 97 // 80 // 98 G4UIExecutive* ui = nullptr; << 81 G4Random::setTheEngine(new CLHEP::RanecuEngine); 99 if (!macro.size()) { << 100 ui = new G4UIExecutive(argc, argv); << 101 } << 102 82 103 // Setting the application-specific Stepping << 83 G4int myseed = 1234; 104 // << 84 if (argc > 2) myseed = atoi(argv[argc-1]); 105 auto verbosity = new F04SteppingVerbose; << 106 85 107 // Construct the default run manager 86 // Construct the default run manager 108 // 87 // 109 auto runManager = G4RunManagerFactory::Creat << 88 #ifdef G4MULTITHREADED >> 89 G4MTRunManager * runManager = new G4MTRunManager; >> 90 #else >> 91 G4VSteppingVerbose::SetInstance(new F04SteppingVerbose); >> 92 G4RunManager * runManager = new G4RunManager; >> 93 #endif >> 94 >> 95 G4Random::setTheSeed(myseed); >> 96 >> 97 G4String physicsList = "QGSP_BERT"; 110 98 111 G4Random::setTheSeed(randomSeed); << 99 #ifndef WIN32 >> 100 G4int c = 0; >> 101 while ((c=getopt(argc,argv,"p")) != -1) >> 102 { >> 103 switch (c) >> 104 { >> 105 case 'p': >> 106 physicsList = optarg; >> 107 G4cout << "Physics List used is " << physicsList << G4endl; >> 108 break; >> 109 case ':': /* -p without operand */ >> 110 fprintf(stderr,"Option -%c requires an operand\n", optopt); >> 111 break; >> 112 case '?': >> 113 fprintf(stderr,"Unrecognised option: -%c\n", optopt); >> 114 } >> 115 } >> 116 #endif 112 117 113 // Set mandatory initialization classes 118 // Set mandatory initialization classes 114 // 119 // 115 // Detector construction 120 // Detector construction 116 auto detector = new F04DetectorConstruction( << 121 F04DetectorConstruction* detector = new F04DetectorConstruction(); 117 runManager->SetUserInitialization(detector); 122 runManager->SetUserInitialization(detector); 118 // Physics list 123 // Physics list 119 runManager->SetUserInitialization(new F04Phy 124 runManager->SetUserInitialization(new F04PhysicsList(physicsList)); 120 // User action initialization 125 // User action initialization 121 runManager->SetUserInitialization(new F04Act 126 runManager->SetUserInitialization(new F04ActionInitialization(detector)); 122 127 123 // Initialize G4 kernel 128 // Initialize G4 kernel 124 // 129 // 125 // runManager->Initialize(); << 130 //runManager->Initialize(); 126 131 >> 132 #ifdef G4VIS_USE 127 // Initialize visualization 133 // Initialize visualization 128 // 134 // 129 G4VisManager* visManager = new G4VisExecutiv 135 G4VisManager* visManager = new G4VisExecutive; 130 // G4VisExecutive can take a verbosity argum 136 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance. 131 // G4VisManager* visManager = new G4VisExecu 137 // G4VisManager* visManager = new G4VisExecutive("Quiet"); 132 visManager->Initialize(); 138 visManager->Initialize(); >> 139 #endif 133 140 134 // Get the pointer to the User Interface man 141 // Get the pointer to the User Interface manager 135 // 142 // 136 G4UImanager* UImanager = G4UImanager::GetUIp 143 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 137 144 138 // Process macro or start UI session << 145 #ifndef WIN32 139 // << 146 G4int optmax = argc; 140 if (macro.size()) { << 147 if (argc > 2) { optmax = optmax-1; } 141 // batch mode << 148 142 G4String command = "/control/execute "; << 149 if (optind < optmax) 143 UImanager->ApplyCommand(command + macro); << 150 { >> 151 G4String command = "/control/execute "; >> 152 for ( ; optind < optmax; optind++) >> 153 { >> 154 G4String macroFilename = argv[optind]; >> 155 UImanager->ApplyCommand(command+macroFilename); >> 156 } >> 157 } >> 158 #else // Simple UI for Windows runs, no possibility of additional arguments >> 159 if (argc!=1) // batch mode >> 160 { >> 161 G4String command = "/control/execute "; >> 162 G4String fileName = argv[1]; >> 163 UImanager->ApplyCommand(command+fileName); 144 } 164 } 145 else { << 165 #endif 146 // interactive mode : define UI session << 166 else 147 if (startPhase == "preinit") { << 167 { 148 // start in PreInit> phase if requested << 168 // Define (G)UI terminal for interactive mode 149 G4cout << "At the prompt, issue commands << 169 #ifdef G4UI_USE 150 G4cout << "/run/initialize" << G4endl; << 170 G4UIExecutive * ui = new G4UIExecutive(argc,argv); 151 G4cout << "Then if you want a viewer:" < << 171 #ifdef G4VIS_USE 152 G4cout << "/control/execute vis.mac" << << 172 // UImanager->ApplyCommand("/control/execute vis.mac"); 153 G4cout << "Then: " << G4endl; << 173 G4cout << "At the prompt, issue commands to set up detector & field, then:" 154 G4cout << "/run/beamOn … etc." << G4en << 174 << G4endl; 155 } << 175 G4cout << "/run/initialize" << G4endl; 156 else { << 176 G4cout << "Then if you want a viewer:"<< G4endl; 157 // perform initialization and draw geome << 177 G4cout << "/control/execute vis.mac" << G4endl; 158 UImanager->ApplyCommand("/control/execut << 178 G4cout << "Then: " << G4endl; 159 } << 179 G4cout << "/run/beamOn … etc." << G4endl; 160 if (ui->IsGUI()) { << 180 #endif 161 UImanager->ApplyCommand("/control/execut << 181 if (ui->IsGUI()) 162 } << 182 UImanager->ApplyCommand("/control/execute gui.mac"); 163 ui->SessionStart(); << 183 ui->SessionStart(); 164 delete ui; << 184 delete ui; >> 185 #endif 165 } 186 } 166 187 167 // Job termination 188 // Job termination 168 // Free the store: user actions, physics_lis 189 // Free the store: user actions, physics_list and detector_description are 169 // owned and deleted by the 190 // owned and deleted by the run manager, so they should not 170 // be deleted in the main() 191 // be deleted in the main() program ! 171 192 172 delete verbosity; << 193 #ifdef G4VIS_USE 173 delete visManager; 194 delete visManager; >> 195 #endif 174 delete runManager; 196 delete runManager; 175 197 176 return 0; 198 return 0; 177 } 199 } 178 200 179 //....oooOO0OOooo........oooOO0OOooo........oo 201 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 180 202