In [1]:
import re
from pathlib import Path

import numpy as np
import escape as esc

esc.require("0.9.8")
Loading material database from C:\dev\escape-core\.venv-gpu\Lib\site-packages\escape\scattering\..\data\mdb\materials.db

X-ray Server reference curves¶

These curves were calculated by Sergey Stepanov's X-ray Server. The diffraction sections use GID_sl and esc.spechrxrd and compare the curves directly. The off-specular sections use TRDS_sl and esc.offspecrefl. They take the server curves as data, attach counting errors, and fit the roughness.

The server's material code Si is amorphous, so the Darwin curve was requested as the crystal code Silicon. The GaAs/AlAs superlattice is the archive already stored in HighResXDiffrac/GaAs_AlAs_x20_GaAs and was not requested again.

Susceptibility is printed before each overlay. ESCAPE stores a scattering-length density, and the server stores susceptibility. With the source wavelength in Å the conversion used here is χ = −λ² SLD / π. A difference in χ is a materials difference. The diffraction and diffuse-scattering comparison is the overlay that follows.

Shared loaders¶

Server .dat files are two columns, angle in degrees and intensity. The HRXRD angle is the incidence angle. The off-specular angle is the sample angle θ of a rocking scan at fixed 2θ = 1°.

In [2]:
WL = 1.540562
SRC = esc.xrays(WL, units="angstrom")
K0 = 2.0 * np.pi / SRC.wavelength
ROOT = Path(".")
ARCHIVE = Path("../HighResXDiffrac/GaAs_AlAs_x20_GaAs/data")


def chi_of(sld):
    return -(WL ** 2) * sld / np.pi


def load_curve(path):
    angle, intensity = np.loadtxt(path, unpack=True)
    return np.asarray(angle, float), np.asarray(intensity, float)


def parse_tbl(path):
    text = Path(path).read_text(encoding="utf-8", errors="replace")
    pair = re.compile(r"\(([-+0-9.DdEe]+),([-+0-9.DdEe]+)\)")
    rows = []
    for line in text.splitlines():
        if re.match(r"\s+\d+\s+", line) and "(" in line:
            found = [(float(a), float(b)) for a, b in pair.findall(line)]
            if found:
                rows.append(
                    {
                        "text": " ".join(line.split()),
                        "chi0": complex(*found[0]),
                        "chih": complex(*found[1]) if len(found) > 1 else None,
                    }
                )
    beta = 1.0
    match = re.search(r"Asymmetry factor.*\|\s*([+-]?\d+(?:\.\d+)?(?:[Ee][+-]?\d+)?)", text)
    if match:
        beta = float(match.group(1))
    hkl = None
    match = re.search(
        r"Bragg reflection.*?\(\s*(-?\d+)\s*,\s*(-?\d+)\s*,\s*(-?\d+)\s*\)",
        text,
    )
    if match:
        hkl = tuple(int(value) for value in match.groups())
    daa = None
    match = re.search(r"<d\(a\)/a>.*\|\s*([+-]?\d+(?:\.\d+)?(?:[Ee][+-]?\d+)?)", text)
    if match:
        daa = float(match.group(1))
    incidence = exit_angle = None
    match = re.search(
        r"incident & exit angles.*?\|\s*"
        r"([+-]?\d+(?:\.\d+)?(?:[Ee][+-]?\d+)?)\s+"
        r"([+-]?\d+(?:\.\d+)?(?:[Ee][+-]?\d+)?)",
        text,
    )
    if match:
        incidence = float(match.group(1))
        exit_angle = float(match.group(2))
    return {
        "rows": rows,
        "beta": beta,
        "hkl": hkl,
        "daa": daa,
        "incidence": incidence,
        "exit": exit_angle,
    }


def case_paths(case_id):
    folder = ROOT / "data" / case_id
    dats = sorted(folder.glob("*.dat"))
    tbls = sorted(path for path in folder.glob("*.tbl") if path.stat().st_size > 200)
    if not dats or not tbls:
        return None
    return dats[-1], tbls[-1]


