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