Here we will walk through the creation of a Larch plugin for the MBACK algorithm by Tsu-Chien Weng, et al.. MBACK is a method of normalizing XAS μ(E) by matching it to tabulated values of atomic cross sections.

To accommodate instrumental and sample-related effects in the background of the measured data, this background function is used:

μback(E)=[∑0mCi(E−E0)i]+A⋅erfc((E−Eem)/ξ)This includes a Legendre polynomial of order *m* added to a
complementary error function used to approximate the effect of Compton
scattering in the discriminator window of an energy-discriminating
detector, which is often responsible for a highly non-linear shape to
the pre-edge region of the measured μ(E) data.

This normalization function has *m+3* parameters -- *m* Legendre
polynomial coefficients, the amplitude (*A*) and width (ξ) of
the complementary error function, and a scaling factor (*s*) for the
measured data. The centroid of the error function (Eem) is set
to the centroid of the emission line associated with the measured
absorption edge. This function is then minimized to determine the
background function parameters:

Here, μdata(E) is the measured spectrum and μtab(E) is the tabulated cross section.

**:FIXME:** katex does not yet support `\mathrm`

or `\operatorname`

,
so `erfc()`

looks bad.... Also display math would be nice.

The plugin that implements this is at https://github.com/xraypy/xraylarch/blob/master/plugins/xafs/mback.py . In the next few sections, we will step through the parts of that file.