def residual(server, model):
    server = np.asarray(server, float)
    model = np.asarray(model, float)
    mask = (server > 0) & (model > 0) & np.isfinite(server) & np.isfinite(model)
    if not np.any(mask):
        print("no positive overlapping points")
        return
    ratio = server[mask] / model[mask]
    scale = float(np.median(ratio))
    dex = np.abs(np.log10(server[mask]) - np.log10(scale * model[mask]))
    print(
        f"points={mask.sum()}  median(server/ESCAPE)={scale:.4g}  "
        f"median |log10|={np.median(dex):.3f} dex  max={np.max(dex):.3f} dex"
    )


def print_server_chi(info):
    seen = set()
    for row in info["rows"]:
        chi0 = row["chi0"]
        chih = row["chih"]
        key = (
            round(chi0.real, 12),
            round(chi0.imag, 12),
            None if chih is None else round(chih.real, 12),
            None if chih is None else round(chih.imag, 12),
        )
        if key in seen:
            continue
        seen.add(key)
        line = f"server chi0=({chi0.real:.6e}, {chi0.imag:.6e})"
        if chih is not None:
            line += f"  chih=({chih.real:.6e}, {chih.imag:.6e})"
        print(line)
        print(" ", row["text"][:110])


def print_escape_chi(label, material, hkl=None):
    chi0 = chi_of(material.sld0(SRC))
    print(f"{label} chi0=({chi0.real:.6e}, {chi0.imag:.6e})")
    if hkl is not None:
        real, imag, phase = material.sldh(SRC, *hkl)
        print(
            f"{label} sldh=({real:.6e}, {imag:.6e}) phase/pi={phase:.3f} "
            f"for {hkl}"
        )


def hrxrd_kernel(sample, h, k, l, beta, formalism, name):
    theta = esc.var("theta")
    p0 = K0 * esc.sin(theta * np.pi / 180.0)
    kernel = esc.spechrxrd(
        p0, sample, h, k, l, beta, formalism, source=SRC, name=name
    )
    return theta, kernel


def show_curve(kernel, angle, intensity, title):
    data = esc.data(angle, intensity, np.zeros_like(intensity), copy=True, name=title)
    model = esc.model(kernel, data, residuals_scale="log", weight_type="none")
    return model.show().config(
        ylog=True, xlabel="incidence [deg]", ylabel="Intensity", title=title
    )

Si (004) Darwin curve¶

Perfect crystal, symmetric Bragg, σ polarization, matrix size fixed at 4×4 on the server, scan ±150 arcsec, 81 points. ESCAPE is evaluated with both 2x2 and 4x4. Away from grazing the two formalisms should agree with the server.

In [3]:
paths = case_paths("si004_darwin")
if paths is None:
    print("si004_darwin was not saved")
    si_view = None
else:
    dat_path, tbl_path = paths
    info = parse_tbl(tbl_path)
    angle, intensity = load_curve(dat_path)
    silicon = esc.crystal("Silicon", density="mdb")
    print_server_chi(info)
    print_escape_chi("ESCAPE Silicon", silicon, (0, 0, 4))
    substrate = esc.substrate(silicon, 0.0)
    sample = esc.multilayer(frgr=esc.air(), bkgr=substrate)
    for formalism in ("4x4", "2x2"):
        theta, kernel = hrxrd_kernel(
            sample, 0, 0, 4, info["beta"], formalism, f"Si 004 {formalism}"
        )
        model = np.asarray(kernel(angle), dtype=float)
        print(formalism, end=" ")
        residual(intensity, model)
        if formalism == "4x4":
            si_kernel = kernel
    si_view = show_curve(si_kernel, angle, intensity, "Si (004), server vs ESCAPE 4x4")
