Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // This example is provided by the Geant4-DNA collaboration 27 // Any report or published results obtained using the Geant4-DNA software 28 // shall cite the following Geant4-DNA collaboration publication: 29 // Med. Phys. 37 (2010) 4692-4708 30 // and papers 31 // M. Batmunkh et al. J Radiat Res Appl Sci 8 (2015) 498-507 32 // O. Belov et al. Physica Medica 32 (2016) 1510-1520 33 // The Geant4-DNA web site is available at http://geant4-dna.org 34 // 35 // ------------------------------------------------------------------- 36 // November 2016 37 // ------------------------------------------------------------------- 38 // 39 /// \file neuron.cc 40 /// \brief Implementation of the neuron example 41 // 42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 43 #include "ActionInitialization.hh" 44 #include "CommandLineParser.hh" 45 #include "DetectorConstruction.hh" 46 #include "PhysicsList.hh" 47 48 #include "G4DNAChemistryManager.hh" 49 #include "G4RunManagerFactory.hh" 50 #include "G4Timer.hh" 51 #include "G4Types.hh" 52 #include "G4UIExecutive.hh" 53 #include "G4UImanager.hh" 54 #include "G4VisExecutive.hh" 55 56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 58 using namespace std; 59 using namespace G4DNAPARSER; 60 61 CommandLineParser* parser(0); 62 63 void Parse(int& argc, char** argv); 64 65 int main(int argc, char** argv) 66 { 67 // run time in Geant4 68 G4Timer* timer = new G4Timer(); 69 timer->Start(); 70 71 ////////// 72 // Parse options given in commandLine 73 // 74 Parse(argc, argv); 75 76 ////////// 77 // Construct the run manager according to whether MT is activated or not 78 // 79 Command* commandLine(0); 80 81 auto* runManager = G4RunManagerFactory::CreateRunManager(); 82 83 if ((commandLine = parser->GetCommandIfActive("-mt"))) { 84 G4int nThreads = 2; 85 86 if (commandLine->GetOption() == "NMAX") { 87 nThreads = G4Threading::G4GetNumberOfCores(); 88 } 89 else { 90 nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption()); 91 } 92 runManager->SetNumberOfThreads(nThreads); 93 94 G4cout << "===== neuron is started with " << runManager->GetNumberOfThreads() 95 << " threads of MT MODE =====" << G4endl; 96 } 97 98 // Set mandatory user initialization classes 99 DetectorConstruction* detector = new DetectorConstruction; 100 runManager->SetUserInitialization(detector); 101 runManager->SetUserInitialization(new PhysicsList); 102 103 // User action initialization 104 runManager->SetUserInitialization(new ActionInitialization(detector)); 105 106 // Initialize G4 kernel 107 runManager->Initialize(); 108 109 // Initialize visualization 110 G4VisManager* visManager = new G4VisExecutive; 111 visManager->Initialize(); 112 113 // Get the pointer to the User Interface manager 114 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 115 G4UIExecutive* ui(0); 116 117 // interactive mode : define UI session 118 if ((commandLine = parser->GetCommandIfActive("-gui"))) { 119 ui = new G4UIExecutive(argc, argv, commandLine->GetOption()); 120 121 if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac"); 122 123 if (parser->GetCommandIfActive("-novis") == 0) 124 // visualization is used by default 125 { 126 if ((commandLine = parser->GetCommandIfActive("-vis"))) 127 // select a visualization driver if needed (e.g. HepFile) 128 { 129 UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption()); 130 } 131 else 132 // by default OGL is used 133 { 134 UImanager->ApplyCommand("/vis/open OGL 800x600-0+0"); 135 } 136 UImanager->ApplyCommand("/control/execute vis.mac"); 137 } 138 } 139 else 140 // to be use visualization file (= store the visualization into 141 // an external file: 142 // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ... 143 { 144 if ((commandLine = parser->GetCommandIfActive("-vis"))) { 145 UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption()); 146 UImanager->ApplyCommand("/control/execute vis.mac"); 147 } 148 } 149 150 if ((commandLine = parser->GetCommandIfActive("-mac"))) { 151 G4String command = "/control/execute "; 152 UImanager->ApplyCommand(command + commandLine->GetOption()); 153 } 154 else { 155 UImanager->ApplyCommand("/control/execute "); // neuron.in 156 } 157 158 if ((commandLine = parser->GetCommandIfActive("-gui"))) { 159 ui->SessionStart(); 160 delete ui; 161 } 162 163 // calculation time 164 timer->Stop(); 165 G4cout << " Calculation time = " << timer->GetRealElapsed() << " s \n" 166 << G4endl; 167 168 delete visManager; 169 delete runManager; 170 171 return 0; 172 } 173 174 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 175 176 void GetNameAndPathOfExecutable(char** argv, G4String& executable, G4String& path) 177 { 178 // Get the last position of '/' 179 std::string aux(argv[0]); 180 181 // get '/' or '\\' depending on unix/mac or windows. 182 #if defined(_WIN32) || defined(WIN32) 183 int pos = aux.rfind('\\'); 184 #else 185 int pos = aux.rfind('/'); 186 #endif 187 188 // Get the path and the name 189 path = aux.substr(0, pos + 1); 190 executable = aux.substr(pos + 1); 191 } 192 193 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 194 195 void Parse(int& argc, char** argv) 196 { 197 ////////// 198 // Parse options given in commandLine 199 // 200 parser = CommandLineParser::GetParser(); 201 202 parser->AddCommand("-gui", Command::OptionNotCompulsory, 203 "Select geant4 UI or just launch a geant4 terminal session", "qt"); 204 205 parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute", "macFile.mac"); 206 207 // You cann your own command, as for instance: 208 // parser->AddCommand("-seed", 209 // Command::WithOption, 210 // "Give a seed value in argument to be tested", "seed"); 211 // it is then up to you to manage this option 212 213 parser->AddCommand("-mt", Command::WithOption, "Launch in MT mode (events computed in parallel)", 214 " NOT RECOMMANDED WITH CHEMISTRY)", "2"); 215 216 parser->AddCommand("-sXY", Command::OptionNotCompulsory, 217 "Initial beam position uniformly spread on a square!"); 218 parser->AddCommand("-dXY", Command::OptionNotCompulsory, 219 "Initial beam position uniformly spread on a disk!"); 220 221 parser->AddCommand("-dnaliv", Command::OptionNotCompulsory, "Activate Livermore + DNAPhysics"); 222 parser->AddCommand("-dnachemON", Command::OptionNotCompulsory, 223 "Activate Livermore + DNAPhysics + DNAChemistry"); 224 parser->AddCommand("-dnahad", Command::OptionNotCompulsory, 225 "Activate Hadronic + Livermore + DNAPhysics"); 226 227 parser->AddCommand("-swc", Command::WithOption, "Give a SWC file to simulation", "fileName.swc"); 228 229 parser->AddCommand("-network", 230 Command::WithOption, // OptionNotCompulsory, 231 "Give a DAT file to simulation", "fileName.dat"); 232 233 parser->AddCommand("-vis", Command::WithOption, "Select a visualization driver", 234 "OGL 600x600-0+0"); 235 236 parser->AddCommand("-novis", Command::WithoutOption, "Deactivate visualization when using GUI"); 237 238 G4String exec; 239 G4String path; 240 GetNameAndPathOfExecutable(argv, exec, path); 241 242 parser->AddCommand("-out", Command::OptionNotCompulsory, "Output files", exec); 243 244 ////////// 245 // If -h or --help is given in option : print help and exit 246 // 247 if (parser->Parse(argc, argv) != 0) // help is being printed 248 { 249 // if you are using ROOT, create a TApplication in this condition in order 250 // to print the help from ROOT as well 251 CommandLineParser::DeleteInstance(); 252 std::exit(0); 253 } 254 /////////// 255 // Kill application if wrong argument in command line 256 // 257 if (parser->CheckIfNotHandledOptionsExists(argc, argv)) { 258 // if you are using ROOT, you should initialise your TApplication 259 // before this condition 260 abort(); 261 } 262 } 263