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 // and papers 30 // and papers 31 // M. Batmunkh et al. J Radiat Res Appl Sci 8 31 // M. Batmunkh et al. J Radiat Res Appl Sci 8 (2015) 498-507 32 // O. Belov et al. Physica Medica 32 (2016) 15 32 // O. Belov et al. Physica Medica 32 (2016) 1510-1520 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 // ------------------------------------------- 35 // ------------------------------------------------------------------- 36 // November 2016 36 // November 2016 37 // ------------------------------------------- 37 // ------------------------------------------------------------------- 38 // 38 // 39 /// \file neuron.cc 39 /// \file neuron.cc 40 /// \brief Implementation of the neuron exampl 40 /// \brief Implementation of the neuron example 41 // 41 // 42 //....oooOO0OOooo........oooOO0OOooo........oo 42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 43 #include "ActionInitialization.hh" << 43 #include "G4Types.hh" 44 #include "CommandLineParser.hh" << 45 #include "DetectorConstruction.hh" << 46 #include "PhysicsList.hh" << 47 << 48 #include "G4DNAChemistryManager.hh" << 49 #include "G4RunManagerFactory.hh" 44 #include "G4RunManagerFactory.hh" >> 45 #include "G4DNAChemistryManager.hh" 50 #include "G4Timer.hh" 46 #include "G4Timer.hh" 51 #include "G4Types.hh" << 52 #include "G4UIExecutive.hh" << 53 #include "G4UImanager.hh" 47 #include "G4UImanager.hh" >> 48 #include "G4UIExecutive.hh" 54 #include "G4VisExecutive.hh" 49 #include "G4VisExecutive.hh" >> 50 #include "CommandLineParser.hh" >> 51 #include "ActionInitialization.hh" >> 52 #include "DetectorConstruction.hh" >> 53 #include "PhysicsList.hh" 55 54 56 //....oooOO0OOooo........oooOO0OOooo........oo 55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 56 58 using namespace std; 57 using namespace std; 59 using namespace G4DNAPARSER; 58 using namespace G4DNAPARSER; 60 << 61 CommandLineParser* parser(0); 59 CommandLineParser* parser(0); 62 60 63 void Parse(int& argc, char** argv); 61 void Parse(int& argc, char** argv); 64 62 65 int main(int argc, char** argv) << 63 int main(int argc,char** argv) 66 { 64 { >> 65 67 // run time in Geant4 66 // run time in Geant4 68 G4Timer* timer = new G4Timer(); << 67 G4Timer *timer = new G4Timer(); 69 timer->Start(); 68 timer->Start(); 70 69 71 ////////// 70 ////////// 72 // Parse options given in commandLine 71 // Parse options given in commandLine 73 // 72 // 74 Parse(argc, argv); 73 Parse(argc, argv); 75 74 76 ////////// 75 ////////// 77 // Construct the run manager according to wh 76 // Construct the run manager according to whether MT is activated or not 78 // 77 // 79 Command* commandLine(0); 78 Command* commandLine(0); 80 79 81 auto* runManager = G4RunManagerFactory::Crea << 80 auto* runManager= G4RunManagerFactory::CreateRunManager(); 82 << 81 if ((commandLine = parser->GetCommandIfActive("-mt"))) 83 if ((commandLine = parser->GetCommandIfActiv << 82 { 84 G4int nThreads = 2; << 83 int nThreads = 2; 85 << 84 if(commandLine->GetOption() == "NMAX") 86 if (commandLine->GetOption() == "NMAX") { << 85 { 87 nThreads = G4Threading::G4GetNumberOfCor << 86 nThreads = G4Threading::G4GetNumberOfCores(); 88 } 87 } 89 else { << 88 else 90 nThreads = G4UIcommand::ConvertToInt(com << 89 { >> 90 nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption()); 91 } 91 } 92 runManager->SetNumberOfThreads(nThreads); 92 runManager->SetNumberOfThreads(nThreads); 93 93 94 G4cout << "===== neuron is started with " << 94 G4cout << "===== neuron is started with " 95 << " threads of MT MODE =====" << G << 95 << runManager->GetNumberOfThreads() >> 96 << " threads of MT MODE =====" << G4endl; 96 } 97 } 97 98 98 // Set mandatory user initialization classes 99 // Set mandatory user initialization classes 99 DetectorConstruction* detector = new Detecto 100 DetectorConstruction* detector = new DetectorConstruction; 100 runManager->SetUserInitialization(detector); 101 runManager->SetUserInitialization(detector); 101 runManager->SetUserInitialization(new Physic 102 runManager->SetUserInitialization(new PhysicsList); 102 103 103 // User action initialization 104 // User action initialization 104 runManager->SetUserInitialization(new Action 105 runManager->SetUserInitialization(new ActionInitialization(detector)); 105 106 106 // Initialize G4 kernel 107 // Initialize G4 kernel 107 runManager->Initialize(); 108 runManager->Initialize(); 108 109 109 // Initialize visualization 110 // Initialize visualization 110 G4VisManager* visManager = new G4VisExecutiv 111 G4VisManager* visManager = new G4VisExecutive; 111 visManager->Initialize(); 112 visManager->Initialize(); 112 113 113 // Get the pointer to the User Interface man 114 // Get the pointer to the User Interface manager 114 G4UImanager* UImanager = G4UImanager::GetUIp 115 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 115 G4UIExecutive* ui(0); 116 G4UIExecutive* ui(0); 116 117 117 // interactive mode : define UI session 118 // interactive mode : define UI session 118 if ((commandLine = parser->GetCommandIfActiv << 119 if ((commandLine = parser->GetCommandIfActive("-gui"))) 119 ui = new G4UIExecutive(argc, argv, command << 120 { >> 121 ui = new G4UIExecutive(argc, argv, >> 122 commandLine->GetOption()); 120 123 121 if (ui->IsGUI()) UImanager->ApplyCommand(" << 124 if(ui->IsGUI()) >> 125 UImanager->ApplyCommand("/control/execute gui.mac"); 122 126 123 if (parser->GetCommandIfActive("-novis") = << 127 if(parser->GetCommandIfActive("-novis") == 0) 124 // visualization is used by default 128 // visualization is used by default 125 { 129 { 126 if ((commandLine = parser->GetCommandIfA << 130 if((commandLine = parser->GetCommandIfActive("-vis"))) 127 // select a visualization driver if need 131 // select a visualization driver if needed (e.g. HepFile) 128 { 132 { 129 UImanager->ApplyCommand(G4String("/vis << 133 UImanager->ApplyCommand(G4String("/vis/open ")+ >> 134 commandLine->GetOption()); 130 } 135 } 131 else 136 else 132 // by default OGL is used 137 // by default OGL is used 133 { 138 { 134 UImanager->ApplyCommand("/vis/open OGL 139 UImanager->ApplyCommand("/vis/open OGL 800x600-0+0"); 135 } 140 } 136 UImanager->ApplyCommand("/control/execut 141 UImanager->ApplyCommand("/control/execute vis.mac"); 137 } 142 } 138 } 143 } 139 else 144 else 140 // to be use visualization file (= store the 145 // to be use visualization file (= store the visualization into 141 // an external file: 146 // an external file: 142 // ASCIITree ; DAWNFILE ; HepRepFile ; VRML 147 // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ... 143 { 148 { 144 if ((commandLine = parser->GetCommandIfAct << 149 if ((commandLine = parser->GetCommandIfActive("-vis"))) 145 UImanager->ApplyCommand(G4String("/vis/o << 150 { >> 151 UImanager->ApplyCommand(G4String("/vis/open ")+commandLine->GetOption()); 146 UImanager->ApplyCommand("/control/execut 152 UImanager->ApplyCommand("/control/execute vis.mac"); 147 } 153 } 148 } 154 } 149 155 150 if ((commandLine = parser->GetCommandIfActiv << 156 if ((commandLine = parser->GetCommandIfActive("-mac"))) >> 157 { 151 G4String command = "/control/execute "; 158 G4String command = "/control/execute "; 152 UImanager->ApplyCommand(command + commandL 159 UImanager->ApplyCommand(command + commandLine->GetOption()); 153 } 160 } 154 else { << 161 else 155 UImanager->ApplyCommand("/control/execute << 162 { >> 163 UImanager->ApplyCommand("/control/execute "); //neuron.in 156 } 164 } 157 165 158 if ((commandLine = parser->GetCommandIfActiv << 166 if ((commandLine = parser->GetCommandIfActive("-gui"))) >> 167 { 159 ui->SessionStart(); 168 ui->SessionStart(); 160 delete ui; 169 delete ui; 161 } 170 } 162 171 163 // calculation time 172 // calculation time 164 timer->Stop(); 173 timer->Stop(); 165 G4cout << " Calculation time << 174 G4cout << " Calculation time = " 166 << G4endl; << 175 << timer->GetRealElapsed() << " s \n"<< G4endl; 167 176 168 delete visManager; 177 delete visManager; 169 delete runManager; 178 delete runManager; 170 179 171 return 0; 180 return 0; 172 } 181 } 173 182 174 //....oooOO0OOooo........oooOO0OOooo........oo 183 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 175 184 176 void GetNameAndPathOfExecutable(char** argv, G << 185 void GetNameAndPathOfExecutable(char** argv, >> 186 G4String& executable, >> 187 G4String& path) 177 { 188 { 178 // Get the last position of '/' 189 // Get the last position of '/' 179 std::string aux(argv[0]); 190 std::string aux(argv[0]); 180 191 181 // get '/' or '\\' depending on unix/mac or 192 // get '/' or '\\' depending on unix/mac or windows. 182 #if defined(_WIN32) || defined(WIN32) 193 #if defined(_WIN32) || defined(WIN32) 183 int pos = aux.rfind('\\'); 194 int pos = aux.rfind('\\'); 184 #else 195 #else 185 int pos = aux.rfind('/'); 196 int pos = aux.rfind('/'); 186 #endif 197 #endif 187 198 188 // Get the path and the name 199 // Get the path and the name 189 path = aux.substr(0, pos + 1); 200 path = aux.substr(0, pos + 1); 190 executable = aux.substr(pos + 1); 201 executable = aux.substr(pos + 1); 191 } 202 } 192 203 193 //....oooOO0OOooo........oooOO0OOooo........oo 204 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 194 205 195 void Parse(int& argc, char** argv) 206 void Parse(int& argc, char** argv) 196 { 207 { 197 ////////// 208 ////////// 198 // Parse options given in commandLine 209 // Parse options given in commandLine 199 // 210 // 200 parser = CommandLineParser::GetParser(); 211 parser = CommandLineParser::GetParser(); 201 212 202 parser->AddCommand("-gui", Command::OptionNo << 213 parser->AddCommand("-gui", 203 "Select geant4 UI or just << 214 Command::OptionNotCompulsory, 204 << 215 "Select geant4 UI or just launch a geant4 terminal session", 205 parser->AddCommand("-mac", Command::WithOpti << 216 "qt"); 206 << 217 207 // You cann your own command, as for instanc << 218 parser->AddCommand("-mac", 208 // parser->AddCommand("-seed", << 219 Command::WithOption, 209 // Command::WithOption, << 220 "Give a mac file to execute", 210 // "Give a seed value in << 221 "macFile.mac"); 211 // it is then up to you to manage this optio << 222 212 << 223 // You cann your own command, as for instance: 213 parser->AddCommand("-mt", Command::WithOptio << 224 // parser->AddCommand("-seed", 214 " NOT RECOMMANDED WITH CH << 225 // Command::WithOption, >> 226 // "Give a seed value in argument to be tested", "seed"); >> 227 // it is then up to you to manage this option >> 228 >> 229 parser->AddCommand("-mt", >> 230 Command::WithOption, >> 231 "Launch in MT mode (events computed in parallel)", >> 232 " NOT RECOMMANDED WITH CHEMISTRY)", >> 233 "2"); 215 234 216 parser->AddCommand("-sXY", Command::OptionNo 235 parser->AddCommand("-sXY", Command::OptionNotCompulsory, 217 "Initial beam position un 236 "Initial beam position uniformly spread on a square!"); 218 parser->AddCommand("-dXY", Command::OptionNo 237 parser->AddCommand("-dXY", Command::OptionNotCompulsory, 219 "Initial beam position un 238 "Initial beam position uniformly spread on a disk!"); 220 239 221 parser->AddCommand("-dnaliv", Command::Optio << 240 parser->AddCommand("-dnaliv", Command::OptionNotCompulsory, >> 241 "Activate Livermore + DNAPhysics"); 222 parser->AddCommand("-dnachemON", Command::Op 242 parser->AddCommand("-dnachemON", Command::OptionNotCompulsory, 223 "Activate Livermore + DNA 243 "Activate Livermore + DNAPhysics + DNAChemistry"); 224 parser->AddCommand("-dnahad", Command::Optio 244 parser->AddCommand("-dnahad", Command::OptionNotCompulsory, 225 "Activate Hadronic + Live 245 "Activate Hadronic + Livermore + DNAPhysics"); 226 246 227 parser->AddCommand("-swc", Command::WithOpti << 247 parser->AddCommand("-swc", >> 248 Command::WithOption, >> 249 "Give a SWC file to simulation", >> 250 "fileName.swc"); 228 251 229 parser->AddCommand("-network", 252 parser->AddCommand("-network", 230 Command::WithOption, // << 253 Command::WithOption, //OptionNotCompulsory, 231 "Give a DAT file to simul << 254 "Give a DAT file to simulation", 232 << 255 "fileName.dat"); 233 parser->AddCommand("-vis", Command::WithOpti << 256 >> 257 parser->AddCommand("-vis", >> 258 Command::WithOption, >> 259 "Select a visualization driver", 234 "OGL 600x600-0+0"); 260 "OGL 600x600-0+0"); 235 261 236 parser->AddCommand("-novis", Command::Withou << 262 parser->AddCommand("-novis", >> 263 Command::WithoutOption, >> 264 "Deactivate visualization when using GUI"); 237 265 238 G4String exec; 266 G4String exec; 239 G4String path; 267 G4String path; 240 GetNameAndPathOfExecutable(argv, exec, path) << 268 GetNameAndPathOfExecutable(argv,exec, path); 241 269 242 parser->AddCommand("-out", Command::OptionNo << 270 parser->AddCommand("-out", >> 271 Command::OptionNotCompulsory, >> 272 "Output files", >> 273 exec); 243 274 244 ////////// 275 ////////// 245 // If -h or --help is given in option : prin 276 // If -h or --help is given in option : print help and exit 246 // 277 // 247 if (parser->Parse(argc, argv) != 0) // help << 278 if (parser->Parse(argc, argv) != 0) // help is being printed 248 { 279 { 249 // if you are using ROOT, create a TApplic 280 // if you are using ROOT, create a TApplication in this condition in order 250 // to print the help from ROOT as well 281 // to print the help from ROOT as well 251 CommandLineParser::DeleteInstance(); 282 CommandLineParser::DeleteInstance(); 252 std::exit(0); 283 std::exit(0); 253 } 284 } >> 285 254 /////////// 286 /////////// 255 // Kill application if wrong argument in com 287 // Kill application if wrong argument in command line 256 // 288 // 257 if (parser->CheckIfNotHandledOptionsExists(a << 289 if (parser->CheckIfNotHandledOptionsExists(argc, argv)) >> 290 { 258 // if you are using ROOT, you should initi 291 // if you are using ROOT, you should initialise your TApplication 259 // before this condition 292 // before this condition 260 abort(); 293 abort(); 261 } 294 } 262 } 295 } 263 296