si_view
server chi0=(-1.500000e-05, 3.500000e-07)  chih=(7.700000e-06, 3.200000e-07)
  1 0.0 0.000E+00 0.0 Silicon 1.000 ss 1.00 1.00 (-.15E-04,0.35E-06) (0.77E-05,0.32E-06) 1.000 0.000
ESCAPE Silicon chi0=(-1.515761e-05, 3.454609e-07)
ESCAPE Silicon sldh=(1.095200e-05, 4.572886e-07) phase/pi=-1.000 for (0, 0, 4)
4x4 points=81  median(server/ESCAPE)=0.8607  median |log10|=0.012 dex  max=0.447 dex
2x2 points=81  median(server/ESCAPE)=0.8591  median |log10|=0.013 dex  max=0.446 dex
Out[3]:

In0.2Ga0.8As on GaAs (004)¶

One 500 Å pseudomorphic layer, da/a=auto on the server, symmetric (004), ±1500 arcsec, 121 points, 4×4. ESCAPE builds the same layer with Vegard's law and esc.epitaxial_unitcell at zero relaxation. The database Poisson ratios are ν(GaAs) = 0.3117 and ν(InAs) = 0.352, and C12/C11 = ν/(1−ν). That is the same biaxial relation the server uses for da/a=auto.

In [4]:
paths = case_paths("ingaas_strained")
if paths is None:
    print("ingaas_strained was not saved")
    ingaas_view = None
else:
    dat_path, tbl_path = paths
    info = parse_tbl(tbl_path)
    angle, intensity = load_curve(dat_path)
    x_in = 0.2
    a_gaas, a_inas = 5.6532, 6.0584
    nu = (1.0 - x_in) * 0.3117 + x_in * 0.352
    c12_c11 = nu / (1.0 - nu)
    a_bulk = (1.0 - x_in) * a_gaas + x_in * a_inas
    eps_par = (a_gaas - a_bulk) / a_bulk
    eps_perp = -2.0 * c12_c11 * eps_par
    daa = (a_bulk * (1.0 + eps_perp) - a_gaas) / a_gaas
    print(f"server <da/a>={info['daa']:.6e}  ESCAPE epitaxial da/a={daa:.6e}")
    gaas_cell = esc.unitcell(a_gaas, a_gaas, a_gaas, 90, 90, 90)
    inas_cell = esc.unitcell(a_inas, a_inas, a_inas, 90, 90, 90)
    alloy_cell = esc.alloy_unitcell(x_in, gaas_cell, inas_cell)
    epi_cell = esc.epitaxial_unitcell(alloy_cell, gaas_cell, 0.0, c12_c11)
    density = (1.0 - x_in) * 5.3176 + x_in * 5.667
    layer_mat = esc.binary_alloy_crystal(
        "GaAs", "InAs", x_in, density, epi_cell, name="InGaAs"
    )
    gaas = esc.crystal("GaAs", density="mdb")
    print_server_chi(info)
    print_escape_chi("ESCAPE InGaAs", layer_mat, (0, 0, 4))
    print_escape_chi("ESCAPE GaAs", gaas, (0, 0, 4))
    layer = esc.layer(layer_mat, 500.0, 0.0)
    substrate = esc.substrate(gaas, 0.0)
    sample = esc.multilayer(frgr=esc.air(), bkgr=substrate)
    sample.add(layer)
    for formalism in ("4x4", "2x2"):
        theta, kernel = hrxrd_kernel(
            sample, 0, 0, 4, info["beta"], formalism, f"InGaAs {formalism}"
        )
        model = np.asarray(kernel(angle), dtype=float)
        print(formalism, end=" ")
        residual(intensity, model)
        if formalism == "4x4":
            ingaas_kernel = kernel
    ingaas_view = show_curve(
        ingaas_kernel, angle, intensity, "InGaAs (004), server vs ESCAPE 4x4"
    )
