Geant4  10.02.p02
G4OpBoundaryProcess.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
27 // Optical Photon Boundary Process Class Implementation
29 //
30 // File: G4OpBoundaryProcess.cc
31 // Description: Discrete Process -- reflection/refraction at
32 // optical interfaces
33 // Version: 1.1
34 // Created: 1997-06-18
35 // Modified: 1998-05-25 - Correct parallel component of polarization
36 // (thanks to: Stefano Magni + Giovanni Pieri)
37 // 1998-05-28 - NULL Rindex pointer before reuse
38 // (thanks to: Stefano Magni)
39 // 1998-06-11 - delete *sint1 in oblique reflection
40 // (thanks to: Giovanni Pieri)
41 // 1998-06-19 - move from GetLocalExitNormal() to the new
42 // method: GetLocalExitNormal(&valid) to get
43 // the surface normal in all cases
44 // 1998-11-07 - NULL OpticalSurface pointer before use
45 // comparison not sharp for: std::abs(cost1) < 1.0
46 // remove sin1, sin2 in lines 556,567
47 // (thanks to Stefano Magni)
48 // 1999-10-10 - Accommodate changes done in DoAbsorption by
49 // changing logic in DielectricMetal
50 // 2001-10-18 - avoid Linux (gcc-2.95.2) warning about variables
51 // might be used uninitialized in this function
52 // moved E2_perp, E2_parl and E2_total out of 'if'
53 // 2003-11-27 - Modified line 168-9 to reflect changes made to
54 // G4OpticalSurface class ( by Fan Lei)
55 // 2004-02-02 - Set theStatus = Undefined at start of DoIt
56 // 2005-07-28 - add G4ProcessType to constructor
57 // 2006-11-04 - add capability of calculating the reflectivity
58 // off a metal surface by way of a complex index
59 // of refraction - Thanks to Sehwook Lee and John
60 // Hauptman (Dept. of Physics - Iowa State Univ.)
61 // 2009-11-10 - add capability of simulating surface reflections
62 // with Look-Up-Tables (LUT) containing measured
63 // optical reflectance for a variety of surface
64 // treatments - Thanks to Martin Janecek and
65 // William Moses (Lawrence Berkeley National Lab.)
66 // 2013-06-01 - add the capability of simulating the transmission
67 // of a dichronic filter
68 //
69 // Author: Peter Gumplinger
70 // adopted from work by Werner Keil - April 2/96
71 // mail: gum@triumf.ca
72 //
74 
75 #include "G4ios.hh"
76 #include "G4PhysicalConstants.hh"
77 #include "G4OpProcessSubType.hh"
78 
79 #include "G4OpBoundaryProcess.hh"
80 #include "G4GeometryTolerance.hh"
81 
82 #include "G4VSensitiveDetector.hh"
84 
85 #include "G4SystemOfUnits.hh"
86 
88 // Class Implementation
90 
92  // Operators
94 
95 // G4OpBoundaryProcess::operator=(const G4OpBoundaryProcess &right)
96 // {
97 // }
98 
100  // Constructors
102 
104  G4ProcessType type)
105  : G4VDiscreteProcess(processName, type)
106 {
107  if ( verboseLevel > 0) {
108  G4cout << GetProcessName() << " is created " << G4endl;
109  }
110 
112 
114  theModel = glisur;
116  theReflectivity = 1.;
117  theEfficiency = 0.;
118  theTransmittance = 0.;
119 
120  theSurfaceRoughness = 0.;
121 
122  prob_sl = 0.;
123  prob_ss = 0.;
124  prob_bs = 0.;
125 
126  PropertyPointer = NULL;
127  PropertyPointer1 = NULL;
128  PropertyPointer2 = NULL;
129 
130  Material1 = NULL;
131  Material2 = NULL;
132 
133  OpticalSurface = NULL;
134 
137 
138  iTE = iTM = 0;
139  thePhotonMomentum = 0.;
140  Rindex1 = Rindex2 = 1.;
141  cost1 = cost2 = sint1 = sint2 = 0.;
142 
143  idx = idy = 0;
144  DichroicVector = NULL;
145 }
146 
147 // G4OpBoundaryProcess::G4OpBoundaryProcess(const G4OpBoundaryProcess &right)
148 // {
149 // }
150 
152  // Destructors
154 
156 
158  // Methods
160 
161 // PostStepDoIt
162 // ------------
163 //
164 
167 {
169 
170  aParticleChange.Initialize(aTrack);
172 
173  // Get hyperStep from G4ParallelWorldProcess
174  // NOTE: PostSetpDoIt of this process should be
175  // invoked after G4ParallelWorldProcess!
176 
177  const G4Step* pStep = &aStep;
178 
180 
181  if (hStep) pStep = hStep;
182 
183  G4bool isOnBoundary =
185 
186  if (isOnBoundary) {
187  Material1 = pStep->GetPreStepPoint()->GetMaterial();
188  Material2 = pStep->GetPostStepPoint()->GetMaterial();
189  } else {
192  return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
193  }
194 
195  G4VPhysicalVolume* thePrePV =
196  pStep->GetPreStepPoint() ->GetPhysicalVolume();
197  G4VPhysicalVolume* thePostPV =
199 
200  if ( verboseLevel > 0 ) {
201  G4cout << " Photon at Boundary! " << G4endl;
202  if (thePrePV) G4cout << " thePrePV: " << thePrePV->GetName() << G4endl;
203  if (thePostPV) G4cout << " thePostPV: " << thePostPV->GetName() << G4endl;
204  }
205 
206  if (aTrack.GetStepLength()<=kCarTolerance/2){
209  return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
210  }
211 
212  const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
213 
214  thePhotonMomentum = aParticle->GetTotalMomentum();
215  OldMomentum = aParticle->GetMomentumDirection();
216  OldPolarization = aParticle->GetPolarization();
217 
218  if ( verboseLevel > 0 ) {
219  G4cout << " Old Momentum Direction: " << OldMomentum << G4endl;
220  G4cout << " Old Polarization: " << OldPolarization << G4endl;
221  }
222 
223  G4ThreeVector theGlobalPoint = pStep->GetPostStepPoint()->GetPosition();
224 
225  G4bool valid;
226  // Use the new method for Exit Normal in global coordinates,
227  // which provides the normal more reliably.
228 
229  // ID of Navigator which limits step
230 
232  std::vector<G4Navigator*>::iterator iNav =
234  GetActiveNavigatorsIterator();
236  (iNav[hNavId])->GetGlobalExitNormal(theGlobalPoint,&valid);
237 
238  if (valid) {
240  }
241  else
242  {
244  ed << " G4OpBoundaryProcess/PostStepDoIt(): "
245  << " The Navigator reports that it returned an invalid normal"
246  << G4endl;
247  G4Exception("G4OpBoundaryProcess::PostStepDoIt", "OpBoun01",
249  "Invalid Surface Normal - Geometry must return valid surface normal");
250  }
251 
252  if (OldMomentum * theGlobalNormal > 0.0) {
253 #ifdef G4OPTICAL_DEBUG
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
271 #endif
272  }
273 
274  G4MaterialPropertiesTable* aMaterialPropertiesTable;
275  G4MaterialPropertyVector* Rindex;
276 
277  aMaterialPropertiesTable = Material1->GetMaterialPropertiesTable();
278  if (aMaterialPropertiesTable) {
279  Rindex = aMaterialPropertiesTable->GetProperty("RINDEX");
280  }
281  else {
286  return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
287  }
288 
289  if (Rindex) {
290  Rindex1 = Rindex->Value(thePhotonMomentum);
291  }
292  else {
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;
308 
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 =
324  if(Surface == NULL)
325  Surface =
327  }
328  else {
329  Surface =
331  if(Surface == NULL)
332  Surface =
334  }
335  }
336 
337  if (Surface) OpticalSurface =
338  dynamic_cast <G4OpticalSurface*> (Surface->GetSurfaceProperty());
339 
340  if (OpticalSurface) {
341 
342  type = OpticalSurface->GetType();
345 
346  aMaterialPropertiesTable = OpticalSurface->
347  GetMaterialPropertiesTable();
348 
349  if (aMaterialPropertiesTable) {
350 
353  Rindex = aMaterialPropertiesTable->GetProperty("RINDEX");
354  if (Rindex) {
355  Rindex2 = Rindex->Value(thePhotonMomentum);
356  }
357  else {
362  return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
363  }
364  }
365 
367  aMaterialPropertiesTable->GetProperty("REFLECTIVITY");
369  aMaterialPropertiesTable->GetProperty("REALRINDEX");
371  aMaterialPropertiesTable->GetProperty("IMAGINARYRINDEX");
372 
373  iTE = 1;
374  iTM = 1;
375 
376  if (PropertyPointer) {
377 
380 
381  } else if (PropertyPointer1 && PropertyPointer2) {
382 
384 
385  }
386 
388  aMaterialPropertiesTable->GetProperty("EFFICIENCY");
389  if (PropertyPointer) {
390  theEfficiency =
392  }
393 
395  aMaterialPropertiesTable->GetProperty("TRANSMITTANCE");
396  if (PropertyPointer) {
399  }
400 
401  if (aMaterialPropertiesTable->
402  ConstPropertyExists("SURFACEROUGHNESS"))
403  theSurfaceRoughness = aMaterialPropertiesTable->
404  GetConstProperty("SURFACEROUGHNESS");
405 
406  if ( theModel == unified ) {
408  aMaterialPropertiesTable->GetProperty("SPECULARLOBECONSTANT");
409  if (PropertyPointer) {
410  prob_sl =
412  } else {
413  prob_sl = 0.0;
414  }
415 
417  aMaterialPropertiesTable->GetProperty("SPECULARSPIKECONSTANT");
418  if (PropertyPointer) {
419  prob_ss =
421  } else {
422  prob_ss = 0.0;
423  }
424 
426  aMaterialPropertiesTable->GetProperty("BACKSCATTERCONSTANT");
427  if (PropertyPointer) {
428  prob_bs =
430  } else {
431  prob_bs = 0.0;
432  }
433  }
434  }
435  else if (theFinish == polishedbackpainted ||
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){
449  return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
450  }
451  aMaterialPropertiesTable =
453  if (aMaterialPropertiesTable)
454  Rindex = aMaterialPropertiesTable->GetProperty("RINDEX");
455  if (Rindex) {
456  Rindex2 = Rindex->Value(thePhotonMomentum);
457  }
458  else {
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 
481 
482  }
483  else if (type == dielectric_dielectric) {
484 
485  if ( theFinish == polishedbackpainted ||
488  }
489  else {
490  G4double rand = G4UniformRand();
491  if ( rand > theReflectivity ) {
492  if (rand > theReflectivity + theTransmittance) {
493  DoAbsorption();
494  } else {
498  }
499  }
500  else {
501  if ( theFinish == polishedfrontpainted ) {
502  DoReflection();
503  }
504  else if ( theFinish == groundfrontpainted ) {
506  DoReflection();
507  }
508  else {
510  }
511  }
512  }
513  }
514  else {
515 
516  G4cerr << " Error: G4BoundaryProcess: illegal boundary type " << G4endl;
517  return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
518 
519  }
520 
521  NewMomentum = NewMomentum.unit();
523 
524  if ( verboseLevel > 0) {
525  G4cout << " New Momentum Direction: " << NewMomentum << G4endl;
526  G4cout << " New Polarization: " << NewPolarization << G4endl;
528  }
529 
532 
534  G4MaterialPropertyVector* 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);
543 }
544 
546 {
547  if ( theStatus == Undefined )
548  G4cout << " *** Undefined *** " << G4endl;
549  if ( theStatus == Transmission )
550  G4cout << " *** Transmission *** " << G4endl;
551  if ( theStatus == FresnelRefraction )
552  G4cout << " *** FresnelRefraction *** " << G4endl;
553  if ( theStatus == FresnelReflection )
554  G4cout << " *** FresnelReflection *** " << G4endl;
556  G4cout << " *** TotalInternalReflection *** " << G4endl;
558  G4cout << " *** LambertianReflection *** " << G4endl;
559  if ( theStatus == LobeReflection )
560  G4cout << " *** LobeReflection *** " << G4endl;
561  if ( theStatus == SpikeReflection )
562  G4cout << " *** SpikeReflection *** " << G4endl;
563  if ( theStatus == BackScattering )
564  G4cout << " *** BackScattering *** " << G4endl;
566  G4cout << " *** PolishedLumirrorAirReflection *** " << G4endl;
568  G4cout << " *** PolishedLumirrorGlueReflection *** " << G4endl;
570  G4cout << " *** PolishedAirReflection *** " << G4endl;
572  G4cout << " *** PolishedTeflonAirReflection *** " << G4endl;
574  G4cout << " *** PolishedTiOAirReflection *** " << G4endl;
576  G4cout << " *** PolishedTyvekAirReflection *** " << G4endl;
578  G4cout << " *** PolishedVM2000AirReflection *** " << G4endl;
580  G4cout << " *** PolishedVM2000GlueReflection *** " << G4endl;
582  G4cout << " *** EtchedLumirrorAirReflection *** " << G4endl;
584  G4cout << " *** EtchedLumirrorGlueReflection *** " << G4endl;
586  G4cout << " *** EtchedAirReflection *** " << G4endl;
588  G4cout << " *** EtchedTeflonAirReflection *** " << G4endl;
590  G4cout << " *** EtchedTiOAirReflection *** " << G4endl;
592  G4cout << " *** EtchedTyvekAirReflection *** " << G4endl;
594  G4cout << " *** EtchedVM2000AirReflection *** " << G4endl;
596  G4cout << " *** EtchedVM2000GlueReflection *** " << G4endl;
598  G4cout << " *** GroundLumirrorAirReflection *** " << G4endl;
600  G4cout << " *** GroundLumirrorGlueReflection *** " << G4endl;
602  G4cout << " *** GroundAirReflection *** " << G4endl;
604  G4cout << " *** GroundTeflonAirReflection *** " << G4endl;
606  G4cout << " *** GroundTiOAirReflection *** " << G4endl;
608  G4cout << " *** GroundTyvekAirReflection *** " << G4endl;
610  G4cout << " *** GroundVM2000AirReflection *** " << G4endl;
612  G4cout << " *** GroundVM2000GlueReflection *** " << G4endl;
613  if ( theStatus == Absorption )
614  G4cout << " *** Absorption *** " << G4endl;
615  if ( theStatus == Detection )
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;
627 }
628 
631  const G4ThreeVector& Normal ) const
632 {
633  G4ThreeVector FacetNormal;
634 
635  if (theModel == unified || theModel == LUT) {
636 
637  /* This function code alpha to a random value taken from the
638  distribution p(alpha) = g(alpha; 0, sigma_alpha)*std::sin(alpha),
639  for alpha > 0 and alpha < 90, where g(alpha; 0, sigma_alpha)
640  is a gaussian distribution with mean 0 and standard deviation
641  sigma_alpha. */
642 
643  G4double alpha;
644 
645  G4double sigma_alpha = 0.0;
646  if (OpticalSurface) sigma_alpha = OpticalSurface->GetSigmaAlpha();
647 
648  if (sigma_alpha == 0.0) return FacetNormal = Normal;
649 
650  G4double f_max = std::min(1.0,4.*sigma_alpha);
651 
652  G4double phi, SinAlpha, CosAlpha, SinPhi, CosPhi, unit_x, unit_y, unit_z;
653  G4ThreeVector tmpNormal;
654 
655  do {
656  do {
657  alpha = G4RandGauss::shoot(0.0,sigma_alpha);
658  // Loop checking, 13-Aug-2015, Peter Gumplinger
659  } while (G4UniformRand()*f_max > std::sin(alpha) || alpha >= halfpi );
660 
661  phi = G4UniformRand()*twopi;
662 
663  SinAlpha = std::sin(alpha);
664  CosAlpha = std::cos(alpha);
665  SinPhi = std::sin(phi);
666  CosPhi = std::cos(phi);
667 
668  unit_x = SinAlpha * CosPhi;
669  unit_y = SinAlpha * SinPhi;
670  unit_z = CosAlpha;
671 
672  FacetNormal.setX(unit_x);
673  FacetNormal.setY(unit_y);
674  FacetNormal.setZ(unit_z);
675 
676  tmpNormal = Normal;
677 
678  FacetNormal.rotateUz(tmpNormal);
679  // Loop checking, 13-Aug-2015, Peter Gumplinger
680  } while (Momentum * FacetNormal >= 0.0);
681  }
682  else {
683 
684  G4double polish = 1.0;
685  if (OpticalSurface) polish = OpticalSurface->GetPolish();
686 
687  if (polish < 1.0) {
688  do {
689  G4ThreeVector smear;
690  do {
691  smear.setX(2.*G4UniformRand()-1.0);
692  smear.setY(2.*G4UniformRand()-1.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;
707 }
708 
710 {
711  G4int n = 0;
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 {
727  }
728  break;
729  }
730  else {
731 
733  if ( n > 1 ) {
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 ) {
756  }
757  else {
758 
761  } else {
764  }
765  }
766 
767  PdotN = OldMomentum * theFacetNormal;
768  NewMomentum = OldMomentum - (2.*PdotN)*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  }
788 
789  }
790 
791  }
792 
795 
796  }
797 
798  // Loop checking, 13-Aug-2015, Peter Gumplinger
799  } while (NewMomentum * theGlobalNormal < 0.0);
800 }
801 
803 {
804  G4int thetaIndex, phiIndex;
805  G4double AngularDistributionValue, thetaRad, phiRad, EdotN;
806  G4ThreeVector PerpendicularVectorTheta, PerpendicularVectorPhi;
807 
810 
811  G4int thetaIndexMax = OpticalSurface->GetThetaIndexMax();
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 {
825  }
826  break;
827  }
828  else {
829  // Calculate Angle between Normal and Photon Momentum
830  G4double anglePhotonToNormal =
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
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:
866  NewPolarization = -OldPolarization + (2.*EdotN)*theFacetNormal;
867  }
868  // Loop checking, 13-Aug-2015, Peter Gumplinger
869  } while (NewMomentum * theGlobalNormal <= 0.0);
870 }
871 
873 {
874  // Calculate Angle between Normal and Photon Momentum
875  G4double anglePhotonToNormal = OldMomentum.angle(-theGlobalNormal);
876 
877  // Round it to closest integer
878  G4double angleIncident = std::floor(180/pi*anglePhotonToNormal+0.5);
879 
880  if (!DichroicVector) {
882  }
883 
884 
885  if (DichroicVector) {
886  G4double wavelength = h_Planck*c_light/thePhotonMomentum;
888  DichroicVector->Value(wavelength/nm,angleIncident,idx,idy)*perCent;
889 // G4cout << "wavelength: " << std::floor(wavelength/nm)
890 // << "nm" << G4endl;
891 // G4cout << "Incident angle: " << angleIncident << "deg" << G4endl;
892 // G4cout << "Transmittance: "
893 // << std::floor(theTransmittance/perCent) << "%" << G4endl;
894  } else {
896  ed << " G4OpBoundaryProcess/DielectricDichroic(): "
897  << " The dichroic surface has no G4Physics2DVector"
898  << G4endl;
899  G4Exception("G4OpBoundaryProcess::DielectricDichroic", "OpBoun03",
900  FatalException,ed,
901  "A dichroic surface must have an associated G4Physics2DVector");
902  }
903 
904  if ( !G4BooleanRand(theTransmittance) ) { // Not transmitted, so reflect
905 
906  if ( theModel == glisur || theFinish == polished ) {
907  DoReflection();
908  } else {
910  if ( theStatus == LambertianReflection ) {
911  DoReflection();
912  } else if ( theStatus == BackScattering ) {
915  } else {
916  G4double PdotN, EdotN;
917  do {
920  PdotN = OldMomentum * theFacetNormal;
921  NewMomentum = OldMomentum - (2.*PdotN)*theFacetNormal;
922  // Loop checking, 13-Aug-2015, Peter Gumplinger
923  } while (NewMomentum * theGlobalNormal <= 0.0);
925  NewPolarization = -OldPolarization + (2.*EdotN)*theFacetNormal;
926  }
927  }
928 
929  } else {
930 
934 
935  }
936 }
937 
939 {
940  G4bool Inside = false;
941  G4bool Swap = false;
942 
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);
950  }
951 
952  leap:
953 
954  G4bool Through = false;
955  G4bool Done = false;
956 
957  G4double PdotN, EdotN;
958 
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;
973  }
974 
975  if ( theFinish == polished ) {
977  }
978  else {
981  }
982 
983  PdotN = OldMomentum * 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 
1003 
1004  if ( !SurfaceRoughnessCriterionPass ) theStatus =
1006 
1007  if ( theModel == unified && theFinish != polished )
1008  ChooseReflection();
1009 
1010  if ( theStatus == LambertianReflection ) {
1011  DoReflection();
1012  }
1013  else if ( theStatus == BackScattering ) {
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 
1071 
1072  if ( !SurfaceRoughnessCriterionPass ) theStatus =
1074 
1075  if ( theModel == unified && theFinish != polished )
1076  ChooseReflection();
1077 
1078  if ( theStatus == LambertianReflection ) {
1079  DoReflection();
1080  }
1081  else if ( theStatus == BackScattering ) {
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) {
1109  }
1110  else {
1112  }
1113 
1114  }
1115  }
1116  }
1117  else { // photon gets transmitted
1118 
1119  // Simulate transmission/refraction
1120 
1121  Inside = !Inside;
1122  Through = true;
1124 
1125  if (sint1 > 0.0) { // incident ray oblique
1126 
1127  alpha = cost1 - cost2*(Rindex2/Rindex1);
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 
1144 
1145  }
1146  }
1147  }
1148 
1149  OldMomentum = NewMomentum.unit();
1151 
1152  if (theStatus == FresnelRefraction) {
1153  Done = (NewMomentum * theGlobalNormal <= 0.0);
1154  }
1155  else {
1156  Done = (NewMomentum * theGlobalNormal >= 0.0);
1157  }
1158 
1159  // Loop checking, 13-Aug-2015, Peter Gumplinger
1160  } while (!Done);
1161 
1162  if (Inside && !Swap) {
1163  if( theFinish == polishedbackpainted ||
1165 
1166  G4double rand = G4UniformRand();
1167  if ( rand > theReflectivity ) {
1168  if (rand > theReflectivity + theTransmittance) {
1169  DoAbsorption();
1170  } else {
1174  }
1175  }
1176  else {
1177  if (theStatus != FresnelRefraction ) {
1179  }
1180  else {
1181  Swap = !Swap;
1184  }
1185  if ( theFinish == groundbackpainted )
1187 
1188  DoReflection();
1189 
1192 
1193  goto leap;
1194  }
1195  }
1196  }
1197 }
1198 
1199 // GetMeanFreePath
1200 // ---------------
1201 //
1203  G4double ,
1205 {
1206  *condition = Forced;
1207 
1208  return DBL_MAX;
1209 }
1210 
1212 {
1214  G4double magP= OldMomentum.mag();
1215  G4double magN= theFacetNormal.mag();
1216  G4double incidentangle = pi - std::acos(PdotN/(magP*magN));
1217 
1218  return incidentangle;
1219 }
1220 
1222  G4double E1_parl,
1223  G4double incidentangle,
1224  G4double RealRindex,
1225  G4double ImaginaryRindex)
1226 {
1227  G4complex Reflectivity, Reflectivity_TE, Reflectivity_TM;
1228  G4complex N1(Rindex1, 0), N2(RealRindex, ImaginaryRindex);
1229  G4complex CosPhi;
1230 
1231  G4complex u(1,0); //unit number 1
1232 
1233  G4complex numeratorTE; // E1_perp=1 E1_parl=0 -> TE polarization
1234  G4complex numeratorTM; // E1_parl=1 E1_perp=0 -> TM polarization
1235  G4complex denominatorTE, denominatorTM;
1236  G4complex rTM, rTE;
1237 
1238  G4MaterialPropertiesTable* aMaterialPropertiesTable =
1240  G4MaterialPropertyVector* aPropertyPointerR =
1241  aMaterialPropertiesTable->GetProperty("REALRINDEX");
1242  G4MaterialPropertyVector* aPropertyPointerI =
1243  aMaterialPropertiesTable->GetProperty("IMAGINARYRINDEX");
1244  if (aPropertyPointerR && aPropertyPointerI) {
1245  G4double RRindex = aPropertyPointerR->Value(thePhotonMomentum);
1246  G4double IRindex = aPropertyPointerI->Value(thePhotonMomentum);
1247  N1 = G4complex(RRindex,IRindex);
1248  }
1249 
1250  // Following two equations, rTM and rTE, are from: "Introduction To Modern
1251  // Optics" written by Fowles
1252 
1253  CosPhi=std::sqrt(u-((std::sin(incidentangle)*std::sin(incidentangle))*(N1*N1)/(N2*N2)));
1254 
1255  numeratorTE = N1*std::cos(incidentangle) - N2*CosPhi;
1256  denominatorTE = N1*std::cos(incidentangle) + N2*CosPhi;
1257  rTE = numeratorTE/denominatorTE;
1258 
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
1264  // depending on the fraction of TE and TM polarization
1265  // when TE polarization, E1_parl=0 and E1_perp=1, R=abs(rTE)^2 and
1266  // when TM polarization, E1_parl=1 and E1_perp=0, R=abs(rTM)^2
1267 
1268  Reflectivity_TE = (rTE*conj(rTE))*(E1_perp*E1_perp)
1269  / (E1_perp*E1_perp + E1_parl*E1_parl);
1270  Reflectivity_TM = (rTM*conj(rTM))*(E1_parl*E1_parl)
1271  / (E1_perp*E1_perp + E1_parl*E1_parl);
1272  Reflectivity = Reflectivity_TE + Reflectivity_TM;
1273 
1274  do {
1275  if(G4UniformRand()*real(Reflectivity) > real(Reflectivity_TE))
1276  {iTE = -1;}else{iTE = 1;}
1277  if(G4UniformRand()*real(Reflectivity) > real(Reflectivity_TM))
1278  {iTM = -1;}else{iTM = 1;}
1279  // Loop checking, 13-Aug-2015, Peter Gumplinger
1280  } while(iTE<0&&iTM<0);
1281 
1282  return real(Reflectivity);
1283 
1284 }
1285 
1287 {
1288  G4double RealRindex =
1290  G4double ImaginaryRindex =
1292 
1293  // calculate FacetNormal
1294  if ( theFinish == ground ) {
1295  theFacetNormal =
1297  } else {
1299  }
1300 
1302  cost1 = -PdotN;
1303 
1304  if (std::abs(cost1) < 1.0 - kCarTolerance) {
1305  sint1 = std::sqrt(1. - cost1*cost1);
1306  } else {
1307  sint1 = 0.0;
1308  }
1309 
1310  G4ThreeVector A_trans, A_paral, E1pp, E1pl;
1311  G4double E1_perp, E1_parl;
1312 
1313  if (sint1 > 0.0 ) {
1314  A_trans = OldMomentum.cross(theFacetNormal);
1315  A_trans = A_trans.unit();
1316  E1_perp = OldPolarization * A_trans;
1317  E1pp = E1_perp * A_trans;
1318  E1pl = OldPolarization - E1pp;
1319  E1_parl = E1pl.mag();
1320  }
1321  else {
1322  A_trans = OldPolarization;
1323  // Here we Follow Jackson's conventions and we set the
1324  // parallel component = 1 in case of a ray perpendicular
1325  // to the surface
1326  E1_perp = 0.0;
1327  E1_parl = 1.0;
1328  }
1329 
1330  //calculate incident angle
1331  G4double incidentangle = GetIncidentAngle();
1332 
1333  //calculate the reflectivity depending on incident angle,
1334  //polarization and complex refractive
1335 
1336  theReflectivity =
1337  GetReflectivity(E1_perp, E1_parl, incidentangle,
1338  RealRindex, ImaginaryRindex);
1339 }
1340 
1342 {
1343  G4Step aStep = *pStep;
1344 
1346 
1348  if (sd) return sd->Hit(&aStep);
1349  else return false;
1350 }
G4double condition(const G4ErrorSymMatrix &m)
ThreeVector shoot(const G4int Ap, const G4int Af)
void G4SwapObj(T *a, T *b)
Definition: templates.hh:129
G4MaterialPropertyVector * GetProperty(const char *key)
static const double halfpi
Definition: G4SIunits.hh:76
G4OpticalSurfaceModel GetModel() const
G4int verboseLevel
Definition: G4VProcess.hh:368
G4double GetReflectivity(G4double E1_perp, G4double E1_parl, G4double incidentangle, G4double RealRindex, G4double ImaginaryRindex)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
CLHEP::Hep3Vector G4ThreeVector
G4Physics2DVector * DichroicVector
G4double GetVelocity() const
const G4DynamicParticle * GetDynamicParticle() const
G4StepStatus GetStepStatus() const
G4Material * GetMaterial() const
G4OpticalSurface * OpticalSurface
G4double GetSurfaceTolerance() const
G4VParticleChange * PostStepDoIt(const G4Track &aTrack, const G4Step &aStep)
void ProposePolarization(G4double Px, G4double Py, G4double Pz)
const G4SurfaceType & GetType() const
G4OpBoundaryProcessStatus
G4OpBoundaryProcess(const G4String &processName="OpBoundary", G4ProcessType type=fOptical)
G4SurfaceType
G4MaterialPropertyVector * PropertyPointer1
int G4int
Definition: G4Types.hh:78
G4OpticalSurfaceFinish theFinish
void ProposeLocalEnergyDeposit(G4double anEnergyPart)
static G4LogicalBorderSurface * GetSurface(const G4VPhysicalVolume *vol1, const G4VPhysicalVolume *vol2)
G4double GetTotalMomentum() const
G4StepPoint * GetPreStepPoint() const
G4OpBoundaryProcessStatus theStatus
std::complex< G4double > G4complex
Definition: G4Types.hh:81
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
G4double Value(G4double x, G4double y, size_t &lastidx, size_t &lastidy) const
G4double GetPolish() const
G4VPhysicalVolume * GetPhysicalVolume() const
const G4String & GetName() const
const G4ThreeVector & GetPosition() const
G4int GetPhiIndexMax(void) const
G4bool G4BooleanRand(const G4double prob) const
bool G4bool
Definition: G4Types.hh:79
const G4ThreeVector & GetMomentumDirection() const
static const double nm
Definition: G4SIunits.hh:111
static const double twopi
Definition: G4SIunits.hh:75
G4bool Hit(G4Step *aStep)
void SetProcessSubType(G4int)
Definition: G4VProcess.hh:432
G4double GetMeanFreePath(const G4Track &, G4double, G4ForceCondition *condition)
static const double perCent
Definition: G4SIunits.hh:329
void BoundaryProcessVerbose(void) const
Definition: G4Step.hh:76
const G4int n
G4LogicalVolume * GetMotherLogical() const
G4double Value(G4double theEnergy, size_t &lastidx) const
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
G4OpticalSurfaceFinish GetFinish() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4TransportationManager * GetTransportationManager()
G4OpticalSurfaceModel theModel
G4bool InvokeSD(const G4Step *step)
virtual void Initialize(const G4Track &)
G4LogicalVolume * GetLogicalVolume() const
G4MaterialPropertyVector * PropertyPointer
static const double pi
Definition: G4SIunits.hh:74
G4Physics2DVector * GetDichroicVector()
void G4SwapPtr(T *&a, T *&b)
Definition: templates.hh:121
G4MaterialPropertiesTable * GetMaterialPropertiesTable() const
Definition: G4Material.hh:252
G4StepPoint * GetPostStepPoint() const
void AddTotalEnergyDeposit(G4double value)
const G4ThreeVector & GetPolarization() const
G4ParticleChange aParticleChange
Definition: G4VProcess.hh:289
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
#define G4endl
Definition: G4ios.hh:61
G4SurfaceProperty * GetSurfaceProperty() const
G4VSensitiveDetector * GetSensitiveDetector() const
void ProposeMomentumDirection(G4double Px, G4double Py, G4double Pz)
G4MaterialPropertyVector * PropertyPointer2
double G4double
Definition: G4Types.hh:76
void ProposeTrackStatus(G4TrackStatus status)
G4double GetSigmaAlpha() const
G4ForceCondition
static const G4double alpha
void ProposeVelocity(G4double finalVelocity)
#define DBL_MAX
Definition: templates.hh:83
G4int GetThetaIndexMax(void) const
virtual G4VParticleChange * PostStepDoIt(const G4Track &, const G4Step &)
G4double GetStepLength() const
static G4GeometryTolerance * GetInstance()
static const G4Step * GetHyperStep()
G4GLOB_DLL std::ostream G4cerr
G4ThreeVector GetFacetNormal(const G4ThreeVector &Momentum, const G4ThreeVector &Normal) const
G4ProcessType
static G4LogicalSkinSurface * GetSurface(const G4LogicalVolume *vol)