{
"cells": [
{
"cell_type": "markdown",
"id": "9f5bfd59-1c97-41a3-b723-188079807d4a",
"metadata": {},
"source": [
"# Absorption and Multiple Scattering Correction"
]
},
{
"cell_type": "markdown",
"id": "b7473260-c9e2-4f72-b920-da6915f06786",
"metadata": {},
"source": [
"## General aspects\n",
"\n",
"When neutrons travel into the sample, there are multiple types of events that can happen, and two typical ones are scattering and absorption. Specifically concerning the scattering event, there are also two types -- single scattering and multiple scattering. Fundamentally, it is only the single scattering event that we are concerned about for extracting structural information, in a general sense. Therefore, in practice, we need to correct for both the absorption and multiple scattering effects. With this regard, the Mantid concept page as in Ref. {cite}`mantid_abs_ms` presents a nice summary about the undelying principles and the practical implementation in Mantid framework. On top of that, the derivation of the Paalman-Pings scheme for the absorption correction is detailed below. First, the complete expression of the full Paalman-Pings formulation is as follows,\n",
"\n",
"$$\\begin{align}I_{S+C}^{E} = I_{S}A_{S,SC} + I_{C}A_{C,SC} + I_{SC}A_{SC,SC}\\tag{1}\\end{align}$$\n",
"\n",
"where,\n",
"\n",
"- $S$ for sample, $C$ for container\n",
"\n",
"- $I_{S+C}^{E}$ experimentally measured intensity from $S+C$.\n",
"\n",
"- $I_S$ theoretical intensity from the isolated sample.\n",
"\n",
"- $I_C$ theoretical intensity from the isolated container.\n",
"\n",
"- $I_{SC}$ theoretical intensity from the correlated sample and container interface.\n",
"\n",
"- $A_{S,SC}$ is the absorption factor for scattering in the sample region and absorption by the sample and container.\n",
"\n",
"- $A_{C,SC}$ is the absorption factor for scattering in the container region and absorption by the sample and container.\n",
"\n",
"- $A_{AC,SC}$ is the absorption factor for scattering in the correlated sample and container interface and absorption by the sample and container.\n",
"\n",
"Ignoring the contribution from the correlated interface between the sample and container, the exression can be simplified to,\n",
"\n",
"$$\\begin{align}I_{S+C}^{E} = I_{S}A_{S,SC} + I_{C}A_{C,SC}\\tag{2}\\end{align}$$\n",
"\n",
"For the empty container measurement, one has,\n",
"\n",
"$$I_C^E = I_CA_{C,C} \\Rightarrow I_C = \\frac{1}{A_{C,C}}I_C^E\\tag{3}$$\n",
"\n",
"where,\n",
"\n",
"- $I_C^E$ experimentally measured intensity from $S+C$experimentally measured intensity from $C$.\n",
"\n",
"- $A_{C,C}$ is the absorption factor for scattering in the container region and absorption by the container.\n",
"\n",
"Putting Eqn. (2) and (3) together, one could obtain,\n",
"\n",
"$$I_{S+C}^E = I_SA_{S,SC} + \\frac{A_{C,SC}}{A_{C,C}}I_C^E \\Rightarrow I_S = \\frac{1}{A_{S,SC}}I_{S+C}^E - \\frac{A_{C,SC}}{A_{S,SC}}\\frac{1}{A_{C,C}}I_C^E$$\n",
"\n",
"Following such a scheme, the absorption coefficients (i.e., those $A$'s) can be evaluated in a numerical integration approach and applied to the experimentally measured intensities to correct for the absorption effect as detailed above. There are two other simpler variations of the full Paalman-Pings approach -- the `SampleOnly` approach and the `SampleAndContainer` approach, of which the formulation is presented in the following equations, respectively,\n",
"\n",
"$$I_S^E = I_SA_{S,S}$$\n",
"\n",
"$$I_{S+C}^E = I_SA_{S,S} + I_CA_{C,C}$$\n",
"\n",
"In the `SampleOnly` approach, the contribution from the container is ignored in terms of absorption effect, whereas the `SampleAndContainer` approach is assuming the scattering-absorption event happens indenpedently in between the sample and container."
]
},