File: MagneticLayerImperfect.py

package info (click to toggle)
bornagain 23.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,948 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (75 lines) | stat: -rwxr-xr-x 2,299 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
"""
Realistic (imperfect) example for polarized reflectometry.
Sample contains a magnetic layer,
similar to Devishvili et al., Rev. Sci. Instrum. 84, 025112 (2013).
"""
import numpy
import bornagain as ba
from bornagain import nm, ba_plot as bp, deg, R3
from math import sin, cos

def get_sample():
    # Materials
    Bmag = 1.6e6
    Bangle = 0 * deg
    B = R3(Bmag*sin(Bangle), Bmag*cos(Bangle), 0)
    vacuum = ba.MaterialBySLD("Vacuum", 0, 0)
    material_Pd = ba.MaterialBySLD("Pd", 4.0099e-6, 1.3019e-09)
    material_Fe = ba.MaterialBySLD("Fe", 8.0241e-06, 6.0448e-10, B)
    material_substrate = ba.MaterialBySLD("MgO", 5.9803e-06, 9.3996e-12)

    autocorr = ba.SelfAffineFractalModel(2*nm, 0.7, 25*nm)
    transient = ba.TanhTransient()
    roughness = ba.Roughness(autocorr, transient)

    # Layers
    layer_vacuum = ba.Layer(vacuum)
    layer_Pd = ba.Layer(material_Pd, 12*nm, roughness)
    layer_Fe = ba.Layer(material_Fe, 100*nm, roughness)
    layer_substrate = ba.Layer(material_substrate, roughness)

    # Multilayer
    sample = ba.Sample()
    sample.addLayer(layer_vacuum)
    sample.addLayer(layer_Pd)
    sample.addLayer(layer_Fe)
    sample.addLayer(layer_substrate)

    return sample


def simulate(p_dir, a_dir, p_eff, a_eff, title):
    sample = get_sample()

    qzs = numpy.linspace(0.1, 1.5, 1500)
    distr = ba.DistributionGaussian(0., 1., 25, 4.)

    scan = ba.QzScan(qzs)
    scan.setAbsoluteQResolution(distr, 0.008)

    scan.setPolarization(p_dir*p_eff)
    scan.setAnalyzer(a_dir*a_eff)

    simulation = ba.SpecularSimulation(scan, sample)
    simulation.setBackground(ba.ConstantBackground(1e-7))

    result = simulation.simulate()
    result.setTitle(title)

    return result


if __name__ == '__main__':
    # polarizer and analyzer efficiencies
    p_eff = 0.986
    a_eff = 0.970

    results_pp = simulate(R3(0, +1, 0), R3(0, +1, 0), p_eff, a_eff, "$++$")
    results_pm = simulate(R3(0, +1, 0), R3(0, -1, 0), p_eff, a_eff, "$+-$")
    results_mp = simulate(R3(0, -1, 0), R3(0, +1, 0), p_eff, a_eff, "$-+$")
    results_mm = simulate(R3(0, -1, 0), R3(0, -1, 0), p_eff, a_eff, "$--$")

    results = [results_pp, results_pm, results_mp, results_mm]
    from bornagain import ba_check
    ba_check.persistence_test(results)