import numpy as np
from pathlib import Path
import escape as esc
esc.require("0.9.8")
wavelength = 1.540562
src = esc.xrays(wavelength, units="angstrom")
wave = 2.0 * np.pi / src.wavelength
degree = np.pi / 180.0
data_dir = Path("data")
Off-specular reflectivity of a W/Si multilayer. ESCAPE against the X-ray Server¶
This notebook compares ESCAPE with Sergey Stepanov's X-ray Server, program TRDS, for the multilayer of ../offspecular/notebook.ipynb: ten periods of 15 Å tungsten and 35 Å silicon on silicon, Cu Kα (1.540562 Å), σ polarization. Every interface has σ = 4 Å, ξ = 300 Å and Hurst exponent 1. Where a model needs it, the vertical correlation length is L_v = 2000 Å. The server stores one set of roughness parameters for the whole stack, so all 21 interfaces carry the same values here too.
The curves are in data/<case>/. A rocking curve is θ, 2θ and intensity. A detector scan is 2θ, θ and intensity. A map is θ, 2θ and intensity. The server returns the diffuse cross-section without the specular delta function, the same quantity as esc.offspecrefl.
Each server curve is turned into a dataset with counting errors for 10⁴ counts on its brightest point. A Levenberg–Marquardt optimizer then adjusts only the intensity scale I0. It should end close to 1. A few per cent come from the different optical constants of the two programs.
The scans are:
- rocking curves (θ scans at a fixed detector angle 2θ) at the first three Bragg orders,
- detector scans (2θ scans) at four incident angles, 0.4°, 0.8°, 1.2° and 1.6°,
- a map over θ from 0.1° to 4.1° and 2θ from 0.2° to 6.2°.
The incident angle is θ and the exit angle is 2θ − θ. The server skips points where the exit angle would be negative, so the map is a triangle in these coordinates.
The stack is built once for each roughness model. TRDS models 1 to 6 are uncorrelated, completely replicated (conformal), Ming, Lagally, Holy and Spiller roughness. For Spiller roughness the server's L_v is converted to ESCAPE's relaxation length ν = ξ²/L_v. The densities are the ones the server prints in its table: 19.3 g/cm³ for W and 2.33 g/cm³ for Si.
load_curve reads data/<case>/*.dat. The first column is the scanned angle and the second is the fixed angle: θ and 2θ for a rocking curve or a map, 2θ and θ for a detector scan. lagally_rock has only θ and intensity; its detector angle is 2θ = 3.531°.
def stack(rough):
tungsten = esc.amorphous("W", density=19.3, name="W")
silicon = esc.amorphous("Si", density=2.33, name="Si")
period = esc.layer_stack(repeat=10, name="W/Si")
period.add(esc.layer(tungsten, 15.0, rough, name="W"))
period.add(esc.layer(silicon, 35.0, rough, name="Si"))
result = esc.multilayer(
name="W/Si x10",
frgr=esc.air("Air"),
bkgr=esc.substrate(silicon, rough, name="Substrate"),
)
result.add(period)
return result
def load_curve(case):
table = np.loadtxt(next((data_dir / case).glob("*.dat")), ndmin=2)
if table.shape[1] == 2:
table = np.column_stack([table[:, 0], np.full(len(table), 3.531), table[:, 1]])
return table
def diffuse(structure, alpha_i, alpha_f, name):
return esc.offspecrefl(
wave * (esc.cos(alpha_f) - esc.cos(alpha_i)),
wave * esc.sin(alpha_i),
wave * esc.sin(alpha_f),
structure,
source=src,
formalism="full",
name=name,
)
def measured(intensity):
scale = 1.0e4 / float(np.max(intensity))
errors = np.sqrt(np.maximum(intensity * scale, 1.0)) / scale
return errors
lagally = esc.lagally_roughness(4.0, 300.0, 1.0, 300.0, 2000.0)
lagally_xc1000 = esc.lagally_roughness(4.0, 300.0, 1.0, 1000.0, 2000.0)
lagally_xc3000 = esc.lagally_roughness(4.0, 300.0, 1.0, 3000.0, 2000.0)
uncorrelated = esc.roughness(4.0, lateral=300.0, hurst=1.0)
conformal = esc.conformal_roughness(4.0, 300.0, 1.0)
ming = esc.ming_roughness(4.0, 300.0, 1.0, 2000.0)
holy = esc.holy_roughness(4.0, 300.0, 1.0)
holy_small = esc.holy_roughness(1.5, 300.0, 1.0)
spiller = esc.spiller_roughness(4.0, 300.0, 1.0, 300.0 ** 2 / 2000.0)
compare_scans turns every scan of one server job into a model. In a rocking curve the variable is θ and 2θ is fixed. In a detector scan the variable is 2θ and θ is fixed. All curves of one job share the scale I0.
def compare_scans(case, structure, title, rocking):
table = load_curve(case)
I0 = esc.par("I0", 0.8, userlim=[0.3, 3.0])
models = []
for offset in np.unique(table[:, 1]):
rows = table[np.isclose(table[:, 1], offset)]
x = rows[:, 0].copy()
y = rows[:, 2].copy()
if rocking:
theta = esc.var("theta")
alpha_i = theta * degree
alpha_f = (offset - theta) * degree
label = f"2θ = {offset:.3f}°"
else:
two_theta = esc.var("two_theta")
alpha_i = esc.func(two_theta, offset * degree)
alpha_f = (two_theta - offset) * degree
keep = x > offset
x, y = x[keep].copy(), y[keep].copy()
label = f"θ = {offset:.2f}°"
data = esc.data(x, y, measured(y), copy=True, name=label)
models.append(esc.model(
I0 * diffuse(structure, alpha_i, alpha_f, label), data,
residuals_scale="none", weight_type="data", normalize_cost=True,
name=label,
))
opt = esc.levmar(
esc.modelstack(models, name=title),
xtol=1.0e-7, ftol=1.0e-9, gtol=1.0e-6, maxiter=20, maxfev=60,
nupdate=5, epsfcn=1.0e-7,
)
opt()
print(f"{title}: I0 = {I0.value:.3f}, cost = {opt.best_cost:.3g}")
return opt
Lagally roughness, the sample of notebook.ipynb¶
TRDS model 4 with ξ = 300 Å, the cross-term length ξ× = 300 Å and L_v = 2000 Å. With ξ× = ξ the Lagally model is the same as the Ming model without skew.
Rocking curves at the first three Bragg orders¶
The detector stays at 2θ = 1.795°, 3.531° and 5.267°, near the first three Bragg angles of the 50 Å period. Each rocking curve runs along a Bragg sheet. The server skipped θ values above 2θ, where the exit angle would be negative.
wsi = stack(lagally)
opt_rocks = compare_scans("lagally_rocks", wsi, "Lagally, rocking curves", rocking=True)
opt_rocks.show().config_model(ylog=True, xlabel="θ [deg]", ylabel="Intensity [a.u.]")
Lagally, rocking curves: I0 = 1.022, cost = 0.03
Detector scans at four incident angles¶
Each scan crosses the Bragg sheets where θ + exit angle matches a Bragg order. The intensity spikes there.
opt_det = compare_scans("lagally_det", wsi, "Lagally, detector scans", rocking=False)
opt_det.show().config_model(ylog=True, xlabel="2θ [deg]", ylabel="Intensity [a.u.]")
Lagally, detector scans: I0 = 0.999, cost = 0.138
Map¶
The map has 41 values of θ and 31 values of 2θ. 871 points have a positive exit angle. The coordinates are interleaved in alphabetical order of the variable names, so each point is (theta, two_theta). The scale is fixed at 1.
def compare_map(case, structure, name):
table = load_curve(case)
theta = esc.var("theta")
two_theta = esc.var("two_theta")
kernel = diffuse(structure, theta * degree, (two_theta - theta) * degree, name)
coordinates = table[:, :2].flatten().copy()
server = table[:, 2].copy()
data = esc.data(coordinates, server, measured(server), copy=True, name=name)
model = esc.model(kernel, data, residuals_scale="none", weight_type="data", name=name)
escape = np.asarray(kernel(coordinates), float)
return model, table, escape
map_model, map_table, map_escape = compare_map("lagally_map", wsi, "Lagally map")
positive = map_table[:, 2] > 1.0e-3 * map_table[:, 2].max()
ratio = map_table[positive, 2] / map_escape[positive]
print(f"server / ESCAPE above 1e-3 of the maximum: median {np.median(ratio):.3f}, "
f"5% {np.percentile(ratio, 5):.3f}, 95% {np.percentile(ratio, 95):.3f}")
map_model.show().config(cblog=True, xlabel="θ [deg]", ylabel="2θ [deg]")
server / ESCAPE above 1e-3 of the maximum: median 0.988, 5% 0.936, 95% 1.053
Lagally roughness with a long cross-term length: negative intensities¶
The Lagally cross term between interfaces j and k is σ² exp(−|z_j − z_k|/L_v) exp[−(r/ξ×)²], while each interface's own term is σ² exp[−(r/ξ)²]. When ξ× differs from ξ, the cross term can be larger at some in-plane momentum than the two own terms allow. The set of correlations is then not a valid covariance, and the diffuse intensity can come out negative. The server refuses ξ× < ξ ("L_cross >= L_h"). It accepts ξ× > ξ.
Two maps were calculated with ξ× = 1000 Å and ξ× = 3000 Å, all other values unchanged. The cell counts the points where ESCAPE is negative and the points where the server returns exactly zero. Points on the edge of the triangle, where the exit angle is exactly zero, are left out: there ESCAPE returns zero and the server sometimes a finite value.
for case, structure in [
("lagally_xc1000_map", stack(lagally_xc1000)),
("lagally_xc3000_map", stack(lagally_xc3000)),
]:
model, table, escape = compare_map(case, structure, case)
inside = table[:, 1] > table[:, 0]
server = table[inside, 2]
escape = escape[inside]
negative = escape < 0.0
zero = server == 0.0
both = (escape > 0.0) & (server > 0.0)
ratio = server[both] / escape[both]
print(f"{case}: ESCAPE < 0 at {negative.sum()} points, server = 0 at {zero.sum()}, "
f"both at {np.sum(negative & zero)}")
print(f" positive points: server / ESCAPE median {np.median(ratio):.3f}, "
f"1% {np.percentile(ratio, 1):.3f}, 99% {np.percentile(ratio, 99):.3f}")
lagally_xc1000_map: ESCAPE < 0 at 235 points, server = 0 at 235, both at 235
positive points: server / ESCAPE median 0.987, 1% 0.852, 99% 1.085
lagally_xc3000_map: ESCAPE < 0 at 155 points, server = 0 at 153, both at 153
positive points: server / ESCAPE median 0.987, 1% 0.944, 99% 1.093
The server writes zero wherever ESCAPE is negative: it clips the negative cross-section. The only exceptions are two mirror-image points of the ξ× = 3000 Å map where the intensity changes sign; both programs give about 10⁻⁴ of the maximum there, ESCAPE slightly below zero and the server slightly above. On the positive points the two programs agree as well as for ξ× = ξ.
The slice below is the row θ = 0.4° of the ξ× = 3000 Å map on a linear scale. ESCAPE is negative from 2θ ≈ 0.6° to 1.6°, around the specular condition 2θ = 0.8°; the server sits at zero there. Beyond that range the two agree again. Neither number is physical: the parameters describe a stack that cannot exist. Keep ξ× equal to ξ, or make exp(−Δz/L_v) small.
table = load_curve("lagally_xc3000_map")
row = table[np.isclose(table[:, 0], 0.4) & (table[:, 1] > 0.4)]
two_theta = esc.var("two_theta")
slice_kernel = diffuse(
stack(lagally_xc3000), esc.func(two_theta, 0.4 * degree), (two_theta - 0.4) * degree,
"θ = 0.4°, ξ× = 3000 Å",
)
x = row[:, 1].copy()
y = row[:, 2].copy()
slice_data = esc.data(x, y, measured(y), copy=True, name="server")
slice_model = esc.model(slice_kernel, slice_data, residuals_scale="none",
weight_type="data", name="θ = 0.4°, ξ× = 3000 Å")
print(" 2θ server ESCAPE")
for xi, yi, ei in zip(x[:10], y[:10], np.asarray(slice_kernel(x), float)[:10]):
print(f"{xi:5.2f} {yi:11.3e} {ei:11.3e}")
slice_model.show().config(ylog=False, xlabel="2θ [deg]", ylabel="Intensity [a.u.]")
2θ server ESCAPE 0.60 0.000e+00 -3.852e-04 0.80 0.000e+00 -4.309e-03 1.00 0.000e+00 -3.327e-03 1.20 0.000e+00 -2.494e-03 1.40 0.000e+00 -2.315e-03 1.60 0.000e+00 -4.637e-04 1.80 2.327e-04 2.330e-04 2.00 8.350e-04 8.023e-04 2.20 3.429e-04 3.381e-04 2.40 3.030e-04 2.960e-04
The other correlation models¶
Detector scans at the same four incident angles, for the other TRDS models. Uncorrelated roughness has no cross terms. Conformal roughness replicates every interface without decay. Ming roughness damps the replication with L_v = 2000 Å; with ξ× = ξ it gives the same curves as the Lagally scans above. Holy roughness accumulates: every interface inherits the increments of all interfaces below it, so σ = 4 Å on 21 interfaces gives √21 · 4 ≈ 18 Å at the surface. Spiller roughness also accumulates, but an inherited copy broadens and weakens with distance; L_v = 2000 Å corresponds to ν = 45 Å.
Uncorrelated¶
opt = compare_scans("uncorrelated_det", stack(uncorrelated), "Uncorrelated", rocking=False)
opt.show().config_model(ylog=True, xlabel="2θ [deg]", ylabel="Intensity [a.u.]")
Uncorrelated: I0 = 1.000, cost = 0.035
Conformal¶
opt = compare_scans("conformal_det", stack(conformal), "Conformal", rocking=False)
opt.show().config_model(ylog=True, xlabel="2θ [deg]", ylabel="Intensity [a.u.]")
Conformal: I0 = 0.998, cost = 0.214
Ming¶
opt = compare_scans("ming_det", stack(ming), "Ming", rocking=False)
opt.show().config_model(ylog=True, xlabel="2θ [deg]", ylabel="Intensity [a.u.]")
Ming: I0 = 0.999, cost = 0.138
Spiller¶
opt = compare_scans("spiller_det", stack(spiller), "Spiller", rocking=False)
opt.show().config_model(ylog=True, xlabel="2θ [deg]", ylabel="Intensity [a.u.]")
Spiller: I0 = 0.998, cost = 0.0498
Holy¶
With σ = 4 Å the two programs agree at small vertical momentum transfer qz and part at large qz: at qz = 0.4 Å⁻¹ the server is about ten times lower. With σ = 1.5 Å on the same stack they agree everywhere (second job below). The models are the same; the difference appears when the accumulated roughness makes K = qz² C(r) large, about 50 at qz = 0.4 Å⁻¹ for 18 Å. ESCAPE evaluates this term with a closed-form series. Its numerical integration paths (fixed rule and adaptive) give the same result to six digits, so the difference is most likely a limit of the server's numerical transform in that regime.
opt = compare_scans("holy_det", stack(holy), "Holy, σ = 4 Å", rocking=False)
opt.show().config_model(ylog=True, xlabel="2θ [deg]", ylabel="Intensity [a.u.]")
Holy, σ = 4 Å: I0 = 0.822, cost = 3.97
opt = compare_scans("holy_s1p5_det", stack(holy_small), "Holy, σ = 1.5 Å", rocking=False)
opt.show().config_model(ylog=True, xlabel="2θ [deg]", ylabel="Intensity [a.u.]")
Holy, σ = 1.5 Å: I0 = 0.992, cost = 0.0754
Summary¶
| Job | Agreement with the server |
|---|---|
| Lagally, ξ× = ξ: rocking curves, detector scans, map | within a few per cent, I0 ≈ 1 |
| Lagally, ξ× = 1000 Å and 3000 Å | same where positive; ESCAPE negative exactly where the server returns 0 |
| Lagally, ξ× < ξ | refused by the server |
| Uncorrelated, conformal, Ming, Spiller | within a few per cent |
| Holy, σ = 1.5 Å | within a few per cent |
| Holy, σ = 4 Å (≈ 18 Å accumulated) | agrees at small qz, server up to 10 times lower at large qz |
The negative intensities are a property of the parameters, not of either program. ESCAPE returns them so an invalid parameter set is visible; the server hides them as zeros.