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 // ------------------------------------------------------------------- 27 // 28 // GEANT4 Class file 29 // 30 // File name: G4OpticalParameters 31 // 32 // Author: Daren Sawkey based on G4EmParameters 33 // 34 // Creation date: 14.07.2020 35 // 36 // Modifications: 37 // 38 // ------------------------------------------------------------------- 39 // 40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 42 43 #include "G4OpticalParameters.hh" 44 #include "G4OpticalParametersMessenger.hh" 45 #include "G4PhysicalConstants.hh" 46 #include "G4UnitsTable.hh" 47 #include "G4SystemOfUnits.hh" 48 #include "G4ApplicationState.hh" 49 #include "G4StateManager.hh" 50 51 G4OpticalParameters* G4OpticalParameters::theInstance = nullptr; 52 53 #ifdef G4MULTITHREADED 54 G4Mutex G4OpticalParameters::opticalParametersMutex = G4MUTEX_INITIALIZER; 55 #endif 56 57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 58 59 G4OpticalParameters* G4OpticalParameters::Instance() 60 { 61 if(nullptr == theInstance) 62 { 63 #ifdef G4MULTITHREADED 64 G4MUTEXLOCK(&opticalParametersMutex); 65 if(nullptr == theInstance) 66 { 67 #endif 68 static G4OpticalParameters manager; 69 theInstance = &manager; 70 #ifdef G4MULTITHREADED 71 } 72 G4MUTEXUNLOCK(&opticalParametersMutex); 73 #endif 74 } 75 return theInstance; 76 } 77 78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 79 80 G4OpticalParameters::~G4OpticalParameters() { delete theMessenger; } 81 82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 83 84 G4OpticalParameters::G4OpticalParameters() 85 { 86 theMessenger = new G4OpticalParametersMessenger(this); 87 Initialise(); 88 89 fStateManager = G4StateManager::GetStateManager(); 90 } 91 92 void G4OpticalParameters::SetDefaults() 93 { 94 if(!IsLocked()) 95 { 96 Initialise(); 97 } 98 } 99 100 void G4OpticalParameters::Initialise() 101 { 102 verboseLevel = 1; 103 104 cerenkovStackPhotons = true; 105 cerenkovTrackSecondariesFirst = true; 106 cerenkovVerboseLevel = 1; 107 cerenkovMaxPhotons = 100; 108 cerenkovMaxBetaChange = 10.; 109 110 scintByParticleType = false; 111 scintTrackInfo = false; 112 scintStackPhotons = true; 113 scintFiniteRiseTime = false; 114 scintTrackSecondariesFirst = true; 115 scintVerboseLevel = 1; 116 117 wlsTimeProfileName = "delta"; 118 wlsVerboseLevel = 1; 119 120 wls2TimeProfileName = "delta"; 121 wls2VerboseLevel = 1; 122 123 absorptionVerboseLevel = 1; 124 125 rayleighVerboseLevel = 1; 126 127 mieVerboseLevel = 1; 128 129 boundaryInvokeSD = false; 130 boundaryVerboseLevel = 1; 131 132 processActivation["OpRayleigh"] = true; 133 processActivation["OpBoundary"] = true; 134 processActivation["OpMieHG"] = true; 135 processActivation["OpAbsorption"] = true; 136 processActivation["OpWLS"] = true; 137 processActivation["OpWLS2"] = true; 138 processActivation["Cerenkov"] = true; 139 processActivation["Scintillation"] = true; 140 } 141 142 void G4OpticalParameters::SetVerboseLevel(G4int val) 143 { 144 if(IsLocked()) 145 { 146 return; 147 } 148 verboseLevel = val; 149 SetCerenkovVerboseLevel(verboseLevel); 150 SetScintVerboseLevel(verboseLevel); 151 SetRayleighVerboseLevel(verboseLevel); 152 SetAbsorptionVerboseLevel(verboseLevel); 153 SetMieVerboseLevel(verboseLevel); 154 SetBoundaryVerboseLevel(verboseLevel); 155 SetWLSVerboseLevel(verboseLevel); 156 SetWLS2VerboseLevel(verboseLevel); 157 } 158 159 G4int G4OpticalParameters::GetVerboseLevel() const { return verboseLevel; } 160 161 void G4OpticalParameters::SetProcessActivation(const G4String& process, 162 G4bool val) 163 { 164 // Configure the physics constructor to use/not use a selected process. 165 // This method can only be called in PreInit> phase (before execution of 166 // ConstructProcess). The process is not added to particle's process manager 167 // and so it cannot be re-activated later in Idle> phase with the command 168 // /process/activate. 169 170 if(IsLocked()) 171 { 172 return; 173 } 174 if(processActivation[process] == val) 175 return; 176 177 // processActivation keys defined at initialisation 178 if(processActivation.find(process) != processActivation.end()) 179 { 180 processActivation[process] = val; 181 } 182 else 183 { 184 G4ExceptionDescription ed; 185 ed << "Process name " << process << " out of bounds."; 186 G4Exception("G4OpticalParameters::SetProcessActivation()", "Optical013", 187 FatalException, ed); 188 } 189 } 190 191 G4bool G4OpticalParameters::GetProcessActivation(const G4String& process) const 192 { 193 return processActivation.find(process)->second; 194 } 195 196 void G4OpticalParameters::SetCerenkovStackPhotons(G4bool val) 197 { 198 if(IsLocked()) 199 { 200 return; 201 } 202 cerenkovStackPhotons = val; 203 } 204 205 G4bool G4OpticalParameters::GetCerenkovStackPhotons() const 206 { 207 return cerenkovStackPhotons; 208 } 209 210 void G4OpticalParameters::SetCerenkovVerboseLevel(G4int val) 211 { 212 if(IsLocked()) 213 { 214 return; 215 } 216 cerenkovVerboseLevel = val; 217 } 218 219 G4int G4OpticalParameters::GetCerenkovVerboseLevel() const 220 { 221 return cerenkovVerboseLevel; 222 } 223 224 void G4OpticalParameters::SetCerenkovMaxPhotonsPerStep(G4int val) 225 { 226 if(IsLocked()) 227 { 228 return; 229 } 230 cerenkovMaxPhotons = val; 231 } 232 233 G4int G4OpticalParameters::GetCerenkovMaxPhotonsPerStep() const 234 { 235 return cerenkovMaxPhotons; 236 } 237 238 void G4OpticalParameters::SetCerenkovMaxBetaChange(G4double val) 239 { 240 if(IsLocked()) 241 { 242 return; 243 } 244 cerenkovMaxBetaChange = val; 245 } 246 247 G4double G4OpticalParameters::GetCerenkovMaxBetaChange() const 248 { 249 return cerenkovMaxBetaChange; 250 } 251 252 void G4OpticalParameters::SetCerenkovTrackSecondariesFirst(G4bool val) 253 { 254 if(IsLocked()) 255 { 256 return; 257 } 258 cerenkovTrackSecondariesFirst = val; 259 } 260 261 G4bool G4OpticalParameters::GetCerenkovTrackSecondariesFirst() const 262 { 263 return cerenkovTrackSecondariesFirst; 264 } 265 266 void G4OpticalParameters::SetScintByParticleType(G4bool val) 267 { 268 if(IsLocked()) 269 { 270 return; 271 } 272 scintByParticleType = val; 273 } 274 275 G4bool G4OpticalParameters::GetScintByParticleType() const 276 { 277 return scintByParticleType; 278 } 279 280 void G4OpticalParameters::SetScintTrackInfo(G4bool val) 281 { 282 if(IsLocked()) 283 { 284 return; 285 } 286 scintTrackInfo = val; 287 } 288 289 G4bool G4OpticalParameters::GetScintTrackInfo() const { return scintTrackInfo; } 290 291 void G4OpticalParameters::SetScintTrackSecondariesFirst(G4bool val) 292 { 293 if(IsLocked()) 294 { 295 return; 296 } 297 scintTrackSecondariesFirst = val; 298 } 299 300 G4bool G4OpticalParameters::GetScintTrackSecondariesFirst() const 301 { 302 return scintTrackSecondariesFirst; 303 } 304 305 void G4OpticalParameters::SetScintFiniteRiseTime(G4bool val) 306 { 307 if(IsLocked()) 308 { 309 return; 310 } 311 scintFiniteRiseTime = val; 312 } 313 314 G4bool G4OpticalParameters::GetScintFiniteRiseTime() const 315 { 316 return scintFiniteRiseTime; 317 } 318 319 void G4OpticalParameters::SetScintStackPhotons(G4bool val) 320 { 321 if(IsLocked()) 322 { 323 return; 324 } 325 scintStackPhotons = val; 326 } 327 328 G4bool G4OpticalParameters::GetScintStackPhotons() const 329 { 330 return scintStackPhotons; 331 } 332 333 void G4OpticalParameters::SetScintVerboseLevel(G4int val) 334 { 335 if(IsLocked()) 336 { 337 return; 338 } 339 scintVerboseLevel = val; 340 } 341 342 G4int G4OpticalParameters::GetScintVerboseLevel() const 343 { 344 return scintVerboseLevel; 345 } 346 347 void G4OpticalParameters::SetWLSTimeProfile(const G4String& val) 348 { 349 if(IsLocked()) 350 { 351 return; 352 } 353 wlsTimeProfileName = val; 354 } 355 356 G4String G4OpticalParameters::GetWLSTimeProfile() const 357 { 358 return wlsTimeProfileName; 359 } 360 361 void G4OpticalParameters::SetWLSVerboseLevel(G4int val) 362 { 363 if(IsLocked()) 364 { 365 return; 366 } 367 wlsVerboseLevel = val; 368 } 369 370 G4int G4OpticalParameters::GetWLSVerboseLevel() const 371 { 372 return wlsVerboseLevel; 373 } 374 375 void G4OpticalParameters::SetWLS2TimeProfile(const G4String& val) 376 { 377 if(IsLocked()) 378 { 379 return; 380 } 381 wls2TimeProfileName = val; 382 } 383 384 G4String G4OpticalParameters::GetWLS2TimeProfile() const 385 { 386 return wls2TimeProfileName; 387 } 388 389 void G4OpticalParameters::SetWLS2VerboseLevel(G4int val) 390 { 391 if(IsLocked()) 392 { 393 return; 394 } 395 wls2VerboseLevel = val; 396 } 397 398 G4int G4OpticalParameters::GetWLS2VerboseLevel() const 399 { 400 return wls2VerboseLevel; 401 } 402 403 void G4OpticalParameters::SetBoundaryVerboseLevel(G4int val) 404 { 405 if(IsLocked()) 406 { 407 return; 408 } 409 boundaryVerboseLevel = val; 410 } 411 412 G4int G4OpticalParameters::GetBoundaryVerboseLevel() const 413 { 414 return boundaryVerboseLevel; 415 } 416 417 void G4OpticalParameters::SetBoundaryInvokeSD(G4bool val) 418 { 419 if(IsLocked()) 420 { 421 return; 422 } 423 boundaryInvokeSD = val; 424 } 425 426 G4bool G4OpticalParameters::GetBoundaryInvokeSD() const 427 { 428 return boundaryInvokeSD; 429 } 430 431 void G4OpticalParameters::SetAbsorptionVerboseLevel(G4int val) 432 { 433 if(IsLocked()) 434 { 435 return; 436 } 437 absorptionVerboseLevel = val; 438 } 439 440 G4int G4OpticalParameters::GetAbsorptionVerboseLevel() const 441 { 442 return absorptionVerboseLevel; 443 } 444 445 void G4OpticalParameters::SetRayleighVerboseLevel(G4int val) 446 { 447 if(IsLocked()) 448 { 449 return; 450 } 451 rayleighVerboseLevel = val; 452 } 453 454 G4int G4OpticalParameters::GetRayleighVerboseLevel() const 455 { 456 return rayleighVerboseLevel; 457 } 458 459 void G4OpticalParameters::SetMieVerboseLevel(G4int val) 460 { 461 if(IsLocked()) 462 { 463 return; 464 } 465 mieVerboseLevel = val; 466 } 467 468 G4int G4OpticalParameters::GetMieVerboseLevel() const 469 { 470 return mieVerboseLevel; 471 } 472 473 void G4OpticalParameters::PrintWarning(G4ExceptionDescription& ed) const 474 { 475 G4Exception("G4EmParameters", "Optical0020", JustWarning, ed); 476 } 477 478 void G4OpticalParameters::StreamInfo(std::ostream& os) const 479 { 480 G4long prec = os.precision(5); 481 os 482 << "=======================================================================" 483 << "\n"; 484 os 485 << "====== Optical Physics Parameters ========" 486 << "\n"; 487 os 488 << "=======================================================================" 489 << "\n"; 490 491 os << " Cerenkov process active: " 492 << GetProcessActivation("Cerenkov") << "\n"; 493 os << " Cerenkov maximum photons per step: " << cerenkovMaxPhotons 494 << "\n"; 495 os << " Cerenkov maximum beta change per step: " << cerenkovMaxBetaChange 496 << " %\n"; 497 os << " Cerenkov stack photons: " << cerenkovStackPhotons 498 << "\n"; 499 os << " Cerenkov track secondaries first: " 500 << cerenkovTrackSecondariesFirst << "\n"; 501 os << " Scintillation process active: " 502 << GetProcessActivation("Scintillation") << "\n"; 503 os << " Scintillation finite rise time: " << scintFiniteRiseTime 504 << "\n"; 505 os << " Scintillation by particle type: " << scintByParticleType 506 << "\n"; 507 os << " Scintillation record track info: " << scintTrackInfo << "\n"; 508 os << " Scintillation stack photons: " << scintStackPhotons << "\n"; 509 os << " Scintillation track secondaries first: " << scintTrackSecondariesFirst 510 << "\n"; 511 os << " WLS process active: " 512 << GetProcessActivation("OpWLS") << "\n"; 513 os << " WLS time profile name: " << wlsTimeProfileName 514 << "\n"; 515 os << " WLS2 process active: " 516 << GetProcessActivation("OpWLS2") << "\n"; 517 os << " WLS2 time profile name: " << wls2TimeProfileName 518 << "\n"; 519 os << " Boundary process active: " 520 << GetProcessActivation("OpBoundary") << "\n"; 521 os << " Boundary invoke sensitive detector: " << boundaryInvokeSD << "\n"; 522 os << " Rayleigh process active: " 523 << GetProcessActivation("OpRayleigh") << "\n"; 524 os << " MieHG process active: " 525 << GetProcessActivation("OpMieHG") << "\n"; 526 os << " Absorption process active: " 527 << GetProcessActivation("OpAbsorption") << "\n"; 528 os 529 << "=======================================================================" 530 << "\n"; 531 os.precision(prec); 532 } 533 534 void G4OpticalParameters::Dump() const 535 { 536 #ifdef G4MULTITHREADED 537 G4MUTEXLOCK(&opticalParametersMutex); 538 #endif 539 StreamInfo(G4cout); 540 #ifdef G4MULTITHREADED 541 G4MUTEXUNLOCK(&opticalParametersMutex); 542 #endif 543 } 544 545 std::ostream& operator<<(std::ostream& os, const G4OpticalParameters& par) 546 { 547 par.StreamInfo(os); 548 return os; 549 } 550 551 G4bool G4OpticalParameters::IsLocked() const 552 { 553 return (!G4Threading::IsMasterThread() || 554 (fStateManager->GetCurrentState() != G4State_PreInit && 555 fStateManager->GetCurrentState() != G4State_Init && 556 fStateManager->GetCurrentState() != G4State_Idle)); 557 } 558