Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // This example is provided by the Geant4-DNA 27 // Any report or published results obtained us 28 // shall cite the following Geant4-DNA collabo 29 // Med. Phys. 37 (2010) 4692-4708 30 // J. Comput. Phys. 274 (2014) 841-882 31 // The Geant4-DNA web site is available at htt 32 // 33 // 34 /// \file chem4.cc 35 /// \brief Chem4 example 36 37 #include "ActionInitialization.hh" 38 #include "CommandLineParser.hh" 39 #include "DetectorConstruction.hh" 40 #include "PhysicsList.hh" 41 42 #include "G4DNAChemistryManager.hh" 43 #include "G4RunManagerFactory.hh" 44 #include "G4UIExecutive.hh" 45 #include "G4UImanager.hh" 46 #include "G4VisExecutive.hh" 47 48 /* 49 * WARNING : Geant4 was initially not intended 50 * This code is delivered as a prototype 51 * We will be happy to hear from you, do not h 52 * communicate on the difficulties you may enc 53 * The user interface may change in the next r 54 * code has started 55 */ 56 57 //....oooOO0OOooo........oooOO0OOooo........oo 58 59 using namespace G4DNAPARSER; 60 CommandLineParser* parser(0); 61 long seed = 0; 62 63 unsigned int noise(); 64 void SetSeed(); 65 66 void Parse(int& argc, char** argv); 67 68 //....oooOO0OOooo........oooOO0OOooo........oo 69 70 int main(int argc, char** argv) 71 { 72 // Parse options given in commandLine 73 Parse(argc, argv); 74 Command* commandLine(0); 75 SetSeed(); 76 77 // Construct the run manager according to wh 78 // 79 auto* runManager = G4RunManagerFactory::Crea 80 81 if ((commandLine = parser->GetCommandIfActiv 82 int nThreads = 2; 83 if (commandLine->GetOption() == "NMAX") { 84 nThreads = G4Threading::G4GetNumberOfCor 85 } 86 else { 87 nThreads = G4UIcommand::ConvertToInt(com 88 } 89 90 runManager->SetNumberOfThreads(nThreads); 91 } 92 93 G4cout << "********************************* 94 << "******\n===== Chem4 is started wi 95 << G4Threading::G4GetNumberOfCores() 96 << " available threads =====\n\n***** 97 << "*******************************" 98 99 // Set mandatory initialization classes 100 runManager->SetUserInitialization(new Physic 101 runManager->SetUserInitialization(new Detect 102 runManager->SetUserInitialization(new Action 103 104 // Initialize visualization 105 G4VisManager* visManager = new G4VisExecutiv 106 // G4VisExecutive can take a verbosity argum 107 // G4VisManager* visManager = new G4VisExecu 108 visManager->Initialize(); 109 110 // Get the pointer to the User Interface man 111 G4UImanager* UImanager = G4UImanager::GetUIp 112 G4UIExecutive* ui(0); 113 114 // interactive mode : define UI session 115 if ((commandLine = parser->GetCommandIfActiv 116 ui = new G4UIExecutive(argc, argv, command 117 118 if (ui->IsGUI()) UImanager->ApplyCommand(" 119 120 if (parser->GetCommandIfActive("-novis") = 121 // visualization is used by default 122 if ((commandLine = parser->GetCommandIfA 123 // select a visualization driver if ne 124 UImanager->ApplyCommand(G4String("/vis 125 } 126 else { 127 // by default OGL is used 128 UImanager->ApplyCommand("/vis/open OGL 129 } 130 UImanager->ApplyCommand("/control/execut 131 } 132 } 133 else { 134 // to be use visualization file (= store t 135 // an external file: 136 // ASCIITree ; DAWNFILE ; HepRepFile ; VR 137 if ((commandLine = parser->GetCommandIfAct 138 UImanager->ApplyCommand(G4String("/vis/o 139 UImanager->ApplyCommand("/control/execut 140 } 141 } 142 143 if ((commandLine = parser->GetCommandIfActiv 144 G4String command = "/control/execute "; 145 UImanager->ApplyCommand(command + commandL 146 } 147 else { 148 UImanager->ApplyCommand("/control/execute 149 } 150 151 if ((commandLine = parser->GetCommandIfActiv 152 ui->SessionStart(); 153 delete ui; 154 } 155 156 // Job termination 157 // Free the store: user actions, physics_lis 158 // owned and deleted by the run manager, so 159 // in the main() program ! 160 delete visManager; 161 delete runManager; 162 CommandLineParser::DeleteInstance(); 163 return 0; 164 } 165 166 //....oooOO0OOooo........oooOO0OOooo........oo 167 168 bool IsBracket(char c) 169 { 170 switch (c) { 171 case '[': 172 case ']': 173 return true; 174 default: 175 return false; 176 } 177 } 178 179 //....oooOO0OOooo........oooOO0OOooo........oo 180 181 void SetSeed() 182 { 183 Command* commandLine(0); 184 185 if ((commandLine = parser->GetCommandIfActiv 186 seed = atoi(commandLine->GetOption().c_str 187 } 188 189 if (seed == 0) // If no seed given in argum 190 { 191 long jobID_int = 0; 192 long noice = 0; 193 194 //____________________________________ 195 // In case on cluster 196 if ((commandLine = parser->GetCommandIfAct 197 noice = labs((long)noise()); 198 199 const char* env = std::getenv("PBS_JOBID 200 201 if (env) { 202 G4String buffer(env); 203 G4String jobID_string = buffer.substr( 204 jobID_string.erase(std::remove_if(jobI 205 jobID_string.end()) 206 jobID_int = atoi(jobID_string.c_str()) 207 } 208 else { 209 env = std::getenv("SGE_TASK_ID"); 210 if (env) jobID_int = atoi(env); 211 } 212 } // end cluster 213 214 //____________________________________ 215 seed = ((long)time(NULL)) + jobID_int + no 216 } 217 218 G4cout << "Seed used : " << seed << G4endl; 219 G4Random::setTheEngine(new CLHEP::MixMaxRng( 220 G4Random::setTheSeed(seed); 221 222 // Choose the Random engine 223 // CLHEP::HepRandom::setTheEngine(new CLHEP: 224 } 225 226 //....oooOO0OOooo........oooOO0OOooo........oo 227 228 unsigned int noise() 229 { 230 #if defined(WIN32) || defined(_WIN32) || defin 231 // TODO: MS Win 232 return std::time(0); 233 #else 234 unsigned int random_seed, random_seed_a, ran 235 std::ifstream file("/dev/urandom", std::ios: 236 if (file.is_open()) { 237 char* memblock; 238 int size = sizeof(int); 239 memblock = new char[size]; 240 file.read(memblock, size); 241 file.close(); 242 random_seed_a = *reinterpret_cast<int*>(me 243 delete[] memblock; 244 } // end if 245 else { 246 random_seed_a = 0; 247 } 248 random_seed_b = std::time(0); 249 random_seed = random_seed_a xor random_seed_ 250 return random_seed; 251 #endif 252 } 253 254 //....oooOO0OOooo........oooOO0OOooo........oo 255 256 void Parse(int& argc, char** argv) 257 { 258 ////////// 259 // Parse options given in commandLine 260 // 261 parser = CommandLineParser::GetParser(); 262 263 parser->AddCommand("-gui", Command::OptionNo 264 "Select geant4 UI or just 265 "session", 266 "qt"); 267 268 parser->AddCommand("-mac", Command::WithOpti 269 270 parser->AddCommand("-seed", Command::WithOpt 271 "seed"); 272 273 parser->AddCommand("-mt", Command::WithOptio 274 "Launch in MT mode (event 275 " NOT RECOMMANDED WITH CH 276 "2"); 277 278 parser->AddCommand("-chemOFF", Command::With 279 280 parser->AddCommand("-vis", Command::WithOpti 281 "OGL 600x600-0+0"); 282 283 parser->AddCommand("-novis", Command::Withou 284 285 parser->AddCommand("-cluster", Command::With 286 "Launch the code on a clu 287 288 ////////// 289 // If -h or --help is given in option : prin 290 // 291 if (parser->Parse(argc, argv) != 0) // help 292 { 293 // if you are using ROOT, create a TApplic 294 // to print the help from ROOT as well 295 CommandLineParser::DeleteInstance(); 296 std::exit(0); 297 } 298 299 /////////// 300 // Kill application if wrong argument in com 301 // 302 if (parser->CheckIfNotHandledOptionsExists(a 303 // if you are using ROOT, you should initi 304 // before this condition 305 std::exit(0); 306 } 307 } 308