Debian Codegraph @

hugo/content/ref/fit/ex/reflectometry-pt-layer.md

raw
1 +++
2 title = "Reflectometry: Fit Pt layer"
3 weight = 50
4 +++
5
6 ### Reflectometry: Fit Pt layer
7
8 In this example, we want to demonstrate how to fit experimental reflectivity data
9 that was obtained by a time-of-flight experiment with unpolarized neutrons.
10 Experimental data is available for a sample of a roughly 50 nm thick platinum layer on top of a silicon substrate that is published in [this repository](https://doi.org/10.5281/zenodo.4072376).
11
12 The mesaurements were made by Timothy Charlton, Haile Ambaye and Michael Fitzsimmons (ORNL)
13 on a sample provided by Eric Fullerton (UCSD).
14
15
16 #### Fit model
17
18 We describe the above experiment by a three-layer model, where as usual the top layer is
19 the vacuum and the substrate layer is the silicon substrate.
20 On top of the silicon substrate, we place the platinum layer.
21 The materials of both layers are described by their SLD, where we use literature values
22 for both silicon as well as platinum and keep them constant throughout the fitting procedure.
23
24 The main parameters of the sample are stored in dictionary, where they are defined by a unique `name`
25 and the following six parameters are utilized:
26
27 * Beam intensity: `intensity`
28
29 We explicitly fit the beam intensity, in order to compensate for possible experimental errors
30 and to circumvent problems with the rather large variance in the reflectivity data at low $Q$-values.
31
32 * Roughness on top of the Pt layer: `r_pt/nm`
33
34 * Roughness on top of the Si substrate: `r_si/nm`
35
36 * Thickness of the Pt layer: `t_pt/nm`
37
38 * The relative $Q$-resolution: `q_res/q` ([c.f.](/ref/instr/scan/tof-resolution))
39
40 * A $Q$-offset: `q_offset`
41
42 This global offset is introduced to account for uncertainties in the angle at which the measurement is performed.
43
44 Due to saturation of the detector it is possible that the intensity at low $Q$-values (i.e. at high count rates)
45 is underestimated.
46 Furthermore, there is a rather large variance in the data that also leads to a rather bad fit in this region.
47 Therefore, we neglect the data in the low $Q$-region by choosing a cutoff at $Q_{\text{min}} = $ 0.18.
48 This value is selected by hand after performing several fits and visually selecting a good result.
49
50 ##### $Q$-offset
51
52 Currently, BornAgain does not have an API support for an offset of the $Q$-axis.
53 Therefore, we need to shift the $Q$-axis before performing a simulation
54 ```python
55 q_axis = q_axis + parameters["q_offset"]
56 ```
57
58 This shift then needs to be counter-transformed when returning the results in the `qr(result)` function
59 ```python
60 q = numpy.array(result.result().axis(ba.Axes.QSPACE)) - q_offset
61 ```
62
63 ##### Initial parameters
64
65 In order to successfully fit this example, we chose some sane starting values and
66 the example code that is fully given below, can be run with the following command:
67 ```python
68 python3 Pt_layer_fit.py fit
69 ```
70 This performs a simulation with the initial parameters and yields the following result:
71
72 {{< galleryscg >}}
73 {{< figscg src="/img/draw/Pt-Layer-initial.png" width="550px" caption="Reflectivity with the initial parameters before fitting">}}
74 {{< /galleryscg >}}
75
76 Immediately afterwards the fit is performed.
77
78
79 #### Fit result
80
81 In order to run the fitting procedure, the following command can be issued:
82
83 ```python
84 python3 Pt_layer_fit.py fit
85 ```
86
87 We need to allow a few seconds computational time and BornAgain should compute the following result
88
89 {{< galleryscg >}}
90 {{< figscg src="/img/draw/Pt-Layer-final.png" width="550px" caption="Reflectivity with the parameters obtained from our fit">}}
91 {{< /galleryscg >}}
92
93
94 If the `fit` keyword is omitted from the command line
95 ```python
96 python3 Pt_layer_fit.py
97 ```
98 a simulation is performed with our fit results and one should obtain the result shown above.
99
100 {{< show-ex file="fit/specular/Pt_layer_fit.py" >}}