ingaas_view
server <da/a>=2.781000e-02  ESCAPE epitaxial da/a=2.781236e-02
server chi0=(-2.900000e-05, 1.200000e-06)  chih=(1.700000e-05, 1.000000e-06)
  1 500.0 0.278E-01 A 0.0 InAs 0.200 1.00 1.00 (-.29E-04,0.12E-05) (0.17E-04,0.10E-05) 1.000 0.000
server chi0=(-2.900000e-05, 8.400000e-07)  chih=(1.700000e-05, 7.800000e-07)
  2 0.0 0.000E+00 0.0 GaAs 1.000 ss 1.00 1.00 (-.29E-04,0.84E-06) (0.17E-04,0.78E-06) 1.000 0.000
ESCAPE InGaAs chi0=(-2.950597e-05, 1.143028e-06)
ESCAPE InGaAs sldh=(2.485143e-05, 1.513033e-06) phase/pi=-1.000 for (0, 0, 4)
ESCAPE GaAs chi0=(-2.911119e-05, 8.710416e-07)
ESCAPE GaAs sldh=(2.405953e-05, 1.153003e-06) phase/pi=1.000 for (0, 0, 4)
4x4 points=121  median(server/ESCAPE)=0.867  median |log10|=0.006 dex  max=0.068 dex
2x2 points=121  median(server/ESCAPE)=0.8681  median |log10|=0.004 dex  max=0.055 dex
Out[4]:

GaAs (113) grazing incidence¶

Coplanar grazing incidence on a (001) surface. The server table gives the Bragg geometry as incidence 1.627 degrees and exit 52.106 degrees, and the saved column is the incidence angle. spechrxrd sets the exit wavevector from ph = p0 / beta. Holding beta at the Bragg value drags the exit angle along with the incidence, so the calculated curve is a needle at the kinematic Bragg angle.

On this GID scan the exit angle stays at the Bragg exit, and beta(incidence) = sin(incidence) / sin(exit). That 2x2 curve is the diffracted intensity. The 4x4 value still mixes in the specular wave on the low-angle side, so the overlay uses 2x2.

In [5]:
paths = case_paths("gaas113_grazing")
if paths is None:
    print("gaas113_grazing was not saved")
    grazing_view = None
else:
    dat_path, tbl_path = paths
    info = parse_tbl(tbl_path)
    angle, intensity = load_curve(dat_path)
    h, k, l = info["hkl"]
    print(
        f"server (hkl)={info['hkl']}  Bragg incidence={info['incidence']}  "
        f"exit={info['exit']}  beta={info['beta']:.6e}"
    )
    gaas = esc.crystal("GaAs", density="mdb")
    print_server_chi(info)
    print_escape_chi("ESCAPE GaAs", gaas, (h, k, l))
    substrate = esc.substrate(gaas, 0.0)
    sample = esc.multilayer(frgr=esc.air(), bkgr=substrate)
    sin_exit = np.sin(np.deg2rad(info["exit"]))
    matched = None
    for formalism in ("2x2", "4x4"):
        model = []
        for incidence in angle:
            beta = float(np.sin(np.deg2rad(incidence)) / sin_exit)
            _theta, kernel = hrxrd_kernel(
                sample, h, k, l, beta, formalism, f"GaAs 113 {formalism}"
            )
            model.append(float(np.asarray(kernel(incidence))))
        model = np.asarray(model, float)
        print(formalism, end=" ")
        residual(intensity, model)
        if formalism == "2x2":
            matched = model
    theta = esc.var("theta")
    grazing_kernel = esc.linterp(theta, angle, matched)
    grazing_view = show_curve(
        grazing_kernel, angle, intensity, "GaAs (113) grazing, server vs ESCAPE 2x2"
    )
grazing_view
server (hkl)=(1, 1, 3)  Bragg incidence=1.626788  exit=52.10559  beta=3.597441e-02
server chi0=(-2.900000e-05, 8.400000e-07)  chih=(1.300000e-05, 5.600000e-07)
  1 0.0 0.000E+00 0.0 GaAs 1.000 ss 1.00 1.00 (-.29E-04,0.84E-06) (0.13E-04,0.56E-06) 1.033 0.000
ESCAPE GaAs chi0=(-2.911119e-05, 8.710416e-07)
ESCAPE GaAs sldh=(1.873385e-05, 8.223787e-07) phase/pi=-0.970 for (1, 1, 3)
2x2 points=61  median(server/ESCAPE)=0.886  median |log10|=0.021 dex  max=0.059 dex
4x4 points=61  median(server/ESCAPE)=0.01745  median |log10|=0.528 dex  max=3.167 dex
Out[5]:

GaAs/AlAs ×20, from the existing archive¶

Twenty periods of 100 Å GaAs and 70 Å AlAs on GaAs, σ = 2 Å, AlAs da/a = 0.00298, Cu Kα, (004), matrix reduction Fly on the server. ESCAPE uses the 2x2 kernel. The curve is g1743010.dat and is not a new server request.

In [6]:
dat_path = ARCHIVE / "g1743010.dat"
tbl_path = ARCHIVE / "g1743010.tbl"
info = parse_tbl(tbl_path)
angle, intensity = load_curve(dat_path)
gaas_cell = esc.unitcell(5.6532, 5.6532, 5.6532, 90, 90, 90)
alas_cell = esc.strained_unitcell(2.98e-3, gaas_cell)
gaas = esc.crystal("GaAs", density="mdb", ucell=gaas_cell)
alas = esc.crystal("AlAs", density="mdb", ucell=alas_cell)
print_server_chi(info)
print_escape_chi("ESCAPE GaAs", gaas, (0, 0, 4))
print_escape_chi("ESCAPE AlAs", alas, (0, 0, 4))
gaas_layer = esc.layer(gaas, 100.0, 2.0)
alas_layer = esc.layer(alas, 70.0, 2.0)
substrate = esc.substrate(gaas, 0.0)
sample = esc.multilayer(frgr=esc.air(), bkgr=substrate)
stack = esc.layer_stack(repeat=20)
stack.add(gaas_layer)
stack.add(alas_layer)
sample.add(stack)
theta, kernel = hrxrd_kernel(sample, 0, 0, 4, 1.0, "2x2", "GaAs/AlAs 2x2")
model = np.asarray(kernel(angle), dtype=float)
print("2x2", end=" ")
residual(intensity, model)
sl_view = show_curve(kernel, angle, intensity, "GaAs/AlAs x20, server vs ESCAPE 2x2")
sl_view
server chi0=(-2.900000e-05, 8.400000e-07)  chih=(1.700000e-05, 7.800000e-07)
  1 100.0 0.000E+00 2.0 GaAs 1.000 1.00 1.00 (-.29E-04,0.84E-06) (0.17E-04,0.78E-06) 1.000 0.000
server chi0=(-2.100000e-05, 5.900000e-07)  chih=(1.200000e-05, 5.400000e-07)
  2 70.0 0.298E-02 A 2.0 AlAs 1.000 1.00 1.00 (-.21E-04,0.59E-06) (0.12E-04,0.54E-06) 1.000 0.000
ESCAPE GaAs chi0=(-2.911119e-05, 8.710416e-07)
ESCAPE GaAs sldh=(2.405953e-05, 1.153003e-06) phase/pi=1.000 for (0, 0, 4)
ESCAPE AlAs chi0=(-2.123774e-05, 6.041456e-07)
ESCAPE AlAs sldh=(1.717752e-05, 7.997111e-07) phase/pi=1.000 for (0, 0, 4)
2x2 points=401  median(server/ESCAPE)=0.8674  median |log10|=0.007 dex  max=1.792 dex
Out[6]:

Off-specular reflectivity. Silicon surface.¶

