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 // The Geant4-DNA web site is available at htt 30 // The Geant4-DNA web site is available at http://geant4-dna.org 31 // 31 // >> 32 // $ID$ 32 /// \file wholeNuclearDNA.cc 33 /// \file wholeNuclearDNA.cc 33 /// \brief Implementation of the microdosimetr 34 /// \brief Implementation of the microdosimetry example 34 // 35 // 35 //....oooOO0OOooo........oooOO0OOooo........oo 36 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 36 #include "G4RunManagerFactory.hh" << 37 37 #include "G4Types.hh" << 38 #ifdef G4MULTITHREADED 38 #include "G4UIExecutive.hh" << 39 #include "G4MTRunManager.hh" >> 40 #else >> 41 #include "G4RunManager.hh" >> 42 #endif >> 43 39 #include "G4UImanager.hh" 44 #include "G4UImanager.hh" 40 #include "G4UItcsh.hh" << 45 #include "G4UIExecutive.hh" 41 #include "G4UIterminal.hh" 46 #include "G4UIterminal.hh" >> 47 #include "G4UItcsh.hh" 42 #include "G4VisExecutive.hh" 48 #include "G4VisExecutive.hh" 43 #ifdef G4UI_USE_QT << 44 # include "G4UIQt.hh" << 45 #endif << 46 49 47 #include "ActionInitialization.hh" 50 #include "ActionInitialization.hh" 48 #include "CommandLineParser.hh" << 49 #include "DetectorConstruction.hh" 51 #include "DetectorConstruction.hh" 50 #include "PhysicsList.hh" 52 #include "PhysicsList.hh" >> 53 #include "CommandLineParser.hh" >> 54 #include "G4UIQt.hh" 51 55 52 //....oooOO0OOooo........oooOO0OOooo........oo 56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 53 57 54 using namespace G4DNAPARSER; 58 using namespace G4DNAPARSER; 55 CommandLineParser* parser(0); 59 CommandLineParser* parser(0); 56 60 57 void Parse(int& argc, char** argv); 61 void Parse(int& argc, char** argv); 58 62 59 int main(int argc, char** argv) << 63 int main(int argc,char** argv) 60 { 64 { >> 65 // Choose the Random engine >> 66 >> 67 G4Random::setTheEngine(new CLHEP::RanecuEngine); >> 68 61 ////////// 69 ////////// 62 // Parse options given in commandLine 70 // Parse options given in commandLine 63 // 71 // 64 Parse(argc, argv); 72 Parse(argc, argv); 65 73 66 ////////// 74 ////////// 67 // Construct the run manager according to wh 75 // Construct the run manager according to whether MT is activated or not 68 // 76 // 69 Command* commandLine(0); 77 Command* commandLine(0); 70 78 71 auto* runManager = G4RunManagerFactory::Crea << 79 #ifdef G4MULTITHREADED 72 if ((commandLine = parser->GetCommandIfActiv << 80 G4MTRunManager* runManager= new G4MTRunManager; >> 81 if ((commandLine = parser->GetCommandIfActive("-mt"))) >> 82 { 73 int nThreads = 2; 83 int nThreads = 2; 74 if (commandLine->GetOption() == "NMAX") { << 84 if(commandLine->GetOption() == "NMAX") 75 nThreads = G4Threading::G4GetNumberOfCor << 85 { >> 86 nThreads = G4Threading::G4GetNumberOfCores(); 76 } 87 } 77 else { << 88 else 78 nThreads = G4UIcommand::ConvertToInt(com << 89 { >> 90 nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption()); 79 } 91 } 80 << 92 G4cout << "===== WholeNuclearDNA is started with " >> 93 << runManager->GetNumberOfThreads() >> 94 << " threads =====" << G4endl; >> 95 81 runManager->SetNumberOfThreads(nThreads); 96 runManager->SetNumberOfThreads(nThreads); 82 << 83 G4cout << "===== WholeNuclearDNA is starte << 84 << " threads =====" << G4endl; << 85 } 97 } >> 98 #else >> 99 G4RunManager* runManager = new G4RunManager(); >> 100 #endif 86 101 87 // Set mandatory user initialization classes 102 // Set mandatory user initialization classes 88 DetectorConstruction* detector = new Detecto 103 DetectorConstruction* detector = new DetectorConstruction; 89 runManager->SetUserInitialization(detector); 104 runManager->SetUserInitialization(detector); 90 runManager->SetUserInitialization(new Physic 105 runManager->SetUserInitialization(new PhysicsList); 91 runManager->SetUserInitialization(new Action 106 runManager->SetUserInitialization(new ActionInitialization()); 92 << 107 93 // Initialize G4 kernel 108 // Initialize G4 kernel 94 runManager->Initialize(); 109 runManager->Initialize(); 95 110 96 // Initialize visualization 111 // Initialize visualization 97 G4VisManager* visManager = new G4VisExecutiv 112 G4VisManager* visManager = new G4VisExecutive; 98 // G4VisExecutive can take a verbosity argum 113 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance. 99 // G4VisManager* visManager = new G4VisExecu 114 // G4VisManager* visManager = new G4VisExecutive("Quiet"); 100 visManager->Initialize(); 115 visManager->Initialize(); 101 116 102 // Get the pointer to the User Interface man 117 // Get the pointer to the User Interface manager 103 G4UImanager* UImanager = G4UImanager::GetUIp 118 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 104 G4UIExecutive* ui(0); 119 G4UIExecutive* ui(0); 105 120 106 // interactive mode : define UI session 121 // interactive mode : define UI session 107 if ((commandLine = parser->GetCommandIfActiv << 122 if ((commandLine = parser->GetCommandIfActive("-gui"))) 108 ui = new G4UIExecutive(argc, argv, command << 123 { >> 124 ui = new G4UIExecutive(argc, argv, >> 125 commandLine->GetOption()); 109 126 110 if (ui->IsGUI()) UImanager->ApplyCommand(" << 127 if(ui->IsGUI()) >> 128 UImanager->ApplyCommand("/control/execute gui.mac"); 111 129 112 if (parser->GetCommandIfActive("-novis") = << 130 if(parser->GetCommandIfActive("-novis") == 0) 113 // visualization is used by default 131 // visualization is used by default 114 { 132 { 115 if ((commandLine = parser->GetCommandIfA << 133 if((commandLine = parser->GetCommandIfActive("-vis"))) 116 // select a visualization driver if need 134 // select a visualization driver if needed (e.g. HepFile) 117 { 135 { 118 UImanager->ApplyCommand(G4String("/vis << 136 UImanager->ApplyCommand(G4String("/vis/open ")+ >> 137 commandLine->GetOption()); 119 } 138 } 120 else 139 else 121 // by default OGL is used 140 // by default OGL is used 122 { 141 { 123 UImanager->ApplyCommand("/vis/open OGL 142 UImanager->ApplyCommand("/vis/open OGL 800x600-0+0"); 124 } 143 } 125 UImanager->ApplyCommand("/control/execut 144 UImanager->ApplyCommand("/control/execute vis.mac"); 126 } 145 } 127 } 146 } 128 else 147 else 129 // to be use visualization file (= store the 148 // to be use visualization file (= store the visualization into 130 // an external file: 149 // an external file: 131 // ASCIITree ; DAWNFILE ; HepRepFile ; VRML 150 // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ... 132 { 151 { 133 if ((commandLine = parser->GetCommandIfAct << 152 if ((commandLine = parser->GetCommandIfActive("-vis"))) 134 UImanager->ApplyCommand(G4String("/vis/o << 153 { >> 154 UImanager->ApplyCommand(G4String("/vis/open ")+commandLine->GetOption()); 135 UImanager->ApplyCommand("/control/execut 155 UImanager->ApplyCommand("/control/execute vis.mac"); 136 } 156 } 137 } 157 } 138 158 139 if ((commandLine = parser->GetCommandIfActiv << 159 if ((commandLine = parser->GetCommandIfActive("-mac"))) >> 160 { 140 G4String command = "/control/execute "; 161 G4String command = "/control/execute "; 141 UImanager->ApplyCommand(command + commandL 162 UImanager->ApplyCommand(command + commandLine->GetOption()); 142 } 163 } 143 else { << 164 else >> 165 { 144 UImanager->ApplyCommand("/control/execute 166 UImanager->ApplyCommand("/control/execute wholeNuclearDNA.in"); 145 } 167 } 146 168 147 if ((commandLine = parser->GetCommandIfActiv << 169 if ((commandLine = parser->GetCommandIfActive("-gui"))) >> 170 { 148 #ifdef G4UI_USE_QT 171 #ifdef G4UI_USE_QT 149 G4UIQt* UIQt = static_cast<G4UIQt*>(UImana << 172 G4UIQt* UIQt = static_cast<G4UIQt*> (UImanager->GetG4UIWindow()); 150 if (UIQt) { << 173 if ( UIQt) { 151 UIQt->AddViewerTabFromFile("README", "RE << 174 UIQt->AddViewerTabFromFile("README", "README from "+ G4String(argv[0])); 152 } 175 } 153 #endif 176 #endif 154 ui->SessionStart(); 177 ui->SessionStart(); 155 delete ui; 178 delete ui; 156 } 179 } 157 180 158 delete visManager; 181 delete visManager; 159 delete runManager; 182 delete runManager; 160 183 161 return 0; 184 return 0; 162 } 185 } 163 186 164 //....oooOO0OOooo........oooOO0OOooo........oo 187 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 165 188 166 void GetNameAndPathOfExecutable(char** argv, G << 189 void GetNameAndPathOfExecutable(char** argv, >> 190 G4String& executable, >> 191 G4String& path) 167 { 192 { 168 // Get the last position of '/' 193 // Get the last position of '/' 169 std::string aux(argv[0]); 194 std::string aux(argv[0]); 170 195 171 // get '/' or '\\' depending on unix/mac or 196 // get '/' or '\\' depending on unix/mac or windows. 172 #if defined(_WIN32) || defined(WIN32) 197 #if defined(_WIN32) || defined(WIN32) 173 int pos = aux.rfind('\\'); 198 int pos = aux.rfind('\\'); 174 #else 199 #else 175 int pos = aux.rfind('/'); 200 int pos = aux.rfind('/'); 176 #endif 201 #endif 177 202 178 // Get the path and the name 203 // Get the path and the name 179 path = aux.substr(0, pos + 1); 204 path = aux.substr(0, pos + 1); 180 executable = aux.substr(pos + 1); 205 executable = aux.substr(pos + 1); 181 } 206 } 182 207 183 //....oooOO0OOooo........oooOO0OOooo........oo 208 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 184 209 185 void Parse(int& argc, char** argv) 210 void Parse(int& argc, char** argv) 186 { 211 { 187 ////////// 212 ////////// 188 // Parse options given in commandLine 213 // Parse options given in commandLine 189 // 214 // 190 parser = CommandLineParser::GetParser(); 215 parser = CommandLineParser::GetParser(); 191 216 192 parser->AddCommand("-gui", Command::OptionNo << 217 parser->AddCommand("-gui", 193 "Select geant4 UI or just << 218 Command::OptionNotCompulsory, 194 << 219 "Select geant4 UI or just launch a geant4 terminal session", 195 parser->AddCommand("-mac", Command::WithOpti << 220 "qt"); 196 << 221 197 // You cann your own command, as for instanc << 222 parser->AddCommand("-mac", 198 // parser->AddCommand("-seed", << 223 Command::WithOption, 199 // Command::WithOption, << 224 "Give a mac file to execute", 200 // "Give a seed value in << 225 "macFile.mac"); 201 // it is then up to you to manage this optio << 226 202 << 227 // You cann your own command, as for instance: 203 parser->AddCommand("-mt", Command::WithOptio << 228 // parser->AddCommand("-seed", >> 229 // Command::WithOption, >> 230 // "Give a seed value in argument to be tested", "seed"); >> 231 // it is then up to you to manage this option >> 232 >> 233 #ifdef G4MULTITHREADED >> 234 parser->AddCommand("-mt", >> 235 Command::WithOption, >> 236 "Launch in MT mode (events computed in parallel)", 204 "2"); 237 "2"); >> 238 #endif 205 239 206 parser->AddCommand("-vis", Command::WithOpti << 240 parser->AddCommand("-vis", >> 241 Command::WithOption, >> 242 "Select a visualization driver", 207 "OGL 600x600-0+0"); 243 "OGL 600x600-0+0"); 208 244 209 parser->AddCommand("-novis", Command::Withou << 245 parser->AddCommand("-novis", >> 246 Command::WithoutOption, >> 247 "Deactivate visualization when using GUI"); 210 248 211 G4String exec; 249 G4String exec; 212 G4String path; 250 G4String path; 213 GetNameAndPathOfExecutable(argv, exec, path) 251 GetNameAndPathOfExecutable(argv, exec, path); 214 252 215 parser->AddCommand("-out", Command::OptionNo << 253 parser->AddCommand("-out", >> 254 Command::OptionNotCompulsory, >> 255 "Output files (ROOT is used by default)", 216 exec); 256 exec); 217 257 218 ////////// 258 ////////// 219 // If -h or --help is given in option : prin 259 // If -h or --help is given in option : print help and exit 220 // 260 // 221 if (parser->Parse(argc, argv) != 0) // help << 261 if (parser->Parse(argc, argv) != 0) // help is being printed 222 { 262 { 223 // if you are using ROOT, create a TApplic 263 // if you are using ROOT, create a TApplication in this condition in order 224 // to print the help from ROOT as well 264 // to print the help from ROOT as well 225 CommandLineParser::DeleteInstance(); 265 CommandLineParser::DeleteInstance(); 226 std::exit(0); 266 std::exit(0); 227 } 267 } 228 268 229 /////////// 269 /////////// 230 // Kill application if wrong argument in com 270 // Kill application if wrong argument in command line 231 // 271 // 232 if (parser->CheckIfNotHandledOptionsExists(a << 272 if (parser->CheckIfNotHandledOptionsExists(argc, argv)) >> 273 { 233 // if you are using ROOT, you should initi 274 // if you are using ROOT, you should initialise your TApplication 234 // before this condition 275 // before this condition 235 abort(); 276 abort(); 236 } 277 } 237 } 278 } >> 279 >> 280 238 281