Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/optical/src/G4OpBoundaryProcess.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /processes/optical/src/G4OpBoundaryProcess.cc (Version 11.3.0) and /processes/optical/src/G4OpBoundaryProcess.cc (Version 10.0.p1)


  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         prob_sl = 0.;
129 G4OpBoundaryProcess::~G4OpBoundaryProcess() =  << 121         prob_ss = 0.;
                                                   >> 122         prob_bs = 0.;
130                                                   123 
131 //....oooOO0OOooo........oooOO0OOooo........oo << 124         PropertyPointer  = NULL;
132 void G4OpBoundaryProcess::PreparePhysicsTable( << 125         PropertyPointer1 = NULL;
133 {                                              << 126         PropertyPointer2 = NULL;
134   Initialise();                                << 
135 }                                              << 
136                                                   127 
137 //....oooOO0OOooo........oooOO0OOooo........oo << 128         Material1 = NULL;
138 void G4OpBoundaryProcess::Initialise()         << 129         Material2 = NULL;
139 {                                              << 
140   G4OpticalParameters* params = G4OpticalParam << 
141   SetInvokeSD(params->GetBoundaryInvokeSD());  << 
142   SetVerboseLevel(params->GetBoundaryVerboseLe << 
143 }                                              << 
144                                                   130 
145 //....oooOO0OOooo........oooOO0OOooo........oo << 131         OpticalSurface = NULL;
146 G4VParticleChange* G4OpBoundaryProcess::PostSt << 
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         kCarTolerance = G4GeometryTolerance::GetInstance()
175   G4VPhysicalVolume* thePostPV = pStep->GetPos << 134                         ->GetSurfaceTolerance();
176                                                   135 
177   if(verboseLevel > 1)                         << 136         iTE = iTM = 0;
178   {                                            << 137         thePhotonMomentum = 0.;
179     G4cout << " Photon at Boundary! " << G4end << 138         Rindex1 = Rindex2 = cost1 = cost2 = sint1 = sint2 = 0.;
180     if(thePrePV != nullptr)                    << 
181       G4cout << " thePrePV:  " << thePrePV->Ge << 
182     if(thePostPV != nullptr)                   << 
183       G4cout << " thePostPV: " << thePostPV->G << 
184   }                                            << 
185                                                   139 
186   G4double stepLength = aTrack.GetStepLength() << 140         idx = idy = 0;
187   if(stepLength <= fCarTolerance)              << 141         DichroicVector = NULL;
188   {                                            << 142 }
189     fStatus = StepTooSmall;                    << 
190     if(verboseLevel > 1)                       << 
191       BoundaryProcessVerbose();                << 
192                                                << 
193     G4MaterialPropertyVector* groupvel = nullp << 
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                                                   143 
226   const G4DynamicParticle* aParticle = aTrack. << 144 // G4OpBoundaryProcess::G4OpBoundaryProcess(const G4OpBoundaryProcess &right)
                                                   >> 145 // {
                                                   >> 146 // }
                                                   >> 147 
                                                   >> 148         ////////////////
                                                   >> 149         // Destructors
                                                   >> 150         ////////////////
                                                   >> 151 
                                                   >> 152 G4OpBoundaryProcess::~G4OpBoundaryProcess(){}
                                                   >> 153 
                                                   >> 154         ////////////
                                                   >> 155         // Methods
                                                   >> 156         ////////////
227                                                   157 
228   fPhotonMomentum  = aParticle->GetTotalMoment << 158 // PostStepDoIt
229   fOldMomentum     = aParticle->GetMomentumDir << 159 // ------------
230   fOldPolarization = aParticle->GetPolarizatio << 160 //
231                                                << 
232   if(verboseLevel > 1)                         << 
233   {                                            << 
234     G4cout << " Old Momentum Direction: " << f << 
235            << " Old Polarization:       " << f << 
236   }                                            << 
237                                                   161 
238   G4ThreeVector theGlobalPoint = pStep->GetPos << 162 G4VParticleChange*
239   G4bool valid;                                << 163 G4OpBoundaryProcess::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep)
                                                   >> 164 {
                                                   >> 165         theStatus = Undefined;
240                                                   166 
241   // ID of Navigator which limits step         << 167         aParticleChange.Initialize(aTrack);
242   G4int hNavId = G4ParallelWorldProcess::GetHy << 168         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                                                   169 
261   if(fOldMomentum * fGlobalNormal > 0.0)       << 170         // Get hyperStep from  G4ParallelWorldProcess
262   {                                            << 171         //  NOTE: PostSetpDoIt of this process should be
263 #ifdef G4OPTICAL_DEBUG                         << 172         //        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                                                   173 
288   G4MaterialPropertyVector* rIndexMPV = nullpt << 174         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                                                   175 
308   fReflectivity      = 1.;                     << 176         const G4Step* hStep = G4ParallelWorldProcess::GetHyperStep();
309   fEfficiency        = 0.;                     << 177         
310   fTransmittance     = 0.;                     << 178         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                                                   179 
343   if(surface != nullptr)                       << 180         G4bool isOnBoundary =
344   {                                            << 181                 (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                                                   182 
376       fRealRIndexMPV = sMPT->GetProperty(kREAL << 183         if (isOnBoundary) {
377       fImagRIndexMPV = sMPT->GetProperty(kIMAG << 184            Material1 = pStep->GetPreStepPoint()->GetMaterial();
378       f_iTE = f_iTM = 1;                       << 185            Material2 = pStep->GetPostStepPoint()->GetMaterial();
379                                                << 186         } else {
380       G4MaterialPropertyVector* pp;            << 187            theStatus = NotAtBoundary;
381       if((pp = sMPT->GetProperty(kREFLECTIVITY << 188            if ( verboseLevel > 0) BoundaryProcessVerbose();
382       {                                        << 189            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         }                                         190         }
484         else                                   << 191 
485         {                                      << 192         G4VPhysicalVolume* thePrePV  =
486           DielectricDielectric();              << 193                                pStep->GetPreStepPoint() ->GetPhysicalVolume();
487         }                                      << 194         G4VPhysicalVolume* thePostPV =
488       }                                        << 195                                pStep->GetPostStepPoint()->GetPhysicalVolume();
489     }                                          << 196 
490   }                                            << 197         if ( verboseLevel > 0 ) {
491   else if(type == dielectric_metal)            << 198            G4cout << " Photon at Boundary! " << G4endl;
492   {                                            << 199            if (thePrePV)  G4cout << " thePrePV:  " << thePrePV->GetName()  << G4endl;
493     DielectricMetal();                         << 200            if (thePostPV) G4cout << " thePostPV: " << thePostPV->GetName() << G4endl;
494   }                                            << 
495   else if(type == dielectric_LUT)              << 
496   {                                            << 
497     DielectricLUT();                           << 
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         }                                         201         }
524         G4Exception("G4OpBoundaryProcess", "Op << 
525       }                                        << 
526     }                                          << 
527     return G4VDiscreteProcess::PostStepDoIt(aT << 
528   }                                            << 
529                                                   202 
530   fNewMomentum     = fNewMomentum.unit();      << 203   if (aTrack.GetStepLength()<=kCarTolerance/2){
531   fNewPolarization = fNewPolarization.unit();  << 204           theStatus = StepTooSmall;
                                                   >> 205                 if ( verboseLevel > 0) BoundaryProcessVerbose();
                                                   >> 206           return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
                                                   >> 207   }
532                                                   208 
533   if(verboseLevel > 1)                         << 209         const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
534   {                                            << 
535     G4cout << " New Momentum Direction: " << f << 
536            << " New Polarization:       " << f << 
537     BoundaryProcessVerbose();                  << 
538   }                                            << 
539                                                   210 
540   aParticleChange.ProposeMomentumDirection(fNe << 211   thePhotonMomentum = aParticle->GetTotalMomentum();
541   aParticleChange.ProposePolarization(fNewPola << 212         OldMomentum       = aParticle->GetMomentumDirection();
                                                   >> 213   OldPolarization   = aParticle->GetPolarization();
542                                                   214 
543   if(fStatus == FresnelRefraction || fStatus = << 215         if ( verboseLevel > 0 ) {
544   {                                            << 216            G4cout << " Old Momentum Direction: " << OldMomentum     << G4endl;
545     // not all surface types check that fMater << 217            G4cout << " Old Polarization:       " << OldPolarization << G4endl;
546     G4MaterialPropertiesTable* aMPT = fMateria << 218         }
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                                                   219 
559   if(fStatus == Detection && fInvokeSD)        << 220         G4ThreeVector theGlobalPoint = pStep->GetPostStepPoint()->GetPosition();
560     InvokeSD(pStep);                           << 
561   return G4VDiscreteProcess::PostStepDoIt(aTra << 
562 }                                              << 
563                                                   221 
564 //....oooOO0OOooo........oooOO0OOooo........oo << 222         G4bool valid;
565 void G4OpBoundaryProcess::BoundaryProcessVerbo << 223         //  Use the new method for Exit Normal in global coordinates,
566 {                                              << 224         //    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                                                   225 
655   G4cout << " ***" << G4endl;                  << 226         // ID of Navigator which limits step
656 }                                              << 
657                                                   227 
658 //....oooOO0OOooo........oooOO0OOooo........oo << 228         G4int hNavId = G4ParallelWorldProcess::GetHypNavigatorID();
659 G4ThreeVector G4OpBoundaryProcess::GetFacetNor << 229         std::vector<G4Navigator*>::iterator iNav =
660   const G4ThreeVector& momentum, const G4Three << 230                 G4TransportationManager::GetTransportationManager()->
661 {                                              << 231                                          GetActiveNavigatorsIterator();
662   G4ThreeVector facetNormal;                   << 232         theGlobalNormal =
663   if(fModel == unified || fModel == LUT || fMo << 233                    (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                                                   234 
723 //....oooOO0OOooo........oooOO0OOooo........oo << 235         if (valid) {
724 void G4OpBoundaryProcess::DielectricMetal()    << 236           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         }                                         237         }
761       }                                        << 238         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         {                                         239         {
772           DoReflection();                      << 240           G4ExceptionDescription ed;
                                                   >> 241           ed << " G4OpBoundaryProcess/PostStepDoIt(): "
                                                   >> 242                  << " The Navigator reports that it returned an invalid normal"
                                                   >> 243                  << G4endl;
                                                   >> 244           G4Exception("G4OpBoundaryProcess::PostStepDoIt", "OpBoun01",
                                                   >> 245                       EventMustBeAborted,ed,
                                                   >> 246                       "Invalid Surface Normal - Geometry must return valid surface normal");
773         }                                         247         }
774         else if(fStatus == BackScattering)     << 248 
775         {                                      << 249         if (OldMomentum * theGlobalNormal > 0.0) {
776           fNewMomentum     = -fOldMomentum;    << 250 #ifdef G4OPTICAL_DEBUG
777           fNewPolarization = -fOldPolarization << 251            G4ExceptionDescription ed;
                                                   >> 252            ed << " G4OpBoundaryProcess/PostStepDoIt(): "
                                                   >> 253               << " theGlobalNormal points in a wrong direction. "
                                                   >> 254               << G4endl;
                                                   >> 255            ed << "    The momentum of the photon arriving at interface (oldMomentum)"
                                                   >> 256               << " must exit the volume cross in the step. " << G4endl;
                                                   >> 257            ed << "  So it MUST have dot < 0 with the normal that Exits the new volume (globalNormal)." << G4endl;
                                                   >> 258            ed << "  >> The dot product of oldMomentum and global Normal is " << OldMomentum*theGlobalNormal << G4endl;
                                                   >> 259            ed << "     Old Momentum  (during step)     = " << OldMomentum << G4endl;
                                                   >> 260            ed << "     Global Normal (Exiting New Vol) = " << theGlobalNormal << G4endl;
                                                   >> 261            ed << G4endl;
                                                   >> 262            G4Exception("G4OpBoundaryProcess::PostStepDoIt", "OpBoun02",
                                                   >> 263                        EventMustBeAborted,  // Or JustWarning to see if it happens repeatedbly on one ray
                                                   >> 264                        ed,
                                                   >> 265                       "Invalid Surface Normal - Geometry must return valid surface normal pointing in the right direction");
                                                   >> 266 #else
                                                   >> 267            theGlobalNormal = -theGlobalNormal;
                                                   >> 268 #endif
778         }                                         269         }
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                                                   270 
793           if(f_iTE > 0 && f_iTM > 0)           << 271   G4MaterialPropertiesTable* aMaterialPropertiesTable;
794           {                                    << 272         G4MaterialPropertyVector* Rindex;
795             fNewPolarization =                 << 273 
796               -fOldPolarization +              << 274   aMaterialPropertiesTable = Material1->GetMaterialPropertiesTable();
797               (2. * fOldPolarization * fFacetN << 275         if (aMaterialPropertiesTable) {
798           }                                    << 276     Rindex = aMaterialPropertiesTable->GetProperty("RINDEX");
799           else if(f_iTE > 0)                   << 277   }
800           {                                    << 278   else {
801             A_trans = (fSint1 > 0.0) ? fOldMom << 279           theStatus = NoRINDEX;
802                                      : fOldPol << 280                 if ( verboseLevel > 0) BoundaryProcessVerbose();
803             fNewPolarization = -A_trans;       << 281                 aParticleChange.ProposeLocalEnergyDeposit(thePhotonMomentum);
                                                   >> 282     aParticleChange.ProposeTrackStatus(fStopAndKill);
                                                   >> 283     return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
                                                   >> 284   }
                                                   >> 285 
                                                   >> 286         if (Rindex) {
                                                   >> 287     Rindex1 = Rindex->Value(thePhotonMomentum);
                                                   >> 288   }
                                                   >> 289   else {
                                                   >> 290           theStatus = NoRINDEX;
                                                   >> 291                 if ( verboseLevel > 0) BoundaryProcessVerbose();
                                                   >> 292                 aParticleChange.ProposeLocalEnergyDeposit(thePhotonMomentum);
                                                   >> 293     aParticleChange.ProposeTrackStatus(fStopAndKill);
                                                   >> 294     return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
                                                   >> 295   }
                                                   >> 296 
                                                   >> 297         theReflectivity =  1.;
                                                   >> 298         theEfficiency   =  0.;
                                                   >> 299         theTransmittance = 0.;
                                                   >> 300 
                                                   >> 301         theModel = glisur;
                                                   >> 302         theFinish = polished;
                                                   >> 303 
                                                   >> 304         G4SurfaceType type = dielectric_dielectric;
                                                   >> 305 
                                                   >> 306         Rindex = NULL;
                                                   >> 307         OpticalSurface = NULL;
                                                   >> 308 
                                                   >> 309         G4LogicalSurface* Surface = NULL;
                                                   >> 310 
                                                   >> 311         Surface = G4LogicalBorderSurface::GetSurface(thePrePV, thePostPV);
                                                   >> 312 
                                                   >> 313         if (Surface == NULL){
                                                   >> 314           G4bool enteredDaughter= (thePostPV->GetMotherLogical() ==
                                                   >> 315                                    thePrePV ->GetLogicalVolume());
                                                   >> 316     if(enteredDaughter){
                                                   >> 317       Surface = 
                                                   >> 318               G4LogicalSkinSurface::GetSurface(thePostPV->GetLogicalVolume());
                                                   >> 319       if(Surface == NULL)
                                                   >> 320         Surface =
                                                   >> 321                 G4LogicalSkinSurface::GetSurface(thePrePV->GetLogicalVolume());
                                                   >> 322     }
                                                   >> 323     else {
                                                   >> 324       Surface =
                                                   >> 325               G4LogicalSkinSurface::GetSurface(thePrePV->GetLogicalVolume());
                                                   >> 326       if(Surface == NULL)
                                                   >> 327         Surface =
                                                   >> 328                 G4LogicalSkinSurface::GetSurface(thePostPV->GetLogicalVolume());
                                                   >> 329     }
                                                   >> 330   }
                                                   >> 331 
                                                   >> 332   if (Surface) OpticalSurface = 
                                                   >> 333            dynamic_cast <G4OpticalSurface*> (Surface->GetSurfaceProperty());
                                                   >> 334 
                                                   >> 335   if (OpticalSurface) {
                                                   >> 336 
                                                   >> 337            type      = OpticalSurface->GetType();
                                                   >> 338      theModel  = OpticalSurface->GetModel();
                                                   >> 339      theFinish = OpticalSurface->GetFinish();
                                                   >> 340 
                                                   >> 341      aMaterialPropertiesTable = OpticalSurface->
                                                   >> 342           GetMaterialPropertiesTable();
                                                   >> 343 
                                                   >> 344            if (aMaterialPropertiesTable) {
                                                   >> 345 
                                                   >> 346               if (theFinish == polishedbackpainted ||
                                                   >> 347                   theFinish == groundbackpainted ) {
                                                   >> 348                   Rindex = aMaterialPropertiesTable->GetProperty("RINDEX");
                                                   >> 349             if (Rindex) {
                                                   >> 350                      Rindex2 = Rindex->Value(thePhotonMomentum);
                                                   >> 351                   }
                                                   >> 352                   else {
                                                   >> 353          theStatus = NoRINDEX;
                                                   >> 354                      if ( verboseLevel > 0) BoundaryProcessVerbose();
                                                   >> 355                      aParticleChange.ProposeLocalEnergyDeposit(thePhotonMomentum);
                                                   >> 356                      aParticleChange.ProposeTrackStatus(fStopAndKill);
                                                   >> 357                      return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
                                                   >> 358                   }
                                                   >> 359               }
                                                   >> 360 
                                                   >> 361               PropertyPointer =
                                                   >> 362                       aMaterialPropertiesTable->GetProperty("REFLECTIVITY");
                                                   >> 363               PropertyPointer1 =
                                                   >> 364                       aMaterialPropertiesTable->GetProperty("REALRINDEX");
                                                   >> 365               PropertyPointer2 =
                                                   >> 366                       aMaterialPropertiesTable->GetProperty("IMAGINARYRINDEX");
                                                   >> 367 
                                                   >> 368               iTE = 1;
                                                   >> 369               iTM = 1;
                                                   >> 370 
                                                   >> 371               if (PropertyPointer) {
                                                   >> 372 
                                                   >> 373                  theReflectivity =
                                                   >> 374                           PropertyPointer->Value(thePhotonMomentum);
                                                   >> 375 
                                                   >> 376               } else if (PropertyPointer1 && PropertyPointer2) {
                                                   >> 377 
                                                   >> 378                  CalculateReflectivity();
                                                   >> 379 
                                                   >> 380               }
                                                   >> 381 
                                                   >> 382               PropertyPointer =
                                                   >> 383               aMaterialPropertiesTable->GetProperty("EFFICIENCY");
                                                   >> 384               if (PropertyPointer) {
                                                   >> 385                       theEfficiency =
                                                   >> 386                       PropertyPointer->Value(thePhotonMomentum);
                                                   >> 387               }
                                                   >> 388 
                                                   >> 389               PropertyPointer =
                                                   >> 390               aMaterialPropertiesTable->GetProperty("TRANSMITTANCE");
                                                   >> 391               if (PropertyPointer) {
                                                   >> 392                       theTransmittance =
                                                   >> 393                       PropertyPointer->Value(thePhotonMomentum);
                                                   >> 394               }
                                                   >> 395 
                                                   >> 396         if ( theModel == unified ) {
                                                   >> 397           PropertyPointer =
                                                   >> 398     aMaterialPropertiesTable->GetProperty("SPECULARLOBECONSTANT");
                                                   >> 399           if (PropertyPointer) {
                                                   >> 400                          prob_sl =
                                                   >> 401        PropertyPointer->Value(thePhotonMomentum);
                                                   >> 402                 } else {
                                                   >> 403                          prob_sl = 0.0;
                                                   >> 404                 }
                                                   >> 405 
                                                   >> 406           PropertyPointer =
                                                   >> 407     aMaterialPropertiesTable->GetProperty("SPECULARSPIKECONSTANT");
                                                   >> 408           if (PropertyPointer) {
                                                   >> 409                          prob_ss =
                                                   >> 410        PropertyPointer->Value(thePhotonMomentum);
                                                   >> 411                 } else {
                                                   >> 412                          prob_ss = 0.0;
                                                   >> 413                 }
                                                   >> 414 
                                                   >> 415           PropertyPointer =
                                                   >> 416     aMaterialPropertiesTable->GetProperty("BACKSCATTERCONSTANT");
                                                   >> 417           if (PropertyPointer) {
                                                   >> 418                          prob_bs =
                                                   >> 419        PropertyPointer->Value(thePhotonMomentum);
                                                   >> 420                 } else {
                                                   >> 421                          prob_bs = 0.0;
                                                   >> 422                 }
                                                   >> 423         }
                                                   >> 424      }
                                                   >> 425            else if (theFinish == polishedbackpainted ||
                                                   >> 426                     theFinish == groundbackpainted ) {
                                                   >> 427                       aParticleChange.ProposeLocalEnergyDeposit(thePhotonMomentum);
                                                   >> 428                       aParticleChange.ProposeTrackStatus(fStopAndKill);
                                                   >> 429                       return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
                                                   >> 430            }
                                                   >> 431         }
                                                   >> 432 
                                                   >> 433         if (type == dielectric_dielectric ) {
                                                   >> 434            if (theFinish == polished || theFinish == ground ) {
                                                   >> 435 
                                                   >> 436         if (Material1 == Material2){
                                                   >> 437      theStatus = SameMaterial;
                                                   >> 438                  if ( verboseLevel > 0) BoundaryProcessVerbose();
                                                   >> 439      return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
                                                   >> 440         }
                                                   >> 441               aMaterialPropertiesTable =
                                                   >> 442                      Material2->GetMaterialPropertiesTable();
                                                   >> 443               if (aMaterialPropertiesTable)
                                                   >> 444                  Rindex = aMaterialPropertiesTable->GetProperty("RINDEX");
                                                   >> 445               if (Rindex) {
                                                   >> 446                  Rindex2 = Rindex->Value(thePhotonMomentum);
                                                   >> 447               }
                                                   >> 448               else {
                                                   >> 449      theStatus = NoRINDEX;
                                                   >> 450                  if ( verboseLevel > 0) BoundaryProcessVerbose();
                                                   >> 451                  aParticleChange.ProposeLocalEnergyDeposit(thePhotonMomentum);
                                                   >> 452                  aParticleChange.ProposeTrackStatus(fStopAndKill);
                                                   >> 453                  return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
                                                   >> 454         }
                                                   >> 455            }
                                                   >> 456         }
                                                   >> 457 
                                                   >> 458   if (type == dielectric_metal) {
                                                   >> 459 
                                                   >> 460     DielectricMetal();
                                                   >> 461 
                                                   >> 462           // Uncomment the following lines if you wish to have 
                                                   >> 463           //         Transmission instead of Absorption
                                                   >> 464           // if (theStatus == Absorption) {
                                                   >> 465           //    return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
                                                   >> 466           // }
                                                   >> 467 
                                                   >> 468   }
                                                   >> 469         else if (type == dielectric_LUT) {
                                                   >> 470 
                                                   >> 471           DielectricLUT();
                                                   >> 472 
                                                   >> 473         }
                                                   >> 474         else if (type == dielectric_dichroic) {
                                                   >> 475 
                                                   >> 476           DielectricDichroic();
                                                   >> 477 
                                                   >> 478         }
                                                   >> 479   else if (type == dielectric_dielectric) {
                                                   >> 480 
                                                   >> 481           if ( theFinish == polishedbackpainted ||
                                                   >> 482                theFinish == groundbackpainted ) {
                                                   >> 483              DielectricDielectric();
804           }                                       484           }
805           else if(f_iTM > 0)                   << 485     else {
806           {                                    << 486              if ( !G4BooleanRand(theReflectivity) ) {
807             fNewPolarization =                 << 487                 DoAbsorption();
808               -fNewMomentum.cross(A_trans).uni << 488              }
                                                   >> 489              else {
                                                   >> 490                 if ( theFinish == polishedfrontpainted ) {
                                                   >> 491                    DoReflection();
                                                   >> 492                 }
                                                   >> 493                 else if ( theFinish == groundfrontpainted ) {
                                                   >> 494                    theStatus = LambertianReflection;
                                                   >> 495                    DoReflection();
                                                   >> 496                 }
                                                   >> 497                 else {
                                                   >> 498                    DielectricDielectric();
                                                   >> 499                 }
                                                   >> 500              }
809           }                                       501           }
810         }                                         502         }
811       }                                        << 503   else {
812       fOldMomentum     = fNewMomentum;         << 504 
813       fOldPolarization = fNewPolarization;     << 505     G4cerr << " Error: G4BoundaryProcess: illegal boundary type " << G4endl;
814     }                                          << 506     return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
815     // Loop checking, 13-Aug-2015, Peter Gumpl << 507 
816   } while(fNewMomentum * fGlobalNormal < 0.0); << 508   }
                                                   >> 509 
                                                   >> 510         NewMomentum = NewMomentum.unit();
                                                   >> 511         NewPolarization = NewPolarization.unit();
                                                   >> 512 
                                                   >> 513         if ( verboseLevel > 0) {
                                                   >> 514      G4cout << " New Momentum Direction: " << NewMomentum     << G4endl;
                                                   >> 515      G4cout << " New Polarization:       " << NewPolarization << G4endl;
                                                   >> 516            BoundaryProcessVerbose();
                                                   >> 517         }
                                                   >> 518 
                                                   >> 519   aParticleChange.ProposeMomentumDirection(NewMomentum);
                                                   >> 520   aParticleChange.ProposePolarization(NewPolarization);
                                                   >> 521 
                                                   >> 522         if ( theStatus == FresnelRefraction ) {
                                                   >> 523            G4MaterialPropertyVector* groupvel =
                                                   >> 524            Material2->GetMaterialPropertiesTable()->GetProperty("GROUPVEL");
                                                   >> 525            G4double finalVelocity = groupvel->Value(thePhotonMomentum);
                                                   >> 526            aParticleChange.ProposeVelocity(finalVelocity);
                                                   >> 527         }
                                                   >> 528 
                                                   >> 529         if ( theStatus == Detection ) InvokeSD(pStep);
                                                   >> 530 
                                                   >> 531         return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
817 }                                                 532 }
818                                                   533 
819 //....oooOO0OOooo........oooOO0OOooo........oo << 534 void G4OpBoundaryProcess::BoundaryProcessVerbose() const
820 void G4OpBoundaryProcess::DielectricLUT()      << 
821 {                                                 535 {
822   G4int thetaIndex, phiIndex;                  << 536         if ( theStatus == Undefined )
823   G4double angularDistVal, thetaRad, phiRad;   << 537                 G4cout << " *** Undefined *** " << G4endl;
824   G4ThreeVector perpVectorTheta, perpVectorPhi << 538         if ( theStatus == FresnelRefraction )
825                                                << 539                 G4cout << " *** FresnelRefraction *** " << G4endl;
826   fStatus = G4OpBoundaryProcessStatus(         << 540         if ( theStatus == FresnelReflection )
827     G4int(fFinish) + (G4int(NoRINDEX) - G4int( << 541                 G4cout << " *** FresnelReflection *** " << G4endl;
828                                                << 542         if ( theStatus == TotalInternalReflection )
829   G4int thetaIndexMax = fOpticalSurface->GetTh << 543                 G4cout << " *** TotalInternalReflection *** " << G4endl;
830   G4int phiIndexMax   = fOpticalSurface->GetPh << 544         if ( theStatus == LambertianReflection )
831                                                << 545                 G4cout << " *** LambertianReflection *** " << G4endl;
832   G4double rand;                               << 546         if ( theStatus == LobeReflection )
833                                                << 547                 G4cout << " *** LobeReflection *** " << G4endl;
834   do                                           << 548         if ( theStatus == SpikeReflection )
835   {                                            << 549                 G4cout << " *** SpikeReflection *** " << G4endl;
836     rand = G4UniformRand();                    << 550         if ( theStatus == BackScattering )
837     if(rand > fReflectivity)                   << 551                 G4cout << " *** BackScattering *** " << G4endl;
838     {                                          << 552         if ( theStatus == PolishedLumirrorAirReflection )
839       if(rand > fReflectivity + fTransmittance << 553                 G4cout << " *** PolishedLumirrorAirReflection *** " << G4endl;
840       {                                        << 554         if ( theStatus == PolishedLumirrorGlueReflection )
841         DoAbsorption();                        << 555                 G4cout << " *** PolishedLumirrorGlueReflection *** " << G4endl;
842       }                                        << 556         if ( theStatus == PolishedAirReflection )
843       else                                     << 557                 G4cout << " *** PolishedAirReflection *** " << G4endl;
844       {                                        << 558         if ( theStatus == PolishedTeflonAirReflection )
845         fStatus          = Transmission;       << 559                 G4cout << " *** PolishedTeflonAirReflection *** " << G4endl;
846         fNewMomentum     = fOldMomentum;       << 560         if ( theStatus == PolishedTiOAirReflection )
847         fNewPolarization = fOldPolarization;   << 561                 G4cout << " *** PolishedTiOAirReflection *** " << G4endl;
848       }                                        << 562         if ( theStatus == PolishedTyvekAirReflection )
849       break;                                   << 563                 G4cout << " *** PolishedTyvekAirReflection *** " << G4endl;
850     }                                          << 564         if ( theStatus == PolishedVM2000AirReflection )
851     else                                       << 565                 G4cout << " *** PolishedVM2000AirReflection *** " << G4endl;
852     {                                          << 566         if ( theStatus == PolishedVM2000GlueReflection )
853       // Calculate Angle between Normal and Ph << 567                 G4cout << " *** PolishedVM2000GlueReflection *** " << G4endl;
854       G4double anglePhotonToNormal = fOldMomen << 568         if ( theStatus == EtchedLumirrorAirReflection )
855       // Round to closest integer: LBNL model  << 569                 G4cout << " *** EtchedLumirrorAirReflection *** " << G4endl;
856       G4int angleIncident = (G4int)std::lrint( << 570         if ( theStatus == EtchedLumirrorGlueReflection )
857                                                << 571                 G4cout << " *** EtchedLumirrorGlueReflection *** " << G4endl;
858       // Take random angles THETA and PHI,     << 572         if ( theStatus == EtchedAirReflection )
859       // and see if below Probability - if not << 573                 G4cout << " *** EtchedAirReflection *** " << G4endl;
860       do                                       << 574         if ( theStatus == EtchedTeflonAirReflection )
861       {                                        << 575                 G4cout << " *** EtchedTeflonAirReflection *** " << G4endl;
862         thetaIndex = (G4int)G4RandFlat::shootI << 576         if ( theStatus == EtchedTiOAirReflection )
863         phiIndex   = (G4int)G4RandFlat::shootI << 577                 G4cout << " *** EtchedTiOAirReflection *** " << G4endl;
864         // Find probability with the new indec << 578         if ( theStatus == EtchedTyvekAirReflection )
865         angularDistVal = fOpticalSurface->GetA << 579                 G4cout << " *** EtchedTyvekAirReflection *** " << G4endl;
866           angleIncident, thetaIndex, phiIndex) << 580         if ( theStatus == EtchedVM2000AirReflection )
867         // Loop checking, 13-Aug-2015, Peter G << 581                 G4cout << " *** EtchedVM2000AirReflection *** " << G4endl;
868       } while(!G4BooleanRand(angularDistVal)); << 582         if ( theStatus == EtchedVM2000GlueReflection )
869                                                << 583                 G4cout << " *** EtchedVM2000GlueReflection *** " << G4endl;
870       thetaRad = G4double(-90 + 4 * thetaIndex << 584         if ( theStatus == GroundLumirrorAirReflection )
871       phiRad   = G4double(-90 + 5 * phiIndex)  << 585                 G4cout << " *** GroundLumirrorAirReflection *** " << G4endl;
872       // Rotate Photon Momentum in Theta, then << 586         if ( theStatus == GroundLumirrorGlueReflection )
873       fNewMomentum = -fOldMomentum;            << 587                 G4cout << " *** GroundLumirrorGlueReflection *** " << G4endl;
874                                                << 588         if ( theStatus == GroundAirReflection )
875       perpVectorTheta = fNewMomentum.cross(fGl << 589                 G4cout << " *** GroundAirReflection *** " << G4endl;
876       if(perpVectorTheta.mag() < fCarTolerance << 590         if ( theStatus == GroundTeflonAirReflection )
877       {                                        << 591                 G4cout << " *** GroundTeflonAirReflection *** " << G4endl;
878         perpVectorTheta = fNewMomentum.orthogo << 592         if ( theStatus == GroundTiOAirReflection )
879       }                                        << 593                 G4cout << " *** GroundTiOAirReflection *** " << G4endl;
880       fNewMomentum =                           << 594         if ( theStatus == GroundTyvekAirReflection )
881         fNewMomentum.rotate(anglePhotonToNorma << 595                 G4cout << " *** GroundTyvekAirReflection *** " << G4endl;
882       perpVectorPhi = perpVectorTheta.cross(fN << 596         if ( theStatus == GroundVM2000AirReflection )
883       fNewMomentum  = fNewMomentum.rotate(-phi << 597                 G4cout << " *** GroundVM2000AirReflection *** " << G4endl;
884                                                << 598         if ( theStatus == GroundVM2000GlueReflection )
885       // Rotate Polarization too:              << 599                 G4cout << " *** GroundVM2000GlueReflection *** " << G4endl;
886       fFacetNormal     = (fNewMomentum - fOldM << 600         if ( theStatus == Absorption )
887       fNewPolarization = -fOldPolarization +   << 601                 G4cout << " *** Absorption *** " << G4endl;
888                          (2. * fOldPolarizatio << 602         if ( theStatus == Detection )
889     }                                          << 603                 G4cout << " *** Detection *** " << G4endl;
890     // Loop checking, 13-Aug-2015, Peter Gumpl << 604         if ( theStatus == NotAtBoundary )
891   } while(fNewMomentum * fGlobalNormal <= 0.0) << 605                 G4cout << " *** NotAtBoundary *** " << G4endl;
                                                   >> 606         if ( theStatus == SameMaterial )
                                                   >> 607                 G4cout << " *** SameMaterial *** " << G4endl;
                                                   >> 608         if ( theStatus == StepTooSmall )
                                                   >> 609                 G4cout << " *** StepTooSmall *** " << G4endl;
                                                   >> 610         if ( theStatus == NoRINDEX )
                                                   >> 611                 G4cout << " *** NoRINDEX *** " << G4endl;
                                                   >> 612         if ( theStatus == Dichroic )
                                                   >> 613                 G4cout << " *** Dichroic Transmission *** " << G4endl;
892 }                                                 614 }
893                                                   615 
894 //....oooOO0OOooo........oooOO0OOooo........oo << 616 G4ThreeVector
895 void G4OpBoundaryProcess::DielectricLUTDAVIS() << 617 G4OpBoundaryProcess::GetFacetNormal(const G4ThreeVector& Momentum,
                                                   >> 618                   const G4ThreeVector&  Normal ) const
896 {                                                 619 {
897   G4int angindex, random, angleIncident;       << 620         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                                                   621 
928         if(angleIncident <= 0.01)              << 622   if (theModel == unified || theModel == LUT) {
929         {                                      << 
930           fNewMomentum = fOldMomentum;         << 
931           break;                               << 
932         }                                      << 
933                                                   623 
934         do                                     << 624   /* This function code alpha to a random value taken from the
935         {                                      << 625            distribution p(alpha) = g(alpha; 0, sigma_alpha)*std::sin(alpha),
936           random = (G4int)G4RandFlat::shootInt << 626            for alpha > 0 and alpha < 90, where g(alpha; 0, sigma_alpha)
937           angindex =                           << 627            is a gaussian distribution with mean 0 and standard deviation
938             (((random * 2) - 1)) + angleIncide << 628            sigma_alpha.  */
939                                                << 629 
940           azimuth =                            << 630      G4double alpha;
941             fOpticalSurface->GetAngularDistrib << 631 
942           elevation = fOpticalSurface->GetAngu << 632      G4double sigma_alpha = 0.0;
943         } while(elevation == 0. && azimuth ==  << 633      if (OpticalSurface) sigma_alpha = OpticalSurface->GetSigmaAlpha();
944                                                << 634 
945         sinEl = std::sin(elevation);           << 635            if (sigma_alpha == 0.0) return FacetNormal = Normal;
946         vNorm = (fGlobalNormal.cross(fOldMomen << 636 
947         u     = vNorm.cross(fGlobalNormal) * ( << 637      G4double f_max = std::min(1.0,4.*sigma_alpha);
948         vNorm *= (sinEl * std::sin(azimuth));  << 638 
949         // fGlobalNormal shouldn't be modified << 639      do {
950         w            = (fGlobalNormal *= std:: << 640         do {
951         fNewMomentum = u + vNorm + w;          << 641            alpha = G4RandGauss::shoot(0.0,sigma_alpha);
952                                                << 642         } while (G4UniformRand()*f_max > std::sin(alpha) || alpha >= halfpi );
953         // Rotate Polarization too:            << 643 
954         fFacetNormal     = (fNewMomentum - fOl << 644         G4double phi = G4UniformRand()*twopi;
955         fNewPolarization = -fOldPolarization + << 645 
956                                                << 646         G4double SinAlpha = std::sin(alpha);
957       }                                        << 647         G4double CosAlpha = std::cos(alpha);
958     }                                          << 648               G4double SinPhi = std::sin(phi);
959     else                                       << 649               G4double CosPhi = std::cos(phi);
960     {                                          << 650 
961       fStatus = LobeReflection;                << 651               G4double unit_x = SinAlpha * CosPhi;
962                                                << 652               G4double unit_y = SinAlpha * SinPhi;
963       if(angleIncident == 0)                   << 653               G4double unit_z = CosAlpha;
964       {                                        << 654 
965         fNewMomentum = -fOldMomentum;          << 655         FacetNormal.setX(unit_x);
966         break;                                 << 656         FacetNormal.setY(unit_y);
967       }                                        << 657         FacetNormal.setZ(unit_z);
968                                                << 658 
969       do                                       << 659         G4ThreeVector tmpNormal = Normal;
970       {                                        << 660 
971         random   = (G4int)G4RandFlat::shootInt << 661         FacetNormal.rotateUz(tmpNormal);
972         angindex = (((random * 2) - 1)) + (ang << 662      } while (Momentum * FacetNormal >= 0.0);
973                                                << 663   }
974         azimuth = fOpticalSurface->GetAngularD << 664   else {
975         elevation = fOpticalSurface->GetAngula << 665 
976       } while(elevation == 0. && azimuth == 0. << 666      G4double  polish = 1.0;
977                                                << 667      if (OpticalSurface) polish = OpticalSurface->GetPolish();
978       sinEl = std::sin(elevation);             << 668 
979       vNorm = (fGlobalNormal.cross(fOldMomentu << 669            if (polish < 1.0) {
980       u     = vNorm.cross(fGlobalNormal) * (si << 670               do {
981       vNorm *= (sinEl * std::sin(azimuth));    << 671                  G4ThreeVector smear;
982       // fGlobalNormal shouldn't be modified h << 672                  do {
983       w = (fGlobalNormal *= std::cos(elevation << 673                     smear.setX(2.*G4UniformRand()-1.0);
984                                                << 674                     smear.setY(2.*G4UniformRand()-1.0);
985       fNewMomentum = u + vNorm + w;            << 675                     smear.setZ(2.*G4UniformRand()-1.0);
986                                                << 676                  } while (smear.mag()>1.0);
987       // Rotate Polarization too: (needs revis << 677                  smear = (1.-polish) * smear;
988       fNewPolarization = fOldPolarization;     << 678                  FacetNormal = Normal + smear;
989     }                                          << 679               } while (Momentum * FacetNormal >= 0.0);
990   } while(fNewMomentum * fGlobalNormal <= 0.0) << 680               FacetNormal = FacetNormal.unit();
                                                   >> 681      }
                                                   >> 682            else {
                                                   >> 683               FacetNormal = Normal;
                                                   >> 684            }
                                                   >> 685   }
                                                   >> 686   return FacetNormal;
991 }                                                 687 }
992                                                   688 
993 //....oooOO0OOooo........oooOO0OOooo........oo << 689 void G4OpBoundaryProcess::DielectricMetal()
994 void G4OpBoundaryProcess::DielectricDichroic() << 
995 {                                                 690 {
996   // Calculate Angle between Normal and Photon << 691         G4int n = 0;
997   G4double anglePhotonToNormal = fOldMomentum. << 
998                                                   692 
999   // Round it to closest integer               << 693   do {
1000   G4double angleIncident = std::floor(180. /  << 
1001                                                  694 
1002   if(!fDichroicVector)                        << 695            n++;
1003   {                                           << 
1004     if(fOpticalSurface)                       << 
1005       fDichroicVector = fOpticalSurface->GetD << 
1006   }                                           << 
1007                                                  696 
1008   if(fDichroicVector)                         << 697            if( !G4BooleanRand(theReflectivity) && n == 1 ) {
1009   {                                           << 
1010     G4double wavelength = h_Planck * c_light  << 
1011     fTransmittance      = fDichroicVector->Va << 
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                                                  698 
1030   if(!G4BooleanRand(fTransmittance))          << 699              // Comment out DoAbsorption and uncomment theStatus = Absorption;
1031   {  // Not transmitted, so reflect           << 700              // if you wish to have Transmission instead of Absorption
1032     if(fModel == glisur || fFinish == polishe << 701 
1033     {                                         << 702              DoAbsorption();
1034       DoReflection();                         << 703              // theStatus = Absorption;
1035     }                                         << 704              break;
1036     else                                      << 705 
1037     {                                         << 706            }
1038       ChooseReflection();                     << 707            else {
1039       if(fStatus == LambertianReflection)     << 708 
1040       {                                       << 709              if (PropertyPointer1 && PropertyPointer2) {
1041         DoReflection();                       << 710                 if ( n > 1 ) {
1042       }                                       << 711                    CalculateReflectivity();
1043       else if(fStatus == BackScattering)      << 712                    if ( !G4BooleanRand(theReflectivity) ) {
1044       {                                       << 713                       DoAbsorption();
1045         fNewMomentum     = -fOldMomentum;     << 714                       break;
1046         fNewPolarization = -fOldPolarization; << 715                    }
1047       }                                       << 716                 }
1048       else                                    << 717              }
1049       {                                       << 718 
1050         G4double PdotN, EdotN;                << 719              if ( theModel == glisur || theFinish == polished ) {
1051         do                                    << 720 
1052         {                                     << 721                 DoReflection();
1053           if(fStatus == LobeReflection)       << 722 
1054           {                                   << 723              } else {
1055             fFacetNormal = GetFacetNormal(fOl << 724 
1056           }                                   << 725                 if ( n == 1 ) ChooseReflection();
1057           PdotN        = fOldMomentum * fFace << 726                                                                                 
1058           fNewMomentum = fOldMomentum - (2. * << 727                 if ( theStatus == LambertianReflection ) {
1059           // Loop checking, 13-Aug-2015, Pete << 728                    DoReflection();
1060         } while(fNewMomentum * fGlobalNormal  << 729                 }
1061                                               << 730                 else if ( theStatus == BackScattering ) {
1062         EdotN            = fOldPolarization * << 731                    NewMomentum = -OldMomentum;
1063         fNewPolarization = -fOldPolarization  << 732                    NewPolarization = -OldPolarization;
1064       }                                       << 733                 }
1065     }                                         << 734                 else {
1066   }                                           << 735 
1067   else                                        << 736                    if(theStatus==LobeReflection){
1068   {                                           << 737                      if ( PropertyPointer1 && PropertyPointer2 ){
1069     fStatus          = Dichroic;              << 738                      } else {
1070     fNewMomentum     = fOldMomentum;          << 739                         theFacetNormal =
1071     fNewPolarization = fOldPolarization;      << 740                             GetFacetNormal(OldMomentum,theGlobalNormal);
1072   }                                           << 741                      }
1073 }                                             << 742                    }
                                                   >> 743 
                                                   >> 744                    G4double PdotN = OldMomentum * theFacetNormal;
                                                   >> 745                    NewMomentum = OldMomentum - (2.*PdotN)*theFacetNormal;
                                                   >> 746                    G4double EdotN = OldPolarization * theFacetNormal;
                                                   >> 747 
                                                   >> 748                    G4ThreeVector A_trans, A_paral;
                                                   >> 749 
                                                   >> 750                    if (sint1 > 0.0 ) {
                                                   >> 751                       A_trans = OldMomentum.cross(theFacetNormal);
                                                   >> 752                       A_trans = A_trans.unit();
                                                   >> 753                    } else {
                                                   >> 754                       A_trans  = OldPolarization;
                                                   >> 755                    }
                                                   >> 756                    A_paral   = NewMomentum.cross(A_trans);
                                                   >> 757                    A_paral   = A_paral.unit();
                                                   >> 758 
                                                   >> 759                    if(iTE>0&&iTM>0) {
                                                   >> 760                      NewPolarization = 
                                                   >> 761                            -OldPolarization + (2.*EdotN)*theFacetNormal;
                                                   >> 762                    } else if (iTE>0) {
                                                   >> 763                      NewPolarization = -A_trans;
                                                   >> 764                    } else if (iTM>0) {
                                                   >> 765                      NewPolarization = -A_paral;
                                                   >> 766                    }
                                                   >> 767 
                                                   >> 768                 }
1074                                                  769 
1075 //....oooOO0OOooo........oooOO0OOooo........o << 770              }
1076 void G4OpBoundaryProcess::DielectricDielectri << 
1077 {                                             << 
1078   G4bool inside = false;                      << 
1079   G4bool swap   = false;                      << 
1080                                                  771 
1081   if(fFinish == polished)                     << 772              OldMomentum = NewMomentum;
1082   {                                           << 773              OldPolarization = NewPolarization;
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                                                  774 
1102 leap:                                         << 775      }
1103                                                  776 
1104   G4bool through = false;                     << 777   } while (NewMomentum * theGlobalNormal < 0.0);
1105   G4bool done    = false;                     << 778 }
1106                                                  779 
1107   G4ThreeVector A_trans, A_paral, E1pp, E1pl; << 780 void G4OpBoundaryProcess::DielectricLUT()
1108   G4double E1_perp, E1_parl;                  << 781 {
1109   G4double s1, s2, E2_perp, E2_parl, E2_total << 782         G4int thetaIndex, phiIndex;
1110   G4double E2_abs, C_parl, C_perp;            << 783         G4double AngularDistributionValue, thetaRad, phiRad, EdotN;
1111   G4double alpha;                             << 784         G4ThreeVector PerpendicularVectorTheta, PerpendicularVectorPhi;
1112                                               << 785 
1113   do                                          << 786         theStatus = G4OpBoundaryProcessStatus(G4int(theFinish) + 
1114   {                                           << 787                            (G4int(NoRINDEX)-G4int(groundbackpainted)));
1115     if(through)                               << 788 
1116     {                                         << 789         G4int thetaIndexMax = OpticalSurface->GetThetaIndexMax();
1117       swap          = !swap;                  << 790         G4int phiIndexMax   = OpticalSurface->GetPhiIndexMax();
1118       through       = false;                  << 791 
1119       fGlobalNormal = -fGlobalNormal;         << 792         do {
1120       G4SwapPtr(fMaterial1, fMaterial2);      << 793            if ( !G4BooleanRand(theReflectivity) ) // Not reflected, so Absorbed
1121       G4SwapObj(&fRindex1, &fRindex2);        << 794               DoAbsorption();
1122     }                                         << 795            else {
1123                                               << 796               // Calculate Angle between Normal and Photon Momentum
1124     if(fFinish == polished)                   << 797               G4double anglePhotonToNormal = 
1125     {                                         << 798                                           OldMomentum.angle(-theGlobalNormal);
1126       fFacetNormal = fGlobalNormal;           << 799               // Round it to closest integer
1127     }                                         << 800               G4int angleIncident = G4int(std::floor(180/pi*anglePhotonToNormal+0.5));
1128     else                                      << 801 
1129     {                                         << 802               // Take random angles THETA and PHI, 
1130       fFacetNormal = GetFacetNormal(fOldMomen << 803               // and see if below Probability - if not - Redo
1131     }                                         << 804               do {
1132                                               << 805                  thetaIndex = G4RandFlat::shootInt(thetaIndexMax-1);
1133     cost1 = -fOldMomentum * fFacetNormal;     << 806                  phiIndex = G4RandFlat::shootInt(phiIndexMax-1);
1134     if(std::abs(cost1) < 1.0 - fCarTolerance) << 807                  // Find probability with the new indeces from LUT
1135     {                                         << 808                  AngularDistributionValue = OpticalSurface -> 
1136       fSint1 = std::sqrt(1. - cost1 * cost1); << 809                    GetAngularDistributionValue(angleIncident,
1137       sint2  = fSint1 * fRindex1 / fRindex2;  << 810                                                thetaIndex,
1138       // this isn't a sine as we might expect << 811                                                phiIndex);
1139     }                                         << 812               } while ( !G4BooleanRand(AngularDistributionValue) );
1140     else                                      << 813 
1141     {                                         << 814               thetaRad = (-90 + 4*thetaIndex)*pi/180;
1142       fSint1 = 0.0;                           << 815               phiRad = (-90 + 5*phiIndex)*pi/180;
1143       sint2  = 0.0;                           << 816               // Rotate Photon Momentum in Theta, then in Phi
1144     }                                         << 817               NewMomentum = -OldMomentum;
1145                                               << 818               PerpendicularVectorTheta = NewMomentum.cross(theGlobalNormal);
1146     // TOTAL INTERNAL REFLECTION              << 819               if (PerpendicularVectorTheta.mag() > kCarTolerance ) {
1147     if(sint2 >= 1.0)                          << 820                  PerpendicularVectorPhi = 
1148     {                                         << 821                                   PerpendicularVectorTheta.cross(NewMomentum);
1149       swap = false;                           << 822               }
1150                                               << 823               else {
1151       fStatus = TotalInternalReflection;      << 824                  PerpendicularVectorTheta = NewMomentum.orthogonal();
1152       if(!surfaceRoughnessCriterionPass)      << 825                  PerpendicularVectorPhi =
1153         fStatus = LambertianReflection;       << 826                                   PerpendicularVectorTheta.cross(NewMomentum);
1154       if(fModel == unified && fFinish != poli << 827               }
1155         ChooseReflection();                   << 828               NewMomentum =
1156       if(fStatus == LambertianReflection)     << 829                  NewMomentum.rotate(anglePhotonToNormal-thetaRad,
1157       {                                       << 830                                     PerpendicularVectorTheta);
1158         DoReflection();                       << 831               NewMomentum = NewMomentum.rotate(-phiRad,PerpendicularVectorPhi);
1159       }                                       << 832               // Rotate Polarization too:
1160       else if(fStatus == BackScattering)      << 833               theFacetNormal = (NewMomentum - OldMomentum).unit();
1161       {                                       << 834               EdotN = OldPolarization * theFacetNormal;
1162         fNewMomentum     = -fOldMomentum;     << 835               NewPolarization = -OldPolarization + (2.*EdotN)*theFacetNormal;
1163         fNewPolarization = -fOldPolarization; << 836            }
1164       }                                       << 837         } while (NewMomentum * theGlobalNormal <= 0.0);
1165       else                                    << 838 }
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                                                  839 
1255             fNewPolarization = C_parl * A_par << 840 void G4OpBoundaryProcess::DielectricDichroic()
1256           }                                   << 841 {
1257           else                                << 842         // Calculate Angle between Normal and Photon Momentum
1258           {  // incident ray perpendicular    << 843         G4double anglePhotonToNormal = OldMomentum.angle(-theGlobalNormal);
1259             if(fRindex2 > fRindex1)           << 
1260             {                                 << 
1261               fNewPolarization = -fOldPolariz << 
1262             }                                 << 
1263             else                              << 
1264             {                                 << 
1265               fNewPolarization = fOldPolariza << 
1266             }                                 << 
1267           }                                   << 
1268         }                                     << 
1269       }                                       << 
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                                                  844 
1286           fNewPolarization = C_parl * A_paral << 845         // Round it to closest integer
1287         }                                     << 846         G4double angleIncident = std::floor(180/pi*anglePhotonToNormal+0.5);
1288         else                                  << 847 
1289         {  // incident ray perpendicular      << 848         if (!DichroicVector) {
1290           fNewMomentum     = fOldMomentum;    << 849            if (OpticalSurface) DichroicVector = OpticalSurface->GetDichroicVector();
1291           fNewPolarization = fOldPolarization << 
1292         }                                        850         }
1293       }                                       << 
1294     }                                         << 
1295                                                  851 
1296     fOldMomentum     = fNewMomentum.unit();   << 
1297     fOldPolarization = fNewPolarization.unit( << 
1298                                                  852 
1299     if(fStatus == FresnelRefraction)          << 853         if (DichroicVector) {
1300     {                                         << 854            G4double wavelength = h_Planck*c_light/thePhotonMomentum;
1301       done = (fNewMomentum * fGlobalNormal <= << 855            theTransmittance =
1302     }                                         << 856              DichroicVector->Value(wavelength/nm,angleIncident,idx,idy)*perCent;
1303     else                                      << 857 //            G4cout << "wavelength: " << std::floor(wavelength/nm) 
1304     {                                         << 858 //                                     << "nm" << G4endl;
1305       done = (fNewMomentum * fGlobalNormal >= << 859 //            G4cout << "Incident angle: " << angleIncident << "deg" << G4endl;
1306     }                                         << 860 //            G4cout << "Transmittance: " 
1307     // Loop checking, 13-Aug-2015, Peter Gump << 861 //                   << std::floor(theTransmittance/perCent) << "%" << G4endl;
1308   } while(!done);                             << 862         } else {
1309                                               << 863            G4ExceptionDescription ed;
1310   if(inside && !swap)                         << 864            ed << " G4OpBoundaryProcess/DielectricDichroic(): "
1311   {                                           << 865               << " The dichroic surface has no G4Physics2DVector"
1312     if(fFinish == polishedbackpainted || fFin << 866               << G4endl;
1313     {                                         << 867            G4Exception("G4OpBoundaryProcess::DielectricDichroic", "OpBoun03",
1314       G4double rand = G4UniformRand();        << 868                        FatalException,ed,
1315       if(rand > fReflectivity + fTransmittanc << 869                        "A dichroic surface must have an associated G4Physics2DVector");
1316       {                                       << 870         }
1317         DoAbsorption();                       << 871 
1318       }                                       << 872         if ( !G4BooleanRand(theTransmittance) ) // Not transmitted, so reflect
1319       else if(rand > fReflectivity)           << 873            DoReflection();
1320       {                                       << 874         else {
1321         fStatus          = Transmission;      << 875            theStatus = Dichroic;
1322         fNewMomentum     = fOldMomentum;      << 876            NewMomentum = OldMomentum;
1323         fNewPolarization = fOldPolarization;  << 877            NewPolarization = OldPolarization;
1324       }                                       << 
1325       else                                    << 
1326       {                                       << 
1327         if(fStatus != FresnelRefraction)      << 
1328         {                                     << 
1329           fGlobalNormal = -fGlobalNormal;     << 
1330         }                                        878         }
1331         else                                  << 879 }
1332         {                                     << 
1333           swap = !swap;                       << 
1334           G4SwapPtr(fMaterial1, fMaterial2);  << 
1335           G4SwapObj(&fRindex1, &fRindex2);    << 
1336         }                                     << 
1337         if(fFinish == groundbackpainted)      << 
1338           fStatus = LambertianReflection;     << 
1339                                                  880 
1340         DoReflection();                       << 881 void G4OpBoundaryProcess::DielectricDielectric()
                                                   >> 882 {
                                                   >> 883   G4bool Inside = false;
                                                   >> 884   G4bool Swap = false;
1341                                                  885 
1342         fGlobalNormal = -fGlobalNormal;       << 886   leap:
1343         fOldMomentum  = fNewMomentum;         << 
1344                                                  887 
1345         goto leap;                            << 888         G4bool Through = false;
1346       }                                       << 889   G4bool Done = false;
1347     }                                         << 890 
1348   }                                           << 891   do {
                                                   >> 892 
                                                   >> 893      if (Through) {
                                                   >> 894         Swap = !Swap;
                                                   >> 895         Through = false;
                                                   >> 896         theGlobalNormal = -theGlobalNormal;
                                                   >> 897         G4SwapPtr(Material1,Material2);
                                                   >> 898         G4SwapObj(&Rindex1,&Rindex2);
                                                   >> 899      }
                                                   >> 900   
                                                   >> 901      if ( theFinish == polished ) {
                                                   >> 902           theFacetNormal = theGlobalNormal;
                                                   >> 903      }
                                                   >> 904      else {
                                                   >> 905           theFacetNormal =
                                                   >> 906                        GetFacetNormal(OldMomentum,theGlobalNormal);
                                                   >> 907      }
                                                   >> 908 
                                                   >> 909      G4double PdotN = OldMomentum * theFacetNormal;
                                                   >> 910      G4double EdotN = OldPolarization * theFacetNormal;
                                                   >> 911 
                                                   >> 912      cost1 = - PdotN;
                                                   >> 913      if (std::abs(cost1) < 1.0-kCarTolerance){
                                                   >> 914         sint1 = std::sqrt(1.-cost1*cost1);
                                                   >> 915         sint2 = sint1*Rindex1/Rindex2;     // *** Snell's Law ***
                                                   >> 916      }
                                                   >> 917      else {
                                                   >> 918         sint1 = 0.0;
                                                   >> 919         sint2 = 0.0;
                                                   >> 920      }
                                                   >> 921 
                                                   >> 922      if (sint2 >= 1.0) {
                                                   >> 923 
                                                   >> 924         // Simulate total internal reflection
                                                   >> 925 
                                                   >> 926         if (Swap) Swap = !Swap;
                                                   >> 927 
                                                   >> 928               theStatus = TotalInternalReflection;
                                                   >> 929 
                                                   >> 930         if ( theModel == unified && theFinish != polished )
                                                   >> 931                  ChooseReflection();
                                                   >> 932 
                                                   >> 933         if ( theStatus == LambertianReflection ) {
                                                   >> 934      DoReflection();
                                                   >> 935         }
                                                   >> 936         else if ( theStatus == BackScattering ) {
                                                   >> 937      NewMomentum = -OldMomentum;
                                                   >> 938      NewPolarization = -OldPolarization;
                                                   >> 939         }
                                                   >> 940         else {
                                                   >> 941 
                                                   >> 942                  PdotN = OldMomentum * theFacetNormal;
                                                   >> 943      NewMomentum = OldMomentum - (2.*PdotN)*theFacetNormal;
                                                   >> 944      EdotN = OldPolarization * theFacetNormal;
                                                   >> 945      NewPolarization = -OldPolarization + (2.*EdotN)*theFacetNormal;
                                                   >> 946 
                                                   >> 947         }
                                                   >> 948      }
                                                   >> 949      else if (sint2 < 1.0) {
                                                   >> 950 
                                                   >> 951         // Calculate amplitude for transmission (Q = P x N)
                                                   >> 952 
                                                   >> 953         if (cost1 > 0.0) {
                                                   >> 954            cost2 =  std::sqrt(1.-sint2*sint2);
                                                   >> 955         }
                                                   >> 956         else {
                                                   >> 957            cost2 = -std::sqrt(1.-sint2*sint2);
                                                   >> 958         }
                                                   >> 959 
                                                   >> 960         G4ThreeVector A_trans, A_paral, E1pp, E1pl;
                                                   >> 961         G4double E1_perp, E1_parl;
                                                   >> 962 
                                                   >> 963         if (sint1 > 0.0) {
                                                   >> 964            A_trans = OldMomentum.cross(theFacetNormal);
                                                   >> 965                  A_trans = A_trans.unit();
                                                   >> 966            E1_perp = OldPolarization * A_trans;
                                                   >> 967                  E1pp    = E1_perp * A_trans;
                                                   >> 968                  E1pl    = OldPolarization - E1pp;
                                                   >> 969                  E1_parl = E1pl.mag();
                                                   >> 970               }
                                                   >> 971         else {
                                                   >> 972            A_trans  = OldPolarization;
                                                   >> 973            // Here we Follow Jackson's conventions and we set the
                                                   >> 974            // parallel component = 1 in case of a ray perpendicular
                                                   >> 975            // to the surface
                                                   >> 976            E1_perp  = 0.0;
                                                   >> 977            E1_parl  = 1.0;
                                                   >> 978         }
                                                   >> 979 
                                                   >> 980               G4double s1 = Rindex1*cost1;
                                                   >> 981               G4double E2_perp = 2.*s1*E1_perp/(Rindex1*cost1+Rindex2*cost2);
                                                   >> 982               G4double E2_parl = 2.*s1*E1_parl/(Rindex2*cost1+Rindex1*cost2);
                                                   >> 983               G4double E2_total = E2_perp*E2_perp + E2_parl*E2_parl;
                                                   >> 984               G4double s2 = Rindex2*cost2*E2_total;
                                                   >> 985 
                                                   >> 986               G4double TransCoeff;
                                                   >> 987 
                                                   >> 988               if (theTransmittance > 0) TransCoeff = theTransmittance;
                                                   >> 989               else if (cost1 != 0.0) TransCoeff = s2/s1;
                                                   >> 990               else TransCoeff = 0.0;
                                                   >> 991 
                                                   >> 992         G4double E2_abs, C_parl, C_perp;
                                                   >> 993 
                                                   >> 994         if ( !G4BooleanRand(TransCoeff) ) {
                                                   >> 995 
                                                   >> 996            // Simulate reflection
                                                   >> 997 
                                                   >> 998                  if (Swap) Swap = !Swap;
                                                   >> 999 
                                                   >> 1000      theStatus = FresnelReflection;
                                                   >> 1001 
                                                   >> 1002      if ( theModel == unified && theFinish != polished )
                                                   >> 1003                  ChooseReflection();
                                                   >> 1004 
                                                   >> 1005      if ( theStatus == LambertianReflection ) {
                                                   >> 1006         DoReflection();
                                                   >> 1007      }
                                                   >> 1008      else if ( theStatus == BackScattering ) {
                                                   >> 1009         NewMomentum = -OldMomentum;
                                                   >> 1010         NewPolarization = -OldPolarization;
                                                   >> 1011      }
                                                   >> 1012      else {
                                                   >> 1013 
                                                   >> 1014                     PdotN = OldMomentum * theFacetNormal;
                                                   >> 1015               NewMomentum = OldMomentum - (2.*PdotN)*theFacetNormal;
                                                   >> 1016 
                                                   >> 1017               if (sint1 > 0.0) {   // incident ray oblique
                                                   >> 1018 
                                                   >> 1019            E2_parl   = Rindex2*E2_parl/Rindex1 - E1_parl;
                                                   >> 1020            E2_perp   = E2_perp - E1_perp;
                                                   >> 1021            E2_total  = E2_perp*E2_perp + E2_parl*E2_parl;
                                                   >> 1022                        A_paral   = NewMomentum.cross(A_trans);
                                                   >> 1023                        A_paral   = A_paral.unit();
                                                   >> 1024            E2_abs    = std::sqrt(E2_total);
                                                   >> 1025            C_parl    = E2_parl/E2_abs;
                                                   >> 1026            C_perp    = E2_perp/E2_abs;
                                                   >> 1027 
                                                   >> 1028                        NewPolarization = C_parl*A_paral + C_perp*A_trans;
                                                   >> 1029 
                                                   >> 1030               }
                                                   >> 1031 
                                                   >> 1032               else {               // incident ray perpendicular
                                                   >> 1033 
                                                   >> 1034                  if (Rindex2 > Rindex1) {
                                                   >> 1035               NewPolarization = - OldPolarization;
                                                   >> 1036                  }
                                                   >> 1037                  else {
                                                   >> 1038                     NewPolarization =   OldPolarization;
                                                   >> 1039                  }
                                                   >> 1040 
                                                   >> 1041               }
                                                   >> 1042            }
                                                   >> 1043         }
                                                   >> 1044         else { // photon gets transmitted
                                                   >> 1045 
                                                   >> 1046            // Simulate transmission/refraction
                                                   >> 1047 
                                                   >> 1048      Inside = !Inside;
                                                   >> 1049      Through = true;
                                                   >> 1050      theStatus = FresnelRefraction;
                                                   >> 1051 
                                                   >> 1052            if (sint1 > 0.0) {      // incident ray oblique
                                                   >> 1053 
                                                   >> 1054         G4double alpha = cost1 - cost2*(Rindex2/Rindex1);
                                                   >> 1055         NewMomentum = OldMomentum + alpha*theFacetNormal;
                                                   >> 1056         NewMomentum = NewMomentum.unit();
                                                   >> 1057         PdotN = -cost2;
                                                   >> 1058                     A_paral = NewMomentum.cross(A_trans);
                                                   >> 1059                     A_paral = A_paral.unit();
                                                   >> 1060         E2_abs     = std::sqrt(E2_total);
                                                   >> 1061         C_parl     = E2_parl/E2_abs;
                                                   >> 1062         C_perp     = E2_perp/E2_abs;
                                                   >> 1063 
                                                   >> 1064                     NewPolarization = C_parl*A_paral + C_perp*A_trans;
                                                   >> 1065 
                                                   >> 1066            }
                                                   >> 1067            else {                  // incident ray perpendicular
                                                   >> 1068 
                                                   >> 1069         NewMomentum = OldMomentum;
                                                   >> 1070         NewPolarization = OldPolarization;
                                                   >> 1071 
                                                   >> 1072            }
                                                   >> 1073         }
                                                   >> 1074      }
                                                   >> 1075 
                                                   >> 1076      OldMomentum = NewMomentum.unit();
                                                   >> 1077      OldPolarization = NewPolarization.unit();
                                                   >> 1078 
                                                   >> 1079      if (theStatus == FresnelRefraction) {
                                                   >> 1080         Done = (NewMomentum * theGlobalNormal <= 0.0);
                                                   >> 1081      } 
                                                   >> 1082      else {
                                                   >> 1083         Done = (NewMomentum * theGlobalNormal >= 0.0);
                                                   >> 1084      }
                                                   >> 1085 
                                                   >> 1086   } while (!Done);
                                                   >> 1087 
                                                   >> 1088   if (Inside && !Swap) {
                                                   >> 1089           if( theFinish == polishedbackpainted ||
                                                   >> 1090               theFinish == groundbackpainted ) {
                                                   >> 1091 
                                                   >> 1092         if( !G4BooleanRand(theReflectivity) ) {
                                                   >> 1093     DoAbsorption();
                                                   >> 1094               }
                                                   >> 1095         else {
                                                   >> 1096     if (theStatus != FresnelRefraction ) {
                                                   >> 1097        theGlobalNormal = -theGlobalNormal;
                                                   >> 1098           }
                                                   >> 1099           else {
                                                   >> 1100        Swap = !Swap;
                                                   >> 1101        G4SwapPtr(Material1,Material2);
                                                   >> 1102        G4SwapObj(&Rindex1,&Rindex2);
                                                   >> 1103           }
                                                   >> 1104     if ( theFinish == groundbackpainted )
                                                   >> 1105           theStatus = LambertianReflection;
                                                   >> 1106 
                                                   >> 1107           DoReflection();
                                                   >> 1108 
                                                   >> 1109           theGlobalNormal = -theGlobalNormal;
                                                   >> 1110     OldMomentum = NewMomentum;
                                                   >> 1111 
                                                   >> 1112           goto leap;
                                                   >> 1113         }
                                                   >> 1114     }
                                                   >> 1115   }
1349 }                                                1116 }
1350                                                  1117 
1351 //....oooOO0OOooo........oooOO0OOooo........o << 1118 // GetMeanFreePath
1352 G4double G4OpBoundaryProcess::GetMeanFreePath << 1119 // ---------------
                                                   >> 1120 //
                                                   >> 1121 G4double G4OpBoundaryProcess::GetMeanFreePath(const G4Track& ,
                                                   >> 1122                                               G4double ,
1353                                                  1123                                               G4ForceCondition* condition)
1354 {                                                1124 {
1355   *condition = Forced;                        << 1125   *condition = Forced;
1356   return DBL_MAX;                             << 1126 
                                                   >> 1127   return DBL_MAX;
1357 }                                                1128 }
1358                                                  1129 
1359 //....oooOO0OOooo........oooOO0OOooo........o << 1130 G4double G4OpBoundaryProcess::GetIncidentAngle() 
1360 G4double G4OpBoundaryProcess::GetIncidentAngl << 
1361 {                                                1131 {
1362   return pi - std::acos(fOldMomentum * fFacet << 1132     G4double PdotN = OldMomentum * theFacetNormal;
1363                         (fOldMomentum.mag() * << 1133     G4double magP= OldMomentum.mag();
                                                   >> 1134     G4double magN= theFacetNormal.mag();
                                                   >> 1135     G4double incidentangle = pi - std::acos(PdotN/(magP*magN));
                                                   >> 1136 
                                                   >> 1137     return incidentangle;
1364 }                                                1138 }
1365                                                  1139 
1366 //....oooOO0OOooo........oooOO0OOooo........o << 
1367 G4double G4OpBoundaryProcess::GetReflectivity    1140 G4double G4OpBoundaryProcess::GetReflectivity(G4double E1_perp,
1368                                                  1141                                               G4double E1_parl,
1369                                                  1142                                               G4double incidentangle,
1370                                               << 1143                                               G4double RealRindex,
1371                                               << 1144                                               G4double ImaginaryRindex)
1372 {                                                1145 {
1373   G4complex reflectivity, reflectivity_TE, re << 
1374   G4complex N1(fRindex1, 0.), N2(realRindex,  << 
1375   G4complex cosPhi;                           << 
1376                                                  1146 
1377   G4complex u(1., 0.);  // unit number 1      << 1147   G4complex Reflectivity, Reflectivity_TE, Reflectivity_TM;
                                                   >> 1148   G4complex N(RealRindex, ImaginaryRindex);
                                                   >> 1149   G4complex CosPhi;
                                                   >> 1150 
                                                   >> 1151   G4complex u(1,0);           //unit number 1
1378                                                  1152 
1379   G4complex numeratorTE;  // E1_perp=1 E1_par << 1153   G4complex numeratorTE;      // E1_perp=1 E1_parl=0 -> TE polarization
1380   G4complex numeratorTM;  // E1_parl=1 E1_per << 1154   G4complex numeratorTM;      // E1_parl=1 E1_perp=0 -> TM polarization
1381   G4complex denominatorTE, denominatorTM;        1155   G4complex denominatorTE, denominatorTM;
1382   G4complex rTM, rTE;                            1156   G4complex rTM, rTE;
1383                                                  1157 
1384   G4MaterialPropertiesTable* MPT = fMaterial1 << 
1385   G4MaterialPropertyVector* ppR  = MPT->GetPr << 
1386   G4MaterialPropertyVector* ppI  = MPT->GetPr << 
1387   if(ppR && ppI)                              << 
1388   {                                           << 
1389     G4double rRindex = ppR->Value(fPhotonMome << 
1390     G4double iRindex = ppI->Value(fPhotonMome << 
1391     N1               = G4complex(rRindex, iRi << 
1392   }                                           << 
1393                                               << 
1394   // Following two equations, rTM and rTE, ar    1158   // Following two equations, rTM and rTE, are from: "Introduction To Modern
1395   // Optics" written by Fowles                   1159   // Optics" written by Fowles
1396   cosPhi = std::sqrt(u - ((std::sin(incidenta << 
1397                           (N1 * N1) / (N2 * N << 
1398                                                  1160 
1399   numeratorTE   = N1 * std::cos(incidentangle << 1161   CosPhi=std::sqrt(u-((std::sin(incidentangle)*std::sin(incidentangle))/(N*N)));
1400   denominatorTE = N1 * std::cos(incidentangle << 1162 
1401   rTE           = numeratorTE / denominatorTE << 1163   numeratorTE   = std::cos(incidentangle) - N*CosPhi;
1402                                               << 1164   denominatorTE = std::cos(incidentangle) + N*CosPhi;
1403   numeratorTM   = N2 * std::cos(incidentangle << 1165   rTE = numeratorTE/denominatorTE;
1404   denominatorTM = N2 * std::cos(incidentangle << 1166 
1405   rTM           = numeratorTM / denominatorTM << 1167   numeratorTM   = N*std::cos(incidentangle) - CosPhi;
                                                   >> 1168   denominatorTM = N*std::cos(incidentangle) + CosPhi;
                                                   >> 1169   rTM = numeratorTM/denominatorTM;
1406                                                  1170 
1407   // This is my (PG) calculaton for reflectiv << 1171   // This is my calculaton for reflectivity on a metalic surface
1408   // depending on the fraction of TE and TM p    1172   // depending on the fraction of TE and TM polarization
1409   // when TE polarization, E1_parl=0 and E1_p    1173   // 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    1174   // when TM polarization, E1_parl=1 and E1_perp=0, R=abs(rTM)^2
1411                                                  1175 
1412   reflectivity_TE = (rTE * conj(rTE)) * (E1_p << 1176   Reflectivity_TE =  (rTE*conj(rTE))*(E1_perp*E1_perp)
1413                     (E1_perp * E1_perp + E1_p << 1177                     / (E1_perp*E1_perp + E1_parl*E1_parl);
1414   reflectivity_TM = (rTM * conj(rTM)) * (E1_p << 1178   Reflectivity_TM =  (rTM*conj(rTM))*(E1_parl*E1_parl)
1415                     (E1_perp * E1_perp + E1_p << 1179                     / (E1_perp*E1_perp + E1_parl*E1_parl);
1416   reflectivity = reflectivity_TE + reflectivi << 1180   Reflectivity    = Reflectivity_TE + Reflectivity_TM;
1417                                               << 1181 
1418   do                                          << 1182   do {
1419   {                                           << 1183      if(G4UniformRand()*real(Reflectivity) > real(Reflectivity_TE))
1420     if(G4UniformRand() * real(reflectivity) > << 1184        {iTE = -1;}else{iTE = 1;}
1421     {                                         << 1185      if(G4UniformRand()*real(Reflectivity) > real(Reflectivity_TM))
1422       f_iTE = -1;                             << 1186        {iTM = -1;}else{iTM = 1;}
1423     }                                         << 1187   } while(iTE<0&&iTM<0);
1424     else                                      << 1188 
1425     {                                         << 1189   return real(Reflectivity);
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 << 
1437   } while(f_iTE < 0 && f_iTM < 0);            << 
1438                                                  1190 
1439   return real(reflectivity);                  << 
1440 }                                                1191 }
1441                                                  1192 
1442 //....oooOO0OOooo........oooOO0OOooo........o << 
1443 void G4OpBoundaryProcess::CalculateReflectivi    1193 void G4OpBoundaryProcess::CalculateReflectivity()
1444 {                                                1194 {
1445   G4double realRindex = fRealRIndexMPV->Value << 1195   G4double RealRindex =
1446   G4double imaginaryRindex =                  << 1196            PropertyPointer1->Value(thePhotonMomentum);
1447     fImagRIndexMPV->Value(fPhotonMomentum, id << 1197   G4double ImaginaryRindex =
                                                   >> 1198            PropertyPointer2->Value(thePhotonMomentum);
1448                                                  1199 
1449   // calculate FacetNormal                       1200   // calculate FacetNormal
1450   if(fFinish == ground)                       << 1201   if ( theFinish == ground ) {
1451   {                                           << 1202      theFacetNormal =
1452     fFacetNormal = GetFacetNormal(fOldMomentu << 1203                GetFacetNormal(OldMomentum, theGlobalNormal);
1453   }                                           << 1204   } else {
1454   else                                        << 1205      theFacetNormal = theGlobalNormal;
1455   {                                           << 
1456     fFacetNormal = fGlobalNormal;             << 
1457   }                                              1206   }
1458                                                  1207 
1459   G4double cost1 = -fOldMomentum * fFacetNorm << 1208   G4double PdotN = OldMomentum * theFacetNormal;
1460   if(std::abs(cost1) < 1.0 - fCarTolerance)   << 1209   cost1 = -PdotN;
1461   {                                           << 1210 
1462     fSint1 = std::sqrt(1. - cost1 * cost1);   << 1211   if (std::abs(cost1) < 1.0 - kCarTolerance) {
1463   }                                           << 1212      sint1 = std::sqrt(1. - cost1*cost1);
1464   else                                        << 1213   } else {
1465   {                                           << 1214      sint1 = 0.0;
1466     fSint1 = 0.0;                             << 
1467   }                                              1215   }
1468                                                  1216 
1469   G4ThreeVector A_trans, A_paral, E1pp, E1pl;    1217   G4ThreeVector A_trans, A_paral, E1pp, E1pl;
1470   G4double E1_perp, E1_parl;                     1218   G4double E1_perp, E1_parl;
1471                                                  1219 
1472   if(fSint1 > 0.0)                            << 1220   if (sint1 > 0.0 ) {
1473   {                                           << 1221      A_trans = OldMomentum.cross(theFacetNormal);
1474     A_trans = (fOldMomentum.cross(fFacetNorma << 1222      A_trans = A_trans.unit();
1475     E1_perp = fOldPolarization * A_trans;     << 1223      E1_perp = OldPolarization * A_trans;
1476     E1pp    = E1_perp * A_trans;              << 1224      E1pp    = E1_perp * A_trans;
1477     E1pl    = fOldPolarization - E1pp;        << 1225      E1pl    = OldPolarization - E1pp;
1478     E1_parl = E1pl.mag();                     << 1226      E1_parl = E1pl.mag();
1479   }                                           << 1227   }
1480   else                                        << 1228   else {
1481   {                                           << 1229      A_trans  = OldPolarization;
1482     A_trans = fOldPolarization;               << 1230      // Here we Follow Jackson's conventions and we set the
1483     // Here we Follow Jackson's conventions a << 1231      // parallel component = 1 in case of a ray perpendicular
1484     // component = 1 in case of a ray perpend << 1232      // to the surface
1485     E1_perp = 0.0;                            << 1233      E1_perp  = 0.0;
1486     E1_parl = 1.0;                            << 1234      E1_parl  = 1.0;
1487   }                                              1235   }
1488                                                  1236 
                                                   >> 1237   //calculate incident angle
1489   G4double incidentangle = GetIncidentAngle()    1238   G4double incidentangle = GetIncidentAngle();
1490                                                  1239 
1491   // calculate the reflectivity depending on  << 1240   //calculate the reflectivity depending on incident angle,
1492   // polarization and complex refractive      << 1241   //polarization and complex refractive
1493   fReflectivity = GetReflectivity(E1_perp, E1 << 1242 
1494                                   imaginaryRi << 1243   theReflectivity =
                                                   >> 1244              GetReflectivity(E1_perp, E1_parl, incidentangle,
                                                   >> 1245                                                  RealRindex, ImaginaryRindex);
1495 }                                                1246 }
1496                                                  1247 
1497 //....oooOO0OOooo........oooOO0OOooo........o << 
1498 G4bool G4OpBoundaryProcess::InvokeSD(const G4    1248 G4bool G4OpBoundaryProcess::InvokeSD(const G4Step* pStep)
1499 {                                                1249 {
1500   G4Step aStep = *pStep;                         1250   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                                               << 
1517 //....oooOO0OOooo........oooOO0OOooo........o << 
1518 void G4OpBoundaryProcess::SetVerboseLevel(G4i << 
1519 {                                             << 
1520   verboseLevel = verbose;                     << 
1521   G4OpticalParameters::Instance()->SetBoundar << 
1522 }                                             << 
1523                                               << 
1524 //....oooOO0OOooo........oooOO0OOooo........o << 
1525 void G4OpBoundaryProcess::CoatedDielectricDie << 
1526 {                                             << 
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                                                  1251 
1729     fOldMomentum = fNewMomentum.unit();       << 1252   aStep.AddTotalEnergyDeposit(thePhotonMomentum);
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                                                  1253 
1741   } while (!done);                            << 1254   G4VSensitiveDetector* sd = aStep.GetPostStepPoint()->GetSensitiveDetector();
1742 }                                             << 1255   if (sd) return sd->Hit(&aStep);
1743                                               << 1256   else return false;
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 }                                                1257 }
1832                                                  1258