Diffuse reflectivity from a bare silicon surface. The curve was calculated by the X-ray Server program TRDS and saved as data/si_surface/tds27191.dat. Cu Kα (1.540562 Å), σ polarization. The roughness is uncorrelated, with σ = 5 Å, a lateral correlation length of 500 Å and a Hurst exponent of 1.

The scan is a rocking curve at fixed 2θ = 1°. θ runs from 0.08° to 0.92°, and the exit angle is 1° − θ. At θ = 0.5° the point lies on the specular rod. The value stored there is the diffuse intensity. The server column is a cross-section. Io puts 10⁴ counts on the brightest point, and the error bar is √(I / Io).

The roughness and the lateral correlation length stay at the values used to calculate the curve. The height of the rocking curve cannot separate the roughness amplitude from an overall scale, so the optimizer adjusts I0 only. I0 starts at 0.8.

In [7]:
sigma = esc.par("Roughness", 5.0, units="Å", fixed=True, userlim=[1.0, 12.0])
lateral = esc.par("Lateral correlation", 500.0, units="Å", fixed=True, userlim=[150.0, 2000.0])
hurst = esc.par("Hurst", 1.0, fixed=True, userlim=[0.2, 1.0])

Silicon is taken from the material database. The density is kept fixed. The surface roughness is self-affine and uncorrelated, which on a single interface is the whole model.

In [8]:
silicon = esc.crystal("Silicon", density="mdb", density_fixed=True, name="Silicon")
surface_rough = esc.roughness(sigma, lateral=lateral, hurst=hurst, name="Si roughness")
sample = esc.multilayer(
    name="Si surface",
    frgr=esc.air("Air"),
    bkgr=esc.substrate(silicon, surface_rough, name="Si"),
)
sample.show(source=SRC)
Out[8]:

θ is the sample angle in degrees. The wave-vector components follow from θ and from the exit angle 1° − θ.

In [9]:
theta = esc.var("theta")
degree = np.pi / 180.0
alpha_i = theta * degree
alpha_f = (1.0 - theta) * degree
wave = 2.0 * np.pi / SRC.wavelength
diffuse = esc.offspecrefl(
    wave * (esc.cos(alpha_f) - esc.cos(alpha_i)),
    wave * esc.sin(alpha_i),
    wave * esc.sin(alpha_f),
    sample,
    source=SRC,
    formalism="full",
    name="Si surface",
)
I0 = esc.par("I0", 0.8, userlim=[0.5, 1.5])
I = I0 * diffuse

Load the server curve and attach the counting errors.

In [10]:
angle, measured = np.loadtxt("data/si_surface/tds27191.dat", unpack=True)
measured = np.asarray(measured, float)
# Io puts 1e4 counts on the brightest point. The bar is the Poisson error.
Io = 1.0e4 / np.max(measured)
errors = np.sqrt(measured / Io)
data = esc.data(angle, measured, errors, copy=True, name="Si surface")
model = esc.model(
    I, data, residuals_scale="none", weight_type="data", name="Si surface"
)
opt_surface = esc.levmar(
    model,
    xtol=1.0e-6,
    ftol=1.0e-8,
    gtol=1.0e-6,
    maxiter=25,
    maxfev=300,
    nupdate=5,
    epsfcn=1.0e-7,
)
opt_surface()
print("cost", opt_surface.best_cost)
print("roughness", sigma.value, "lateral", lateral.value, "I0", I0.value)
model.show().config(ylog=True, xlabel="theta [deg]", ylabel="Intensity [a.u.]")
cost 0.6615084621014752
roughness 5.0 lateral 500.0 I0 0.9960072767787445
Out[10]:
In [11]:
opt_surface
Out[11]:
Name: Levenberg-Marquardt 	Parameters number:          5
Parameter           	Value          	+-	Error     	Units     	Fixed
I0                  	        0.99601	+-	0.0018878 	          	    0
Silicon density     	         2.3293	+-	0         	g/cm^3    	    1
Roughness           	              5	+-	0         	Å         	    1
Lateral correlation 	            500	+-	0         	Å         	    1
Hurst               	              1	+-	0         	          	    1

