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