Component Manual for the Xray-Tracing Package McXtrace, version 3.8.6

2.2  The x-ray weight

A totally realistic semi-classical simulation will require that each x-ray is at any time either present or lost. On many beamlines the sheer abundance of x-ray photons makes it impractical to trace each and every photon from the source. This is particularly the case at XFELs. Additionally, only a very small fraction of the initial x-rays will ever be detected, and simulations of this kind will therefore waste much time in dealing with x-rays that never hit the detector.

A way of dealing with these issues and speed up calculations is to introduce a x-ray ”weight factor” for each simulated ray and to adjust this weight according to the path of the ray. If e.g. the reflectivity of a certain optical component is 10%, and only reflected x-rays ray are considered later in the simulations, the x-ray weight will be multiplied by 0.10 when passing this component, but every x-ray is allowed to reflect in the component. In contrast, the totally realistic simulation of the component would require on average ten incoming x-rays for each reflected one.

Let the initial x-ray weight be \(p_0\) and let us denote the weight multiplication factor in the \(j\)’th component by \(\pi _j\). The resulting weight factor for the x-ray ray after passage of the whole beamline becomes the product of all contributions \begin {equation} \label {e:probprod} p = p_n = p_0 \prod _{j=1}^n \pi _j . \end {equation} Each adjustement factor should be \(0 < \pi _j < 1\), except in special circumstances, so that total flux can only decrease through the simulation. For convenience, the value of \(p\) is updated (within each component) during the simulation.

Simulation by weight adjustment is performed whenever possible. This includes

2.2.1  Statistical errors of non-integer counts

In a typical simulation, the result will consist of a count of x-ray histories (”rays”) with different weights. The sum of these weights is an estimate of the mean number of x-rays hitting the monitor (or detector) per second in a “real” experiment. One may write the counting result as \begin {equation} \label {psum} I = \sum _i p_i = N \overline {p} , \end {equation} where \(N\) is the number of rays hitting the detector and the horizontal bar denotes averaging. By performing the weight transformations, the (statistical) mean value of \(I\) is unchanged. However, \(N\) will in general be enhanced, and this will improve the accuracy of the simulation.

To give an estimate of the statistical error, we proceed as follows: Let us first for simplicity assume that all the counted x-ray weights are almost equal, \(p_i \approx \overline {p}\), and that we observe a large number of x-rays, \(N \geq 10\). Then \(N\) almost follows a normal distribution with the uncertainty \(\sigma (N) = \sqrt {N}\) 1. Hence, the statistical uncertainty of the observed intensity becomes \begin {equation} \label {e:sigI1} \sigma (I) = \sqrt {N} \overline {p} = I / \sqrt {N} , \end {equation} as is used in real x-ray experiments (where \(\overline {p} \equiv 1\)). For a better approximation we return to Eq. (2.3). Allowing variations in both \(N\) and \(\overline {p}\), we calculate the variance of the resulting intensity, assuming that the two variables are independent: \begin {equation} \sigma ^2(I) = \sigma ^2(N) \overline {p}^2 + N^2 \sigma ^2(\overline {p}) . \end {equation} Assuming as before that \(N\) follows a normal distribution, we reach \(\sigma ^2(N) \overline {p}^2 = N \overline {p}^2\). Further, assuming that the individual weights, \(p_i\), follow a Gaussian distribution (which in some cases is far from the truth) we have \(N^2 \sigma ^2(\overline {p}) = \sigma ^2(\sum _i p_i) = N \sigma ^2(p_i)\) and reach \begin {equation} \sigma ^2(I) = N \left ( \overline {p}^2 + \sigma ^2(p_i) \right ). \end {equation} The statistical variance of the \(p_i\)’s is estimated by \(\sigma ^2(p_i) \approx (\sum _i p_i^2 - N \overline {p}^2) / (N-1)\). The resulting variance then reads \begin {equation} \sigma ^2(I) = \frac {N}{N-1} \left ( \sum _i p_i^2 - \overline {p}^2 \right ) . \end {equation} For almost any positive value of \(N\), this is very well approximated by the simple expression \begin {equation} \sigma ^2(I) \approx \sum _i p_i^2 . \end {equation} As a consistency check, we note that for all \(p_i\) equal, this reduces to eq. (2.4)

In order to compute the intensities and uncertainties, the detector components in McXtrace will keep track of \(N=\sum _i p_i^0, I=\sum _i p_i^1\), and \(M_2 = \sum _i p_i^2\).