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 // Phys. Med. Biol. 63(10) (2018) 105014-12pp 31 // Phys. Med. Biol. 63(10) (2018) 105014-12pp 32 // The Geant4-DNA web site is available at htt 32 // The Geant4-DNA web site is available at http://geant4-dna.org 33 // 33 // 34 // 34 // 35 /// \file chem5.cc 35 /// \file chem5.cc 36 /// \brief Chem5 example 36 /// \brief Chem5 example 37 37 38 #include "ActionInitialization.hh" << 39 #include "CommandLineParser.hh" << 40 #include "DetectorConstruction.hh" 38 #include "DetectorConstruction.hh" 41 #include "PhysicsList.hh" 39 #include "PhysicsList.hh" >> 40 #include "ActionInitialization.hh" 42 41 43 #include "G4DNAChemistryManager.hh" << 44 #include "G4RunManagerFactory.hh" 42 #include "G4RunManagerFactory.hh" 45 #include "G4UIExecutive.hh" << 43 >> 44 #include "G4DNAChemistryManager.hh" 46 #include "G4UImanager.hh" 45 #include "G4UImanager.hh" >> 46 #include "G4UIExecutive.hh" 47 #include "G4VisExecutive.hh" 47 #include "G4VisExecutive.hh" 48 48 >> 49 #include "CommandLineParser.hh" >> 50 49 /* 51 /* 50 * WARNING : Geant4 was initially not intended 52 * WARNING : Geant4 was initially not intended for this kind of application 51 * This code is delivered as a prototype 53 * This code is delivered as a prototype 52 * We will be happy to hear from you, do not h 54 * We will be happy to hear from you, do not hesitate to send your feedback and 53 * communicate on the difficulties you may enc 55 * communicate on the difficulties you may encounter 54 * The user interface may change in the next r 56 * The user interface may change in the next releases since a reiteration of the 55 * code has started 57 * code has started 56 */ 58 */ 57 59 58 //....oooOO0OOooo........oooOO0OOooo........oo 60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 59 61 60 using namespace G4DNAPARSER; 62 using namespace G4DNAPARSER; 61 CommandLineParser* parser(0); 63 CommandLineParser* parser(0); 62 long seed = 0; 64 long seed = 0; 63 65 64 unsigned int noise(); 66 unsigned int noise(); 65 void SetSeed(); 67 void SetSeed(); 66 68 67 void Parse(int& argc, char** argv); 69 void Parse(int& argc, char** argv); 68 70 69 //....oooOO0OOooo........oooOO0OOooo........oo 71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 70 72 71 int main(int argc, char** argv) 73 int main(int argc, char** argv) 72 { 74 { 73 // Parse options given in commandLine 75 // Parse options given in commandLine 74 Parse(argc, argv); 76 Parse(argc, argv); 75 Command* commandLine(0); 77 Command* commandLine(0); 76 SetSeed(); 78 SetSeed(); 77 79 78 // Construct the run manager according to wh 80 // Construct the run manager according to whether MT is activated or not 79 // 81 // 80 auto* runManager = G4RunManagerFactory::Crea << 82 auto* runManager= G4RunManagerFactory::CreateRunManager(); 81 83 82 if ((commandLine = parser->GetCommandIfActiv << 84 if((commandLine = parser->GetCommandIfActive("-mt"))) >> 85 { 83 int nThreads = 2; 86 int nThreads = 2; 84 if (commandLine->GetOption() == "NMAX") { << 87 if(commandLine->GetOption() == "NMAX") >> 88 { 85 nThreads = G4Threading::G4GetNumberOfCor 89 nThreads = G4Threading::G4GetNumberOfCores(); 86 } 90 } 87 else { << 91 else >> 92 { 88 nThreads = G4UIcommand::ConvertToInt(com 93 nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption()); 89 } 94 } 90 95 91 runManager->SetNumberOfThreads(nThreads); 96 runManager->SetNumberOfThreads(nThreads); 92 } 97 } 93 98 94 G4cout << "********************************* 99 G4cout << "**************************************************************" 95 << "******\n===== Chem5 is started wi << 100 << "******\n===== Chem5 is started with " >> 101 << runManager->GetNumberOfThreads() << " of " 96 << G4Threading::G4GetNumberOfCores() 102 << G4Threading::G4GetNumberOfCores() 97 << " available threads =====\n\n***** 103 << " available threads =====\n\n*************************************" 98 << "*******************************" << 104 <<"*******************************" >> 105 << G4endl; 99 106 100 // Set mandatory initialization classes 107 // Set mandatory initialization classes 101 runManager->SetUserInitialization(new Physic 108 runManager->SetUserInitialization(new PhysicsList()); 102 runManager->SetUserInitialization(new Detect 109 runManager->SetUserInitialization(new DetectorConstruction()); 103 runManager->SetUserInitialization(new Action 110 runManager->SetUserInitialization(new ActionInitialization()); 104 111 105 // Initialize G4 kernel 112 // Initialize G4 kernel 106 runManager->Initialize(); 113 runManager->Initialize(); 107 114 108 // Initialize visualization 115 // Initialize visualization 109 G4VisManager* visManager = new G4VisExecutiv 116 G4VisManager* visManager = new G4VisExecutive(); 110 // G4VisExecutive can take a verbosity argum 117 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance. 111 // G4VisManager* visManager = new G4VisExecu 118 // G4VisManager* visManager = new G4VisExecutive("Quiet"); 112 visManager->Initialize(); 119 visManager->Initialize(); 113 120 114 // Get the pointer to the User Interface man 121 // Get the pointer to the User Interface manager 115 G4UImanager* UImanager = G4UImanager::GetUIp 122 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 116 G4UIExecutive* ui(0); 123 G4UIExecutive* ui(0); 117 124 118 // interactive mode : define UI session 125 // interactive mode : define UI session 119 if ((commandLine = parser->GetCommandIfActiv << 126 if((commandLine = parser->GetCommandIfActive("-gui"))) >> 127 { 120 ui = new G4UIExecutive(argc, argv, command 128 ui = new G4UIExecutive(argc, argv, commandLine->GetOption()); 121 129 122 if (ui->IsGUI()) UImanager->ApplyCommand(" 130 if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac"); 123 131 124 if (parser->GetCommandIfActive("-novis") = << 132 if (parser->GetCommandIfActive("-novis") == 0) >> 133 { 125 // visualization is used by default 134 // visualization is used by default 126 if ((commandLine = parser->GetCommandIfA << 135 if ((commandLine = parser->GetCommandIfActive("-vis"))) >> 136 { 127 // select a visualization driver if ne 137 // select a visualization driver if needed (e.g. HepFile) 128 UImanager->ApplyCommand(G4String("/vis << 138 UImanager->ApplyCommand >> 139 (G4String("/vis/open ") + commandLine->GetOption()); 129 } 140 } 130 else { << 141 else >> 142 { 131 // by default OGL is used 143 // by default OGL is used 132 UImanager->ApplyCommand("/vis/open OGL 144 UImanager->ApplyCommand("/vis/open OGL 800x600-0+0"); 133 } 145 } 134 UImanager->ApplyCommand("/control/execut 146 UImanager->ApplyCommand("/control/execute vis.mac"); 135 } 147 } 136 } 148 } 137 else { << 149 else >> 150 { 138 // to be use visualization file (= store t 151 // to be use visualization file (= store the visualization into 139 // an external file: 152 // an external file: 140 // ASCIITree ; DAWNFILE ; HepRepFile ; VR 153 // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ... 141 if ((commandLine = parser->GetCommandIfAct << 154 if((commandLine = parser->GetCommandIfActive("-vis"))) 142 UImanager->ApplyCommand(G4String("/vis/o << 155 { >> 156 UImanager->ApplyCommand(G4String("/vis/open ") >> 157 + commandLine->GetOption()); 143 UImanager->ApplyCommand("/control/execut 158 UImanager->ApplyCommand("/control/execute vis.mac"); 144 } 159 } 145 } 160 } 146 161 147 if ((commandLine = parser->GetCommandIfActiv << 162 if((commandLine = parser->GetCommandIfActive("-mac"))) >> 163 { 148 G4String command = "/control/execute "; 164 G4String command = "/control/execute "; 149 UImanager->ApplyCommand(command + commandL 165 UImanager->ApplyCommand(command + commandLine->GetOption()); 150 } 166 } 151 else { << 167 else >> 168 { 152 UImanager->ApplyCommand("/control/execute 169 UImanager->ApplyCommand("/control/execute beam.in"); 153 } 170 } 154 171 155 if ((commandLine = parser->GetCommandIfActiv << 172 if((commandLine = parser->GetCommandIfActive("-gui"))) >> 173 { 156 ui->SessionStart(); 174 ui->SessionStart(); 157 delete ui; 175 delete ui; 158 } 176 } 159 177 160 // Job termination 178 // Job termination 161 // Free the store: user actions, physics_lis 179 // Free the store: user actions, physics_list and detector_description are 162 // owned and deleted by the run manager, so 180 // owned and deleted by the run manager, so they should not be deleted 163 // in the main() program ! 181 // in the main() program ! 164 delete visManager; 182 delete visManager; 165 delete runManager; 183 delete runManager; 166 CommandLineParser::DeleteInstance(); 184 CommandLineParser::DeleteInstance(); 167 return 0; 185 return 0; 168 } 186 } 169 187 170 //....oooOO0OOooo........oooOO0OOooo........oo 188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 171 189 172 bool IsBracket(char c) 190 bool IsBracket(char c) 173 { 191 { 174 switch (c) { << 192 switch(c) >> 193 { 175 case '[': 194 case '[': 176 case ']': 195 case ']': 177 return true; 196 return true; 178 default: 197 default: 179 return false; 198 return false; 180 } 199 } 181 } 200 } 182 201 183 //....oooOO0OOooo........oooOO0OOooo........oo 202 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 184 203 185 void SetSeed() 204 void SetSeed() 186 { 205 { 187 Command* commandLine(0); 206 Command* commandLine(0); 188 207 189 if ((commandLine = parser->GetCommandIfActiv << 208 if((commandLine = parser->GetCommandIfActive("-seed"))) >> 209 { 190 seed = atoi(commandLine->GetOption().c_str 210 seed = atoi(commandLine->GetOption().c_str()); 191 } 211 } 192 212 193 if (seed == 0) // If no seed given in argum << 213 if(seed == 0) // If no seed given in argument, setup the seed 194 { 214 { 195 long jobID_int = 0; 215 long jobID_int = 0; 196 long noice = 0; 216 long noice = 0; 197 217 198 //____________________________________ 218 //____________________________________ 199 // In case on cluster 219 // In case on cluster 200 if ((commandLine = parser->GetCommandIfAct << 220 if((commandLine = parser->GetCommandIfActive("-cluster"))) 201 noice = labs((long)noise()); << 221 { >> 222 noice = labs((long) noise()); 202 223 203 const char* env = std::getenv("PBS_JOBID << 224 const char * env = std::getenv("PBS_JOBID"); 204 225 205 if (env) { << 226 if(env) >> 227 { 206 G4String buffer(env); 228 G4String buffer(env); 207 G4String jobID_string = buffer.substr( << 229 G4String jobID_string = buffer.substr(0, buffer.find(".")); 208 jobID_string.erase(std::remove_if(jobI << 230 jobID_string.erase(std::remove_if(jobID_string.begin(), 209 jobID_string.end()) << 231 jobID_string.end(), >> 232 &IsBracket), >> 233 jobID_string.end()); 210 jobID_int = atoi(jobID_string.c_str()) 234 jobID_int = atoi(jobID_string.c_str()); 211 } 235 } 212 else { << 236 else >> 237 { 213 env = std::getenv("SGE_TASK_ID"); 238 env = std::getenv("SGE_TASK_ID"); 214 if (env) jobID_int = atoi(env); << 239 if(env) jobID_int = atoi(env); 215 } 240 } 216 } // end cluster << 241 } // end cluster 217 242 218 //____________________________________ 243 //____________________________________ 219 seed = ((long)time(NULL)) + jobID_int + no << 244 seed = ((long) time(NULL)) + jobID_int + noice; 220 } 245 } 221 246 222 G4cout << "Seed used : " << seed << G4endl; 247 G4cout << "Seed used : " << seed << G4endl; 223 G4Random::setTheEngine(new CLHEP::MixMaxRng( 248 G4Random::setTheEngine(new CLHEP::MixMaxRng()); 224 G4Random::setTheSeed(seed); 249 G4Random::setTheSeed(seed); 225 250 226 // Choose the Random engine 251 // Choose the Random engine 227 // CLHEP::HepRandom::setTheEngine(new CLHEP: 252 // CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine); 228 } 253 } 229 254 230 //....oooOO0OOooo........oooOO0OOooo........oo 255 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 231 256 232 unsigned int noise() 257 unsigned int noise() 233 { 258 { 234 #if defined(WIN32) || defined(_WIN32) || defin << 259 #if defined(WIN32)|| defined(_WIN32)|| defined(__WIN32)&&!defined(__CYGWIN__) 235 // TODO: MS Win 260 // TODO: MS Win 236 return std::time(0); 261 return std::time(0); 237 #else 262 #else 238 unsigned int random_seed, random_seed_a, ran 263 unsigned int random_seed, random_seed_a, random_seed_b; 239 std::ifstream file("/dev/urandom", std::ios: << 264 std::ifstream file ("/dev/urandom", std::ios::binary); 240 if (file.is_open()) { << 265 if (file.is_open()) 241 char* memblock; << 266 { >> 267 char * memblock; 242 int size = sizeof(int); 268 int size = sizeof(int); 243 memblock = new char[size]; << 269 memblock = new char [size]; 244 file.read(memblock, size); << 270 file.read (memblock, size); 245 file.close(); 271 file.close(); 246 random_seed_a = *reinterpret_cast<int*>(me 272 random_seed_a = *reinterpret_cast<int*>(memblock); 247 delete[] memblock; 273 delete[] memblock; 248 } // end if << 274 }// end if 249 else { << 275 else >> 276 { 250 random_seed_a = 0; 277 random_seed_a = 0; 251 } 278 } 252 random_seed_b = std::time(0); 279 random_seed_b = std::time(0); 253 random_seed = random_seed_a xor random_seed_ 280 random_seed = random_seed_a xor random_seed_b; 254 return random_seed; 281 return random_seed; 255 #endif 282 #endif 256 } 283 } 257 284 258 //....oooOO0OOooo........oooOO0OOooo........oo 285 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 259 286 260 void Parse(int& argc, char** argv) 287 void Parse(int& argc, char** argv) 261 { 288 { 262 ////////// 289 ////////// 263 // Parse options given in commandLine 290 // Parse options given in commandLine 264 // 291 // 265 parser = CommandLineParser::GetParser(); 292 parser = CommandLineParser::GetParser(); 266 293 267 parser->AddCommand("-gui", Command::OptionNo 294 parser->AddCommand("-gui", Command::OptionNotCompulsory, 268 "Select geant4 UI or just 295 "Select geant4 UI or just launch a geant4 terminal" 269 "session", 296 "session", 270 "qt"); 297 "qt"); 271 298 272 parser->AddCommand("-mac", Command::WithOpti << 299 parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute", >> 300 "macFile.mac"); 273 301 274 parser->AddCommand("-seed", Command::WithOpt << 302 parser->AddCommand("-seed", 275 "seed"); << 303 Command::WithOption, >> 304 "Give a seed value in argument to be tested", "seed"); 276 305 277 parser->AddCommand("-mt", Command::WithOptio << 306 parser->AddCommand("-mt",Command::WithOption, 278 "Launch in MT mode (event 307 "Launch in MT mode (events computed in parallel," 279 " NOT RECOMMANDED WITH CH << 308 " NOT RECOMMANDED WITH CHEMISTRY)", "2"); 280 "2"); << 281 309 282 parser->AddCommand("-chemOFF", Command::With << 310 parser->AddCommand("-chemOFF", Command::WithoutOption, >> 311 "Deactivate chemistry"); 283 312 284 parser->AddCommand("-vis", Command::WithOpti << 313 parser->AddCommand("-vis", Command::WithOption, 285 "OGL 600x600-0+0"); << 314 "Select a visualization driver", "OGL 600x600-0+0"); 286 315 287 parser->AddCommand("-novis", Command::Withou << 316 parser->AddCommand("-novis", Command::WithoutOption, >> 317 "Deactivate visualization when using GUI"); 288 318 289 parser->AddCommand("-cluster", Command::With 319 parser->AddCommand("-cluster", Command::WithoutOption, 290 "Launch the code on a clu 320 "Launch the code on a cluster, avoid dupplicated seeds"); 291 321 292 ////////// 322 ////////// 293 // If -h or --help is given in option : prin 323 // If -h or --help is given in option : print help and exit 294 // 324 // 295 if (parser->Parse(argc, argv) != 0) // help << 325 if (parser->Parse(argc, argv) != 0) // help is being printed 296 { 326 { 297 // if you are using ROOT, create a TApplic 327 // if you are using ROOT, create a TApplication in this condition in order 298 // to print the help from ROOT as well 328 // to print the help from ROOT as well 299 CommandLineParser::DeleteInstance(); 329 CommandLineParser::DeleteInstance(); 300 std::exit(0); 330 std::exit(0); 301 } 331 } 302 332 303 /////////// 333 /////////// 304 // Kill application if wrong argument in com 334 // Kill application if wrong argument in command line 305 // 335 // 306 if (parser->CheckIfNotHandledOptionsExists(a << 336 if(parser->CheckIfNotHandledOptionsExists(argc, argv)) >> 337 { 307 // if you are using ROOT, you should initi 338 // if you are using ROOT, you should initialise your TApplication 308 // before this condition 339 // before this condition 309 std::exit(0); 340 std::exit(0); 310 } 341 } 311 } 342 } 312 343