Germanium film on silicon.¶

A 200 Å germanium film on the same silicon substrate. Both interfaces use the uncorrelated roughness above, σ = 5 Å and ξ = 500 Å. The server file is data/film_uncorrelated/tds27192.dat. The same rocking curve, the same error bars and the same optimizer are used. The two interfaces share the roughness parameters.

In [12]:
thickness = esc.par("Ge thickness", 200.0, units="Å", fixed=True)
sigma = esc.par("Roughness", 5.0, units="Å", fixed=True, userlim=[2.0, 10.0])
lateral = esc.par("Lateral correlation", 500.0, units="Å", fixed=True, userlim=[150.0, 2000.0])
hurst = esc.par("Hurst", 1.0, fixed=True, userlim=[0.2, 1.0])
In [13]:
germanium = esc.crystal("Germanium", density="mdb", density_fixed=True, name="Germanium")
silicon = esc.crystal("Silicon", density="mdb", density_fixed=True, name="Silicon")
film_rough = esc.roughness(sigma, lateral=lateral, hurst=hurst, name="Ge roughness")
buried_rough = esc.roughness(sigma, lateral=lateral, hurst=hurst, name="Si roughness")
film = esc.layer(germanium, thickness, film_rough, name="Ge")
sample = esc.multilayer(name="Ge/Si", frgr=esc.air("Air"), bkgr=esc.substrate(silicon, buried_rough, name="Si"))
sample.add(film)
sample.show(source=SRC)
Out[13]:
In [14]:
theta = esc.var("theta")
degree = np.pi / 180.0
alpha_i = theta * degree
alpha_f = (1.0 - theta) * degree
wave = 2.0 * np.pi / SRC.wavelength
diffuse = esc.offspecrefl(
    wave * (esc.cos(alpha_f) - esc.cos(alpha_i)),
    wave * esc.sin(alpha_i),
    wave * esc.sin(alpha_f),
    sample,
    source=SRC,
    formalism="full",
    name="Ge/Si",
)
I0 = esc.par("I0", 0.8, userlim=[0.5, 1.5])
I = I0 * diffuse
In [15]:
angle, measured = np.loadtxt("data/film_uncorrelated/tds27192.dat", unpack=True)
measured = np.asarray(measured, float)
# Io puts 1e4 counts on the brightest point. The bar is the Poisson error.
Io = 1.0e4 / np.max(measured)
errors = np.sqrt(measured / Io)
data = esc.data(angle, measured, errors, copy=True, name="Ge/Si")
model = esc.model(
    I, data, residuals_scale="none", weight_type="data", name="Ge/Si"
)
opt_film = esc.levmar(
    model,
    xtol=1.0e-6,
    ftol=1.0e-8,
    gtol=1.0e-6,
    maxiter=25,
    maxfev=300,
    nupdate=5,
    epsfcn=1.0e-7,
)
opt_film()
print("cost", opt_film.best_cost)
print("roughness", sigma.value, "lateral", lateral.value, "I0", I0.value)
model.show().config(ylog=True, xlabel="theta [deg]", ylabel="Intensity [a.u.]")
cost 30.318443384218927
roughness 5.0 lateral 500.0 I0 0.9836169937207476
Out[15]:
In [16]:
opt_film
Out[16]:
Name: Levenberg-Marquardt 	Parameters number:          7
Parameter           	Value          	+-	Error     	Units     	Fixed
I0                  	        0.98362	+-	0.0016982 	          	    0
Germanium density   	         5.3244	+-	0         	g/cm^3    	    1
Ge thickness        	            200	+-	0         	Å         	    1
Roughness           	              5	+-	0         	Å         	    1
Lateral correlation 	            500	+-	0         	Å         	    1
Hurst               	              1	+-	0         	          	    1
Silicon density     	         2.3293	+-	0         	g/cm^3    	    1
In [ ]: