Skip to content

Refl1D Architecture

Brian Benjamin Maranville edited this page Sep 4, 2024 · 6 revisions

Refl1D: the library

connection to bumps:

  • uses bumps.parameter.Parameter objects everywhere that parameters are needed
  • defines a class refl1d.experiment.Experiment that can be used as a model in bumps.fitproblem.FitProblem
    • providing nllf(), residuals() and parameters() methods

Defining a reflectometry model

Defining a sample

  • Slab objects with
    • thickness
    • roughness
    • scattering length density (SLD)
    • absorption (imaginary SLD)
    • optional magnetism (direction and magnitude)
  • sample is Stack made of Slab objects

Defining a probe

  • Neutron or X-Ray probe objects
    • optional polarization (4 cross-sections "mm", "mp", "pm", "pp")
    • angular resolution
    • wavelength resolution
    • optional datasets
      • Q (momentum transfer)
      • R (reflectivity, normalized to incident beam)
      • dR (error on R column)
      • dQ (resolution/uncertainty in Q column)
      • optional incident_angle and wavelength (for fitting theta_offset)

Defining experiment:

The refl1d.experiment.Experiment class is initialized with a sample and a probe object and can be used as a model in bumps.fitproblem.FitProblem

Evaluating a reflectometry model

Profile

First, a set of "profiles" is drawn based on the sample layers, where "profile" means a smooth representation of these quantities as a function of $z$ (depth into the sample):

  • rho (SLD)
  • irho (absorption)
  • rhoM (magnitude of magnetic SLD, if magnetism is defined)
  • thetaM (direction of magnetism, if magnetism is defined)

Reflectivity

$R_{calc}$ is calculated from the profiles above. The inputs to the reflectivity function include

  • the $Q$ values at which to calculate (from the probe object)
  • a table of values of
    • $z$, rho, irho, rhoM, thetaM for the sample

Resolution

A Gaussian resolution kernel is applied to $R_{calc}$, with local kernel width equal to dQ (or the RMS sum of dTheta and dLambda, if they are provided in the Probe object) to account for instrumental resolution effects.

Sometimes $Q$ is "oversampled" with respect to the Q values present in the data, in order to support the Gaussian kernel for every data point (extra Q values are inserted between data Q values), but the output of the resolution smearing is only evaluated at the data Q, for comparison and calculation of the residuals as below. If the data has sufficient density such that dQ >> Q spacing, then no oversampling is required.

Residuals and Negative-log-likelihood

Then

  • $residuals = (R_{data} - R_{calc}) / dR_{data}$
  • $nllf = \sum (residuals^2)$

Refl1D: the applications

refl1d.cli

Almost the same as bumps.cli, with a few custom functions adding profile uncertainty plots to export outputs

refl1d.gui

A WxPython app that inherits nearly everything from bumps.gui, and adds a few custom panels for plotting reflectivity and profile

refl1d.webview

refl1d.webview.server

A webserver that inherits nearly everything from bumps.webview.server, adding custom API calls for getting reflectivity data, and creating profile plots (and profile uncertainty plots)

refl1d.webview.client

A Javascript app written largely with Vue.js components, where most of those components are pulled from the bumps.webview.client library. Custom panels are added in panels.mjs

Clone this wiki locally