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 // J. Comput. Phys. 274 (2014) 841-882 30 // J. Comput. Phys. 274 (2014) 841-882 31 // The Geant4-DNA web site is available at htt 31 // The Geant4-DNA web site is available at http://geant4-dna.org 32 // 32 // 33 // 33 // 34 /// \file chem1.cc 34 /// \file chem1.cc 35 /// \brief Chem1 example 35 /// \brief Chem1 example 36 36 37 #include "ActionInitialization.hh" << 38 #include "CommandLineParser.hh" << 39 #include "DetectorConstruction.hh" 37 #include "DetectorConstruction.hh" 40 #include "PhysicsList.hh" 38 #include "PhysicsList.hh" >> 39 #include "ActionInitialization.hh" >> 40 >> 41 #ifdef G4MULTITHREADED >> 42 #include "G4MTRunManager.hh" >> 43 #else >> 44 #include "G4RunManager.hh" >> 45 #endif 41 46 42 #include "G4DNAChemistryManager.hh" 47 #include "G4DNAChemistryManager.hh" 43 #include "G4RunManagerFactory.hh" << 44 #include "G4UIExecutive.hh" << 45 #include "G4UImanager.hh" 48 #include "G4UImanager.hh" >> 49 #include "G4UIExecutive.hh" 46 #include "G4VisExecutive.hh" 50 #include "G4VisExecutive.hh" 47 51 >> 52 #include "CommandLineParser.hh" >> 53 48 //....oooOO0OOooo........oooOO0OOooo........oo 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 49 55 50 /* 56 /* 51 * WARNING : Geant4 was initially not intended 57 * WARNING : Geant4 was initially not intended for this kind of application 52 * This code is delivered as a prototype 58 * This code is delivered as a prototype 53 * We will be happy to hear from you, do not h 59 * We will be happy to hear from you, do not hesitate to send your feedback and 54 * communicate on the difficulties you may enc 60 * communicate on the difficulties you may encounter 55 * The user interface may change in the next r 61 * The user interface may change in the next releases since a reiteration of the 56 * code has started 62 * code has started 57 */ 63 */ 58 64 59 using namespace G4DNAPARSER; 65 using namespace G4DNAPARSER; 60 CommandLineParser* parser(0); 66 CommandLineParser* parser(0); 61 67 62 void Parse(int& argc, char** argv); 68 void Parse(int& argc, char** argv); 63 69 64 int main(int argc, char** argv) 70 int main(int argc, char** argv) 65 { 71 { 66 ////////// 72 ////////// 67 // Parse options given in commandLine 73 // Parse options given in commandLine 68 // 74 // 69 Parse(argc, argv); 75 Parse(argc, argv); 70 76 71 ////////// 77 ////////// 72 // Construct the run manager according to wh 78 // Construct the run manager according to whether MT is activated or not 73 // 79 // 74 Command* commandLine(nullptr); 80 Command* commandLine(nullptr); 75 81 76 auto* runManager = G4RunManagerFactory::Crea << 82 #ifdef G4MULTITHREADED 77 if ((commandLine = parser->GetCommandIfActiv << 83 G4MTRunManager* runManager= new G4MTRunManager; >> 84 if ((commandLine = parser->GetCommandIfActive("-mt"))) >> 85 { 78 int nThreads = 2; 86 int nThreads = 2; 79 if (commandLine->GetOption() == "NMAX") { << 87 if(commandLine->GetOption() == "NMAX") >> 88 { 80 nThreads = G4Threading::G4GetNumberOfCor 89 nThreads = G4Threading::G4GetNumberOfCores(); 81 } 90 } 82 else { << 91 else >> 92 { 83 nThreads = G4UIcommand::ConvertToInt(com 93 nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption()); 84 } 94 } 85 runManager->SetNumberOfThreads(nThreads); << 95 G4cout << "===== Chem1 is started with " << nThreads 86 G4cout << "===== Chem1 is started with " < << 87 << " threads =====" << G4endl; 96 << " threads =====" << G4endl; >> 97 >> 98 runManager->SetNumberOfThreads(nThreads); 88 } 99 } >> 100 #else >> 101 G4RunManager* runManager = new G4RunManager(); >> 102 #endif >> 103 89 104 90 ////////// 105 ////////// 91 // Set mandatory user initialization classes 106 // Set mandatory user initialization classes 92 // 107 // 93 DetectorConstruction* detector = new Detecto 108 DetectorConstruction* detector = new DetectorConstruction(); 94 runManager->SetUserInitialization(new Physic 109 runManager->SetUserInitialization(new PhysicsList); 95 runManager->SetUserInitialization(detector); 110 runManager->SetUserInitialization(detector); 96 runManager->SetUserInitialization(new Action 111 runManager->SetUserInitialization(new ActionInitialization()); 97 112 98 // Initialize visualization 113 // Initialize visualization 99 G4VisManager* visManager = nullptr; 114 G4VisManager* visManager = nullptr; 100 115 101 // Get the pointer to the User Interface man 116 // Get the pointer to the User Interface manager 102 G4UImanager* UImanager = G4UImanager::GetUIp 117 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 103 G4UIExecutive* ui(nullptr); 118 G4UIExecutive* ui(nullptr); 104 119 105 // interactive mode : define UI session 120 // interactive mode : define UI session 106 if ((commandLine = parser->GetCommandIfActiv << 121 if ((commandLine = parser->GetCommandIfActive("-gui"))) >> 122 { 107 visManager = new G4VisExecutive; 123 visManager = new G4VisExecutive; 108 visManager->Initialize(); 124 visManager->Initialize(); 109 125 110 ui = new G4UIExecutive(argc, argv, command 126 ui = new G4UIExecutive(argc, argv, commandLine->GetOption()); 111 127 112 if (parser->GetCommandIfActive("-novis") = << 128 if(parser->GetCommandIfActive("-novis") == 0) >> 129 { 113 // visualization is used by default 130 // visualization is used by default 114 if ((commandLine = parser->GetCommandIfA << 131 if((commandLine = parser->GetCommandIfActive("-vis"))) >> 132 { 115 // select a visualization driver if ne 133 // select a visualization driver if needed (e.g. HepFile) 116 UImanager->ApplyCommand(G4String("/vis << 134 UImanager->ApplyCommand(G4String("/vis/open ")+ >> 135 commandLine->GetOption()); 117 } 136 } 118 else { << 137 else >> 138 { 119 // by default OGL is used 139 // by default OGL is used 120 UImanager->ApplyCommand("/vis/open OGL 140 UImanager->ApplyCommand("/vis/open OGL 800x600-0+0"); 121 } 141 } 122 UImanager->ApplyCommand("/control/execut 142 UImanager->ApplyCommand("/control/execute vis.mac"); 123 } 143 } 124 144 125 if (ui->IsGUI()) { << 145 if(ui->IsGUI()) >> 146 { 126 UImanager->ApplyCommand("/control/execut 147 UImanager->ApplyCommand("/control/execute gui.mac"); 127 } 148 } 128 } 149 } 129 else if ((commandLine = parser->GetCommandIf << 150 else if ((commandLine = parser->GetCommandIfActive("-vis"))) >> 151 { 130 // to be use visualization file (= store t 152 // to be use visualization file (= store the visualization into 131 // an external file: 153 // an external file: 132 // ASCIITree ; DAWNFILE ; HepRepFile ; VR 154 // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ... 133 visManager = new G4VisExecutive; 155 visManager = new G4VisExecutive; 134 visManager->Initialize(); 156 visManager->Initialize(); 135 157 136 ui = new G4UIExecutive(argc, argv, command 158 ui = new G4UIExecutive(argc, argv, commandLine->GetOption()); 137 UImanager->ApplyCommand(G4String("/vis/ope << 159 UImanager->ApplyCommand(G4String("/vis/open ")+commandLine->GetOption()); 138 UImanager->ApplyCommand("/control/execute 160 UImanager->ApplyCommand("/control/execute vis.mac"); 139 } 161 } 140 << 162 141 if ((commandLine = parser->GetCommandIfActiv << 163 if ((commandLine = parser->GetCommandIfActive("-mac"))) >> 164 { 142 G4String command = "/control/execute "; 165 G4String command = "/control/execute "; 143 UImanager->ApplyCommand(command + commandL 166 UImanager->ApplyCommand(command + commandLine->GetOption()); 144 } 167 } 145 else { << 168 else >> 169 { 146 UImanager->ApplyCommand("/control/execute 170 UImanager->ApplyCommand("/control/execute beam.in"); 147 } 171 } 148 172 149 if (ui) { << 173 if(ui) >> 174 { 150 ui->SessionStart(); 175 ui->SessionStart(); 151 delete ui; 176 delete ui; 152 } 177 } 153 178 154 // Job termination 179 // Job termination 155 // Free the store: user actions, physics_lis 180 // Free the store: user actions, physics_list and detector_description are 156 // owned and deleted by the run manager, so 181 // owned and deleted by the run manager, so they should not be deleted 157 // in the main() program ! 182 // in the main() program ! 158 183 159 delete visManager; 184 delete visManager; 160 delete runManager; 185 delete runManager; 161 186 162 CommandLineParser::DeleteInstance(); 187 CommandLineParser::DeleteInstance(); 163 188 164 return 0; 189 return 0; 165 } 190 } 166 191 167 void Parse(int& argc, char** argv) 192 void Parse(int& argc, char** argv) 168 { 193 { 169 ////////// 194 ////////// 170 // Parse options given in commandLine 195 // Parse options given in commandLine 171 // 196 // 172 parser = CommandLineParser::GetParser(); 197 parser = CommandLineParser::GetParser(); 173 198 174 parser->AddCommand("-gui", Command::OptionNo << 199 parser->AddCommand( 175 "Select geant4 UI or just << 200 "-gui", Command::OptionNotCompulsory, 176 << 201 "Select geant4 UI or just launch a geant4 terminal session", "qt"); 177 parser->AddCommand("-mac", Command::WithOpti << 202 178 << 203 parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute", 179 // You cann your own command, as for instanc << 204 "macFile.mac"); 180 // parser->AddCommand("-seed", << 205 181 // Command::WithOption, << 206 // You cann your own command, as for instance: 182 // "Give a seed value in << 207 // parser->AddCommand("-seed", 183 // it is then up to you to manage this optio << 208 // Command::WithOption, >> 209 // "Give a seed value in argument to be tested", "seed"); >> 210 // it is then up to you to manage this option >> 211 >> 212 #ifdef G4MULTITHREADED >> 213 parser->AddCommand("-mt", >> 214 Command::WithOption, >> 215 "Launch in MT mode (events computed in parallel," >> 216 " NOT RECOMMANDED WITH CHEMISTRY)", "2"); >> 217 #endif 184 218 185 parser->AddCommand("-mt", Command::WithOptio << 219 parser->AddCommand("-chemOFF", Command::WithoutOption, 186 "Launch in MT mode (event << 220 "Deactivate chemistry"); 187 " NOT RECOMMANDED WITH CH << 188 "2"); << 189 221 190 parser->AddCommand("-chemOFF", Command::With << 222 parser->AddCommand("-vis", Command::WithOption, >> 223 "Select a visualization driver", "OGL 600x600-0+0"); 191 224 192 parser->AddCommand("-vis", Command::WithOpti << 225 parser->AddCommand("-novis", Command::WithoutOption, 193 "OGL 600x600-0+0"); << 226 "Deactivate visualization when using GUI"); 194 << 195 parser->AddCommand("-novis", Command::Withou << 196 227 197 ////////// 228 ////////// 198 // If -h or --help is given in option : prin 229 // If -h or --help is given in option : print help and exit 199 // 230 // 200 if (parser->Parse(argc, argv) != 0) // help << 231 if (parser->Parse(argc, argv) != 0) // help is being printed 201 { 232 { 202 // if you are using ROOT, create a TApplic 233 // if you are using ROOT, create a TApplication in this condition in order 203 // to print the help from ROOT as well 234 // to print the help from ROOT as well 204 CommandLineParser::DeleteInstance(); 235 CommandLineParser::DeleteInstance(); 205 std::exit(0); 236 std::exit(0); 206 } 237 } 207 238 208 /////////// 239 /////////// 209 // Kill application if wrong argument in com 240 // Kill application if wrong argument in command line 210 // 241 // 211 if (parser->CheckIfNotHandledOptionsExists(a << 242 if (parser->CheckIfNotHandledOptionsExists(argc, argv)) >> 243 { 212 // if you are using ROOT, you should initi 244 // if you are using ROOT, you should initialise your TApplication 213 // before this condition 245 // before this condition 214 abort(); 246 abort(); 215 } 247 } 216 } 248 } 217 249