
{
"cell_type": "markdown",
"id": "9decf385-9f08-4e89-ae59-ed369eb98c49",
"metadata": {},
"source": [
"## Multiple Scattering Correction\n",
"\n",
"Evaluation of those different absorption coefficients in a numerical manner is nicely presented in the Ref. {cite}`mantid_abs_ms`. Meanwhile, a comprehensive table listing out all the implemented algorithms for performing absorption and multiple scattering correction, together with justification for the undelying algorithms can be found there as well. Specifically concerning the multiple scattering correction, a detailed derivation of the formulation based on multiple assumptions (elastic & isotropic scattering, constant ratio be in between adjacent order of multiple scattering intensities) can also be found. Most details won't be reproduced in current documentation, and one is strongly encouraged to go over the Ref. {cite}`mantid_abs_ms` for better understanding of the topic. Instead, current booklet will focus on those technical implementation relevant aspects, with reference to Ref. {cite}`mantid_abs_ms`.\n",
"\n",
"### Formulation\n",
"\n",
"The final formulation of the multiple scattering will be reproduced here,\n",
"\n",
"$$\\begin{align}I_{total} & = I_1 + I_m \\\\ & = I_1\\frac{\\Delta}{1 - \\Delta} \\\\ & \\Rightarrow \\\\ I_1 & = I_{total}(1 - \\Delta)\\tag{4}\\end{align}$$\n",
"\n",
"where $I_1$ refers to the scattering intensity with the multiple scattering effect corrected, and $I_{total}$ represents the overall measured scattering intensity. $\\Delta$ in the formulation can be expressed as,\n",
"\n",
"$$\\Delta = \\frac{\\rho V A_2}{4\\pi A_1}\\tag{5}$$\n",
"\n",
"where $\\rho$ refers to the number density of the material in question, $V$ for the volume of the sample. $A_1$ and $A_2$ could be evaluated numerically following the formulation below,\n",
"\n",
"$$A_1 = \\frac{1}{V}\\int\\rho\\,\\sigma\\,exp[-\\mu^\\text{s} (l_\\text{S1}^\\text{s} + l_\\text{1D}^\\text{s}) -\\mu^\\text{c} (l_\\text{S1}^\\text{c} + l_\\text{1D}^\\text{c})]dV\\tag{6}$$\n",
"\n",
"where\n",
"$\\rho$ is the effective number density of the scattering element,\n",
"$\\sigma$ is the total scattering cross section of the scattering element,\n",
"$\\mu^\\text{s}$ is the absorption coefficient of the sample,\n",
"$\\mu^\\text{c}$ is the absorption coefficient of the container,\n",
"$l_\\text{S1}^\\text{s}$ is the distance between source and the scattering element within the sample,\n",
"$l_\\text{S1}^\\text{c}$ is the distance between source and the scattering element within the container,\n",
"$l_\\text{1D}^\\text{s}$ is the distance between the scattering element and the detector within the sample,\n",
"and\n",
"$l_\\text{1D}^\\text{s}$ is the distance between the scattering element and the detector within the container.\n",
"\n",
"$$A_2 = \\frac{1}{V^2}\n",
" \\int \\rho_1 \\sigma_1\n",
" \\int \\rho_2 \\sigma_2\n",
" \\dfrac{ \\exp\\left[\n",
" -\\mu^\\text{s}( l_\\text{S1}^\\text{s}\n",
" + l_\\text{12}^\\text{s}\n",
" + l_\\text{2D}^\\text{s}) \n",
" -\\mu^\\text{c}( l_\\text{S1}^\\text{c}\n",
" + l_\\text{12}^\\text{c}\n",
" + l_\\text{2D}^\\text{c})\n",
" \\right]\n",
" }{l_\\text{12}^2}\n",
" dV_2\n",
" dV_1\\tag{7}$$\n",
"\n",
"where\n",
"$\\rho_1$ is the effective number density of the first scattering element,\n",
"$\\sigma_1$ is the total scattering cross section of the first scattering element,\n",
"$\\rho_2$ is the effective number density of the second scattering element,\n",
"$\\sigma_2$ is the total scattering cross section of the second scattering element,\n",
"$l_\\text{S1}^\\text{s}$ is the neutron traveling distance between source and the first scattering element within sample,\n",
"$l_\\text{12}^\\text{s}$ is the neutron traveling distance between the first and second scattering element within sample,\n",
"$l_\\text{2D}^\\text{s}$ is the neutron traveling distance between the second scattering element and detector within sample,\n",
"$l_\\text{S1}^\\text{c}$ is the neutron traveling distance between source and the first scattering element within container,\n",
"$l_\\text{12}^\\text{c}$ is the neutron traveling distance between the first and second scattering element within container,\n",
"$l_\\text{2D}^\\text{c}$ is the neutron traveling distance between the second scattering element and detector within container,\n",
"and\n",
"$l_\\text{12} = l_\\text{12}^\\text{s} + l_\\text{12}^\\text{c}$."
]
},
{
"cell_type": "markdown",
"id": "e53937f6-7ad2-4543-8810-b61f1c1dd320",
"metadata": {
"tags": []
},
"source": [
"### Practical Implementation\n",
"\n",
"The Eqn. (47) in Ref. by P. Peterson, et al. presented a clean and compact formulation for the overall scope of the total scattering data processing. With reference to that and ignoring all the apparatus relevant terms, the normalized (over total number of atoms in sample) sample differential cross section can be given as,\n",
"\n",
"$$\\begin{equation}\n",
" \\frac{d\\sigma^s}{d\\Omega} = \\frac{1}{A_{s,sc}N_s}\\big[\\frac{1}{\\Phi}(1 - \\Delta_{sc})(I_s^E - I_e^E) - \\frac{A_{c,sc}}{A_{c,c}}\\frac{1}{\\Phi}(1 - \\Delta_c)(I_c^E - I_e^E)\\big]\n",
"\\end{equation}\\tag{8}$$\n",
"\n",
"where the subtraction of multiple scattering contribution from the overall intensity for `sample+container` and `container only` is embedded in the coefficients $1 - \\Delta_{sc}$ and $1 - \\Delta_c$, respectively. Here, the formulation for both $\\Delta_{sc}$ and $\\Delta_c$ is presented above and in practice, they can be evaluated using the Mantid multiple scattering calculation algorithm, for `sample+container` and `container only`, respectively.\n",
"\n",
"To make it convenient in terms of implementation, one can rearrange Eqn. (8), to give,\n",
"\n",
"$$\\begin{align}\n",
" \\frac{d\\sigma^s}{d\\Omega} & = \\frac{1}{N_s\\Phi}\\Bigg[\\frac{1}{A_{s,sc}}(1 - \\Delta_{sc})I_s^E\\\\\n",
" & \\hspace{1.8cm} - \\frac{1}{A_{s,sc}}\\frac{A_{c,sc}}{A_{c,c}}(1 - \\Delta_{c})I_c^E\\\\\n",
" & \\hspace{1.8cm} - \\frac{1}{A_{s,sc}}\\bigg[(1 - \\Delta_{sc}) - \\frac{A_{c,sc}}{A_{c,c}}(1 - \\Delta_c)\\bigg]I_e^E\\Bigg]\\tag{9}\n",
"\\end{align}$$\n",
"\n",
"Notice that when the multiple scattering terms become zero, this becomes the [Paalman-Pings equation](https://docs.mantidproject.org/nightly/algorithms/ApplyPaalmanPingsCorrection-v1.html) with $K_C=1$\n",
"\n",
"$$\\begin{equation}\n",
"\\frac{d\\sigma^s}{d\\Omega} = \\frac{1}{A_{S,SC}N_S\\Phi} \\left[\n",
"\\left(I_S^E - I_e^E\\right) - \\frac{A_{C,SC}}{A_{C,C}} \\left( I_C^E - I_e^E\\right)\n",
"\\right]\n",
"\\end{equation}\\tag{10}$$\n",
"\n",
"Then, the three terms within square bracket in Eqn. (9) can be processed and applied when loading in the data in the data reduction workflow, by passing in the following parameters,\n",
"\n",
"$$\\begin{align}\n",
" & \\frac{1}{A_S^{eff}} = \\frac{1}{A_{s,sc}}(1 - \\Delta_{sc})\\\\\n",
" & \\frac{1}{A_C^{eff}} = \\frac{1}{A_{s,sc}}\\frac{A_{c,sc}}{A_{c,c}}(1 - \\Delta_{c})\\\\\n",
" & \\frac{1}{A_e^{eff}} = \\frac{1}{A_{s,sc}}\\bigg[(1 - \\Delta_{sc}) - \\frac{A_{c,sc}}{A_{c,c}}(1 - \\Delta_c)\\bigg]\\tag{11}\n",
"\\end{align}$$\n",
"\n",
"Then Eqn. (9) can be written as\n",
"\n",
"$$\\begin{equation}\n",
"\\frac{d\\sigma^s}{d\\Omega} = \\frac{1}{N_S \\Phi} \\left[\n",
"\\frac{I_S^E}{A_S^{eff}} - \\frac{I_C^E}{A_C^{eff}} - \\frac{I_e^E}{A_e^{eff}}\n",
"\\right]\n",
"\\end{equation}\\tag{12}$$\n",
"\n",
"If introducing some arbitrary scaling factor for either container or empty instrument, Eqn. (12) will turn into,\n",
"\n",
"$$\\begin{equation}\n",
"\\frac{d\\sigma^s}{d\\Omega} = \\frac{1}{N_S \\Phi} \\left[\n",
"\\frac{I_S^E}{A_S^{eff}} - \\frac{K_C I_C^E}{A_C^{eff}} - \\frac{K_e I_e^E}{A_e^{eff}}\n",
"\\right]\n",
"\\end{equation}\\tag{13}$$\n",
"\n",
"where $K_C$ and $K_e$ are the two arbitrary scale factors that we can introduce into the reduction workflow to account for any effects beyond current correction scenario.\n",
"\n",
"For sample only correction, those effective factors becomes,\n",
"\n",
"$$\\begin{align}\n",
" & \\frac{1}{A_S^{eff}} = \\frac{1}{A_{s,s}}(1 - \\Delta_{s})\\\\\n",
" & \\frac{1}{A_e^{eff}} = \\frac{1}{A_{s,s}}(1 - \\Delta_{s})\\tag{14}\n",
"\\end{align}$$\n",
"\n",
"Eqn. (13) then becomes,\n",
"\n",
"$$\\begin{equation}\n",
"\\frac{d\\sigma^s}{d\\Omega} = \\frac{1}{N_S \\Phi} \\left[\n",
"\\frac{I_S^E}{A_S^{eff}} - \\frac{K_e I_e^E}{A_e^{eff}}\n",
"\\right]\n",
"\\end{equation}\\tag{15}$$\n",
"\n",
"where, again, $K_e$ is an arbitrary factor that users can introduce to account for any effects beyond current correction scenario."
]
},
{
"cell_type": "markdown",
"id": "ee1636c9-e4e6-421b-b2e3-cf8ec16d4f21",
"metadata": {},
"source": [
"## Performance Boost\n",
"\n",
"Usually for total scattering data reduction, to bring the data onto an absolute scale could potentially need several cycles of reduction, trying, e.g., different packing fraction values (or equivalent tweaking factors). Suppose one is to change the packing fraction to tweak the high-$Q$ level of the normalized total scattering pattern ($S(Q)$, which is supposed to go to 1 as approaching high $Q$), the re-processing of the data is as simple as applying a scale factor. However, in the case of absorption and/or multiple scattering correction is necessary, changing the packing fraction is non-trivial since the path integration nature of the absorption coefficients as presented above would infer a $Q$-dependent variation of the absorption correction with the changing of the packing fraction. As such, one would have to re-calculate the absorption correction every time the packing fraction or any information about the sample is changed. Therefore, if staying with the pixel-by-pixel level of absorption calculation across the whole instrument, the large number of detectors (e.g., on NOMAD diffractometer at Spallation Neutron Source, SNS, there are ~100,000 detectors in total) would make the absorption calculation rather computationally heavy. This will make the cycling reduction to correct for the scale of the total scattering data unrealistic in practice.\n",
"\n",
"With this regard, we have developed a unsupervised machine learning based approach for grouping detectors according to the similarity in the calculated absorption spectra. After that, we can then stay with such a grouping manner and will only calculate the absorption spectra once for a certain group of detectors, which saves the computational time, significantly.\n",
"\n",
"![abs spectra grouping](../../imgs/abs_grouping.png)\n",
"\n",
"As shown in the graph above, using the KMEANS clustering algorithm, we successfully identified 1,000 groups for NOMAD detectors and two of them were picked up to demonstrate the idea. It can be clearly observed that in between different groups, the absorption spectra as the function of wavelength is distinctive, whereas for spectra within a certain group, the distinction in the absorption spectra can be ignored. This justifies our designed algorithm to only select one representative detector for the absorption calculation for each of the groups identified through the clustering algorithm. Through a test performed using a typical data set (in which ~50 Gb data is involved), with proper caching of the intermediately processed files, the overall reduction time could be reduced to ~2 minutes, in contrast to ~20 minutes with the old routine based on a pixel-by-pixel level of absorption calculation."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ffcd0b6d-625a-4d89-bec0-62ffa6686d5d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python (default)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.13"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}