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