def testTMM(self): # Copied from tmm.tests.basic_test() ROOT.gROOT.ProcessLine( 'std::shared_ptr<ARefractiveIndex> med1(new ARefractiveIndex(1.));' ) ROOT.gROOT.ProcessLine( 'std::shared_ptr<ARefractiveIndex> med2(new ARefractiveIndex(2., 4.));' ) ROOT.gROOT.ProcessLine( 'std::shared_ptr<ARefractiveIndex> med3(new ARefractiveIndex(3., .3));' ) ROOT.gROOT.ProcessLine( 'std::shared_ptr<ARefractiveIndex> med4(new ARefractiveIndex(1., .1));' ) multi = ROOT.AMultilayer(ROOT.med1, ROOT.med4) multi.InsertLayer(ROOT.med2, 2) multi.InsertLayer(ROOT.med3, 3) th_0 = ROOT.std.complex(ROOT.double)(0.1) lam_vac = 100 # Units are not important rs, rp = 0.37273208839139516, 0.37016110373044969 ts, tp = 0.22604491247079261, 0.22824374314132009 reflectance = ctypes.c_double() transmittance = ctypes.c_double() multi.CoherentTMM(ROOT.AMultilayer.kS, th_0, lam_vac, reflectance, transmittance) self.assertAlmostEqual(reflectance.value, rs) self.assertAlmostEqual(transmittance.value, ts) multi.CoherentTMM(ROOT.AMultilayer.kP, th_0, lam_vac, reflectance, transmittance) self.assertAlmostEqual(reflectance.value, rp) self.assertAlmostEqual(transmittance.value, tp) multi.CoherentTMMMixed(th_0, lam_vac, reflectance, transmittance) self.assertAlmostEqual(reflectance.value, (rs + rp) / 2.) self.assertAlmostEqual(transmittance.value, (ts + tp) / 2.) wavelength_v = ROOT.vector('Double_t')() answer = [] for i in range(300, 800): wavelength_v.push_back(i) multi.CoherentTMMMixed(th_0, wavelength_v.back(), reflectance, transmittance) answer.append((reflectance.value, transmittance.value)) reflectance_v = ROOT.vector('Double_t')() transmittance_v = ROOT.vector('Double_t')() multi.CoherentTMMMixed(th_0, wavelength_v, reflectance_v, transmittance_v) for i in range(wavelength_v.size()): self.assertAlmostEqual(answer[i][0], reflectance_v[i]) self.assertAlmostEqual(answer[i][1], transmittance_v[i]) angle_v = ROOT.vector('std::complex<Double_t>')() answer = [] for i in range(500): angle_v.push_back( ROOT.std.complex(ROOT.double)(i * ROOT.TMath.Pi() / 2000.)) multi.CoherentTMMMixed(angle_v.back(), lam_vac, reflectance, transmittance) answer.append((reflectance.value, transmittance.value)) multi.CoherentTMMMixed(angle_v, lam_vac, reflectance_v, transmittance_v) for i in range(angle_v.size()): self.assertAlmostEqual(answer[i][0], reflectance_v[i]) self.assertAlmostEqual(answer[i][1], transmittance_v[i])
def testFresnelReflection(self): manager = makeTheWorld() manager.DisableFresnelReflection(False) # enable lensbox = ROOT.TGeoBBox("lensbox", 0.5 * m, 0.5 * m, 0.5 * m) lens = ROOT.ALens("lens", lensbox) wl = 400 * nm absl = 1 * um idx = 3. ROOT.gROOT.ProcessLine('double idx, k;') ROOT.idx = idx ROOT.k = ROOT.ARefractiveIndex.AbsorptionLengthToExtinctionCoefficient( absl, wl) ROOT.gROOT.ProcessLine( 'refidx = std::make_shared<ARefractiveIndex>(idx, k);') lens.SetRefractiveIndex(ROOT.refidx) manager.GetTopVolume().AddNode(lens, 1) manager.CloseGeometry() if ROOT.gInterpreter.ProcessLine('ROOT_VERSION_CODE;') < \ ROOT.gInterpreter.ProcessLine('ROOT_VERSION(6, 2, 0);'): manager.SetMultiThread(True) manager.SetMaxThreads(4) N = 100000 rays = ROOT.ARayArray() for i in range(N): ray = ROOT.ARay(i, wl, 0, 0, 0.8 * m, 0, 0, 0, -1) rays.Add(ray) manager.TraceNonSequential(rays) n = rays.GetExited().GetLast() + 1 ref = (idx - 1)**2 / (idx + 1)**2 self.assertGreater(ref, (n - n**0.5 * 3) / N) self.assertLess(ref, (n + n**0.5 * 3) / N) layer = ROOT.AMultilayer(ROOT.air, ROOT.TiO2) angle = ROOT.std.complex(ROOT.double)(45 * deg) for wl in (200 * nm, 800 * nm): ref, trans = ctypes.c_double(), ctypes.c_double() layer.CoherentTMMMixed(angle, wl, ref, trans) lens.SetRefractiveIndex(ROOT.TiO2) rays = ROOT.ARayArray() z, dy, dz = 0.51 * m, 1 / 2**0.5, -1 / 2**0.5 for i in range(N): ray = ROOT.ARay(i, wl, 0, 0, z, 0, 0, dy, dz) rays.Add(ray) manager.SetLimit( 3) # stop tracking of photons that entered the lens manager.TraceNonSequential(rays) n = rays.GetExited().GetLast() + 1 self.assertGreater(ref.value, (n - n**0.5 * 3) / N) self.assertLess(ref.value, (n + n**0.5 * 3) / N)