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 // This example is provided by the Geant4-DNA 26 // This example is provided by the Geant4-DNA collaboration 27 // Any report or published results obtained us 27 // Any report or published results obtained using the Geant4-DNA software 28 // shall cite the following Geant4-DNA collabo 28 // shall cite the following Geant4-DNA collaboration publication: 29 // Med. Phys. 37 (2010) 4692-4708 29 // Med. Phys. 37 (2010) 4692-4708 30 // J. Comput. Phys. 274 (2014) 841-882 30 // J. Comput. Phys. 274 (2014) 841-882 31 // The Geant4-DNA web site is available at htt 31 // The Geant4-DNA web site is available at http://geant4-dna.org 32 // 32 // >> 33 // $Id$ 33 // 34 // 34 /// \file chem3.cc << 35 /// \file main.cc 35 /// \brief Chem3 example 36 /// \brief Chem3 example 36 37 37 #include "ActionInitialization.hh" << 38 #include "DetectorConstruction.hh" 38 #include "DetectorConstruction.hh" 39 #include "PhysicsList.hh" 39 #include "PhysicsList.hh" >> 40 #include "ActionInitialization.hh" >> 41 >> 42 #ifdef G4MULTITHREADED >> 43 #include "G4MTRunManager.hh" >> 44 #else >> 45 #include "G4RunManager.hh" >> 46 #endif 40 47 41 #include "G4DNAChemistryManager.hh" 48 #include "G4DNAChemistryManager.hh" 42 #include "G4RunManagerFactory.hh" << 43 #include "G4UIExecutive.hh" << 44 #include "G4UImanager.hh" 49 #include "G4UImanager.hh" >> 50 #include "G4UIExecutive.hh" 45 #include "G4VisExecutive.hh" 51 #include "G4VisExecutive.hh" 46 #ifdef G4UI_USE_QT << 52 #include "G4UIQt.hh" 47 # include "G4UIQt.hh" << 48 #endif << 49 #include "CommandLineParser.hh" 53 #include "CommandLineParser.hh" 50 54 51 //....oooOO0OOooo........oooOO0OOooo........oo 55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 52 56 53 /* 57 /* 54 * WARNING : Geant4 was initially not intended 58 * WARNING : Geant4 was initially not intended for this kind of application 55 * This code is delivered as a prototype 59 * This code is delivered as a prototype 56 * We will be happy to hear from you, do not h 60 * We will be happy to hear from you, do not hesitate to send your feedback and 57 * communicate on the difficulties you may enc 61 * communicate on the difficulties you may encounter 58 * The user interface may change in the next r 62 * The user interface may change in the next releases since a reiteration of the 59 * code has started 63 * code has started 60 */ 64 */ 61 65 62 using namespace G4DNAPARSER; 66 using namespace G4DNAPARSER; 63 CommandLineParser* parser(0); 67 CommandLineParser* parser(0); 64 68 65 void Parse(int& argc, char** argv); 69 void Parse(int& argc, char** argv); 66 70 67 int main(int argc, char** argv) 71 int main(int argc, char** argv) 68 { 72 { 69 ////////// 73 ////////// 70 // Parse options given in commandLine 74 // Parse options given in commandLine 71 // 75 // 72 Parse(argc, argv); 76 Parse(argc, argv); 73 77 74 ////////// 78 ////////// 75 // Construct the run manager according to wh 79 // Construct the run manager according to whether MT is activated or not 76 // 80 // 77 Command* commandLine(0); 81 Command* commandLine(0); 78 82 79 auto* runManager = G4RunManagerFactory::Crea << 83 #ifdef G4MULTITHREADED 80 << 84 G4RunManager* runManager(0); 81 if ((commandLine = parser->GetCommandIfActiv << 85 if ((commandLine = parser->GetCommandIfActive("-mt"))) >> 86 { >> 87 runManager = new G4MTRunManager; 82 int nThreads = 2; 88 int nThreads = 2; 83 const G4String& option = commandLine->GetO 89 const G4String& option = commandLine->GetOption(); 84 if (option == "") { << 90 if(option == "") >> 91 { 85 nThreads = G4UIcommand::ConvertToInt(com 92 nThreads = G4UIcommand::ConvertToInt(commandLine->GetDefaultOption()); 86 } 93 } 87 else if (option == "NMAX") { << 94 else if(option == "NMAX") 88 nThreads = G4Threading::G4GetNumberOfCor << 95 { >> 96 nThreads = G4Threading::G4GetNumberOfCores(); 89 } 97 } 90 else { << 98 else >> 99 { 91 nThreads = G4UIcommand::ConvertToInt(opt 100 nThreads = G4UIcommand::ConvertToInt(option); 92 } 101 } 93 102 94 runManager->SetNumberOfThreads(nThreads); << 103 G4cout << "===== Chem3 is started with " >> 104 << ((G4MTRunManager*) runManager)->GetNumberOfThreads() >> 105 << " threads =====" << G4endl; 95 106 96 G4cout << "===== Chem3 is started with " < << 107 ((G4MTRunManager*) runManager)->SetNumberOfThreads(nThreads); 97 << " threads =====" << G4endl; << 98 } 108 } >> 109 else >> 110 { >> 111 runManager = new G4RunManager(); >> 112 } >> 113 #else >> 114 G4RunManager* runManager = new G4RunManager(); >> 115 #endif 99 116 100 ////////// 117 ////////// 101 // Set mandatory user initialization classes 118 // Set mandatory user initialization classes 102 // 119 // 103 DetectorConstruction* detector = new Detecto 120 DetectorConstruction* detector = new DetectorConstruction; 104 runManager->SetUserInitialization(new Physic 121 runManager->SetUserInitialization(new PhysicsList); 105 runManager->SetUserInitialization(detector); 122 runManager->SetUserInitialization(detector); 106 runManager->SetUserInitialization(new Action 123 runManager->SetUserInitialization(new ActionInitialization()); 107 124 108 // Initialize G4 kernel 125 // Initialize G4 kernel 109 runManager->Initialize(); 126 runManager->Initialize(); 110 127 111 // Initialize visualization 128 // Initialize visualization 112 G4VisManager* visManager = new G4VisExecutiv 129 G4VisManager* visManager = new G4VisExecutive; 113 // G4VisExecutive can take a verbosity argum 130 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance. 114 // G4VisManager* visManager = new G4VisExecu 131 // G4VisManager* visManager = new G4VisExecutive("Quiet"); 115 visManager->Initialize(); 132 visManager->Initialize(); 116 133 117 // Get the pointer to the User Interface man 134 // Get the pointer to the User Interface manager 118 G4UImanager* UImanager = G4UImanager::GetUIp 135 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 119 G4UIExecutive* ui(0); 136 G4UIExecutive* ui(0); 120 137 121 // interactive mode : define UI session 138 // interactive mode : define UI session 122 if ((commandLine = parser->GetCommandIfActiv << 139 if ((commandLine = parser->GetCommandIfActive("-gui"))) >> 140 { 123 ui = new G4UIExecutive(argc, argv, command 141 ui = new G4UIExecutive(argc, argv, commandLine->GetOption()); 124 142 125 if (parser->GetCommandIfActive("-novis") = 143 if (parser->GetCommandIfActive("-novis") == 0) 126 // visualization is used by default 144 // visualization is used by default 127 { 145 { 128 if ((commandLine = parser->GetCommandIfA 146 if ((commandLine = parser->GetCommandIfActive("-vis"))) 129 // select a visualization driver if need 147 // select a visualization driver if needed (e.g. HepFile) 130 { 148 { 131 UImanager->ApplyCommand(G4String("/vis << 149 UImanager->ApplyCommand( >> 150 G4String("/vis/open ") + commandLine->GetOption()); 132 } 151 } 133 else 152 else 134 // by default OGL is used 153 // by default OGL is used 135 { 154 { 136 UImanager->ApplyCommand("/vis/open OGL 155 UImanager->ApplyCommand("/vis/open OGL 800x600-0+0"); 137 } 156 } 138 UImanager->ApplyCommand("/control/execut 157 UImanager->ApplyCommand("/control/execute vis.mac"); 139 } 158 } 140 159 141 if (ui->IsGUI()) UImanager->ApplyCommand(" 160 if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac"); 142 } 161 } 143 else 162 else 144 // to be use visualization file (= store the 163 // to be use visualization file (= store the visualization into 145 // an external file: 164 // an external file: 146 // ASCIITree ; DAWNFILE ; HepRepFile ; VRML 165 // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ... 147 { 166 { 148 if ((commandLine = parser->GetCommandIfAct << 167 if ((commandLine = parser->GetCommandIfActive("-vis"))) 149 UImanager->ApplyCommand(G4String("/vis/o << 168 { >> 169 UImanager->ApplyCommand( >> 170 G4String("/vis/open ") + commandLine->GetOption()); 150 UImanager->ApplyCommand("/control/execut 171 UImanager->ApplyCommand("/control/execute vis.mac"); 151 } 172 } 152 } 173 } 153 174 154 if ((commandLine = parser->GetCommandIfActiv << 175 if ((commandLine = parser->GetCommandIfActive("-mac"))) >> 176 { 155 G4String command = "/control/execute "; 177 G4String command = "/control/execute "; 156 UImanager->ApplyCommand(command + commandL 178 UImanager->ApplyCommand(command + commandLine->GetOption()); 157 } 179 } 158 else { << 180 else >> 181 { 159 UImanager->ApplyCommand("/control/execute 182 UImanager->ApplyCommand("/control/execute beam.in"); 160 } 183 } 161 184 162 if ((commandLine = parser->GetCommandIfActiv << 185 if ((commandLine = parser->GetCommandIfActive("-gui"))) >> 186 { 163 #ifdef G4UI_USE_QT 187 #ifdef G4UI_USE_QT 164 G4UIQt* UIQt = static_cast<G4UIQt*>(UImana << 188 G4UIQt* UIQt = static_cast<G4UIQt*> (UImanager->GetG4UIWindow()); 165 if (UIQt) { << 189 if ( UIQt) { 166 UIQt->AddViewerTabFromFile("README", "RE << 190 UIQt->AddViewerTabFromFile("README", "README from "+ G4String(argv[0])); 167 } 191 } 168 #endif 192 #endif 169 ui->SessionStart(); 193 ui->SessionStart(); 170 delete ui; 194 delete ui; 171 } 195 } 172 196 173 // Job termination 197 // Job termination 174 // Free the store: user actions, physics_lis 198 // Free the store: user actions, physics_list and detector_description are 175 // owned and deleted by the run manager, so 199 // owned and deleted by the run manager, so they should not be deleted 176 // in the main() program ! 200 // in the main() program ! 177 201 178 delete visManager; 202 delete visManager; 179 delete runManager; 203 delete runManager; 180 204 181 CommandLineParser::DeleteInstance(); 205 CommandLineParser::DeleteInstance(); 182 206 183 return 0; 207 return 0; 184 } 208 } 185 209 186 void Parse(int& argc, char** argv) 210 void Parse(int& argc, char** argv) 187 { 211 { 188 ////////// 212 ////////// 189 // Parse options given in commandLine 213 // Parse options given in commandLine 190 // 214 // 191 parser = CommandLineParser::GetParser(); 215 parser = CommandLineParser::GetParser(); 192 216 193 parser->AddCommand("-gui", Command::OptionNo << 217 parser->AddCommand( 194 "Select geant4 UI or just << 218 "-gui", Command::OptionNotCompulsory, 195 << 219 "Select geant4 UI or just launch a geant4 terminal session", "qt"); 196 parser->AddCommand("-mac", Command::WithOpti << 220 197 << 221 parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute", 198 // You cann your own command, as for instanc << 222 "macFile.mac"); 199 // parser->AddCommand("-seed", << 223 200 // Command::WithOption, << 224 // You cann your own command, as for instance: 201 // "Give a seed value in << 225 // parser->AddCommand("-seed", 202 // it is then up to you to manage this optio << 226 // Command::WithOption, >> 227 // "Give a seed value in argument to be tested", "seed"); >> 228 // it is then up to you to manage this option 203 229 >> 230 #ifdef G4MULTITHREADED 204 parser->AddCommand("-mt", Command::OptionNot 231 parser->AddCommand("-mt", Command::OptionNotCompulsory, 205 "Launch in MT mode if ava << 232 "Launch in MT mode (events computed in parallel," 206 " NOT RECOMMENDED WITH CH << 233 " NOT RECOMMANDED WITH CHEMISTRY)", 207 "2"); 234 "2"); >> 235 #endif 208 236 209 parser->AddCommand("-chemOFF", Command::With << 237 parser->AddCommand("-chemOFF", Command::WithoutOption, >> 238 "Deactivate chemistry"); 210 239 211 parser->AddCommand("-vis", Command::WithOpti << 240 parser->AddCommand("-vis", Command::WithOption, 212 "OGL 600x600-0+0"); << 241 "Select a visualization driver", "OGL 600x600-0+0"); 213 242 214 parser->AddCommand("-novis", Command::Withou << 243 parser->AddCommand("-novis", Command::WithoutOption, >> 244 "Deactivate visualization when using GUI"); 215 245 216 ////////// 246 ////////// 217 // If -h or --help is given in option : prin 247 // If -h or --help is given in option : print help and exit 218 // 248 // 219 if (parser->Parse(argc, argv) != 0) // help << 249 if (parser->Parse(argc, argv) != 0) // help is being printed 220 { 250 { 221 // if you are using ROOT, create a TApplic 251 // if you are using ROOT, create a TApplication in this condition in order 222 // to print the help from ROOT as well 252 // to print the help from ROOT as well 223 CommandLineParser::DeleteInstance(); 253 CommandLineParser::DeleteInstance(); 224 std::exit(0); 254 std::exit(0); 225 } 255 } 226 256 227 /////////// 257 /////////// 228 // Kill application if wrong argument in com 258 // Kill application if wrong argument in command line 229 // 259 // 230 if (parser->CheckIfNotHandledOptionsExists(a << 260 if (parser->CheckIfNotHandledOptionsExists(argc, argv)) >> 261 { 231 // if you are using ROOT, you should initi 262 // if you are using ROOT, you should initialise your TApplication 232 // before this condition 263 // before this condition 233 abort(); 264 abort(); 234 } 265 } 235 } 266 } 236 267