PDL/Demos/Ellipsometry.pm untested

filter: Statementstmt 0.0% 0 / 22 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 36 CC 1 SCAR 6.9
CC
1
Cov
0%
info
2.0
_data_dir
2.0
init
2.0
CRAP 2.0
1 package PDL::Demos::Ellipsometry;
2  
3 use strict;
4 use warnings;
5 use PDL;
6 use Physics::Ellipsometry::VASE;
7  
8 sub info {('ellipsometry', 'Spectroscopic ellipsometry (Req: P:G:Simple)')}
9  
10 # Locate data files shipped alongside this module
11 sub _data_dir {
12 (my $dir = $INC{"PDL/Demos/Ellipsometry.pm"}) =~ s/Ellipsometry\.pm$//;
13 return $dir;
14 }
15  
16 sub init {'
17 use PDL;
18 use PDL::Graphics::Simple;
19 use PDL::Constants qw(PI);
20 use PDL::Math;
21 use Physics::Ellipsometry::VASE;
22 use File::Temp qw(tempfile);
23 '}
24  
25 my @demo = (
26  
27 # ── Section 1: Introduction ──────────────────────────────────────────
28 [comment => q{
29 +========================================================+
30 | Spectroscopic Ellipsometry with PDL |
31 | Physics::Ellipsometry::VASE Demo |
32 +========================================================+
33  
34 Ellipsometry measures how polarized light changes upon
35 reflection from a thin-film surface. Two quantities are
36 measured at each wavelength and angle of incidence:
37  
38 Psi -- amplitude ratio of p- and s-polarisations
39 Delta -- phase difference between them
40  
41 Together they encode the optical constants and thickness
42 of each layer in the film stack.
43  
44 This demo walks through the analysis workflow using
45 Physics::Ellipsometry::VASE and PDL, with plots via
46 PDL::Graphics::Simple.
47 }],
48  
49 # ── Section 2: Synthetic ellipsometry data ────────────────────────────
50 [act => q|
51 # Generate synthetic ellipsometry data with PDL
52 # 5 wavelengths, measured at 70 degrees incidence
53 $wavelength = pdl [400, 410, 420, 430, 440];
54 $angle = 70 * ones(5);
55 $psi = 45.0 - 0.05 * $wavelength; # linear Psi model
56 $delta = 80.0 + 0.10 * $wavelength; # linear Delta model
57  
58 print "Wavelength (nm) : $wavelength\n";
59 print "Angle (deg) : $angle\n";
60 print "Psi (deg) : $psi\n";
61 print "Delta (deg) : $delta\n";
62 |],
63  
64 # ── Section 3: Creating a data file and loading it ────────────────────
65 [act => q|
66 # Write synthetic data to a temp file (standard VASE text format)
67 ($fh, $tmpfile) = tempfile(SUFFIX => '.dat', UNLINK => 1);
68 print $fh "# Wavelength(nm) Angle(deg) Psi(deg) Delta(deg)\n";
69 for my $i (0 .. $wavelength->nelem - 1) {
70 printf $fh "%.1f %.1f %.4f %.4f\n",
71 $wavelength->at($i), $angle->at($i),
72 $psi->at($i), $delta->at($i);
73 }
74 close $fh;
75  
76 # Load into a VASE object
77 $vase = Physics::Ellipsometry::VASE->new(layers => 1);
78 $data = $vase->load_data($tmpfile);
79 print "Loaded data shape: ", join('x', $data->dims), "\n";
80 print $data;
81 |],
82  
83 # ── Section 4: Defining a linear model ────────────────────────────────
84 [act => q|
85 # Model function: receives (params, x) and returns [Psi, Delta] flat
86 # params = [a, b, c, d]
87 # Psi = a - b * wavelength
88 # Delta = c + d * wavelength
89  
90 sub linear_model {
91 my ($params, $x) = @_;
92 my ($a, $b, $c, $d) = $params->using(0..3);
93 my $wl = $x->slice(",(0)")->flat; # wavelength column
94 my $psi = $a - $b * $wl;
95 my $del = $c + $d * $wl;
96 return cat($psi, $del)->flat;
97 }
98  
99 print "Linear model function defined.\n";
100 print " Psi = a - b * wavelength\n";
101 print " Delta = c + d * wavelength\n";
102 |],
103  
104 # ── Section 5: Fitting and plotting the linear model ─────────────────
105 [act => q|
106 # Register the model and fit with Levenberg-Marquardt
107 $vase->set_model(\&linear_model);
108  
109 $p0 = pdl [65, 0.05, 80, 0.1]; # initial parameter guesses
110 print "Initial params : $p0\n";
111  
112 $fit = $vase->fit($p0);
113  
114 my ($a, $b, $c, $d) = list $fit;
115 print "\nFitted params:\n";
116 printf " a = %.6f b = %.6f\n", $a, $b;
117 printf " c = %.6f d = %.6f\n", $c, $d;
118 printf " Iterations: %d\n", $vase->{iters};
119 printf " MSE: %.6f\n", $vase->mse($fit);
120 |],
121  
122 [act => q|
123 # Plot the linear model fit using PDL::Graphics::Simple
124 $w = pgswin(size => [8,6], multi => [1,2]);
125  
126 # Evaluate model at fitted parameters
127 $x_plot = $vase->{data}->slice("0:1,:")->xchg(0,1);
128 $y_fit = linear_model($fit, $x_plot);
129 $np = $wavelength->nelem;
130 $psi_fit = $y_fit->slice("0:" . ($np-1));
131 $delta_fit = $y_fit->slice("$np:" . (2*$np-1));
132  
133 # Psi panel
134 $w->plot(with => 'points', $wavelength, $psi,
135 with => 'line', $wavelength, $psi_fit,
136 {title => "Linear Fit: Psi", xlabel => "Wavelength (nm)",
137 ylabel => "Psi (deg)", legend => ['Data','Fit']});
138  
139 # Delta panel
140 $w->plot(with => 'points', $wavelength, $delta,
141 with => 'line', $wavelength, $delta_fit,
142 {title => "Linear Fit: Delta", xlabel => "Wavelength (nm)",
143 ylabel => "Delta (deg)", legend => ['Data','Fit']});
144 |],
145  
146 # ── Section 6: Cauchy dispersion model ────────────────────────────────
147 [comment => q|
148 Now for some real physics!
149  
150 The Cauchy dispersion model describes how the refractive
151 index of a transparent film varies with wavelength:
152  
153 n(lambda) = A + B/lambda^2 + C/lambda^4
154  
155 Combined with the Fresnel equations and thin-film
156 interference (transfer matrix method), this predicts
157 the Psi and Delta measured by the ellipsometer.
158  
159 We will generate realistic data for a ~100nm SiO2 film
160 on silicon and then fit the Cauchy parameters.
161 |],
162  
163 [act => q|
164 # Generate realistic SiO2/Si data using the Cauchy + Fresnel model
165 # True parameters: A=1.46, B=3400 nm^2, n_sub=3.87, d=100 nm
166 $wl_sim = sequence(21) * 15 + 400; # 400-700 nm in 15nm steps
167 $ang_sim = 70 * ones($wl_sim);
168  
169 # Cauchy index for SiO2
170 $n_true = 1.46 + 3400.0 / $wl_sim**2;
171 print "Simulated Cauchy n(lambda) at selected wavelengths:\n";
172 printf " n(400nm) = %.4f\n", $n_true->at(0);
173 printf " n(550nm) = %.4f\n", $n_true->at(10);
174 printf " n(700nm) = %.4f\n", $n_true->at(20);
175 |],
176  
177 [act => q|
178 # Compute Psi & Delta via Fresnel equations for a single film on substrate
179 sub fresnel_cauchy {
180 my ($par, $x) = @_;
181 my ($A, $B, $n2, $d) = $par->using(0..3); # n2 = substrate index, d = thickness (nm)
182 $B = $B * 1e4; # rescale B
183 my $n0 = 1.0; # ambient (air)
184  
185 my $lam = $x->slice(",(0)")->flat;
186 my $theta0 = $x->slice(",(1)")->flat * (PI / 180.0);
187  
188 my $n1 = $A + $B / $lam**2; # Cauchy dispersion
189  
190 # Snell's law
191 my $sin1 = ($n0 * sin($theta0) / $n1)->clip(-0.999, 0.999);
192 my $th1 = asin($sin1);
193 my $sin2 = ($n0 * sin($theta0) / $n2)->clip(-0.999, 0.999);
194 my $th2 = asin($sin2);
195  
196 # Phase thickness
197 my $beta = (2 * PI / $lam) * $n1 * $d * cos($th1);
198  
199 # Fresnel coefficients (air/film and film/substrate)
200 my $r01s = ($n0*cos($theta0) - $n1*cos($th1))
201 / ($n0*cos($theta0) + $n1*cos($th1));
202 my $r01p = ($n1*cos($theta0) - $n0*cos($th1))
203 / ($n1*cos($theta0) + $n0*cos($th1));
204 my $r12s = ($n1*cos($th1) - $n2*cos($th2))
205 / ($n1*cos($th1) + $n2*cos($th2));
206 my $r12p = ($n2*cos($th1) - $n1*cos($th2))
207 / ($n2*cos($th1) + $n1*cos($th2));
208  
209 # Thin-film reflectance
210 my $phase = exp(-2*i()*$beta);
211 my $rs = ($r01s + $r12s*$phase) / (1 + $r01s*$r12s*$phase);
212 my $rp = ($r01p + $r12p*$phase) / (1 + $r01p*$r12p*$phase);
213  
214 # Ellipsometric ratio -> Psi, Delta
215 my $rho = $rp / $rs;
216 my $psi = atan(abs($rho)) * (180.0 / PI);
217 my $delta = carg($rho) * (180.0 / PI);
218  
219 return cat($psi->re, $delta->re)->flat->double;
220 }
221 print "Cauchy + Fresnel model defined.\n";
222 |],
223  
224 [act => q|
225 # Simulate the "measured" data with the true parameters
226 $x_sim = cat($wl_sim, $ang_sim); # shape (npts, 2)
227 $true_params = pdl [1.46, 0.34, 3.87, 100.0]; # A, B/1e4, n_sub, d
228 $y_sim = fresnel_cauchy($true_params, $x_sim);
229 $npts = $wl_sim->nelem;
230 $psi_sim = $y_sim->slice("0:" . ($npts-1));
231 $delta_sim = $y_sim->slice("$npts:" . (2*$npts-1));
232  
233 # Add small noise for realism (seeded for reproducibility)
234 srandom(42);
235 $psi_sim = $psi_sim + 0.1 * grandom($npts);
236 $delta_sim = $delta_sim + 0.2 * grandom($npts);
237  
238 # Write to temp file and load into VASE
239 ($fh2, $tmpfile2) = tempfile(SUFFIX => '.dat', UNLINK => 1);
240 print $fh2 "# Wavelength(nm) Angle(deg) Psi(deg) Delta(deg)\n";
241 for my $i (0 .. $npts - 1) {
242 printf $fh2 "%.1f %.1f %.4f %.4f\n",
243 $wl_sim->at($i), $ang_sim->at($i),
244 $psi_sim->at($i), $delta_sim->at($i);
245 }
246 close $fh2;
247  
248 $cauchy_vase = Physics::Ellipsometry::VASE->new(layers => 1, maxiter => 1000);
249 $cauchy_vase->load_data($tmpfile2);
250 print "Simulated SiO2/Si data loaded ($npts points).\n";
251 |],
252  
253 [act => q{
254 # Fit the Cauchy model -- start from a deliberately offset guess
255 $cauchy_vase->set_model(\&fresnel_cauchy);
256 $guess = pdl [1.50, 0.50, 3.50, 80.0]; # off from truth
257 print "True params : $true_params\n";
258 print "Initial guess: $guess\n\n";
259  
260 eval { $cauchy_fit = $cauchy_vase->fit($guess); };
261 if ($@ || !defined $cauchy_fit) {
262 # If the offset guess didn't converge, try from closer to truth
263 $cauchy_fit = $cauchy_vase->fit(pdl [1.46, 0.35, 3.85, 95.0]);
264 }
265  
266 my ($A_fit, $Bs_fit, $n2_fit, $d_fit) = list $cauchy_fit;
267 my $B_fit = $Bs_fit * 1e4;
268 printf "Fit results (Cauchy SiO2 on Si):\n";
269 printf " A (index) : %.4f (true: 1.4600)\n", $A_fit;
270 printf " B (nm^2) : %.1f (true: 3400.0)\n", $B_fit;
271 printf " n_substrate : %.4f (true: 3.8700)\n", $n2_fit;
272 printf " Thickness (nm) : %.2f (true: 100.00)\n", $d_fit;
273 printf " Iterations : %d\n", $cauchy_vase->{iters};
274 printf " MSE : %.4f\n", $cauchy_vase->mse($cauchy_fit);
275 }],
276  
277 # ── Cauchy fit plot ──────────────────────────────────────────────────
278 [act => q|
279 # Plot the Cauchy model fit
280 $w2 = pgswin(size => [8,6], multi => [1,2]);
281  
282 $y_cauchy_fit = fresnel_cauchy($cauchy_fit, $x_sim);
283 $psi_cf = $y_cauchy_fit->slice("0:" . ($npts-1));
284 $delta_cf = $y_cauchy_fit->slice("$npts:" . (2*$npts-1));
285  
286 $w2->plot(with => 'points', $wl_sim, $psi_sim,
287 with => 'line', $wl_sim, $psi_cf,
288 {title => "Cauchy Fit: Psi (SiO2/Si)", xlabel => "Wavelength (nm)",
289 ylabel => "Psi (deg)", legend => ['Data','Fit']});
290  
291 $w2->plot(with => 'points', $wl_sim, $delta_sim,
292 with => 'line', $wl_sim, $delta_cf,
293 {title => "Cauchy Fit: Delta (SiO2/Si)", xlabel => "Wavelength (nm)",
294 ylabel => "Delta (deg)", legend => ['Data','Fit']});
295 |],
296  
297 # ══════════════════════════════════════════════════════════════════════
298 # Part 2: Multi-layer modeling
299 # ══════════════════════════════════════════════════════════════════════
300  
301 [comment => q|
302 MULTI-LAYER THIN FILM MODELING
303 ==============================
304  
305 Real thin-film stacks have multiple layers. The Transfer
306 Matrix Method (TMM) propagates electromagnetic waves
307 through each interface and layer:
308  
309 Air / Film 1 / Film 2 / ... / Substrate
310  
311 Each layer has:
312 - Complex refractive index N = n + ik
313 - Thickness d (nm)
314 - Dispersion model (Cauchy, Tauc-Lorentz, etc.)
315  
316 The next section fits a real three-layer stack measured
317 with Variable Angle Spectroscopic Ellipsometry (VASE)
318 at three angles of incidence (65, 70, 75 degrees):
319  
320 Air / Ta2O5 (Cauchy) / EMA roughness / Ta metal
321  
322 This uses the built-in TMM, Dispersion, and EMA modules.
323 |],
324  
325 [act => q|
326 # Load multi-layer sub-modules
327 use Physics::Ellipsometry::VASE::TMM qw(psi_delta);
328 use Physics::Ellipsometry::VASE::Dispersion qw(cauchy_nk);
329 use Physics::Ellipsometry::VASE::EMA qw(ema_linear);
330 use Physics::Ellipsometry::VASE::Materials qw(load_material interpolate_material);
331  
332 # Locate demo data files shipped with this module
333 $demo_dir = PDL::Demos::Ellipsometry::_data_dir();
334  
335 # Load Ta metal substrate optical constants (n,k vs wavelength)
336 $ta_metal = load_material("${demo_dir}demo_ta_metal.mat");
337 printf "Ta metal: %d pts, %.0f-%.0f nm\n",
338 $ta_metal->{npts}, $ta_metal->{wav_min}, $ta_metal->{wav_max};
339 |],
340  
341 [act => q|
342 # Load real Woollam VASE data (3 angles, ~500 pts)
343 $ml_vase = Physics::Ellipsometry::VASE->new(
344 layers => 3,
345 circular_delta => 1,
346 deriv_step => 1e-3,
347 min_deriv_step => 0.01,
348 );
349 $ml_vase->load_data("${demo_dir}demo_wafer.dat");
350 delete $ml_vase->{sigma}; # use unweighted fit
351  
352 # Restrict wavelength range to where Ta metal data is available
353 $ml_data = $ml_vase->{data};
354 $wav_col = $ml_data->slice("(0),:")->flat;
355 $wav_min = $ta_metal->{wav_min} > 320 ? $ta_metal->{wav_min} : 320;
356 $wav_max = $ta_metal->{wav_max};
357 $mask = ($wav_col >= $wav_min) & ($wav_col <= $wav_max);
358 $idx = which($mask);
359 $ml_data = $ml_data->dice_axis(1, $idx)->sever;
360 $ml_vase->{data} = $ml_data;
361  
362 printf "Loaded: %s\n", $ml_vase->{sample_name};
363 printf " %d data points, %.0f-%.0f nm\n",
364 $ml_data->getdim(1),
365 $ml_data->slice("(0),:")->min,
366 $ml_data->slice("(0),:")->max;
367  
368 # Show unique angles
369 $ml_angles = $ml_data->slice("(1),:")->flat;
370 my %seen; @unique_ang = sort { $a <=> $b } grep { !$seen{$_}++ } list $ml_angles;
371 printf " Angles: %s deg\n", join(", ", map { sprintf("%.1f", $_) } @unique_ang);
372 |],
373  
374 [act => q|
375 # Define multi-layer model: Air / Ta2O5 (Cauchy) / EMA / Ta metal
376 # Fit parameters (6 total, scaled to order ~1):
377 # [0] A - Cauchy coefficient A
378 # [1] B_s - Cauchy B * 100
379 # [2] C_s - Cauchy C * 10000
380 # [3] d_ta2o5_s - Ta2O5 thickness / 100 (nm)
381 # [4] d_ema_s - EMA roughness thickness (nm)
382 # [5] vf_void - volume fraction of void in EMA layer
383  
384 sub multilayer_model {
385 my ($params, $x_data) = @_;
386 my $A = $params->at(0);
387 my $B = $params->at(1) / 100;
388 my $C = $params->at(2) / 10000;
389 my $d_film = abs($params->at(3)) * 100;
390 my $d_ema = abs($params->at(4)) * 1.0;
391 my $vf_void = $params->at(5);
392 $vf_void = 0.01 if $vf_void < 0.01;
393 $vf_void = 0.999 if $vf_void > 0.999;
394  
395 my $lambda = $x_data->slice(",(0)")->flat;
396 my $theta = $x_data->slice(",(1)")->flat;
397  
398 # Layer 1: Ta2O5 via Cauchy dispersion
399 my ($n1, $k1) = cauchy_nk($lambda, $A, $B, $C);
400 my $N1 = $n1 + i() * $k1;
401  
402 # Layer 2: EMA (Ta2O5 + void) via linear mixing
403 my $eps_film = $N1**2;
404 my $eps_void = pdl(1.0) + i() * pdl(0.0);
405 my $N2 = sqrt(ema_linear($eps_film, $eps_void, $vf_void));
406  
407 # Substrate: Ta metal (point-by-point interpolation)
408 my ($n_ta, $k_ta) = interpolate_material($ta_metal, $lambda);
409 my $N3 = $n_ta + i() * $k_ta;
410  
411 # Ambient
412 my $N0 = pdl(1.0) + i() * pdl(0.0);
413  
414 # TMM for the full stack
415 my ($psi, $delta) = psi_delta(
416 $lambda, $theta,
417 [$N0, $N1, $N2, $N3],
418 [$d_film, $d_ema],
419 );
420  
421 return $psi->append($delta);
422 }
423  
424 print "Multi-layer model defined:\n";
425 print " Air / Ta2O5 (Cauchy) / EMA roughness / Ta metal\n";
426 print " 6 fit parameters: A, B, C, d_Ta2O5, d_EMA, vf_void\n";
427 |],
428  
429 [act => q{
430 # Fit the multi-layer model to the real 3-angle VASE data
431 $ml_vase->set_model(\&multilayer_model);
432  
433 # Grid search over thickness for a good starting point
434 # (thin-film interference creates many local minima in thickness)
435 $ml_x = $ml_data->slice("0:1,:")->xchg(0,1);
436 $ml_y = $ml_data->slice("(2),:")->flat->append($ml_data->slice("(3),:")->flat);
437 $ml_npts = $ml_data->getdim(1);
438 $ml_delta_data = $ml_data->slice("(3),:")->flat;
439  
440 $best_d = 1.96; $best_cost = 1e30;
441 for my $d_s (map { $_ * 0.02 + 1.5 } (0..50)) {
442 my $p = pdl [2.10, 1.0, 0.1, $d_s, 1.0, 0.80];
443 my $ym = multilayer_model($p, $ml_x);
444 my $dm = $ym->slice("$ml_npts:" . (2*$ml_npts-1));
445 my $diff = $dm - $ml_delta_data;
446 $dm -= 360.0 * rint($diff / 360.0);
447 my $cost = sum(($ml_y - $ym)**2)->sclr;
448 if ($cost < $best_cost) { $best_cost = $cost; $best_d = $d_s; }
449 }
450 printf "Grid search: best thickness = %.0f nm (d_s = %.2f)\n", $best_d * 100, $best_d;
451  
452 # Levenberg-Marquardt refinement from the grid-search starting point
453 $ml_guess = pdl [2.10, 1.0, 0.1, $best_d, 1.0, 0.80];
454 print "Fitting with LM refinement...\n";
455  
456 eval { $ml_fit = $ml_vase->fit($ml_guess); };
457 if ($@ || !defined $ml_fit) {
458 print " LM from grid best did not converge, trying refined guess...\n";
459 $ml_fit = $ml_vase->fit(pdl [2.12, 1.8, 0.1, $best_d, 1.0, 0.50]);
460 }
461  
462 # Unpack results
463 my $A_ml = $ml_fit->at(0);
464 my $B_ml = $ml_fit->at(1) / 100;
465 my $C_ml = $ml_fit->at(2) / 10000;
466 my $d_ta2o5 = abs($ml_fit->at(3)) * 1000; # Angstroms
467 my $d_ema_fit = abs($ml_fit->at(4)) * 10; # Angstroms
468 my $vf_ml = $ml_fit->at(5);
469 $vf_ml = 0.01 if $vf_ml < 0.01;
470 $vf_ml = 0.999 if $vf_ml > 0.999;
471  
472 my $n600 = $A_ml + $B_ml / 0.6**2 + $C_ml / 0.6**4;
473  
474 printf "\nMulti-layer fit results:\n";
475 printf " Ta2O5 thickness : %.1f Angstrom (%.1f nm)\n", $d_ta2o5, $d_ta2o5/10;
476 printf " EMA roughness : %.1f Angstrom (%.2f nm)\n", $d_ema_fit, $d_ema_fit/10;
477 printf " Void fraction : %.1f%%\n", $vf_ml * 100;
478 printf " Cauchy A : %.4f\n", $A_ml;
479 printf " n(600nm) : %.4f\n", $n600;
480 printf " Iterations : %d\n", $ml_vase->{iters};
481 printf " MSE : %.4f\n", $ml_vase->mse($ml_fit, nparams => 6);
482 }],
483  
484 # ── Multi-layer fit plot ─────────────────────────────────────────────
485 [act => q|
486 # Plot multi-angle fit: data points vs model curves
487 # Evaluate model at the fitted parameters
488 $ml_x = $ml_data->slice("0:1,:")->xchg(0,1);
489 $ml_ym = multilayer_model($ml_fit, $ml_x);
490 $ml_npts = $ml_data->getdim(1);
491 $ml_psi_fit = $ml_ym->slice("0:" . ($ml_npts-1));
492 $ml_delta_fit = $ml_ym->slice("$ml_npts:" . (2*$ml_npts-1));
493 $ml_wav = $ml_data->slice("(0),:")->flat;
494 $ml_psi_data = $ml_data->slice("(2),:")->flat;
495 $ml_delta_data = $ml_data->slice("(3),:")->flat;
496  
497 # Separate data by angle for color-coded plotting
498 @ml_psi_args = (); @ml_delta_args = ();
499 @ang_labels = ();
500 for my $ang (@unique_ang) {
501 my $m = ($ml_angles == $ang);
502 my $ii = which($m);
503 my $wl_a = $ml_wav->index($ii);
504 my $psi_d = $ml_psi_data->index($ii);
505 my $del_d = $ml_delta_data->index($ii);
506 my $psi_f = $ml_psi_fit->index($ii);
507 my $del_f = $ml_delta_fit->index($ii);
508  
509 push @ang_labels, sprintf("%.0f data", $ang), sprintf("%.0f fit", $ang);
510  
511 push @ml_psi_args, (with => 'points', $wl_a, $psi_d);
512 push @ml_psi_args, (with => 'line', $wl_a, $psi_f);
513  
514 push @ml_delta_args, (with => 'points', $wl_a, $del_d);
515 push @ml_delta_args, (with => 'line', $wl_a, $del_f);
516 }
517  
518 # Plot Psi panel
519 $w3 = pgswin(size => [9,6], multi => [1,2]);
520 $w3->plot(@ml_psi_args,
521 {title => "Air/Ta2O5/EMA/Ta: Psi",
522 xlabel => "Wavelength (nm)", ylabel => "Psi (deg)",
523 legend => \@ang_labels});
524  
525 # Plot Delta panel
526 $w3->plot(@ml_delta_args,
527 {title => "Air/Ta2O5/EMA/Ta: Delta",
528 xlabel => "Wavelength (nm)", ylabel => "Delta (deg)",
529 legend => \@ang_labels});
530  
531 print "Multi-angle fit plotted: Psi and Delta vs wavelength.\n";
532 |],
533  
534 # ── Conclusion ───────────────────────────────────────────────────────
535 [comment => q|
536 This concludes the Physics::Ellipsometry::VASE demo.
537  
538 What we covered:
539 - Creating and loading ellipsometry data
540 - Linear model fitting with Levenberg-Marquardt
541 - Single-layer Cauchy + Fresnel model
542 - Multi-layer modeling with TMM, EMA, and tabulated data
543 - Multi-angle VASE fitting of a real Ta2O5/Ta sample
544 - Plotting fits with PDL::Graphics::Simple
545  
546 To learn more:
547 perldoc Physics::Ellipsometry::VASE
548 perldoc Physics::Ellipsometry::VASE::TMM
549 perldoc Physics::Ellipsometry::VASE::Dispersion
550 https://github.com/jtrujil43/Ellipsometry
551  
552 See the examples/ directory for Tauc-Lorentz oscillator
553 models and publication-quality plotting with Gnuplot.
554 |],
555  
556 );
557  
558 sub demo { @demo }
559  
560 sub done {'
561 undef $w;
562 undef $w2;
563 undef $w3;
564 undef $vase;
565 undef $cauchy_vase;
566 undef $ml_vase;
567 '}
568  
569 1;
570  
571 __END__