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 ////////////////////////////////////////////// 26 //////////////////////////////////////////////////////////////////////// 27 // Optical Photon Boundary Process Class Imple 27 // Optical Photon Boundary Process Class Implementation 28 ////////////////////////////////////////////// 28 //////////////////////////////////////////////////////////////////////// 29 // 29 // 30 // File: G4OpBoundaryProcess.cc 30 // File: G4OpBoundaryProcess.cc 31 // Description: Discrete Process -- reflection 31 // Description: Discrete Process -- reflection/refraction at 32 // optical in 32 // optical interfaces 33 // Version: 1.1 33 // Version: 1.1 34 // Created: 1997-06-18 34 // Created: 1997-06-18 35 // Modified: 1998-05-25 - Correct parallel 35 // Modified: 1998-05-25 - Correct parallel component of polarization 36 // (thanks to: Stefa 36 // (thanks to: Stefano Magni + Giovanni Pieri) 37 // 1998-05-28 - NULL Rindex point 37 // 1998-05-28 - NULL Rindex pointer before reuse 38 // (thanks to: Stefa 38 // (thanks to: Stefano Magni) 39 // 1998-06-11 - delete *sint1 in 39 // 1998-06-11 - delete *sint1 in oblique reflection 40 // (thanks to: Giova 40 // (thanks to: Giovanni Pieri) 41 // 1998-06-19 - move from GetLoca << 41 // 1998-06-19 - move from GetLocalExitNormal() to the new 42 // method: GetLocalE 42 // method: GetLocalExitNormal(&valid) to get 43 // the surface norma 43 // the surface normal in all cases 44 // 1998-11-07 - NULL OpticalSurfa 44 // 1998-11-07 - NULL OpticalSurface pointer before use 45 // comparison not sh 45 // comparison not sharp for: std::abs(cost1) < 1.0 46 // remove sin1, sin2 46 // remove sin1, sin2 in lines 556,567 47 // (thanks to Stefan 47 // (thanks to Stefano Magni) 48 // 1999-10-10 - Accommodate chang 48 // 1999-10-10 - Accommodate changes done in DoAbsorption by 49 // changing logic in 49 // changing logic in DielectricMetal 50 // 2001-10-18 - avoid Linux (gcc- 50 // 2001-10-18 - avoid Linux (gcc-2.95.2) warning about variables 51 // might be used uni 51 // might be used uninitialized in this function 52 // moved E2_perp, E2 52 // moved E2_perp, E2_parl and E2_total out of 'if' 53 // 2003-11-27 - Modified line 168 53 // 2003-11-27 - Modified line 168-9 to reflect changes made to 54 // G4OpticalSurface 54 // G4OpticalSurface class ( by Fan Lei) 55 // 2004-02-02 - Set theStatus = U 55 // 2004-02-02 - Set theStatus = Undefined at start of DoIt 56 // 2005-07-28 - add G4ProcessType 56 // 2005-07-28 - add G4ProcessType to constructor 57 // 2006-11-04 - add capability of 57 // 2006-11-04 - add capability of calculating the reflectivity 58 // off a metal surfa << 58 // off a metal surface by way of a complex index 59 // of refraction - T << 59 // of refraction - Thanks to Sehwook Lee and John 60 // Hauptman (Dept. o 60 // Hauptman (Dept. of Physics - Iowa State Univ.) 61 // 2009-11-10 - add capability of 61 // 2009-11-10 - add capability of simulating surface reflections 62 // with Look-Up-Tabl 62 // with Look-Up-Tables (LUT) containing measured 63 // optical reflectan 63 // optical reflectance for a variety of surface 64 // treatments - Than 64 // treatments - Thanks to Martin Janecek and 65 // William Moses (La 65 // William Moses (Lawrence Berkeley National Lab.) 66 // 2013-06-01 - add the capabilit 66 // 2013-06-01 - add the capability of simulating the transmission 67 // of a dichronic fi 67 // of a dichronic filter 68 // 2017-02-24 - add capability of << 69 // with Look-Up-Tabl << 70 // 68 // 71 // Author: Peter Gumplinger 69 // Author: Peter Gumplinger 72 // adopted from work by Werner Keil - April 70 // adopted from work by Werner Keil - April 2/96 >> 71 // mail: gum@triumf.ca 73 // 72 // 74 ////////////////////////////////////////////// 73 //////////////////////////////////////////////////////////////////////// 75 74 76 #include "G4OpBoundaryProcess.hh" << 77 << 78 #include "G4ios.hh" 75 #include "G4ios.hh" 79 #include "G4GeometryTolerance.hh" << 76 #include "G4PhysicalConstants.hh" 80 #include "G4LogicalBorderSurface.hh" << 81 #include "G4LogicalSkinSurface.hh" << 82 #include "G4OpProcessSubType.hh" 77 #include "G4OpProcessSubType.hh" 83 #include "G4OpticalParameters.hh" << 78 >> 79 #include "G4OpBoundaryProcess.hh" >> 80 #include "G4GeometryTolerance.hh" >> 81 >> 82 #include "G4VSensitiveDetector.hh" 84 #include "G4ParallelWorldProcess.hh" 83 #include "G4ParallelWorldProcess.hh" 85 #include "G4PhysicalConstants.hh" << 84 86 #include "G4SystemOfUnits.hh" 85 #include "G4SystemOfUnits.hh" 87 #include "G4TransportationManager.hh" << 88 #include "G4VSensitiveDetector.hh" << 89 86 90 //....oooOO0OOooo........oooOO0OOooo........oo << 87 ///////////////////////// >> 88 // Class Implementation >> 89 ///////////////////////// >> 90 >> 91 ////////////// >> 92 // Operators >> 93 ////////////// >> 94 >> 95 // G4OpBoundaryProcess::operator=(const G4OpBoundaryProcess &right) >> 96 // { >> 97 // } >> 98 >> 99 ///////////////// >> 100 // Constructors >> 101 ///////////////// >> 102 91 G4OpBoundaryProcess::G4OpBoundaryProcess(const 103 G4OpBoundaryProcess::G4OpBoundaryProcess(const G4String& processName, 92 G4Pro << 104 G4ProcessType type) 93 : G4VDiscreteProcess(processName, ptype) << 105 : G4VDiscreteProcess(processName, type) 94 { 106 { 95 Initialise(); << 107 if ( verboseLevel > 0) { >> 108 G4cout << GetProcessName() << " is created " << G4endl; >> 109 } 96 110 97 if(verboseLevel > 0) << 111 SetProcessSubType(fOpBoundary); 98 { << 99 G4cout << GetProcessName() << " is created << 100 } << 101 SetProcessSubType(fOpBoundary); << 102 112 103 fStatus = Undefined; << 113 theStatus = Undefined; 104 fModel = glisur; << 114 theModel = glisur; 105 fFinish = polished; << 115 theFinish = polished; 106 fReflectivity = 1.; << 116 theReflectivity = 1.; 107 fEfficiency = 0.; << 117 theEfficiency = 0.; 108 fTransmittance = 0.; << 118 theTransmittance = 0.; 109 fSurfaceRoughness = 0.; << 110 fProb_sl = 0.; << 111 fProb_ss = 0.; << 112 fProb_bs = 0.; << 113 << 114 fRealRIndexMPV = nullptr; << 115 fImagRIndexMPV = nullptr; << 116 fMaterial1 = nullptr; << 117 fMaterial2 = nullptr; << 118 fOpticalSurface = nullptr; << 119 fCarTolerance = G4GeometryTolerance::GetIn << 120 << 121 f_iTE = f_iTM = 0; << 122 fPhotonMomentum = 0.; << 123 fRindex1 = fRindex2 = 1.; << 124 fSint1 = 0.; << 125 fDichroicVector = nullptr; << 126 } << 127 119 128 //....oooOO0OOooo........oooOO0OOooo........oo << 120 theSurfaceRoughness = 0.; 129 G4OpBoundaryProcess::~G4OpBoundaryProcess() = << 130 121 131 //....oooOO0OOooo........oooOO0OOooo........oo << 122 prob_sl = 0.; 132 void G4OpBoundaryProcess::PreparePhysicsTable( << 123 prob_ss = 0.; 133 { << 124 prob_bs = 0.; 134 Initialise(); << 135 } << 136 125 137 //....oooOO0OOooo........oooOO0OOooo........oo << 126 PropertyPointer = NULL; 138 void G4OpBoundaryProcess::Initialise() << 127 PropertyPointer1 = NULL; 139 { << 128 PropertyPointer2 = NULL; 140 G4OpticalParameters* params = G4OpticalParam << 141 SetInvokeSD(params->GetBoundaryInvokeSD()); << 142 SetVerboseLevel(params->GetBoundaryVerboseLe << 143 } << 144 129 145 //....oooOO0OOooo........oooOO0OOooo........oo << 130 Material1 = NULL; 146 G4VParticleChange* G4OpBoundaryProcess::PostSt << 131 Material2 = NULL; 147 << 148 { << 149 fStatus = Undefined; << 150 aParticleChange.Initialize(aTrack); << 151 aParticleChange.ProposeVelocity(aTrack.GetVe << 152 << 153 // Get hyperStep from G4ParallelWorldProces << 154 // NOTE: PostSetpDoIt of this process to be << 155 // G4ParallelWorldProcess! << 156 const G4Step* pStep = &aStep; << 157 const G4Step* hStep = G4ParallelWorldProcess << 158 if(hStep != nullptr) << 159 pStep = hStep; << 160 << 161 if(pStep->GetPostStepPoint()->GetStepStatus( << 162 { << 163 fMaterial1 = pStep->GetPreStepPoint()->Get << 164 fMaterial2 = pStep->GetPostStepPoint()->Ge << 165 } << 166 else << 167 { << 168 fStatus = NotAtBoundary; << 169 if(verboseLevel > 1) << 170 BoundaryProcessVerbose(); << 171 return G4VDiscreteProcess::PostStepDoIt(aT << 172 } << 173 132 174 G4VPhysicalVolume* thePrePV = pStep->GetPre << 133 OpticalSurface = NULL; 175 G4VPhysicalVolume* thePostPV = pStep->GetPos << 176 134 177 if(verboseLevel > 1) << 135 kCarTolerance = G4GeometryTolerance::GetInstance() 178 { << 136 ->GetSurfaceTolerance(); 179 G4cout << " Photon at Boundary! " << G4end << 180 if(thePrePV != nullptr) << 181 G4cout << " thePrePV: " << thePrePV->Ge << 182 if(thePostPV != nullptr) << 183 G4cout << " thePostPV: " << thePostPV->G << 184 } << 185 137 186 G4double stepLength = aTrack.GetStepLength() << 138 iTE = iTM = 0; 187 if(stepLength <= fCarTolerance) << 139 thePhotonMomentum = 0.; 188 { << 140 Rindex1 = Rindex2 = 1.; 189 fStatus = StepTooSmall; << 141 cost1 = cost2 = sint1 = sint2 = 0.; 190 if(verboseLevel > 1) << 142 191 BoundaryProcessVerbose(); << 143 idx = idy = 0; 192 << 144 DichroicVector = NULL; 193 G4MaterialPropertyVector* groupvel = nullp << 145 } 194 G4MaterialPropertiesTable* aMPT = fMateria << 195 if(aMPT != nullptr) << 196 { << 197 groupvel = aMPT->GetProperty(kGROUPVEL); << 198 } << 199 << 200 if(groupvel != nullptr) << 201 { << 202 aParticleChange.ProposeVelocity( << 203 groupvel->Value(fPhotonMomentum, idx_g << 204 } << 205 return G4VDiscreteProcess::PostStepDoIt(aT << 206 } << 207 else if (stepLength <= 10.*fCarTolerance && << 208 { // see bug 2510 << 209 ++fNumSmallStepWarnings; << 210 if(verboseLevel > 0) << 211 { << 212 G4ExceptionDescription ed; << 213 ed << "G4OpBoundaryProcess: " << 214 << "Opticalphoton step length: " << s << 215 << "This is larger than the threshold << 216 "to set status StepTooSmall." << G << 217 << "Boundary scattering may be incorr << 218 if(fNumSmallStepWarnings == 10) << 219 { << 220 ed << G4endl << "*** Step size warning << 221 } << 222 G4Exception("G4OpBoundaryProcess", "OpBo << 223 } << 224 } << 225 146 226 const G4DynamicParticle* aParticle = aTrack. << 147 // G4OpBoundaryProcess::G4OpBoundaryProcess(const G4OpBoundaryProcess &right) >> 148 // { >> 149 // } >> 150 >> 151 //////////////// >> 152 // Destructors >> 153 //////////////// >> 154 >> 155 G4OpBoundaryProcess::~G4OpBoundaryProcess(){} >> 156 >> 157 //////////// >> 158 // Methods >> 159 //////////// 227 160 228 fPhotonMomentum = aParticle->GetTotalMoment << 161 // PostStepDoIt 229 fOldMomentum = aParticle->GetMomentumDir << 162 // ------------ 230 fOldPolarization = aParticle->GetPolarizatio << 163 // 231 << 232 if(verboseLevel > 1) << 233 { << 234 G4cout << " Old Momentum Direction: " << f << 235 << " Old Polarization: " << f << 236 } << 237 164 238 G4ThreeVector theGlobalPoint = pStep->GetPos << 165 G4VParticleChange* 239 G4bool valid; << 166 G4OpBoundaryProcess::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep) >> 167 { >> 168 theStatus = Undefined; 240 169 241 // ID of Navigator which limits step << 170 aParticleChange.Initialize(aTrack); 242 G4int hNavId = G4ParallelWorldProcess::GetHy << 171 aParticleChange.ProposeVelocity(aTrack.GetVelocity()); 243 auto iNav = G4TransportationManager::GetT << 244 ->GetActiveNavigatorsIterator( << 245 fGlobalNormal = (iNav[hNavId])->GetGlobalExi << 246 << 247 if(valid) << 248 { << 249 fGlobalNormal = -fGlobalNormal; << 250 } << 251 else << 252 { << 253 G4ExceptionDescription ed; << 254 ed << " G4OpBoundaryProcess/PostStepDoIt() << 255 << " The Navigator reports that it retu << 256 G4Exception( << 257 "G4OpBoundaryProcess::PostStepDoIt", "Op << 258 "Invalid Surface Normal - Geometry must << 259 } << 260 172 261 if(fOldMomentum * fGlobalNormal > 0.0) << 173 // Get hyperStep from G4ParallelWorldProcess 262 { << 174 // NOTE: PostSetpDoIt of this process should be 263 #ifdef G4OPTICAL_DEBUG << 175 // invoked after G4ParallelWorldProcess! 264 G4ExceptionDescription ed; << 265 ed << " G4OpBoundaryProcess/PostStepDoIt() << 266 "wrong direction. " << 267 << G4endl << 268 << " The momentum of the photon arriv << 269 << " must exit the volume cross in th << 270 << " So it MUST have dot < 0 with the << 271 "volume (globalNormal)." << 272 << G4endl << " >> The dot product of << 273 << fOldMomentum * fGlobalNormal << G4en << 274 << " Old Momentum (during step) << 275 << " Global Normal (Exiting New Vol << 276 << G4endl; << 277 G4Exception("G4OpBoundaryProcess::PostStep << 278 EventMustBeAborted, // Or Jus << 279 // repeat << 280 ed, << 281 "Invalid Surface Normal - Geom << 282 "normal pointing in the right << 283 #else << 284 fGlobalNormal = -fGlobalNormal; << 285 #endif << 286 } << 287 176 288 G4MaterialPropertyVector* rIndexMPV = nullpt << 177 const G4Step* pStep = &aStep; 289 G4MaterialPropertiesTable* MPT = fMaterial1- << 290 if(MPT != nullptr) << 291 { << 292 rIndexMPV = MPT->GetProperty(kRINDEX); << 293 } << 294 if(rIndexMPV != nullptr) << 295 { << 296 fRindex1 = rIndexMPV->Value(fPhotonMomentu << 297 } << 298 else << 299 { << 300 fStatus = NoRINDEX; << 301 if(verboseLevel > 1) << 302 BoundaryProcessVerbose(); << 303 aParticleChange.ProposeLocalEnergyDeposit( << 304 aParticleChange.ProposeTrackStatus(fStopAn << 305 return G4VDiscreteProcess::PostStepDoIt(aT << 306 } << 307 178 308 fReflectivity = 1.; << 179 const G4Step* hStep = G4ParallelWorldProcess::GetHyperStep(); 309 fEfficiency = 0.; << 180 310 fTransmittance = 0.; << 181 if (hStep) pStep = hStep; 311 fSurfaceRoughness = 0.; << 312 fModel = glisur; << 313 fFinish = polished; << 314 G4SurfaceType type = dielectric_dielectric; << 315 << 316 rIndexMPV = nullptr; << 317 fOpticalSurface = nullptr; << 318 << 319 G4LogicalSurface* surface = << 320 G4LogicalBorderSurface::GetSurface(thePreP << 321 if(surface == nullptr) << 322 { << 323 if(thePostPV->GetMotherLogical() == thePre << 324 { << 325 surface = G4LogicalSkinSurface::GetSurfa << 326 if(surface == nullptr) << 327 { << 328 surface = << 329 G4LogicalSkinSurface::GetSurface(the << 330 } << 331 } << 332 else << 333 { << 334 surface = G4LogicalSkinSurface::GetSurfa << 335 if(surface == nullptr) << 336 { << 337 surface = << 338 G4LogicalSkinSurface::GetSurface(the << 339 } << 340 } << 341 } << 342 182 343 if(surface != nullptr) << 183 G4bool isOnBoundary = 344 { << 184 (pStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary); 345 fOpticalSurface = << 346 dynamic_cast<G4OpticalSurface*>(surface- << 347 } << 348 if(fOpticalSurface != nullptr) << 349 { << 350 type = fOpticalSurface->GetType(); << 351 fModel = fOpticalSurface->GetModel(); << 352 fFinish = fOpticalSurface->GetFinish(); << 353 << 354 G4MaterialPropertiesTable* sMPT = << 355 fOpticalSurface->GetMaterialPropertiesTa << 356 if(sMPT != nullptr) << 357 { << 358 if(fFinish == polishedbackpainted || fFi << 359 { << 360 rIndexMPV = sMPT->GetProperty(kRINDEX) << 361 if(rIndexMPV != nullptr) << 362 { << 363 fRindex2 = rIndexMPV->Value(fPhotonM << 364 } << 365 else << 366 { << 367 fStatus = NoRINDEX; << 368 if(verboseLevel > 1) << 369 BoundaryProcessVerbose(); << 370 aParticleChange.ProposeLocalEnergyDe << 371 aParticleChange.ProposeTrackStatus(f << 372 return G4VDiscreteProcess::PostStepD << 373 } << 374 } << 375 185 376 fRealRIndexMPV = sMPT->GetProperty(kREAL << 186 if (isOnBoundary) { 377 fImagRIndexMPV = sMPT->GetProperty(kIMAG << 187 Material1 = pStep->GetPreStepPoint()->GetMaterial(); 378 f_iTE = f_iTM = 1; << 188 Material2 = pStep->GetPostStepPoint()->GetMaterial(); 379 << 189 } else { 380 G4MaterialPropertyVector* pp; << 190 theStatus = NotAtBoundary; 381 if((pp = sMPT->GetProperty(kREFLECTIVITY << 191 if ( verboseLevel > 0) BoundaryProcessVerbose(); 382 { << 192 return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep); 383 fReflectivity = pp->Value(fPhotonMomen << 384 } << 385 else if(fRealRIndexMPV && fImagRIndexMPV << 386 { << 387 CalculateReflectivity(); << 388 } << 389 << 390 if((pp = sMPT->GetProperty(kEFFICIENCY)) << 391 { << 392 fEfficiency = pp->Value(fPhotonMomentu << 393 } << 394 if((pp = sMPT->GetProperty(kTRANSMITTANC << 395 { << 396 fTransmittance = pp->Value(fPhotonMome << 397 } << 398 if(sMPT->ConstPropertyExists(kSURFACEROU << 399 { << 400 fSurfaceRoughness = sMPT->GetConstProp << 401 } << 402 << 403 if(fModel == unified) << 404 { << 405 fProb_sl = (pp = sMPT->GetProperty(kSP << 406 ? pp->Value(fPhotonMoment << 407 : 0.; << 408 fProb_ss = (pp = sMPT->GetProperty(kSP << 409 ? pp->Value(fPhotonMoment << 410 : 0.; << 411 fProb_bs = (pp = sMPT->GetProperty(kBA << 412 ? pp->Value(fPhotonMoment << 413 : 0.; << 414 } << 415 } // end of if(sMPT) << 416 else if(fFinish == polishedbackpainted || << 417 { << 418 aParticleChange.ProposeLocalEnergyDeposi << 419 aParticleChange.ProposeTrackStatus(fStop << 420 return G4VDiscreteProcess::PostStepDoIt( << 421 } << 422 } // end of if(fOpticalSurface) << 423 << 424 // DIELECTRIC-DIELECTRIC << 425 if(type == dielectric_dielectric) << 426 { << 427 if(fFinish == polished || fFinish == groun << 428 { << 429 if(fMaterial1 == fMaterial2) << 430 { << 431 fStatus = SameMaterial; << 432 if(verboseLevel > 1) << 433 BoundaryProcessVerbose(); << 434 return G4VDiscreteProcess::PostStepDoI << 435 } << 436 MPT = fMaterial2->GetMaterialPrope << 437 rIndexMPV = nullptr; << 438 if(MPT != nullptr) << 439 { << 440 rIndexMPV = MPT->GetProperty(kRINDEX); << 441 } << 442 if(rIndexMPV != nullptr) << 443 { << 444 fRindex2 = rIndexMPV->Value(fPhotonMom << 445 } << 446 else << 447 { << 448 fStatus = NoRINDEX; << 449 if(verboseLevel > 1) << 450 BoundaryProcessVerbose(); << 451 aParticleChange.ProposeLocalEnergyDepo << 452 aParticleChange.ProposeTrackStatus(fSt << 453 return G4VDiscreteProcess::PostStepDoI << 454 } << 455 } << 456 if(fFinish == polishedbackpainted || fFini << 457 { << 458 DielectricDielectric(); << 459 } << 460 else << 461 { << 462 G4double rand = G4UniformRand(); << 463 if(rand > fReflectivity + fTransmittance << 464 { << 465 DoAbsorption(); << 466 } << 467 else if(rand > fReflectivity) << 468 { << 469 fStatus = Transmission; << 470 fNewMomentum = fOldMomentum; << 471 fNewPolarization = fOldPolarization; << 472 } << 473 else << 474 { << 475 if(fFinish == polishedfrontpainted) << 476 { << 477 DoReflection(); << 478 } << 479 else if(fFinish == groundfrontpainted) << 480 { << 481 fStatus = LambertianReflection; << 482 DoReflection(); << 483 } << 484 else << 485 { << 486 DielectricDielectric(); << 487 } 193 } 488 } << 194 489 } << 195 G4VPhysicalVolume* thePrePV = 490 } << 196 pStep->GetPreStepPoint() ->GetPhysicalVolume(); 491 else if(type == dielectric_metal) << 197 G4VPhysicalVolume* thePostPV = 492 { << 198 pStep->GetPostStepPoint()->GetPhysicalVolume(); 493 DielectricMetal(); << 199 494 } << 200 if ( verboseLevel > 0 ) { 495 else if(type == dielectric_LUT) << 201 G4cout << " Photon at Boundary! " << G4endl; 496 { << 202 if (thePrePV) G4cout << " thePrePV: " << thePrePV->GetName() << G4endl; 497 DielectricLUT(); << 203 if (thePostPV) G4cout << " thePostPV: " << thePostPV->GetName() << G4endl; 498 } << 499 else if(type == dielectric_LUTDAVIS) << 500 { << 501 DielectricLUTDAVIS(); << 502 } << 503 else if(type == dielectric_dichroic) << 504 { << 505 DielectricDichroic(); << 506 } << 507 else if(type == coated) << 508 { << 509 CoatedDielectricDielectric(); << 510 } << 511 else << 512 { << 513 if(fNumBdryTypeWarnings <= 10) << 514 { << 515 ++fNumBdryTypeWarnings; << 516 if(verboseLevel > 0) << 517 { << 518 G4ExceptionDescription ed; << 519 ed << " PostStepDoIt(): Illegal bounda << 520 if(fNumBdryTypeWarnings == 10) << 521 { << 522 ed << "** Boundary type warnings sto << 523 } 204 } 524 G4Exception("G4OpBoundaryProcess", "Op << 525 } << 526 } << 527 return G4VDiscreteProcess::PostStepDoIt(aT << 528 } << 529 205 530 fNewMomentum = fNewMomentum.unit(); << 206 if (aTrack.GetStepLength()<=kCarTolerance/2){ 531 fNewPolarization = fNewPolarization.unit(); << 207 theStatus = StepTooSmall; >> 208 if ( verboseLevel > 0) BoundaryProcessVerbose(); >> 209 return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep); >> 210 } 532 211 533 if(verboseLevel > 1) << 212 const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle(); 534 { << 535 G4cout << " New Momentum Direction: " << f << 536 << " New Polarization: " << f << 537 BoundaryProcessVerbose(); << 538 } << 539 213 540 aParticleChange.ProposeMomentumDirection(fNe << 214 thePhotonMomentum = aParticle->GetTotalMomentum(); 541 aParticleChange.ProposePolarization(fNewPola << 215 OldMomentum = aParticle->GetMomentumDirection(); >> 216 OldPolarization = aParticle->GetPolarization(); 542 217 543 if(fStatus == FresnelRefraction || fStatus = << 218 if ( verboseLevel > 0 ) { 544 { << 219 G4cout << " Old Momentum Direction: " << OldMomentum << G4endl; 545 // not all surface types check that fMater << 220 G4cout << " Old Polarization: " << OldPolarization << G4endl; 546 G4MaterialPropertiesTable* aMPT = fMateria << 221 } 547 G4MaterialPropertyVector* groupvel = nullp << 548 if(aMPT != nullptr) << 549 { << 550 groupvel = aMPT->GetProperty(kGROUPVEL); << 551 } << 552 if(groupvel != nullptr) << 553 { << 554 aParticleChange.ProposeVelocity( << 555 groupvel->Value(fPhotonMomentum, idx_g << 556 } << 557 } << 558 222 559 if(fStatus == Detection && fInvokeSD) << 223 G4ThreeVector theGlobalPoint = pStep->GetPostStepPoint()->GetPosition(); 560 InvokeSD(pStep); << 561 return G4VDiscreteProcess::PostStepDoIt(aTra << 562 } << 563 224 564 //....oooOO0OOooo........oooOO0OOooo........oo << 225 G4bool valid; 565 void G4OpBoundaryProcess::BoundaryProcessVerbo << 226 // Use the new method for Exit Normal in global coordinates, 566 { << 227 // which provides the normal more reliably. 567 G4cout << " *** "; << 568 if(fStatus == Undefined) << 569 G4cout << "Undefined"; << 570 else if(fStatus == Transmission) << 571 G4cout << "Transmission"; << 572 else if(fStatus == FresnelRefraction) << 573 G4cout << "FresnelRefraction"; << 574 else if(fStatus == FresnelReflection) << 575 G4cout << "FresnelReflection"; << 576 else if(fStatus == TotalInternalReflection) << 577 G4cout << "TotalInternalReflection"; << 578 else if(fStatus == LambertianReflection) << 579 G4cout << "LambertianReflection"; << 580 else if(fStatus == LobeReflection) << 581 G4cout << "LobeReflection"; << 582 else if(fStatus == SpikeReflection) << 583 G4cout << "SpikeReflection"; << 584 else if(fStatus == BackScattering) << 585 G4cout << "BackScattering"; << 586 else if(fStatus == PolishedLumirrorAirReflec << 587 G4cout << "PolishedLumirrorAirReflection"; << 588 else if(fStatus == PolishedLumirrorGlueRefle << 589 G4cout << "PolishedLumirrorGlueReflection" << 590 else if(fStatus == PolishedAirReflection) << 591 G4cout << "PolishedAirReflection"; << 592 else if(fStatus == PolishedTeflonAirReflecti << 593 G4cout << "PolishedTeflonAirReflection"; << 594 else if(fStatus == PolishedTiOAirReflection) << 595 G4cout << "PolishedTiOAirReflection"; << 596 else if(fStatus == PolishedTyvekAirReflectio << 597 G4cout << "PolishedTyvekAirReflection"; << 598 else if(fStatus == PolishedVM2000AirReflecti << 599 G4cout << "PolishedVM2000AirReflection"; << 600 else if(fStatus == PolishedVM2000GlueReflect << 601 G4cout << "PolishedVM2000GlueReflection"; << 602 else if(fStatus == EtchedLumirrorAirReflecti << 603 G4cout << "EtchedLumirrorAirReflection"; << 604 else if(fStatus == EtchedLumirrorGlueReflect << 605 G4cout << "EtchedLumirrorGlueReflection"; << 606 else if(fStatus == EtchedAirReflection) << 607 G4cout << "EtchedAirReflection"; << 608 else if(fStatus == EtchedTeflonAirReflection << 609 G4cout << "EtchedTeflonAirReflection"; << 610 else if(fStatus == EtchedTiOAirReflection) << 611 G4cout << "EtchedTiOAirReflection"; << 612 else if(fStatus == EtchedTyvekAirReflection) << 613 G4cout << "EtchedTyvekAirReflection"; << 614 else if(fStatus == EtchedVM2000AirReflection << 615 G4cout << "EtchedVM2000AirReflection"; << 616 else if(fStatus == EtchedVM2000GlueReflectio << 617 G4cout << "EtchedVM2000GlueReflection"; << 618 else if(fStatus == GroundLumirrorAirReflecti << 619 G4cout << "GroundLumirrorAirReflection"; << 620 else if(fStatus == GroundLumirrorGlueReflect << 621 G4cout << "GroundLumirrorGlueReflection"; << 622 else if(fStatus == GroundAirReflection) << 623 G4cout << "GroundAirReflection"; << 624 else if(fStatus == GroundTeflonAirReflection << 625 G4cout << "GroundTeflonAirReflection"; << 626 else if(fStatus == GroundTiOAirReflection) << 627 G4cout << "GroundTiOAirReflection"; << 628 else if(fStatus == GroundTyvekAirReflection) << 629 G4cout << "GroundTyvekAirReflection"; << 630 else if(fStatus == GroundVM2000AirReflection << 631 G4cout << "GroundVM2000AirReflection"; << 632 else if(fStatus == GroundVM2000GlueReflectio << 633 G4cout << "GroundVM2000GlueReflection"; << 634 else if(fStatus == Absorption) << 635 G4cout << "Absorption"; << 636 else if(fStatus == Detection) << 637 G4cout << "Detection"; << 638 else if(fStatus == NotAtBoundary) << 639 G4cout << "NotAtBoundary"; << 640 else if(fStatus == SameMaterial) << 641 G4cout << "SameMaterial"; << 642 else if(fStatus == StepTooSmall) << 643 G4cout << "StepTooSmall"; << 644 else if(fStatus == NoRINDEX) << 645 G4cout << "NoRINDEX"; << 646 else if(fStatus == Dichroic) << 647 G4cout << "Dichroic Transmission"; << 648 else if(fStatus == CoatedDielectricReflectio << 649 G4cout << "Coated Dielectric Reflection"; << 650 else if(fStatus == CoatedDielectricRefractio << 651 G4cout << "Coated Dielectric Refraction"; << 652 else if(fStatus == CoatedDielectricFrustrate << 653 G4cout << "Coated Dielectric Frustrated Tr << 654 228 655 G4cout << " ***" << G4endl; << 229 // ID of Navigator which limits step 656 } << 657 230 658 //....oooOO0OOooo........oooOO0OOooo........oo << 231 G4int hNavId = G4ParallelWorldProcess::GetHypNavigatorID(); 659 G4ThreeVector G4OpBoundaryProcess::GetFacetNor << 232 std::vector<G4Navigator*>::iterator iNav = 660 const G4ThreeVector& momentum, const G4Three << 233 G4TransportationManager::GetTransportationManager()-> 661 { << 234 GetActiveNavigatorsIterator(); 662 G4ThreeVector facetNormal; << 235 theGlobalNormal = 663 if(fModel == unified || fModel == LUT || fMo << 236 (iNav[hNavId])->GetGlobalExitNormal(theGlobalPoint,&valid); 664 { << 665 /* This function codes alpha to a random v << 666 distribution p(alpha) = g(alpha; 0, sigma_ << 667 for alpha > 0 and alpha < 90, where g(alph << 668 gaussian distribution with mean 0 and stan << 669 << 670 G4double sigma_alpha = 0.0; << 671 if(fOpticalSurface) << 672 sigma_alpha = fOpticalSurface->GetSigmaA << 673 if(sigma_alpha == 0.0) << 674 { << 675 return normal; << 676 } << 677 << 678 G4double f_max = std::min(1.0, 4. * sigma_ << 679 G4double alpha, phi, sinAlpha; << 680 << 681 do << 682 { // Loop checking, 13-Aug-2015, Peter Gu << 683 do << 684 { // Loop checking, 13-Aug-2015, Peter << 685 alpha = G4RandGauss::shoot(0.0, sig << 686 sinAlpha = std::sin(alpha); << 687 } while(G4UniformRand() * f_max > sinAlp << 688 << 689 phi = G4UniformRand() * twopi; << 690 facetNormal.set(sinAlpha * std::cos(phi) << 691 std::cos(alpha)); << 692 facetNormal.rotateUz(normal); << 693 } while(momentum * facetNormal >= 0.0); << 694 } << 695 else << 696 { << 697 G4double polish = 1.0; << 698 if(fOpticalSurface) << 699 polish = fOpticalSurface->GetPolish(); << 700 if(polish < 1.0) << 701 { << 702 do << 703 { // Loop checking, 13-Aug-2015, Peter << 704 G4ThreeVector smear; << 705 do << 706 { // Loop checking, 13-Aug-2015, Pete << 707 smear.setX(2. * G4UniformRand() - 1. << 708 smear.setY(2. * G4UniformRand() - 1. << 709 smear.setZ(2. * G4UniformRand() - 1. << 710 } while(smear.mag2() > 1.0); << 711 facetNormal = normal + (1. - polish) * << 712 } while(momentum * facetNormal >= 0.0); << 713 facetNormal = facetNormal.unit(); << 714 } << 715 else << 716 { << 717 facetNormal = normal; << 718 } << 719 } << 720 return facetNormal; << 721 } << 722 237 723 //....oooOO0OOooo........oooOO0OOooo........oo << 238 if (valid) { 724 void G4OpBoundaryProcess::DielectricMetal() << 239 theGlobalNormal = -theGlobalNormal; 725 { << 726 G4int n = 0; << 727 G4double rand; << 728 G4ThreeVector A_trans; << 729 << 730 do << 731 { << 732 ++n; << 733 rand = G4UniformRand(); << 734 if(rand > fReflectivity && n == 1) << 735 { << 736 if(rand > fReflectivity + fTransmittance << 737 { << 738 DoAbsorption(); << 739 } << 740 else << 741 { << 742 fStatus = Transmission; << 743 fNewMomentum = fOldMomentum; << 744 fNewPolarization = fOldPolarization; << 745 } << 746 break; << 747 } << 748 else << 749 { << 750 if(fRealRIndexMPV && fImagRIndexMPV) << 751 { << 752 if(n > 1) << 753 { << 754 CalculateReflectivity(); << 755 if(!G4BooleanRand(fReflectivity)) << 756 { << 757 DoAbsorption(); << 758 break; << 759 } << 760 } 240 } 761 } << 241 else 762 if(fModel == glisur || fFinish == polish << 763 { << 764 DoReflection(); << 765 } << 766 else << 767 { << 768 if(n == 1) << 769 ChooseReflection(); << 770 if(fStatus == LambertianReflection) << 771 { 242 { 772 DoReflection(); << 243 G4ExceptionDescription ed; >> 244 ed << " G4OpBoundaryProcess/PostStepDoIt(): " >> 245 << " The Navigator reports that it returned an invalid normal" >> 246 << G4endl; >> 247 G4Exception("G4OpBoundaryProcess::PostStepDoIt", "OpBoun01", >> 248 EventMustBeAborted,ed, >> 249 "Invalid Surface Normal - Geometry must return valid surface normal"); 773 } 250 } 774 else if(fStatus == BackScattering) << 251 775 { << 252 if (OldMomentum * theGlobalNormal > 0.0) { 776 fNewMomentum = -fOldMomentum; << 253 #ifdef G4OPTICAL_DEBUG 777 fNewPolarization = -fOldPolarization << 254 G4ExceptionDescription ed; >> 255 ed << " G4OpBoundaryProcess/PostStepDoIt(): " >> 256 << " theGlobalNormal points in a wrong direction. " >> 257 << G4endl; >> 258 ed << " The momentum of the photon arriving at interface (oldMomentum)" >> 259 << " must exit the volume cross in the step. " << G4endl; >> 260 ed << " So it MUST have dot < 0 with the normal that Exits the new volume (globalNormal)." << G4endl; >> 261 ed << " >> The dot product of oldMomentum and global Normal is " << OldMomentum*theGlobalNormal << G4endl; >> 262 ed << " Old Momentum (during step) = " << OldMomentum << G4endl; >> 263 ed << " Global Normal (Exiting New Vol) = " << theGlobalNormal << G4endl; >> 264 ed << G4endl; >> 265 G4Exception("G4OpBoundaryProcess::PostStepDoIt", "OpBoun02", >> 266 EventMustBeAborted, // Or JustWarning to see if it happens repeatedbly on one ray >> 267 ed, >> 268 "Invalid Surface Normal - Geometry must return valid surface normal pointing in the right direction"); >> 269 #else >> 270 theGlobalNormal = -theGlobalNormal; >> 271 #endif 778 } 272 } 779 else << 780 { << 781 if(fStatus == LobeReflection) << 782 { << 783 if(!fRealRIndexMPV || !fImagRIndex << 784 { << 785 fFacetNormal = GetFacetNormal(fO << 786 } << 787 // else << 788 // case of complex rindex needs t << 789 } << 790 fNewMomentum = << 791 fOldMomentum - 2. * fOldMomentum * << 792 273 793 if(f_iTE > 0 && f_iTM > 0) << 274 G4MaterialPropertiesTable* aMaterialPropertiesTable; 794 { << 275 G4MaterialPropertyVector* Rindex; 795 fNewPolarization = << 276 796 -fOldPolarization + << 277 aMaterialPropertiesTable = Material1->GetMaterialPropertiesTable(); 797 (2. * fOldPolarization * fFacetN << 278 if (aMaterialPropertiesTable) { 798 } << 279 Rindex = aMaterialPropertiesTable->GetProperty("RINDEX"); 799 else if(f_iTE > 0) << 280 } 800 { << 281 else { 801 A_trans = (fSint1 > 0.0) ? fOldMom << 282 theStatus = NoRINDEX; 802 : fOldPol << 283 if ( verboseLevel > 0) BoundaryProcessVerbose(); 803 fNewPolarization = -A_trans; << 284 aParticleChange.ProposeLocalEnergyDeposit(thePhotonMomentum); >> 285 aParticleChange.ProposeTrackStatus(fStopAndKill); >> 286 return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep); >> 287 } >> 288 >> 289 if (Rindex) { >> 290 Rindex1 = Rindex->Value(thePhotonMomentum); >> 291 } >> 292 else { >> 293 theStatus = NoRINDEX; >> 294 if ( verboseLevel > 0) BoundaryProcessVerbose(); >> 295 aParticleChange.ProposeLocalEnergyDeposit(thePhotonMomentum); >> 296 aParticleChange.ProposeTrackStatus(fStopAndKill); >> 297 return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep); >> 298 } >> 299 >> 300 theReflectivity = 1.; >> 301 theEfficiency = 0.; >> 302 theTransmittance = 0.; >> 303 >> 304 theSurfaceRoughness = 0.; >> 305 >> 306 theModel = glisur; >> 307 theFinish = polished; >> 308 >> 309 G4SurfaceType type = dielectric_dielectric; >> 310 >> 311 Rindex = NULL; >> 312 OpticalSurface = NULL; >> 313 >> 314 G4LogicalSurface* Surface = NULL; >> 315 >> 316 Surface = G4LogicalBorderSurface::GetSurface(thePrePV, thePostPV); >> 317 >> 318 if (Surface == NULL){ >> 319 G4bool enteredDaughter= (thePostPV->GetMotherLogical() == >> 320 thePrePV ->GetLogicalVolume()); >> 321 if(enteredDaughter){ >> 322 Surface = >> 323 G4LogicalSkinSurface::GetSurface(thePostPV->GetLogicalVolume()); >> 324 if(Surface == NULL) >> 325 Surface = >> 326 G4LogicalSkinSurface::GetSurface(thePrePV->GetLogicalVolume()); >> 327 } >> 328 else { >> 329 Surface = >> 330 G4LogicalSkinSurface::GetSurface(thePrePV->GetLogicalVolume()); >> 331 if(Surface == NULL) >> 332 Surface = >> 333 G4LogicalSkinSurface::GetSurface(thePostPV->GetLogicalVolume()); >> 334 } >> 335 } >> 336 >> 337 if (Surface) OpticalSurface = >> 338 dynamic_cast <G4OpticalSurface*> (Surface->GetSurfaceProperty()); >> 339 >> 340 if (OpticalSurface) { >> 341 >> 342 type = OpticalSurface->GetType(); >> 343 theModel = OpticalSurface->GetModel(); >> 344 theFinish = OpticalSurface->GetFinish(); >> 345 >> 346 aMaterialPropertiesTable = OpticalSurface-> >> 347 GetMaterialPropertiesTable(); >> 348 >> 349 if (aMaterialPropertiesTable) { >> 350 >> 351 if (theFinish == polishedbackpainted || >> 352 theFinish == groundbackpainted ) { >> 353 Rindex = aMaterialPropertiesTable->GetProperty("RINDEX"); >> 354 if (Rindex) { >> 355 Rindex2 = Rindex->Value(thePhotonMomentum); >> 356 } >> 357 else { >> 358 theStatus = NoRINDEX; >> 359 if ( verboseLevel > 0) BoundaryProcessVerbose(); >> 360 aParticleChange.ProposeLocalEnergyDeposit(thePhotonMomentum); >> 361 aParticleChange.ProposeTrackStatus(fStopAndKill); >> 362 return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep); >> 363 } >> 364 } >> 365 >> 366 PropertyPointer = >> 367 aMaterialPropertiesTable->GetProperty("REFLECTIVITY"); >> 368 PropertyPointer1 = >> 369 aMaterialPropertiesTable->GetProperty("REALRINDEX"); >> 370 PropertyPointer2 = >> 371 aMaterialPropertiesTable->GetProperty("IMAGINARYRINDEX"); >> 372 >> 373 iTE = 1; >> 374 iTM = 1; >> 375 >> 376 if (PropertyPointer) { >> 377 >> 378 theReflectivity = >> 379 PropertyPointer->Value(thePhotonMomentum); >> 380 >> 381 } else if (PropertyPointer1 && PropertyPointer2) { >> 382 >> 383 CalculateReflectivity(); >> 384 >> 385 } >> 386 >> 387 PropertyPointer = >> 388 aMaterialPropertiesTable->GetProperty("EFFICIENCY"); >> 389 if (PropertyPointer) { >> 390 theEfficiency = >> 391 PropertyPointer->Value(thePhotonMomentum); >> 392 } >> 393 >> 394 PropertyPointer = >> 395 aMaterialPropertiesTable->GetProperty("TRANSMITTANCE"); >> 396 if (PropertyPointer) { >> 397 theTransmittance = >> 398 PropertyPointer->Value(thePhotonMomentum); >> 399 } >> 400 >> 401 if (aMaterialPropertiesTable-> >> 402 ConstPropertyExists("SURFACEROUGHNESS")) >> 403 theSurfaceRoughness = aMaterialPropertiesTable-> >> 404 GetConstProperty("SURFACEROUGHNESS"); >> 405 >> 406 if ( theModel == unified ) { >> 407 PropertyPointer = >> 408 aMaterialPropertiesTable->GetProperty("SPECULARLOBECONSTANT"); >> 409 if (PropertyPointer) { >> 410 prob_sl = >> 411 PropertyPointer->Value(thePhotonMomentum); >> 412 } else { >> 413 prob_sl = 0.0; >> 414 } >> 415 >> 416 PropertyPointer = >> 417 aMaterialPropertiesTable->GetProperty("SPECULARSPIKECONSTANT"); >> 418 if (PropertyPointer) { >> 419 prob_ss = >> 420 PropertyPointer->Value(thePhotonMomentum); >> 421 } else { >> 422 prob_ss = 0.0; >> 423 } >> 424 >> 425 PropertyPointer = >> 426 aMaterialPropertiesTable->GetProperty("BACKSCATTERCONSTANT"); >> 427 if (PropertyPointer) { >> 428 prob_bs = >> 429 PropertyPointer->Value(thePhotonMomentum); >> 430 } else { >> 431 prob_bs = 0.0; >> 432 } >> 433 } >> 434 } >> 435 else if (theFinish == polishedbackpainted || >> 436 theFinish == groundbackpainted ) { >> 437 aParticleChange.ProposeLocalEnergyDeposit(thePhotonMomentum); >> 438 aParticleChange.ProposeTrackStatus(fStopAndKill); >> 439 return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep); >> 440 } >> 441 } >> 442 >> 443 if (type == dielectric_dielectric ) { >> 444 if (theFinish == polished || theFinish == ground ) { >> 445 >> 446 if (Material1 == Material2){ >> 447 theStatus = SameMaterial; >> 448 if ( verboseLevel > 0) BoundaryProcessVerbose(); >> 449 return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep); >> 450 } >> 451 aMaterialPropertiesTable = >> 452 Material2->GetMaterialPropertiesTable(); >> 453 if (aMaterialPropertiesTable) >> 454 Rindex = aMaterialPropertiesTable->GetProperty("RINDEX"); >> 455 if (Rindex) { >> 456 Rindex2 = Rindex->Value(thePhotonMomentum); >> 457 } >> 458 else { >> 459 theStatus = NoRINDEX; >> 460 if ( verboseLevel > 0) BoundaryProcessVerbose(); >> 461 aParticleChange.ProposeLocalEnergyDeposit(thePhotonMomentum); >> 462 aParticleChange.ProposeTrackStatus(fStopAndKill); >> 463 return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep); >> 464 } >> 465 } >> 466 } >> 467 >> 468 if (type == dielectric_metal) { >> 469 >> 470 DielectricMetal(); >> 471 >> 472 } >> 473 else if (type == dielectric_LUT) { >> 474 >> 475 DielectricLUT(); >> 476 >> 477 } >> 478 else if (type == dielectric_dichroic) { >> 479 >> 480 DielectricDichroic(); >> 481 >> 482 } >> 483 else if (type == dielectric_dielectric) { >> 484 >> 485 if ( theFinish == polishedbackpainted || >> 486 theFinish == groundbackpainted ) { >> 487 DielectricDielectric(); 804 } 488 } 805 else if(f_iTM > 0) << 489 else { 806 { << 490 G4double rand = G4UniformRand(); 807 fNewPolarization = << 491 if ( rand > theReflectivity ) { 808 -fNewMomentum.cross(A_trans).uni << 492 if (rand > theReflectivity + theTransmittance) { >> 493 DoAbsorption(); >> 494 } else { >> 495 theStatus = Transmission; >> 496 NewMomentum = OldMomentum; >> 497 NewPolarization = OldPolarization; >> 498 } >> 499 } >> 500 else { >> 501 if ( theFinish == polishedfrontpainted ) { >> 502 DoReflection(); >> 503 } >> 504 else if ( theFinish == groundfrontpainted ) { >> 505 theStatus = LambertianReflection; >> 506 DoReflection(); >> 507 } >> 508 else { >> 509 DielectricDielectric(); >> 510 } >> 511 } 809 } 512 } 810 } 513 } 811 } << 514 else { 812 fOldMomentum = fNewMomentum; << 515 813 fOldPolarization = fNewPolarization; << 516 G4cerr << " Error: G4BoundaryProcess: illegal boundary type " << G4endl; 814 } << 517 return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep); 815 // Loop checking, 13-Aug-2015, Peter Gumpl << 518 816 } while(fNewMomentum * fGlobalNormal < 0.0); << 519 } >> 520 >> 521 NewMomentum = NewMomentum.unit(); >> 522 NewPolarization = NewPolarization.unit(); >> 523 >> 524 if ( verboseLevel > 0) { >> 525 G4cout << " New Momentum Direction: " << NewMomentum << G4endl; >> 526 G4cout << " New Polarization: " << NewPolarization << G4endl; >> 527 BoundaryProcessVerbose(); >> 528 } >> 529 >> 530 aParticleChange.ProposeMomentumDirection(NewMomentum); >> 531 aParticleChange.ProposePolarization(NewPolarization); >> 532 >> 533 if ( theStatus == FresnelRefraction || theStatus == Transmission ) { >> 534 G4MaterialPropertyVector* groupvel = >> 535 Material2->GetMaterialPropertiesTable()->GetProperty("GROUPVEL"); >> 536 G4double finalVelocity = groupvel->Value(thePhotonMomentum); >> 537 aParticleChange.ProposeVelocity(finalVelocity); >> 538 } >> 539 >> 540 if ( theStatus == Detection ) InvokeSD(pStep); >> 541 >> 542 return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep); 817 } 543 } 818 544 819 //....oooOO0OOooo........oooOO0OOooo........oo << 545 void G4OpBoundaryProcess::BoundaryProcessVerbose() const 820 void G4OpBoundaryProcess::DielectricLUT() << 821 { 546 { 822 G4int thetaIndex, phiIndex; << 547 if ( theStatus == Undefined ) 823 G4double angularDistVal, thetaRad, phiRad; << 548 G4cout << " *** Undefined *** " << G4endl; 824 G4ThreeVector perpVectorTheta, perpVectorPhi << 549 if ( theStatus == Transmission ) 825 << 550 G4cout << " *** Transmission *** " << G4endl; 826 fStatus = G4OpBoundaryProcessStatus( << 551 if ( theStatus == FresnelRefraction ) 827 G4int(fFinish) + (G4int(NoRINDEX) - G4int( << 552 G4cout << " *** FresnelRefraction *** " << G4endl; 828 << 553 if ( theStatus == FresnelReflection ) 829 G4int thetaIndexMax = fOpticalSurface->GetTh << 554 G4cout << " *** FresnelReflection *** " << G4endl; 830 G4int phiIndexMax = fOpticalSurface->GetPh << 555 if ( theStatus == TotalInternalReflection ) 831 << 556 G4cout << " *** TotalInternalReflection *** " << G4endl; 832 G4double rand; << 557 if ( theStatus == LambertianReflection ) 833 << 558 G4cout << " *** LambertianReflection *** " << G4endl; 834 do << 559 if ( theStatus == LobeReflection ) 835 { << 560 G4cout << " *** LobeReflection *** " << G4endl; 836 rand = G4UniformRand(); << 561 if ( theStatus == SpikeReflection ) 837 if(rand > fReflectivity) << 562 G4cout << " *** SpikeReflection *** " << G4endl; 838 { << 563 if ( theStatus == BackScattering ) 839 if(rand > fReflectivity + fTransmittance << 564 G4cout << " *** BackScattering *** " << G4endl; 840 { << 565 if ( theStatus == PolishedLumirrorAirReflection ) 841 DoAbsorption(); << 566 G4cout << " *** PolishedLumirrorAirReflection *** " << G4endl; 842 } << 567 if ( theStatus == PolishedLumirrorGlueReflection ) 843 else << 568 G4cout << " *** PolishedLumirrorGlueReflection *** " << G4endl; 844 { << 569 if ( theStatus == PolishedAirReflection ) 845 fStatus = Transmission; << 570 G4cout << " *** PolishedAirReflection *** " << G4endl; 846 fNewMomentum = fOldMomentum; << 571 if ( theStatus == PolishedTeflonAirReflection ) 847 fNewPolarization = fOldPolarization; << 572 G4cout << " *** PolishedTeflonAirReflection *** " << G4endl; 848 } << 573 if ( theStatus == PolishedTiOAirReflection ) 849 break; << 574 G4cout << " *** PolishedTiOAirReflection *** " << G4endl; 850 } << 575 if ( theStatus == PolishedTyvekAirReflection ) 851 else << 576 G4cout << " *** PolishedTyvekAirReflection *** " << G4endl; 852 { << 577 if ( theStatus == PolishedVM2000AirReflection ) 853 // Calculate Angle between Normal and Ph << 578 G4cout << " *** PolishedVM2000AirReflection *** " << G4endl; 854 G4double anglePhotonToNormal = fOldMomen << 579 if ( theStatus == PolishedVM2000GlueReflection ) 855 // Round to closest integer: LBNL model << 580 G4cout << " *** PolishedVM2000GlueReflection *** " << G4endl; 856 G4int angleIncident = (G4int)std::lrint( << 581 if ( theStatus == EtchedLumirrorAirReflection ) 857 << 582 G4cout << " *** EtchedLumirrorAirReflection *** " << G4endl; 858 // Take random angles THETA and PHI, << 583 if ( theStatus == EtchedLumirrorGlueReflection ) 859 // and see if below Probability - if not << 584 G4cout << " *** EtchedLumirrorGlueReflection *** " << G4endl; 860 do << 585 if ( theStatus == EtchedAirReflection ) 861 { << 586 G4cout << " *** EtchedAirReflection *** " << G4endl; 862 thetaIndex = (G4int)G4RandFlat::shootI << 587 if ( theStatus == EtchedTeflonAirReflection ) 863 phiIndex = (G4int)G4RandFlat::shootI << 588 G4cout << " *** EtchedTeflonAirReflection *** " << G4endl; 864 // Find probability with the new indec << 589 if ( theStatus == EtchedTiOAirReflection ) 865 angularDistVal = fOpticalSurface->GetA << 590 G4cout << " *** EtchedTiOAirReflection *** " << G4endl; 866 angleIncident, thetaIndex, phiIndex) << 591 if ( theStatus == EtchedTyvekAirReflection ) 867 // Loop checking, 13-Aug-2015, Peter G << 592 G4cout << " *** EtchedTyvekAirReflection *** " << G4endl; 868 } while(!G4BooleanRand(angularDistVal)); << 593 if ( theStatus == EtchedVM2000AirReflection ) 869 << 594 G4cout << " *** EtchedVM2000AirReflection *** " << G4endl; 870 thetaRad = G4double(-90 + 4 * thetaIndex << 595 if ( theStatus == EtchedVM2000GlueReflection ) 871 phiRad = G4double(-90 + 5 * phiIndex) << 596 G4cout << " *** EtchedVM2000GlueReflection *** " << G4endl; 872 // Rotate Photon Momentum in Theta, then << 597 if ( theStatus == GroundLumirrorAirReflection ) 873 fNewMomentum = -fOldMomentum; << 598 G4cout << " *** GroundLumirrorAirReflection *** " << G4endl; 874 << 599 if ( theStatus == GroundLumirrorGlueReflection ) 875 perpVectorTheta = fNewMomentum.cross(fGl << 600 G4cout << " *** GroundLumirrorGlueReflection *** " << G4endl; 876 if(perpVectorTheta.mag() < fCarTolerance << 601 if ( theStatus == GroundAirReflection ) 877 { << 602 G4cout << " *** GroundAirReflection *** " << G4endl; 878 perpVectorTheta = fNewMomentum.orthogo << 603 if ( theStatus == GroundTeflonAirReflection ) 879 } << 604 G4cout << " *** GroundTeflonAirReflection *** " << G4endl; 880 fNewMomentum = << 605 if ( theStatus == GroundTiOAirReflection ) 881 fNewMomentum.rotate(anglePhotonToNorma << 606 G4cout << " *** GroundTiOAirReflection *** " << G4endl; 882 perpVectorPhi = perpVectorTheta.cross(fN << 607 if ( theStatus == GroundTyvekAirReflection ) 883 fNewMomentum = fNewMomentum.rotate(-phi << 608 G4cout << " *** GroundTyvekAirReflection *** " << G4endl; 884 << 609 if ( theStatus == GroundVM2000AirReflection ) 885 // Rotate Polarization too: << 610 G4cout << " *** GroundVM2000AirReflection *** " << G4endl; 886 fFacetNormal = (fNewMomentum - fOldM << 611 if ( theStatus == GroundVM2000GlueReflection ) 887 fNewPolarization = -fOldPolarization + << 612 G4cout << " *** GroundVM2000GlueReflection *** " << G4endl; 888 (2. * fOldPolarizatio << 613 if ( theStatus == Absorption ) 889 } << 614 G4cout << " *** Absorption *** " << G4endl; 890 // Loop checking, 13-Aug-2015, Peter Gumpl << 615 if ( theStatus == Detection ) 891 } while(fNewMomentum * fGlobalNormal <= 0.0) << 616 G4cout << " *** Detection *** " << G4endl; >> 617 if ( theStatus == NotAtBoundary ) >> 618 G4cout << " *** NotAtBoundary *** " << G4endl; >> 619 if ( theStatus == SameMaterial ) >> 620 G4cout << " *** SameMaterial *** " << G4endl; >> 621 if ( theStatus == StepTooSmall ) >> 622 G4cout << " *** StepTooSmall *** " << G4endl; >> 623 if ( theStatus == NoRINDEX ) >> 624 G4cout << " *** NoRINDEX *** " << G4endl; >> 625 if ( theStatus == Dichroic ) >> 626 G4cout << " *** Dichroic Transmission *** " << G4endl; 892 } 627 } 893 628 894 //....oooOO0OOooo........oooOO0OOooo........oo << 629 G4ThreeVector 895 void G4OpBoundaryProcess::DielectricLUTDAVIS() << 630 G4OpBoundaryProcess::GetFacetNormal(const G4ThreeVector& Momentum, >> 631 const G4ThreeVector& Normal ) const 896 { 632 { 897 G4int angindex, random, angleIncident; << 633 G4ThreeVector FacetNormal; 898 G4double reflectivityValue, elevation, azimu << 899 G4double anglePhotonToNormal; << 900 << 901 G4int lutbin = fOpticalSurface->GetLUTbins( << 902 G4double rand = G4UniformRand(); << 903 << 904 G4double sinEl; << 905 G4ThreeVector u, vNorm, w; << 906 << 907 do << 908 { << 909 anglePhotonToNormal = fOldMomentum.angle(- << 910 << 911 // Davis model has 90 reflection bins: rou << 912 // don't allow angleIncident to be 90 for << 913 angleIncident = std::min( << 914 static_cast<G4int>(std::floor(anglePhoto << 915 reflectivityValue = fOpticalSurface->GetRe << 916 << 917 if(rand > reflectivityValue) << 918 { << 919 if(fEfficiency > 0.) << 920 { << 921 DoAbsorption(); << 922 break; << 923 } << 924 else << 925 { << 926 fStatus = Transmission; << 927 634 928 if(angleIncident <= 0.01) << 635 if (theModel == unified || theModel == LUT) { 929 { << 930 fNewMomentum = fOldMomentum; << 931 break; << 932 } << 933 636 934 do << 637 /* This function code alpha to a random value taken from the 935 { << 638 distribution p(alpha) = g(alpha; 0, sigma_alpha)*std::sin(alpha), 936 random = (G4int)G4RandFlat::shootInt << 639 for alpha > 0 and alpha < 90, where g(alpha; 0, sigma_alpha) 937 angindex = << 640 is a gaussian distribution with mean 0 and standard deviation 938 (((random * 2) - 1)) + angleIncide << 641 sigma_alpha. */ 939 << 642 940 azimuth = << 643 G4double alpha; 941 fOpticalSurface->GetAngularDistrib << 644 942 elevation = fOpticalSurface->GetAngu << 645 G4double sigma_alpha = 0.0; 943 } while(elevation == 0. && azimuth == << 646 if (OpticalSurface) sigma_alpha = OpticalSurface->GetSigmaAlpha(); 944 << 647 945 sinEl = std::sin(elevation); << 648 if (sigma_alpha == 0.0) return FacetNormal = Normal; 946 vNorm = (fGlobalNormal.cross(fOldMomen << 649 947 u = vNorm.cross(fGlobalNormal) * ( << 650 G4double f_max = std::min(1.0,4.*sigma_alpha); 948 vNorm *= (sinEl * std::sin(azimuth)); << 651 949 // fGlobalNormal shouldn't be modified << 652 G4double phi, SinAlpha, CosAlpha, SinPhi, CosPhi, unit_x, unit_y, unit_z; 950 w = (fGlobalNormal *= std:: << 653 G4ThreeVector tmpNormal; 951 fNewMomentum = u + vNorm + w; << 654 952 << 655 do { 953 // Rotate Polarization too: << 656 do { 954 fFacetNormal = (fNewMomentum - fOl << 657 alpha = G4RandGauss::shoot(0.0,sigma_alpha); 955 fNewPolarization = -fOldPolarization + << 658 // Loop checking, 13-Aug-2015, Peter Gumplinger 956 << 659 } while (G4UniformRand()*f_max > std::sin(alpha) || alpha >= halfpi ); 957 } << 660 958 } << 661 phi = G4UniformRand()*twopi; 959 else << 662 960 { << 663 SinAlpha = std::sin(alpha); 961 fStatus = LobeReflection; << 664 CosAlpha = std::cos(alpha); 962 << 665 SinPhi = std::sin(phi); 963 if(angleIncident == 0) << 666 CosPhi = std::cos(phi); 964 { << 667 965 fNewMomentum = -fOldMomentum; << 668 unit_x = SinAlpha * CosPhi; 966 break; << 669 unit_y = SinAlpha * SinPhi; 967 } << 670 unit_z = CosAlpha; 968 << 671 969 do << 672 FacetNormal.setX(unit_x); 970 { << 673 FacetNormal.setY(unit_y); 971 random = (G4int)G4RandFlat::shootInt << 674 FacetNormal.setZ(unit_z); 972 angindex = (((random * 2) - 1)) + (ang << 675 973 << 676 tmpNormal = Normal; 974 azimuth = fOpticalSurface->GetAngularD << 677 975 elevation = fOpticalSurface->GetAngula << 678 FacetNormal.rotateUz(tmpNormal); 976 } while(elevation == 0. && azimuth == 0. << 679 // Loop checking, 13-Aug-2015, Peter Gumplinger 977 << 680 } while (Momentum * FacetNormal >= 0.0); 978 sinEl = std::sin(elevation); << 681 } 979 vNorm = (fGlobalNormal.cross(fOldMomentu << 682 else { 980 u = vNorm.cross(fGlobalNormal) * (si << 683 981 vNorm *= (sinEl * std::sin(azimuth)); << 684 G4double polish = 1.0; 982 // fGlobalNormal shouldn't be modified h << 685 if (OpticalSurface) polish = OpticalSurface->GetPolish(); 983 w = (fGlobalNormal *= std::cos(elevation << 686 984 << 687 if (polish < 1.0) { 985 fNewMomentum = u + vNorm + w; << 688 do { 986 << 689 G4ThreeVector smear; 987 // Rotate Polarization too: (needs revis << 690 do { 988 fNewPolarization = fOldPolarization; << 691 smear.setX(2.*G4UniformRand()-1.0); 989 } << 692 smear.setY(2.*G4UniformRand()-1.0); 990 } while(fNewMomentum * fGlobalNormal <= 0.0) << 693 smear.setZ(2.*G4UniformRand()-1.0); >> 694 // Loop checking, 13-Aug-2015, Peter Gumplinger >> 695 } while (smear.mag()>1.0); >> 696 smear = (1.-polish) * smear; >> 697 FacetNormal = Normal + smear; >> 698 // Loop checking, 13-Aug-2015, Peter Gumplinger >> 699 } while (Momentum * FacetNormal >= 0.0); >> 700 FacetNormal = FacetNormal.unit(); >> 701 } >> 702 else { >> 703 FacetNormal = Normal; >> 704 } >> 705 } >> 706 return FacetNormal; 991 } 707 } 992 708 993 //....oooOO0OOooo........oooOO0OOooo........oo << 709 void G4OpBoundaryProcess::DielectricMetal() 994 void G4OpBoundaryProcess::DielectricDichroic() << 995 { 710 { 996 // Calculate Angle between Normal and Photon << 711 G4int n = 0; 997 G4double anglePhotonToNormal = fOldMomentum. << 712 G4double rand, PdotN, EdotN; >> 713 G4ThreeVector A_trans, A_paral; >> 714 >> 715 do { >> 716 >> 717 n++; >> 718 >> 719 rand = G4UniformRand(); >> 720 if ( rand > theReflectivity && n == 1 ) { >> 721 if (rand > theReflectivity + theTransmittance) { >> 722 DoAbsorption(); >> 723 } else { >> 724 theStatus = Transmission; >> 725 NewMomentum = OldMomentum; >> 726 NewPolarization = OldPolarization; >> 727 } >> 728 break; >> 729 } >> 730 else { >> 731 >> 732 if (PropertyPointer1 && PropertyPointer2) { >> 733 if ( n > 1 ) { >> 734 CalculateReflectivity(); >> 735 if ( !G4BooleanRand(theReflectivity) ) { >> 736 DoAbsorption(); >> 737 break; >> 738 } >> 739 } >> 740 } >> 741 >> 742 if ( theModel == glisur || theFinish == polished ) { >> 743 >> 744 DoReflection(); >> 745 >> 746 } else { >> 747 >> 748 if ( n == 1 ) ChooseReflection(); >> 749 >> 750 if ( theStatus == LambertianReflection ) { >> 751 DoReflection(); >> 752 } >> 753 else if ( theStatus == BackScattering ) { >> 754 NewMomentum = -OldMomentum; >> 755 NewPolarization = -OldPolarization; >> 756 } >> 757 else { >> 758 >> 759 if(theStatus==LobeReflection){ >> 760 if ( PropertyPointer1 && PropertyPointer2 ){ >> 761 } else { >> 762 theFacetNormal = >> 763 GetFacetNormal(OldMomentum,theGlobalNormal); >> 764 } >> 765 } >> 766 >> 767 PdotN = OldMomentum * theFacetNormal; >> 768 NewMomentum = OldMomentum - (2.*PdotN)*theFacetNormal; >> 769 EdotN = OldPolarization * theFacetNormal; >> 770 >> 771 if (sint1 > 0.0 ) { >> 772 A_trans = OldMomentum.cross(theFacetNormal); >> 773 A_trans = A_trans.unit(); >> 774 } else { >> 775 A_trans = OldPolarization; >> 776 } >> 777 A_paral = NewMomentum.cross(A_trans); >> 778 A_paral = A_paral.unit(); >> 779 >> 780 if(iTE>0&&iTM>0) { >> 781 NewPolarization = >> 782 -OldPolarization + (2.*EdotN)*theFacetNormal; >> 783 } else if (iTE>0) { >> 784 NewPolarization = -A_trans; >> 785 } else if (iTM>0) { >> 786 NewPolarization = -A_paral; >> 787 } 998 788 999 // Round it to closest integer << 789 } 1000 G4double angleIncident = std::floor(180. / << 1001 790 1002 if(!fDichroicVector) << 791 } 1003 { << 1004 if(fOpticalSurface) << 1005 fDichroicVector = fOpticalSurface->GetD << 1006 } << 1007 792 1008 if(fDichroicVector) << 793 OldMomentum = NewMomentum; 1009 { << 794 OldPolarization = NewPolarization; 1010 G4double wavelength = h_Planck * c_light << 795 1011 fTransmittance = fDichroicVector->Va << 796 } 1012 i << 1013 perCent; << 1014 // G4cout << "wavelength: " << std::flo << 1015 // << "nm" << << 1016 // G4cout << "Incident angle: " << angl << 1017 // G4cout << "Transmittance: " << 1018 // << std::floor(fTransmittance/ << 1019 } << 1020 else << 1021 { << 1022 G4ExceptionDescription ed; << 1023 ed << " G4OpBoundaryProcess/DielectricDic << 1024 << " The dichroic surface has no G4Phy << 1025 G4Exception("G4OpBoundaryProcess::Dielect << 1026 FatalException, ed, << 1027 "A dichroic surface must have << 1028 } << 1029 797 1030 if(!G4BooleanRand(fTransmittance)) << 1031 { // Not transmitted, so reflect << 1032 if(fModel == glisur || fFinish == polishe << 1033 { << 1034 DoReflection(); << 1035 } << 1036 else << 1037 { << 1038 ChooseReflection(); << 1039 if(fStatus == LambertianReflection) << 1040 { << 1041 DoReflection(); << 1042 } << 1043 else if(fStatus == BackScattering) << 1044 { << 1045 fNewMomentum = -fOldMomentum; << 1046 fNewPolarization = -fOldPolarization; << 1047 } << 1048 else << 1049 { << 1050 G4double PdotN, EdotN; << 1051 do << 1052 { << 1053 if(fStatus == LobeReflection) << 1054 { << 1055 fFacetNormal = GetFacetNormal(fOl << 1056 } << 1057 PdotN = fOldMomentum * fFace << 1058 fNewMomentum = fOldMomentum - (2. * << 1059 // Loop checking, 13-Aug-2015, Pete 798 // Loop checking, 13-Aug-2015, Peter Gumplinger 1060 } while(fNewMomentum * fGlobalNormal << 799 } while (NewMomentum * theGlobalNormal < 0.0); >> 800 } 1061 801 1062 EdotN = fOldPolarization * << 802 void G4OpBoundaryProcess::DielectricLUT() 1063 fNewPolarization = -fOldPolarization << 803 { 1064 } << 804 G4int thetaIndex, phiIndex; 1065 } << 805 G4double AngularDistributionValue, thetaRad, phiRad, EdotN; 1066 } << 806 G4ThreeVector PerpendicularVectorTheta, PerpendicularVectorPhi; 1067 else << 807 1068 { << 808 theStatus = G4OpBoundaryProcessStatus(G4int(theFinish) + 1069 fStatus = Dichroic; << 809 (G4int(NoRINDEX)-G4int(groundbackpainted))); 1070 fNewMomentum = fOldMomentum; << 810 1071 fNewPolarization = fOldPolarization; << 811 G4int thetaIndexMax = OpticalSurface->GetThetaIndexMax(); 1072 } << 812 G4int phiIndexMax = OpticalSurface->GetPhiIndexMax(); >> 813 >> 814 G4double rand; >> 815 >> 816 do { >> 817 rand = G4UniformRand(); >> 818 if ( rand > theReflectivity ) { >> 819 if (rand > theReflectivity + theTransmittance) { >> 820 DoAbsorption(); >> 821 } else { >> 822 theStatus = Transmission; >> 823 NewMomentum = OldMomentum; >> 824 NewPolarization = OldPolarization; >> 825 } >> 826 break; >> 827 } >> 828 else { >> 829 // Calculate Angle between Normal and Photon Momentum >> 830 G4double anglePhotonToNormal = >> 831 OldMomentum.angle(-theGlobalNormal); >> 832 // Round it to closest integer >> 833 G4int angleIncident = G4int(std::floor(180/pi*anglePhotonToNormal+0.5)); >> 834 >> 835 // Take random angles THETA and PHI, >> 836 // and see if below Probability - if not - Redo >> 837 do { >> 838 thetaIndex = G4RandFlat::shootInt(thetaIndexMax-1); >> 839 phiIndex = G4RandFlat::shootInt(phiIndexMax-1); >> 840 // Find probability with the new indeces from LUT >> 841 AngularDistributionValue = OpticalSurface -> >> 842 GetAngularDistributionValue(angleIncident, >> 843 thetaIndex, >> 844 phiIndex); >> 845 // Loop checking, 13-Aug-2015, Peter Gumplinger >> 846 } while ( !G4BooleanRand(AngularDistributionValue) ); >> 847 >> 848 thetaRad = (-90 + 4*thetaIndex)*pi/180; >> 849 phiRad = (-90 + 5*phiIndex)*pi/180; >> 850 // Rotate Photon Momentum in Theta, then in Phi >> 851 NewMomentum = -OldMomentum; >> 852 >> 853 PerpendicularVectorTheta = NewMomentum.cross(theGlobalNormal); >> 854 if (PerpendicularVectorTheta.mag() < kCarTolerance ) >> 855 PerpendicularVectorTheta = NewMomentum.orthogonal(); >> 856 NewMomentum = >> 857 NewMomentum.rotate(anglePhotonToNormal-thetaRad, >> 858 PerpendicularVectorTheta); >> 859 PerpendicularVectorPhi = >> 860 PerpendicularVectorTheta.cross(NewMomentum); >> 861 NewMomentum = NewMomentum.rotate(-phiRad,PerpendicularVectorPhi); >> 862 >> 863 // Rotate Polarization too: >> 864 theFacetNormal = (NewMomentum - OldMomentum).unit(); >> 865 EdotN = OldPolarization * theFacetNormal; >> 866 NewPolarization = -OldPolarization + (2.*EdotN)*theFacetNormal; >> 867 } >> 868 // Loop checking, 13-Aug-2015, Peter Gumplinger >> 869 } while (NewMomentum * theGlobalNormal <= 0.0); 1073 } 870 } 1074 871 1075 //....oooOO0OOooo........oooOO0OOooo........o << 872 void G4OpBoundaryProcess::DielectricDichroic() 1076 void G4OpBoundaryProcess::DielectricDielectri << 1077 { 873 { 1078 G4bool inside = false; << 874 // Calculate Angle between Normal and Photon Momentum 1079 G4bool swap = false; << 875 G4double anglePhotonToNormal = OldMomentum.angle(-theGlobalNormal); 1080 876 1081 if(fFinish == polished) << 877 // Round it to closest integer 1082 { << 878 G4double angleIncident = std::floor(180/pi*anglePhotonToNormal+0.5); 1083 fFacetNormal = fGlobalNormal; << 1084 } << 1085 else << 1086 { << 1087 fFacetNormal = GetFacetNormal(fOldMomentu << 1088 } << 1089 G4double cost1 = -fOldMomentum * fFacetNorm << 1090 G4double cost2 = 0.; << 1091 G4double sint2 = 0.; << 1092 << 1093 G4bool surfaceRoughnessCriterionPass = true << 1094 if(fSurfaceRoughness != 0. && fRindex1 > fR << 1095 { << 1096 G4double wavelength = h_Pl << 1097 G4double surfaceRoughnessCriterion = std: << 1098 (4. * pi * fSurfaceRoughness * fRindex1 << 1099 surfaceRoughnessCriterionPass = G4Boolean << 1100 } << 1101 879 1102 leap: << 880 if (!DichroicVector) { >> 881 if (OpticalSurface) DichroicVector = OpticalSurface->GetDichroicVector(); >> 882 } 1103 883 1104 G4bool through = false; << 1105 G4bool done = false; << 1106 884 1107 G4ThreeVector A_trans, A_paral, E1pp, E1pl; << 885 if (DichroicVector) { 1108 G4double E1_perp, E1_parl; << 886 G4double wavelength = h_Planck*c_light/thePhotonMomentum; 1109 G4double s1, s2, E2_perp, E2_parl, E2_total << 887 theTransmittance = 1110 G4double E2_abs, C_parl, C_perp; << 888 DichroicVector->Value(wavelength/nm,angleIncident,idx,idy)*perCent; 1111 G4double alpha; << 889 // G4cout << "wavelength: " << std::floor(wavelength/nm) 1112 << 890 // << "nm" << G4endl; 1113 do << 891 // G4cout << "Incident angle: " << angleIncident << "deg" << G4endl; 1114 { << 892 // G4cout << "Transmittance: " 1115 if(through) << 893 // << std::floor(theTransmittance/perCent) << "%" << G4endl; 1116 { << 894 } else { 1117 swap = !swap; << 895 G4ExceptionDescription ed; 1118 through = false; << 896 ed << " G4OpBoundaryProcess/DielectricDichroic(): " 1119 fGlobalNormal = -fGlobalNormal; << 897 << " The dichroic surface has no G4Physics2DVector" 1120 G4SwapPtr(fMaterial1, fMaterial2); << 898 << G4endl; 1121 G4SwapObj(&fRindex1, &fRindex2); << 899 G4Exception("G4OpBoundaryProcess::DielectricDichroic", "OpBoun03", 1122 } << 900 FatalException,ed, 1123 << 901 "A dichroic surface must have an associated G4Physics2DVector"); 1124 if(fFinish == polished) << 902 } 1125 { << 903 1126 fFacetNormal = fGlobalNormal; << 904 if ( !G4BooleanRand(theTransmittance) ) { // Not transmitted, so reflect 1127 } << 905 1128 else << 906 if ( theModel == glisur || theFinish == polished ) { 1129 { << 907 DoReflection(); 1130 fFacetNormal = GetFacetNormal(fOldMomen << 908 } else { 1131 } << 909 ChooseReflection(); 1132 << 910 if ( theStatus == LambertianReflection ) { 1133 cost1 = -fOldMomentum * fFacetNormal; << 911 DoReflection(); 1134 if(std::abs(cost1) < 1.0 - fCarTolerance) << 912 } else if ( theStatus == BackScattering ) { 1135 { << 913 NewMomentum = -OldMomentum; 1136 fSint1 = std::sqrt(1. - cost1 * cost1); << 914 NewPolarization = -OldPolarization; 1137 sint2 = fSint1 * fRindex1 / fRindex2; << 915 } else { 1138 // this isn't a sine as we might expect << 916 G4double PdotN, EdotN; 1139 } << 917 do { 1140 else << 918 if (theStatus==LobeReflection) 1141 { << 919 theFacetNormal = GetFacetNormal(OldMomentum,theGlobalNormal); 1142 fSint1 = 0.0; << 920 PdotN = OldMomentum * theFacetNormal; 1143 sint2 = 0.0; << 921 NewMomentum = OldMomentum - (2.*PdotN)*theFacetNormal; 1144 } << 922 // Loop checking, 13-Aug-2015, Peter Gumplinger 1145 << 923 } while (NewMomentum * theGlobalNormal <= 0.0); 1146 // TOTAL INTERNAL REFLECTION << 924 EdotN = OldPolarization * theFacetNormal; 1147 if(sint2 >= 1.0) << 925 NewPolarization = -OldPolarization + (2.*EdotN)*theFacetNormal; 1148 { << 926 } 1149 swap = false; << 927 } 1150 << 928 1151 fStatus = TotalInternalReflection; << 929 } else { 1152 if(!surfaceRoughnessCriterionPass) << 930 1153 fStatus = LambertianReflection; << 931 theStatus = Dichroic; 1154 if(fModel == unified && fFinish != poli << 932 NewMomentum = OldMomentum; 1155 ChooseReflection(); << 933 NewPolarization = OldPolarization; 1156 if(fStatus == LambertianReflection) << 1157 { << 1158 DoReflection(); << 1159 } << 1160 else if(fStatus == BackScattering) << 1161 { << 1162 fNewMomentum = -fOldMomentum; << 1163 fNewPolarization = -fOldPolarization; << 1164 } << 1165 else << 1166 { << 1167 fNewMomentum = << 1168 fOldMomentum - 2. * fOldMomentum * << 1169 fNewPolarization = -fOldPolarization << 1170 << 1171 } << 1172 } << 1173 // NOT TIR << 1174 else if(sint2 < 1.0) << 1175 { << 1176 // Calculate amplitude for transmission << 1177 if(cost1 > 0.0) << 1178 { << 1179 cost2 = std::sqrt(1. - sint2 * sint2) << 1180 } << 1181 else << 1182 { << 1183 cost2 = -std::sqrt(1. - sint2 * sint2 << 1184 } << 1185 << 1186 if(fSint1 > 0.0) << 1187 { << 1188 A_trans = (fOldMomentum.cross(fFacetN << 1189 E1_perp = fOldPolarization * A_trans; << 1190 E1pp = E1_perp * A_trans; << 1191 E1pl = fOldPolarization - E1pp; << 1192 E1_parl = E1pl.mag(); << 1193 } << 1194 else << 1195 { << 1196 A_trans = fOldPolarization; << 1197 // Here we Follow Jackson's conventio << 1198 // component = 1 in case of a ray per << 1199 E1_perp = 0.0; << 1200 E1_parl = 1.0; << 1201 } << 1202 << 1203 s1 = fRindex1 * cost1; << 1204 E2_perp = 2. * s1 * E1_perp / (fRindex << 1205 E2_parl = 2. * s1 * E1_parl / (fRindex << 1206 E2_total = E2_perp * E2_perp + E2_parl << 1207 s2 = fRindex2 * cost2 * E2_total; << 1208 << 1209 // D.Sawkey, 24 May 24 << 1210 // Transmittance has already been taken << 1211 // For e.g. specular surfaces, the rati << 1212 // reflection should be given by the ma << 1213 // TRANSMITTANCE << 1214 //if(fTransmittance > 0.) << 1215 // transCoeff = fTransmittance; << 1216 //else if(cost1 != 0.0) << 1217 if(cost1 != 0.0) << 1218 transCoeff = s2 / s1; << 1219 else << 1220 transCoeff = 0.0; << 1221 << 1222 // NOT TIR: REFLECTION << 1223 if(!G4BooleanRand(transCoeff)) << 1224 { << 1225 swap = false; << 1226 fStatus = FresnelReflection; << 1227 << 1228 if(!surfaceRoughnessCriterionPass) << 1229 fStatus = LambertianReflection; << 1230 if(fModel == unified && fFinish != po << 1231 ChooseReflection(); << 1232 if(fStatus == LambertianReflection) << 1233 { << 1234 DoReflection(); << 1235 } << 1236 else if(fStatus == BackScattering) << 1237 { << 1238 fNewMomentum = -fOldMomentum; << 1239 fNewPolarization = -fOldPolarizatio << 1240 } << 1241 else << 1242 { << 1243 fNewMomentum = << 1244 fOldMomentum - 2. * fOldMomentum << 1245 if(fSint1 > 0.0) << 1246 { // incident ray oblique << 1247 E2_parl = fRindex2 * E2_parl / f << 1248 E2_perp = E2_perp - E1_perp; << 1249 E2_total = E2_perp * E2_perp + E2 << 1250 A_paral = (fNewMomentum.cross(A_ << 1251 E2_abs = std::sqrt(E2_total); << 1252 C_parl = E2_parl / E2_abs; << 1253 C_perp = E2_perp / E2_abs; << 1254 934 1255 fNewPolarization = C_parl * A_par << 1256 } << 1257 else << 1258 { // incident ray perpendicular << 1259 if(fRindex2 > fRindex1) << 1260 { << 1261 fNewPolarization = -fOldPolariz << 1262 } << 1263 else << 1264 { << 1265 fNewPolarization = fOldPolariza << 1266 } << 1267 } << 1268 } 935 } 1269 } << 936 } 1270 // NOT TIR: TRANSMISSION << 1271 else << 1272 { << 1273 inside = !inside; << 1274 through = true; << 1275 fStatus = FresnelRefraction; << 1276 << 1277 if(fSint1 > 0.0) << 1278 { // incident ray oblique << 1279 alpha = cost1 - cost2 * (fRi << 1280 fNewMomentum = (fOldMomentum + alph << 1281 A_paral = (fNewMomentum.cross( << 1282 E2_abs = std::sqrt(E2_total); << 1283 C_parl = E2_parl / E2_abs; << 1284 C_perp = E2_perp / E2_abs; << 1285 937 1286 fNewPolarization = C_parl * A_paral << 938 void G4OpBoundaryProcess::DielectricDielectric() 1287 } << 939 { 1288 else << 940 G4bool Inside = false; 1289 { // incident ray perpendicular << 941 G4bool Swap = false; 1290 fNewMomentum = fOldMomentum; << 942 1291 fNewPolarization = fOldPolarization << 943 G4bool SurfaceRoughnessCriterionPass = 1; >> 944 if (theSurfaceRoughness != 0. && Rindex1 > Rindex2) { >> 945 G4double wavelength = h_Planck*c_light/thePhotonMomentum; >> 946 G4double SurfaceRoughnessCriterion = >> 947 std::exp(-std::pow((4*pi*theSurfaceRoughness*Rindex1*cost1/wavelength),2)); >> 948 SurfaceRoughnessCriterionPass = >> 949 G4BooleanRand(SurfaceRoughnessCriterion); 1292 } 950 } 1293 } << 1294 } << 1295 951 1296 fOldMomentum = fNewMomentum.unit(); << 952 leap: 1297 fOldPolarization = fNewPolarization.unit( << 1298 953 1299 if(fStatus == FresnelRefraction) << 954 G4bool Through = false; 1300 { << 955 G4bool Done = false; 1301 done = (fNewMomentum * fGlobalNormal <= << 1302 } << 1303 else << 1304 { << 1305 done = (fNewMomentum * fGlobalNormal >= << 1306 } << 1307 // Loop checking, 13-Aug-2015, Peter Gump << 1308 } while(!done); << 1309 956 1310 if(inside && !swap) << 957 G4double PdotN, EdotN; 1311 { << 1312 if(fFinish == polishedbackpainted || fFin << 1313 { << 1314 G4double rand = G4UniformRand(); << 1315 if(rand > fReflectivity + fTransmittanc << 1316 { << 1317 DoAbsorption(); << 1318 } << 1319 else if(rand > fReflectivity) << 1320 { << 1321 fStatus = Transmission; << 1322 fNewMomentum = fOldMomentum; << 1323 fNewPolarization = fOldPolarization; << 1324 } << 1325 else << 1326 { << 1327 if(fStatus != FresnelRefraction) << 1328 { << 1329 fGlobalNormal = -fGlobalNormal; << 1330 } << 1331 else << 1332 { << 1333 swap = !swap; << 1334 G4SwapPtr(fMaterial1, fMaterial2); << 1335 G4SwapObj(&fRindex1, &fRindex2); << 1336 } << 1337 if(fFinish == groundbackpainted) << 1338 fStatus = LambertianReflection; << 1339 958 1340 DoReflection(); << 959 G4ThreeVector A_trans, A_paral, E1pp, E1pl; >> 960 G4double E1_perp, E1_parl; >> 961 G4double s1, s2, E2_perp, E2_parl, E2_total, TransCoeff; >> 962 G4double E2_abs, C_parl, C_perp; >> 963 G4double alpha; >> 964 >> 965 do { >> 966 >> 967 if (Through) { >> 968 Swap = !Swap; >> 969 Through = false; >> 970 theGlobalNormal = -theGlobalNormal; >> 971 G4SwapPtr(Material1,Material2); >> 972 G4SwapObj(&Rindex1,&Rindex2); >> 973 } >> 974 >> 975 if ( theFinish == polished ) { >> 976 theFacetNormal = theGlobalNormal; >> 977 } >> 978 else { >> 979 theFacetNormal = >> 980 GetFacetNormal(OldMomentum,theGlobalNormal); >> 981 } >> 982 >> 983 PdotN = OldMomentum * theFacetNormal; >> 984 EdotN = OldPolarization * theFacetNormal; >> 985 >> 986 cost1 = - PdotN; >> 987 if (std::abs(cost1) < 1.0-kCarTolerance){ >> 988 sint1 = std::sqrt(1.-cost1*cost1); >> 989 sint2 = sint1*Rindex1/Rindex2; // *** Snell's Law *** >> 990 } >> 991 else { >> 992 sint1 = 0.0; >> 993 sint2 = 0.0; >> 994 } >> 995 >> 996 if (sint2 >= 1.0) { >> 997 >> 998 // Simulate total internal reflection >> 999 >> 1000 if (Swap) Swap = !Swap; >> 1001 >> 1002 theStatus = TotalInternalReflection; >> 1003 >> 1004 if ( !SurfaceRoughnessCriterionPass ) theStatus = >> 1005 LambertianReflection; >> 1006 >> 1007 if ( theModel == unified && theFinish != polished ) >> 1008 ChooseReflection(); >> 1009 >> 1010 if ( theStatus == LambertianReflection ) { >> 1011 DoReflection(); >> 1012 } >> 1013 else if ( theStatus == BackScattering ) { >> 1014 NewMomentum = -OldMomentum; >> 1015 NewPolarization = -OldPolarization; >> 1016 } >> 1017 else { >> 1018 >> 1019 PdotN = OldMomentum * theFacetNormal; >> 1020 NewMomentum = OldMomentum - (2.*PdotN)*theFacetNormal; >> 1021 EdotN = OldPolarization * theFacetNormal; >> 1022 NewPolarization = -OldPolarization + (2.*EdotN)*theFacetNormal; >> 1023 >> 1024 } >> 1025 } >> 1026 else if (sint2 < 1.0) { >> 1027 >> 1028 // Calculate amplitude for transmission (Q = P x N) >> 1029 >> 1030 if (cost1 > 0.0) { >> 1031 cost2 = std::sqrt(1.-sint2*sint2); >> 1032 } >> 1033 else { >> 1034 cost2 = -std::sqrt(1.-sint2*sint2); >> 1035 } >> 1036 >> 1037 if (sint1 > 0.0) { >> 1038 A_trans = OldMomentum.cross(theFacetNormal); >> 1039 A_trans = A_trans.unit(); >> 1040 E1_perp = OldPolarization * A_trans; >> 1041 E1pp = E1_perp * A_trans; >> 1042 E1pl = OldPolarization - E1pp; >> 1043 E1_parl = E1pl.mag(); >> 1044 } >> 1045 else { >> 1046 A_trans = OldPolarization; >> 1047 // Here we Follow Jackson's conventions and we set the >> 1048 // parallel component = 1 in case of a ray perpendicular >> 1049 // to the surface >> 1050 E1_perp = 0.0; >> 1051 E1_parl = 1.0; >> 1052 } >> 1053 >> 1054 s1 = Rindex1*cost1; >> 1055 E2_perp = 2.*s1*E1_perp/(Rindex1*cost1+Rindex2*cost2); >> 1056 E2_parl = 2.*s1*E1_parl/(Rindex2*cost1+Rindex1*cost2); >> 1057 E2_total = E2_perp*E2_perp + E2_parl*E2_parl; >> 1058 s2 = Rindex2*cost2*E2_total; >> 1059 >> 1060 if (theTransmittance > 0) TransCoeff = theTransmittance; >> 1061 else if (cost1 != 0.0) TransCoeff = s2/s1; >> 1062 else TransCoeff = 0.0; >> 1063 >> 1064 if ( !G4BooleanRand(TransCoeff) ) { >> 1065 >> 1066 // Simulate reflection >> 1067 >> 1068 if (Swap) Swap = !Swap; >> 1069 >> 1070 theStatus = FresnelReflection; >> 1071 >> 1072 if ( !SurfaceRoughnessCriterionPass ) theStatus = >> 1073 LambertianReflection; >> 1074 >> 1075 if ( theModel == unified && theFinish != polished ) >> 1076 ChooseReflection(); >> 1077 >> 1078 if ( theStatus == LambertianReflection ) { >> 1079 DoReflection(); >> 1080 } >> 1081 else if ( theStatus == BackScattering ) { >> 1082 NewMomentum = -OldMomentum; >> 1083 NewPolarization = -OldPolarization; >> 1084 } >> 1085 else { >> 1086 >> 1087 PdotN = OldMomentum * theFacetNormal; >> 1088 NewMomentum = OldMomentum - (2.*PdotN)*theFacetNormal; >> 1089 >> 1090 if (sint1 > 0.0) { // incident ray oblique >> 1091 >> 1092 E2_parl = Rindex2*E2_parl/Rindex1 - E1_parl; >> 1093 E2_perp = E2_perp - E1_perp; >> 1094 E2_total = E2_perp*E2_perp + E2_parl*E2_parl; >> 1095 A_paral = NewMomentum.cross(A_trans); >> 1096 A_paral = A_paral.unit(); >> 1097 E2_abs = std::sqrt(E2_total); >> 1098 C_parl = E2_parl/E2_abs; >> 1099 C_perp = E2_perp/E2_abs; >> 1100 >> 1101 NewPolarization = C_parl*A_paral + C_perp*A_trans; >> 1102 >> 1103 } >> 1104 >> 1105 else { // incident ray perpendicular >> 1106 >> 1107 if (Rindex2 > Rindex1) { >> 1108 NewPolarization = - OldPolarization; >> 1109 } >> 1110 else { >> 1111 NewPolarization = OldPolarization; >> 1112 } >> 1113 >> 1114 } >> 1115 } >> 1116 } >> 1117 else { // photon gets transmitted >> 1118 >> 1119 // Simulate transmission/refraction >> 1120 >> 1121 Inside = !Inside; >> 1122 Through = true; >> 1123 theStatus = FresnelRefraction; >> 1124 >> 1125 if (sint1 > 0.0) { // incident ray oblique >> 1126 >> 1127 alpha = cost1 - cost2*(Rindex2/Rindex1); >> 1128 NewMomentum = OldMomentum + alpha*theFacetNormal; >> 1129 NewMomentum = NewMomentum.unit(); >> 1130 // PdotN = -cost2; >> 1131 A_paral = NewMomentum.cross(A_trans); >> 1132 A_paral = A_paral.unit(); >> 1133 E2_abs = std::sqrt(E2_total); >> 1134 C_parl = E2_parl/E2_abs; >> 1135 C_perp = E2_perp/E2_abs; >> 1136 >> 1137 NewPolarization = C_parl*A_paral + C_perp*A_trans; >> 1138 >> 1139 } >> 1140 else { // incident ray perpendicular >> 1141 >> 1142 NewMomentum = OldMomentum; >> 1143 NewPolarization = OldPolarization; >> 1144 >> 1145 } >> 1146 } >> 1147 } >> 1148 >> 1149 OldMomentum = NewMomentum.unit(); >> 1150 OldPolarization = NewPolarization.unit(); >> 1151 >> 1152 if (theStatus == FresnelRefraction) { >> 1153 Done = (NewMomentum * theGlobalNormal <= 0.0); >> 1154 } >> 1155 else { >> 1156 Done = (NewMomentum * theGlobalNormal >= 0.0); >> 1157 } 1341 1158 1342 fGlobalNormal = -fGlobalNormal; << 1159 // Loop checking, 13-Aug-2015, Peter Gumplinger 1343 fOldMomentum = fNewMomentum; << 1160 } while (!Done); 1344 1161 1345 goto leap; << 1162 if (Inside && !Swap) { 1346 } << 1163 if( theFinish == polishedbackpainted || 1347 } << 1164 theFinish == groundbackpainted ) { 1348 } << 1165 >> 1166 G4double rand = G4UniformRand(); >> 1167 if ( rand > theReflectivity ) { >> 1168 if (rand > theReflectivity + theTransmittance) { >> 1169 DoAbsorption(); >> 1170 } else { >> 1171 theStatus = Transmission; >> 1172 NewMomentum = OldMomentum; >> 1173 NewPolarization = OldPolarization; >> 1174 } >> 1175 } >> 1176 else { >> 1177 if (theStatus != FresnelRefraction ) { >> 1178 theGlobalNormal = -theGlobalNormal; >> 1179 } >> 1180 else { >> 1181 Swap = !Swap; >> 1182 G4SwapPtr(Material1,Material2); >> 1183 G4SwapObj(&Rindex1,&Rindex2); >> 1184 } >> 1185 if ( theFinish == groundbackpainted ) >> 1186 theStatus = LambertianReflection; >> 1187 >> 1188 DoReflection(); >> 1189 >> 1190 theGlobalNormal = -theGlobalNormal; >> 1191 OldMomentum = NewMomentum; >> 1192 >> 1193 goto leap; >> 1194 } >> 1195 } >> 1196 } 1349 } 1197 } 1350 1198 1351 //....oooOO0OOooo........oooOO0OOooo........o << 1199 // GetMeanFreePath 1352 G4double G4OpBoundaryProcess::GetMeanFreePath << 1200 // --------------- >> 1201 // >> 1202 G4double G4OpBoundaryProcess::GetMeanFreePath(const G4Track& , >> 1203 G4double , 1353 1204 G4ForceCondition* condition) 1354 { 1205 { 1355 *condition = Forced; << 1206 *condition = Forced; 1356 return DBL_MAX; << 1207 >> 1208 return DBL_MAX; 1357 } 1209 } 1358 1210 1359 //....oooOO0OOooo........oooOO0OOooo........o << 1211 G4double G4OpBoundaryProcess::GetIncidentAngle() 1360 G4double G4OpBoundaryProcess::GetIncidentAngl << 1361 { 1212 { 1362 return pi - std::acos(fOldMomentum * fFacet << 1213 G4double PdotN = OldMomentum * theFacetNormal; 1363 (fOldMomentum.mag() * << 1214 G4double magP= OldMomentum.mag(); >> 1215 G4double magN= theFacetNormal.mag(); >> 1216 G4double incidentangle = pi - std::acos(PdotN/(magP*magN)); >> 1217 >> 1218 return incidentangle; 1364 } 1219 } 1365 1220 1366 //....oooOO0OOooo........oooOO0OOooo........o << 1367 G4double G4OpBoundaryProcess::GetReflectivity 1221 G4double G4OpBoundaryProcess::GetReflectivity(G4double E1_perp, 1368 1222 G4double E1_parl, 1369 1223 G4double incidentangle, 1370 << 1224 G4double RealRindex, 1371 << 1225 G4double ImaginaryRindex) 1372 { 1226 { 1373 G4complex reflectivity, reflectivity_TE, re << 1227 G4complex Reflectivity, Reflectivity_TE, Reflectivity_TM; 1374 G4complex N1(fRindex1, 0.), N2(realRindex, << 1228 G4complex N1(Rindex1, 0), N2(RealRindex, ImaginaryRindex); 1375 G4complex cosPhi; << 1229 G4complex CosPhi; 1376 1230 1377 G4complex u(1., 0.); // unit number 1 << 1231 G4complex u(1,0); //unit number 1 1378 1232 1379 G4complex numeratorTE; // E1_perp=1 E1_par << 1233 G4complex numeratorTE; // E1_perp=1 E1_parl=0 -> TE polarization 1380 G4complex numeratorTM; // E1_parl=1 E1_per << 1234 G4complex numeratorTM; // E1_parl=1 E1_perp=0 -> TM polarization 1381 G4complex denominatorTE, denominatorTM; 1235 G4complex denominatorTE, denominatorTM; 1382 G4complex rTM, rTE; 1236 G4complex rTM, rTE; 1383 1237 1384 G4MaterialPropertiesTable* MPT = fMaterial1 << 1238 G4MaterialPropertiesTable* aMaterialPropertiesTable = 1385 G4MaterialPropertyVector* ppR = MPT->GetPr << 1239 Material1->GetMaterialPropertiesTable(); 1386 G4MaterialPropertyVector* ppI = MPT->GetPr << 1240 G4MaterialPropertyVector* aPropertyPointerR = 1387 if(ppR && ppI) << 1241 aMaterialPropertiesTable->GetProperty("REALRINDEX"); 1388 { << 1242 G4MaterialPropertyVector* aPropertyPointerI = 1389 G4double rRindex = ppR->Value(fPhotonMome << 1243 aMaterialPropertiesTable->GetProperty("IMAGINARYRINDEX"); 1390 G4double iRindex = ppI->Value(fPhotonMome << 1244 if (aPropertyPointerR && aPropertyPointerI) { 1391 N1 = G4complex(rRindex, iRi << 1245 G4double RRindex = aPropertyPointerR->Value(thePhotonMomentum); >> 1246 G4double IRindex = aPropertyPointerI->Value(thePhotonMomentum); >> 1247 N1 = G4complex(RRindex,IRindex); 1392 } 1248 } 1393 1249 1394 // Following two equations, rTM and rTE, ar 1250 // Following two equations, rTM and rTE, are from: "Introduction To Modern 1395 // Optics" written by Fowles 1251 // Optics" written by Fowles 1396 cosPhi = std::sqrt(u - ((std::sin(incidenta << 1397 (N1 * N1) / (N2 * N << 1398 1252 1399 numeratorTE = N1 * std::cos(incidentangle << 1253 CosPhi=std::sqrt(u-((std::sin(incidentangle)*std::sin(incidentangle))*(N1*N1)/(N2*N2))); 1400 denominatorTE = N1 * std::cos(incidentangle << 1254 1401 rTE = numeratorTE / denominatorTE << 1255 numeratorTE = N1*std::cos(incidentangle) - N2*CosPhi; 1402 << 1256 denominatorTE = N1*std::cos(incidentangle) + N2*CosPhi; 1403 numeratorTM = N2 * std::cos(incidentangle << 1257 rTE = numeratorTE/denominatorTE; 1404 denominatorTM = N2 * std::cos(incidentangle << 1405 rTM = numeratorTM / denominatorTM << 1406 1258 1407 // This is my (PG) calculaton for reflectiv << 1259 numeratorTM = N2*std::cos(incidentangle) - N1*CosPhi; >> 1260 denominatorTM = N2*std::cos(incidentangle) + N1*CosPhi; >> 1261 rTM = numeratorTM/denominatorTM; >> 1262 >> 1263 // This is my calculaton for reflectivity on a metalic surface 1408 // depending on the fraction of TE and TM p 1264 // depending on the fraction of TE and TM polarization 1409 // when TE polarization, E1_parl=0 and E1_p 1265 // when TE polarization, E1_parl=0 and E1_perp=1, R=abs(rTE)^2 and 1410 // when TM polarization, E1_parl=1 and E1_p 1266 // when TM polarization, E1_parl=1 and E1_perp=0, R=abs(rTM)^2 1411 1267 1412 reflectivity_TE = (rTE * conj(rTE)) * (E1_p << 1268 Reflectivity_TE = (rTE*conj(rTE))*(E1_perp*E1_perp) 1413 (E1_perp * E1_perp + E1_p << 1269 / (E1_perp*E1_perp + E1_parl*E1_parl); 1414 reflectivity_TM = (rTM * conj(rTM)) * (E1_p << 1270 Reflectivity_TM = (rTM*conj(rTM))*(E1_parl*E1_parl) 1415 (E1_perp * E1_perp + E1_p << 1271 / (E1_perp*E1_perp + E1_parl*E1_parl); 1416 reflectivity = reflectivity_TE + reflectivi << 1272 Reflectivity = Reflectivity_TE + Reflectivity_TM; 1417 << 1273 1418 do << 1274 do { 1419 { << 1275 if(G4UniformRand()*real(Reflectivity) > real(Reflectivity_TE)) 1420 if(G4UniformRand() * real(reflectivity) > << 1276 {iTE = -1;}else{iTE = 1;} 1421 { << 1277 if(G4UniformRand()*real(Reflectivity) > real(Reflectivity_TM)) 1422 f_iTE = -1; << 1278 {iTM = -1;}else{iTM = 1;} 1423 } << 1424 else << 1425 { << 1426 f_iTE = 1; << 1427 } << 1428 if(G4UniformRand() * real(reflectivity) > << 1429 { << 1430 f_iTM = -1; << 1431 } << 1432 else << 1433 { << 1434 f_iTM = 1; << 1435 } << 1436 // Loop checking, 13-Aug-2015, Peter Gump 1279 // Loop checking, 13-Aug-2015, Peter Gumplinger 1437 } while(f_iTE < 0 && f_iTM < 0); << 1280 } while(iTE<0&&iTM<0); >> 1281 >> 1282 return real(Reflectivity); 1438 1283 1439 return real(reflectivity); << 1440 } 1284 } 1441 1285 1442 //....oooOO0OOooo........oooOO0OOooo........o << 1443 void G4OpBoundaryProcess::CalculateReflectivi 1286 void G4OpBoundaryProcess::CalculateReflectivity() 1444 { 1287 { 1445 G4double realRindex = fRealRIndexMPV->Value << 1288 G4double RealRindex = 1446 G4double imaginaryRindex = << 1289 PropertyPointer1->Value(thePhotonMomentum); 1447 fImagRIndexMPV->Value(fPhotonMomentum, id << 1290 G4double ImaginaryRindex = >> 1291 PropertyPointer2->Value(thePhotonMomentum); 1448 1292 1449 // calculate FacetNormal 1293 // calculate FacetNormal 1450 if(fFinish == ground) << 1294 if ( theFinish == ground ) { 1451 { << 1295 theFacetNormal = 1452 fFacetNormal = GetFacetNormal(fOldMomentu << 1296 GetFacetNormal(OldMomentum, theGlobalNormal); 1453 } << 1297 } else { 1454 else << 1298 theFacetNormal = theGlobalNormal; 1455 { << 1456 fFacetNormal = fGlobalNormal; << 1457 } 1299 } 1458 1300 1459 G4double cost1 = -fOldMomentum * fFacetNorm << 1301 G4double PdotN = OldMomentum * theFacetNormal; 1460 if(std::abs(cost1) < 1.0 - fCarTolerance) << 1302 cost1 = -PdotN; 1461 { << 1303 1462 fSint1 = std::sqrt(1. - cost1 * cost1); << 1304 if (std::abs(cost1) < 1.0 - kCarTolerance) { 1463 } << 1305 sint1 = std::sqrt(1. - cost1*cost1); 1464 else << 1306 } else { 1465 { << 1307 sint1 = 0.0; 1466 fSint1 = 0.0; << 1467 } 1308 } 1468 1309 1469 G4ThreeVector A_trans, A_paral, E1pp, E1pl; 1310 G4ThreeVector A_trans, A_paral, E1pp, E1pl; 1470 G4double E1_perp, E1_parl; 1311 G4double E1_perp, E1_parl; 1471 1312 1472 if(fSint1 > 0.0) << 1313 if (sint1 > 0.0 ) { 1473 { << 1314 A_trans = OldMomentum.cross(theFacetNormal); 1474 A_trans = (fOldMomentum.cross(fFacetNorma << 1315 A_trans = A_trans.unit(); 1475 E1_perp = fOldPolarization * A_trans; << 1316 E1_perp = OldPolarization * A_trans; 1476 E1pp = E1_perp * A_trans; << 1317 E1pp = E1_perp * A_trans; 1477 E1pl = fOldPolarization - E1pp; << 1318 E1pl = OldPolarization - E1pp; 1478 E1_parl = E1pl.mag(); << 1319 E1_parl = E1pl.mag(); 1479 } << 1320 } 1480 else << 1321 else { 1481 { << 1322 A_trans = OldPolarization; 1482 A_trans = fOldPolarization; << 1323 // Here we Follow Jackson's conventions and we set the 1483 // Here we Follow Jackson's conventions a << 1324 // parallel component = 1 in case of a ray perpendicular 1484 // component = 1 in case of a ray perpend << 1325 // to the surface 1485 E1_perp = 0.0; << 1326 E1_perp = 0.0; 1486 E1_parl = 1.0; << 1327 E1_parl = 1.0; 1487 } 1328 } 1488 1329 >> 1330 //calculate incident angle 1489 G4double incidentangle = GetIncidentAngle() 1331 G4double incidentangle = GetIncidentAngle(); 1490 1332 1491 // calculate the reflectivity depending on << 1333 //calculate the reflectivity depending on incident angle, 1492 // polarization and complex refractive << 1334 //polarization and complex refractive 1493 fReflectivity = GetReflectivity(E1_perp, E1 << 1335 1494 imaginaryRi << 1336 theReflectivity = >> 1337 GetReflectivity(E1_perp, E1_parl, incidentangle, >> 1338 RealRindex, ImaginaryRindex); 1495 } 1339 } 1496 1340 1497 //....oooOO0OOooo........oooOO0OOooo........o << 1498 G4bool G4OpBoundaryProcess::InvokeSD(const G4 1341 G4bool G4OpBoundaryProcess::InvokeSD(const G4Step* pStep) 1499 { 1342 { 1500 G4Step aStep = *pStep; 1343 G4Step aStep = *pStep; 1501 aStep.AddTotalEnergyDeposit(fPhotonMomentum << 1502 << 1503 G4VSensitiveDetector* sd = aStep.GetPostSte << 1504 if(sd != nullptr) << 1505 return sd->Hit(&aStep); << 1506 else << 1507 return false; << 1508 } << 1509 << 1510 //....oooOO0OOooo........oooOO0OOooo........o << 1511 inline void G4OpBoundaryProcess::SetInvokeSD( << 1512 { << 1513 fInvokeSD = flag; << 1514 G4OpticalParameters::Instance()->SetBoundar << 1515 } << 1516 1344 1517 //....oooOO0OOooo........oooOO0OOooo........o << 1345 aStep.AddTotalEnergyDeposit(thePhotonMomentum); 1518 void G4OpBoundaryProcess::SetVerboseLevel(G4i << 1519 { << 1520 verboseLevel = verbose; << 1521 G4OpticalParameters::Instance()->SetBoundar << 1522 } << 1523 1346 1524 //....oooOO0OOooo........oooOO0OOooo........o << 1347 G4VSensitiveDetector* sd = aStep.GetPostStepPoint()->GetSensitiveDetector(); 1525 void G4OpBoundaryProcess::CoatedDielectricDie << 1348 if (sd) return sd->Hit(&aStep); 1526 { << 1349 else return false; 1527 G4MaterialPropertyVector* pp = nullptr; << 1528 << 1529 G4MaterialPropertiesTable* MPT = fMaterial2 << 1530 if((pp = MPT->GetProperty(kRINDEX))) << 1531 { << 1532 fRindex2 = pp->Value(fPhotonMomentum, idx << 1533 } << 1534 << 1535 MPT = fOpticalSurface->GetMaterialPropertie << 1536 if((pp = MPT->GetProperty(kCOATEDRINDEX))) << 1537 { << 1538 fCoatedRindex = pp->Value(fPhotonMomentum << 1539 } << 1540 if(MPT->ConstPropertyExists(kCOATEDTHICKNES << 1541 { << 1542 fCoatedThickness = MPT->GetConstProperty( << 1543 } << 1544 if(MPT->ConstPropertyExists(kCOATEDFRUSTRAT << 1545 { << 1546 fCoatedFrustratedTransmission = << 1547 (G4bool)MPT->GetConstProperty(kCOATEDFR << 1548 } << 1549 << 1550 G4double sintTL; << 1551 G4double wavelength = h_Planck * c_light / << 1552 G4double PdotN; << 1553 G4double E1_perp, E1_parl; << 1554 G4double s1, E2_perp, E2_parl, E2_total, tr << 1555 G4double E2_abs, C_parl, C_perp; << 1556 G4double alpha; << 1557 G4ThreeVector A_trans, A_paral, E1pp, E1pl; << 1558 //G4bool Inside = false; << 1559 //G4bool Swap = false; << 1560 G4bool through = false; << 1561 G4bool done = false; << 1562 << 1563 do { << 1564 if (through) << 1565 { << 1566 //Swap = !Swap; << 1567 through = false; << 1568 fGlobalNormal = -fGlobalNormal; << 1569 G4SwapPtr(fMaterial1, fMaterial2); << 1570 G4SwapObj(&fRindex1, &fRindex2); << 1571 } << 1572 << 1573 if(fFinish == polished) << 1574 { << 1575 fFacetNormal = fGlobalNormal; << 1576 } << 1577 else << 1578 { << 1579 fFacetNormal = GetFacetNormal(fOldMomen << 1580 } << 1581 << 1582 PdotN = fOldMomentum * fFacetNormal; << 1583 G4double cost1 = -PdotN; << 1584 G4double sint2, cost2 = 0.; << 1585 << 1586 if (std::abs(cost1) < 1.0 - fCarTolerance << 1587 { << 1588 fSint1 = std::sqrt(1. - cost1 * cost1); << 1589 sint2 = fSint1 * fRindex1 / fRindex2; << 1590 sintTL = fSint1 * fRindex1 / fCoatedRin << 1591 } else << 1592 { << 1593 fSint1 = 0.0; << 1594 sint2 = 0.0; << 1595 sintTL = 0.0; << 1596 } << 1597 << 1598 if (fSint1 > 0.0) << 1599 { << 1600 A_trans = fOldMomentum.cross(fFacetNorm << 1601 A_trans = A_trans.unit(); << 1602 E1_perp = fOldPolarization * A_trans; << 1603 E1pp = E1_perp * A_trans; << 1604 E1pl = fOldPolarization - E1pp; << 1605 E1_parl = E1pl.mag(); << 1606 } << 1607 else << 1608 { << 1609 A_trans = fOldPolarization; << 1610 E1_perp = 0.0; << 1611 E1_parl = 1.0; << 1612 } << 1613 << 1614 s1 = fRindex1 * cost1; << 1615 << 1616 if (cost1 > 0.0) << 1617 { << 1618 cost2 = std::sqrt(1. - sint2 * sint2); << 1619 } << 1620 else << 1621 { << 1622 cost2 = -std::sqrt(1. - sint2 * sint2); << 1623 } << 1624 << 1625 transCoeff = 0.0; << 1626 << 1627 if (sintTL >= 1.0) << 1628 { // --> Angle > Angle Limit << 1629 //Swap = false; << 1630 } << 1631 E2_perp = 2. * s1 * E1_perp / (fRindex1 * << 1632 E2_parl = 2. * s1 * E1_parl / (fRindex2 * << 1633 E2_total = E2_perp * E2_perp + E2_parl * << 1634 << 1635 transCoeff = 1. - GetReflectivityThroughT << 1636 sintTL, E1_perp, E1_p << 1637 if (!G4BooleanRand(transCoeff)) << 1638 { << 1639 if(verboseLevel > 2) << 1640 G4cout << "Reflection from " << fMate << 1641 << fMaterial2->GetName() << G4 << 1642 << 1643 //Swap = false; << 1644 << 1645 if (sintTL >= 1.0) << 1646 { << 1647 fStatus = TotalInternalReflection; << 1648 } << 1649 else << 1650 { << 1651 fStatus = CoatedDielectricReflection; << 1652 } << 1653 << 1654 PdotN = fOldMomentum * fFacetNormal; << 1655 fNewMomentum = fOldMomentum - (2. * Pdo << 1656 << 1657 if (fSint1 > 0.0) { // incident ray o << 1658 << 1659 E2_parl = fRindex2 * E2_parl / fRinde << 1660 E2_perp = E2_perp - E1_perp; << 1661 E2_total = E2_perp * E2_perp + E2_par << 1662 A_paral = fNewMomentum.cross(A_trans) << 1663 A_paral = A_paral.unit(); << 1664 E2_abs = std::sqrt(E2_total); << 1665 C_parl = E2_parl / E2_abs; << 1666 C_perp = E2_perp / E2_abs; << 1667 << 1668 fNewPolarization = C_parl * A_paral + << 1669 << 1670 } << 1671 else << 1672 { // incident ray perpend << 1673 if (fRindex2 > fRindex1) << 1674 { << 1675 fNewPolarization = -fOldPolarizatio << 1676 } << 1677 else << 1678 { << 1679 fNewPolarization = fOldPolarization << 1680 } << 1681 } << 1682 << 1683 } else { // photon gets transmitted << 1684 if (verboseLevel > 2) << 1685 G4cout << "Transmission from " << fMa << 1686 << fMaterial2->GetName() << G4 << 1687 << 1688 //Inside = !Inside; << 1689 through = true; << 1690 << 1691 if (fEfficiency > 0.) << 1692 { << 1693 DoAbsorption(); << 1694 return; << 1695 } << 1696 else << 1697 { << 1698 if (sintTL >= 1.0) << 1699 { << 1700 fStatus = CoatedDielectricFrustrate << 1701 } << 1702 else << 1703 { << 1704 fStatus = CoatedDielectricRefractio << 1705 } << 1706 << 1707 if (fSint1 > 0.0) { // incident << 1708 << 1709 alpha = cost1 - cost2 * (fRindex2 / << 1710 fNewMomentum = fOldMomentum + alpha << 1711 fNewMomentum = fNewMomentum.unit(); << 1712 A_paral = fNewMomentum.cross(A_tran << 1713 A_paral = A_paral.unit(); << 1714 E2_abs = std::sqrt(E2_total); << 1715 C_parl = E2_parl / E2_abs; << 1716 C_perp = E2_perp / E2_abs; << 1717 << 1718 fNewPolarization = C_parl * A_paral << 1719 << 1720 } << 1721 else << 1722 { // incident ray pe << 1723 fNewMomentum = fOldMomentum; << 1724 fNewPolarization = fOldPolarization << 1725 } << 1726 } << 1727 } << 1728 << 1729 fOldMomentum = fNewMomentum.unit(); << 1730 fOldPolarization = fNewPolarization.unit( << 1731 if ((fStatus == CoatedDielectricFrustrate << 1732 (fStatus == CoatedDielectricRefractio << 1733 { << 1734 done = (fNewMomentum * fGlobalNormal <= << 1735 } << 1736 else << 1737 { << 1738 done = (fNewMomentum * fGlobalNormal >= << 1739 } << 1740 << 1741 } while (!done); << 1742 } << 1743 << 1744 //....oooOO0OOooo........oooOO0OOooo........o << 1745 G4double G4OpBoundaryProcess::GetReflectivity << 1746 G4double E1_perp, << 1747 G4double E1_parl, << 1748 G4double wavelength, G4dou << 1749 G4complex Reflectivity, Reflectivity_TE, Re << 1750 G4double gammaTL, costTL; << 1751 << 1752 G4complex i(0, 1); << 1753 G4complex rTM, rTE; << 1754 G4complex r1toTL, rTLto2; << 1755 G4double k0 = 2 * pi / wavelength; << 1756 << 1757 // Angle > Angle limit << 1758 if (sinTL >= 1.0) { << 1759 if (fCoatedFrustratedTransmission) { //Fr << 1760 << 1761 if (cost1 > 0.0) << 1762 { << 1763 gammaTL = std::sqrt(fRindex1 * fRinde << 1764 fCoatedRindex * fCoatedRin << 1765 } << 1766 else << 1767 { << 1768 gammaTL = -std::sqrt(fRindex1 * fRind << 1769 fCoatedRindex * fCoatedRin << 1770 } << 1771 << 1772 // TE << 1773 r1toTL = (fRindex1 * cost1 - i * gammaT << 1774 rTLto2 = (i * gammaTL - fRindex2 * cost << 1775 if (cost1 != 0.0) << 1776 { << 1777 rTE = (r1toTL + rTLto2 * std::exp(-2 << 1778 (1.0 + r1toTL * rTLto2 * std << 1779 } << 1780 // TM << 1781 r1toTL = (fRindex1 * i * gammaTL - fCoa << 1782 (fRindex1 * i * gammaTL + f << 1783 rTLto2 = (fCoatedRindex * fCoatedRindex << 1784 (fCoatedRindex * fCoatedRin << 1785 if (cost1 != 0.0) << 1786 { << 1787 rTM = (r1toTL + rTLto2 * std::exp(-2 << 1788 (1.0 + r1toTL * rTLto2 * std << 1789 } << 1790 } << 1791 else << 1792 { //Total reflection << 1793 return(1.); << 1794 } << 1795 } << 1796 << 1797 // Angle <= Angle limit << 1798 else //if (sinTL < 1.0) << 1799 { << 1800 if (cost1 > 0.0) << 1801 { << 1802 costTL = std::sqrt(1. - sinTL * sinTL); << 1803 } << 1804 else << 1805 { << 1806 costTL = -std::sqrt(1. - sinTL * sinTL) << 1807 } << 1808 // TE << 1809 r1toTL = (fRindex1 * cost1 - fCoatedRinde << 1810 rTLto2 = (fCoatedRindex * costTL - fRinde << 1811 if (cost1 != 0.0) << 1812 { << 1813 rTE = (r1toTL + rTLto2 * std::exp(2.0 * << 1814 (1.0 + r1toTL * rTLto2 * std::exp << 1815 } << 1816 // TM << 1817 r1toTL = (fRindex1 * costTL - fCoatedRind << 1818 rTLto2 = (fCoatedRindex * cost2 - fRindex << 1819 if (cost1 != 0.0) << 1820 { << 1821 rTM = (r1toTL + rTLto2 * std::exp(2.0 * << 1822 (1.0 + r1toTL * rTLto2 * std::exp << 1823 } << 1824 } << 1825 << 1826 Reflectivity_TE = (rTE * conj(rTE)) * (E1_p << 1827 Reflectivity_TM = (rTM * conj(rTM)) * (E1_p << 1828 Reflectivity = Reflectivity_TE + Reflectivi << 1829 << 1830 return real(Reflectivity); << 1831 } 1350 } 1832 1351