Physics/Ellipsometry/VASE/MagnetoOptic.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 65 CC 4 SCAR 20.8
CC
4
Cov
0%
magneto_optic_tensor
20.0
kerr_rotation
2.0
BEGIN
2.0
CRAP 8.0
1 package Physics::Ellipsometry::VASE::MagnetoOptic;
2 use strict;
3 use warnings;
4 use PDL;
5 use PDL::NiceSlice;
6 use PDL::Constants qw(PI);
7 use Exporter 'import';
8  
9 our @EXPORT_OK = qw(magneto_optic_tensor kerr_rotation);
10  
11 our $VERSION = '1.04';
12  
13 =encoding utf8
14  
15 =head1 NAME
16  
17 Physics::Ellipsometry::VASE::MagnetoOptic - Magneto-optic Kerr effect
18 (MOKE) models for spectroscopic ellipsometry
19  
20 =head1 SYNOPSIS
21  
22 use PDL;
23 use Physics::Ellipsometry::VASE::MagnetoOptic qw(
24 magneto_optic_tensor kerr_rotation
25 );
26  
27 my $lambda = sequence(100) * 10 + 400;
28  
29 # Construct MO dielectric tensor for a ferromagnet
30 my $eps_d = pdl(-13.8) + i()*pdl(15.7); # diagonal (Fe at 633nm)
31 my $eps_od = pdl(0.74) + i()*pdl(0.21); # off-diagonal (Q*N)
32 my $tensor = magneto_optic_tensor($eps_d, $eps_od,
33 geometry => 'polar');
34  
35 # Kerr rotation from a semi-infinite magnetic layer
36 my ($theta_K, $eta_K) = kerr_rotation($lambda, 65,
37 eps_diag => pdl(-13.8)+i()*pdl(15.7),
38 Q => pdl(0.04)+i()*pdl(0.006),
39 geometry => 'polar',
40 );
41  
42 =head1 DESCRIPTION
43  
44 The magneto-optic Kerr effect (MOKE) describes the change in
45 polarization state of light upon reflection from a magnetized material.
46 It is widely used for magnetic thin film characterization and has three
47 geometries:
48  
49 =over 4
50  
51 =item B<Polar MOKE> - Magnetization perpendicular to the surface
52 (along z). Produces Kerr rotation in the reflected beam for both
53 s- and p-polarized light. Typically the largest signal.
54  
55 =item B<Longitudinal MOKE> - Magnetization in the surface plane,
56 within the plane of incidence (along x). Produces rotation
57 proportional to cos(θ).
58  
59 =item B<Transverse MOKE> - Magnetization in the surface plane,
60 perpendicular to the plane of incidence (along y). Changes only
61 the p-polarized reflectance amplitude (no rotation; changes Δ only).
62  
63 =back
64  
65 The magneto-optic response is described by the Voigt parameter Q,
66 which quantifies the ratio of off-diagonal to diagonal permittivity:
67  
68 epsilon_xy = i * Q * epsilon_xx
69  
70 The full dielectric tensor for polar geometry:
71  
72 ⎡ ε_xx iQε 0 ⎤
73 ε = ⎢-iQε ε_yy 0 ⎥
74 ⎣ 0 0 ε_zz ⎦
75  
76 For longitudinal geometry, the off-diagonal elements appear in the
77 xz and zx positions.
78  
79 =head1 FUNCTIONS
80  
81 =head2 magneto_optic_tensor
82  
83 my $tensor = magneto_optic_tensor($eps_diag, $eps_offdiag,
84 geometry => 'polar');
85  
86 Constructs the 3×3 dielectric tensor with magneto-optic off-diagonal
87 elements.
88  
89 B<Parameters:>
90  
91 =over 4
92  
93 =item C<$eps_diag> - diagonal permittivity component(s) (complex PDL or scalar)
94  
95 =item C<$eps_offdiag> - off-diagonal permittivity (= i*Q*eps_diag for polar)
96  
97 =item C<geometry> - 'polar', 'longitudinal', or 'transverse'
98  
99 =back
100  
101 B<Returns:> hashref C<{xx, yy, zz, xy, xz, yz}> suitable for use with
102 C<berreman_4x4>.
103  
104 # Fe at 633 nm (polar magnetization)
105 my $t = magneto_optic_tensor(
106 pdl(-13.8) + i()*pdl(15.7),
107 pdl(0.74) + i()*pdl(0.21),
108 geometry => 'polar',
109 );
110 # $t->{xy} contains the off-diagonal element
111  
112 =head2 kerr_rotation
113  
114 my ($theta_K, $eta_K) = kerr_rotation($lambda_nm, $theta_deg, %params);
115  
116 Calculates the complex Kerr angle (rotation + ellipticity) for
117 reflection from a semi-infinite magnetized medium.
118  
119 For polar MOKE at oblique incidence:
120  
121 θ_K + i*η_K = -i * Q * N * cos(θ_t)
122 / ((ε - 1) * cos(θ_m))
123  
124 where θ_t is the refraction angle inside the medium and θ_m depends on
125 the geometry.
126  
127 B<Parameters:>
128  
129 =over 4
130  
131 =item C<eps_diag> - diagonal dielectric constant (complex)
132  
133 =item C<Q> - Voigt magneto-optic parameter (complex)
134  
135 =item C<geometry> - 'polar' (default), 'longitudinal', or 'transverse'
136  
137 =back
138  
139 B<Returns:> two PDL piddles:
140  
141 =over 4
142  
143 =item C<$theta_K> - Kerr rotation angle [millidegrees]
144  
145 =item C<$eta_K> - Kerr ellipticity [millidegrees]
146  
147 =back
148  
149 B<Example — spectral Kerr rotation of iron:>
150  
151 use Physics::Ellipsometry::VASE::MagnetoOptic qw(kerr_rotation);
152  
153 my $lambda = sequence(50) * 20 + 400; # 400-1380 nm
154  
155 # Fe optical and MO constants (energy-dependent)
156 my $E = 1240.0 / $lambda; # eV
157 my $eps = pdl(-13.8) + i()*pdl(15.7); # simplified constant
158 my $Q = pdl(0.04) + i()*pdl(0.006);
159  
160 my ($theta, $eta) = kerr_rotation($lambda, 0,
161 eps_diag => $eps,
162 Q => $Q,
163 geometry => 'polar',
164 );
165 printf "Kerr rotation at 633nm: %.1f mdeg\n", $theta->at(11);
166 printf "Kerr ellipticity at 633nm: %.1f mdeg\n", $eta->at(11);
167  
168 =head1 NOTES
169  
170 =over 4
171  
172 =item * Kerr rotation angles are typically small (0.01-1°), requiring
173 sensitive detection (modulation techniques, lock-in amplifiers).
174  
175 =item * For multilayer magnetic structures, combine with
176 L<Physics::Ellipsometry::VASE::Anisotropy/berreman_4x4> using the
177 tensor from C<magneto_optic_tensor>.
178  
179 =item * Typical Voigt parameters: Fe Q≈0.04, Co Q≈0.05, Ni Q≈0.02
180 at visible wavelengths.
181  
182 =back
183  
184 =head1 SEE ALSO
185  
186 L<Physics::Ellipsometry::VASE::Anisotropy>,
187 L<Physics::Ellipsometry::VASE::TMM>
188  
189 P.M. Oppeneer, "Magneto-optical Kerr spectra", I<Handbook of Magnetic
190 Materials> B<13>, 229 (2001).
191  
192 Z.Q. Qiu and S.D. Bader, "Surface magneto-optic Kerr effect",
193 I<Rev. Sci. Instrum.> B<71>, 1243 (2000).
194  
195 =cut
196  
197 # Magneto-optic dielectric tensor
198 # For a magnetized material, the permittivity tensor has off-diagonal
199 # components that depend on magnetization direction:
200 #
201 # For polar geometry (M || z, perpendicular to surface):
202 # eps = [ eps_xx, -i*Q*eps_xx, 0 ]
203 # [ i*Q*eps_xx, eps_xx, 0 ]
204 # [ 0, 0, eps_zz ]
205 #
206 # For longitudinal geometry (M || y, in plane of incidence):
207 # eps = [ eps_xx, 0, i*Q*eps_xx ]
208 # [ 0, eps_yy, 0 ]
209 # [ -i*Q*eps_xx, 0, eps_zz ]
210 #
211 # Q = Voigt parameter (complex, wavelength-dependent)
212 # Returns tensor hashref compatible with Anisotropy::berreman_4x4
213 #
214 # $eps_diag: diagonal dielectric constant (complex PDL)
215 # $Q: Voigt magneto-optic parameter (complex PDL)
216 # $geometry: 'polar', 'longitudinal', or 'transverse'
217 sub magneto_optic_tensor {
218 my ($eps_diag, $Q, %opts) = @_;
219 my $geometry = $opts{geometry} // 'polar';
220  
221 my $zero = 0 * $eps_diag;
222 my $off_diag = i() * $Q * $eps_diag;
223  
224 if ($geometry eq 'polar') {
225 # M along z (surface normal)
226 return {
227 xx => $eps_diag, yy => $eps_diag, zz => $eps_diag,
228 xy => -$off_diag, xz => $zero, yz => $zero,
229 yx => $off_diag, zx => $zero, zy => $zero,
230 };
231 }
232 elsif ($geometry eq 'longitudinal') {
233 # M along y (in-plane, in scattering plane)
234 return {
235 xx => $eps_diag, yy => $eps_diag, zz => $eps_diag,
236 xy => $zero, xz => $off_diag, yz => $zero,
237 yx => $zero, zx => -$off_diag, zy => $zero,
238 };
239 }
240 elsif ($geometry eq 'transverse') {
241 # M along x (in-plane, perpendicular to scattering plane)
242 return {
243 xx => $eps_diag, yy => $eps_diag, zz => $eps_diag,
244 xy => $zero, xz => $zero, yz => -$off_diag,
245 yx => $zero, zx => $zero, zy => $off_diag,
246 };
247 }
248 else {
249 die "Unknown MO geometry: $geometry (use 'polar', 'longitudinal', 'transverse')";
250 }
251 }
252  
253 # Kerr rotation and ellipticity from reflection coefficients
254 # For the polar MOKE geometry on a semi-infinite magnetic substrate:
255 #
256 # Kerr rotation: theta_K = -Re(rps/rpp) [radians]
257 # Kerr ellipticity: eta_K = -Im(rps/rpp) [radians]
258 #
259 # For a magnetic film on a non-magnetic substrate, the full Berreman
260 # 4x4 calculation is needed (use Anisotropy::berreman_4x4).
261 #
262 # This function provides the simple semi-infinite substrate formula:
263 # r_ps/r_pp = -i*Q*n*cos(theta) / ((n^2-1)*(n^2*cos^2(theta) - 1)^(1/2))
264 #
265 # $lambda_nm: wavelength [nm]
266 # $theta_deg: angle of incidence [deg]
267 # $eps_diag: diagonal dielectric function of magnetic medium (complex PDL)
268 # $Q: Voigt parameter (complex PDL)
269 # Returns: hashref {theta_K => rotation [deg], eta_K => ellipticity [deg],
270 # rps_rpp => complex ratio}
271 sub kerr_rotation {
272 my ($lambda_nm, $theta_deg, $eps_diag, $Q) = @_;
273  
274 require Math::Complex;
275  
276 my $npts = $lambda_nm->nelem;
277 my $theta_rad = $theta_deg * PI / 180.0;
278 my $cos_t = cos($theta_rad);
279 my $sin_t = sin($theta_rad);
280  
281 # Complex refractive index of magnetic medium
282 my $N = sqrt($eps_diag);
283  
284 # cos(theta_t) in the medium via Snell's law (assuming N_ambient=1)
285 my $cos_t_m = sqrt(1.0 - $sin_t**2 / $eps_diag);
286  
287 # Polar Kerr: rps/rpp for semi-infinite magnetized substrate
288 my $numerator = -i() * $Q * $N * $cos_t;
289 my $denominator = ($eps_diag - 1.0) * $cos_t_m;
290  
291 my $ratio = $numerator / ($denominator + 1e-30);
292  
293 # Kerr angles
294 my $theta_K = -$ratio->re * (180.0 / PI); # rotation [deg]
295 my $eta_K = -$ratio->im * (180.0 / PI); # ellipticity [deg]
296  
297 return {
298 theta_K => $theta_K->double,
299 eta_K => $eta_K->double,
300 rps_rpp => $ratio,
301 };
302 }
303  
304 1;