Debian Codegraph @

hugo/content/ref/instr/pol/polarized-spinasymmetry/index.md

raw
1 +++
2 title = "Spin asymmetry example"
3 weight = 40
4 +++
5
6 ### Spin-asymmetry example from NIST
7
8
9 This example shows how to simulate the magnetic layer described on the NIST homepage in the [Magnetically Dead Layers in Spinel Films](https://www.nist.gov/ncnr/magnetically-dead-layers-spinel-films) example.
10 In particular, we want to show how to use BornAgain in order to simulate the spin asymmetry.
11 The sample simulated in this example is very similar to the previous examples introduced in this section.
12 It just consists of a magnetic layer on top of a substrate.
13 During these tutorials, we neglect the magnetically dead layer that forms below the magnetic layer, as there is currently no API in BornAgain to support such a scenario out of the box.
14
15
16 In this first example, we utilize parameters that are deduced from a fit to the data provided on the NIST homepage.
17 How to perform the fit is described in the
18 [extended example](/ref/fit/ex/polarized-spinasymmetry-fit).
19
20
21
22 #### Spin asymmetry
23
24
25 The spin asymmetry is defined as
26
27 $$S = \frac{R^{++} - R^{- -}}{R^{++} + R^{- -}}$$
28
29 Therefore, we only need to perform a normal polarized simulation for the up-up and down-down channels and then compute
30 the spin asymmetry.
31
32 Given the experimental data, the measured spin asymmetry is calculated in the same way.
33 In addition, the error is computed by:
34
35 $$\Delta S = \frac{\sqrt{ 4 {R^{++}}^2 \left( \Delta {R^{- -}} \right)^2 + 4 {R^{- -}}^2 \left( \Delta {R^{++}}\right)^2 }}{ \left( R^{++} + R^{- -}\right)^2 } $$
36
37 This is performed in the function `plotSpinAsymmetry`.
38
39
40
41 #### Further corrections
42
43 We also apply a resolution correction, as described in the
44 [ToF - Resolution effects](/ref/instr/scan/tof-resolution) example.
45
46 Furthermore, we introduce an offest in the $Q$-axis, in order to accomodate for experimental uncertainties
47 in the measurement of $\theta$.
48 For this purpose, the provided $Q$-axis is shifted in the function `get_simulation`:
49
50 ```python
51 q_axis = q_axis + parameters["q_offset"]
52 ```
53
54
55
56 #### Data processing
57
58 After loading the experimental data, we scale the q-axis in order to obtain inverse nm as they are the default units in BornAgain.
59 Furthermore, the reflectivity data is scaled such that its maximum is unity.
60
61 #### Running the example
62
63 This example requires experimental data files from the BornAgain repository
64 ({{% ref-src "testdata/specular/MAFO_Saturated_pp.tab" %}} and
65 {{% ref-src "testdata/specular/MAFO_Saturated_mm.tab" %}}).
66
67 The environment variable `BA_DATA_DIR` must point to the `testdata/` directory.
68 From the build directory, run:
69 ```bash
70 BA_DATA_DIR=../testdata python3 ../auto/Examples/specular/PolarizedSpinAsymmetry.py
71 ```
72
73 #### Simulation result
74
75
76 {{< galleryscg >}}
77 {{< figscg src="/files/fitted/SpinAsymmetry1.png" width="350px" caption="Reflectivity">}}
78 {{< figscg src="/img/auto/specular/PolarizedSpinAsymmetry.png" width="350px" caption="Spin Asymmetry">}}
79 {{< /galleryscg >}}
80
81 Here is the complete example:
82
83 {{< show-ex file="specular/PolarizedSpinAsymmetry.py" >}}