Mathematical Foundations¶
EWALD is built around a small set of reciprocal-space conventions. This page collects the derivations used to interpret detector coordinates, ROI integrations, peak fits, structure candidates, film-optics inputs, and GIWAXS simulation outputs.
The equations below document the working model and notation. Exact numerical
results still depend on the calibration file, detector geometry, image
orientation, masks, and correction choices stored in the active .ewld
project.
Scattering Vector¶
For elastic X-ray scattering, the incident and exit wavevectors have the same magnitude:
where \(\lambda\) is the X-ray wavelength. The momentum transfer is
If \(2\theta\) is the angle between incident and scattered beams, the magnitude is
This is the source of the common conversion between scattering angle and reciprocal-space radius. EWALD displays reciprocal-space axes in \(\text{\AA}^{-1}\) when the calibration supplies length and wavelength metadata.
Detector Pixels To Reciprocal Space¶
A detector pixel is first converted into a ray direction in the laboratory frame. For an idealized flat detector with pixel coordinate \((u, v)\), beam center \((u_0, v_0)\), pixel sizes \(p_u, p_v\), and sample-detector distance \(D\), an unrotated detector ray can be written as
Detector tilts and pyFAI orientation metadata are applied as rotations to this vector. The normalized exit direction is
With the incident beam direction \(\hat{\mathbf{s}}\_i\),
EWALD keeps image rotation and mirror settings separate from detector geometry so users can correct storage/display orientation before accepting the calibrated mapping.
GIWAXS Axes¶
In grazing-incidence workflows, the laboratory axes are usually chosen so the sample surface defines the in-plane directions and the surface normal defines the out-of-plane direction. EWALD uses:
- \(q_z\): out-of-plane component along the sample normal.
- \(q\_{\parallel}\): in-plane magnitude,
For image display and left/right peak separation, EWALD often presents a signed in-plane coordinate \(q*{\mathrm{xy}}\). Conceptually this is an in-plane projection that preserves detector-side sign while retaining the physical scale of \(q*{\parallel}\):
The exact sign convention is controlled by detector orientation, mirroring, and the selected pyFAI sample orientation. The important practical rule is that equal-magnitude peaks on opposite detector sides should appear at opposite signs of \(q\_{\mathrm{xy}}\) after orientation is correct.
Reciprocal Lattice¶
Let the direct lattice basis vectors be columns of
The physics reciprocal basis, including the \(2\pi\) factor, is
For Miller index vector \(\mathbf{h} = [h, k, l]^T\), the reciprocal-lattice vector is
The plane spacing follows from
Combining this with the scattering-vector magnitude gives Bragg's law:
Structure Analysis uses this relationship to compare fitted peak centers against candidate reciprocal-lattice vectors.
Crystal Orientation¶
Candidate structures are rotated into the sample/laboratory frame before comparison with observed peaks. If \(\mathbf{R}\) is the orientation matrix, then the predicted reciprocal vector is
The displayed coordinates are projected from \(\mathbf{q}_{pred}\) to \((q_{\mathrm{xy}}, q_z)\). A simple residual for one assigned peak is
Weighted candidate scores are variations on
where \(\mathbf{W}\_i\) can encode user tolerances, peak confidence, phase tags, or fit uncertainty.
ROI Integration¶
Rectangular ROIs integrate intensity over a bounded region in \((q\_{\mathrm{xy}}, q_z)\). For a horizontal lineout,
For a vertical lineout,
Arch ROIs use polar coordinates in the \(q\_{\mathrm{xy}}, q_z\) plane:
An azimuthal trace over an annulus is
The factor \(q_r\) is the polar-coordinate Jacobian. In discrete detector data, EWALD approximates these integrals by summing finite pixels that fall inside the ROI bounds after masking and correction.
Peak Fitting¶
For one-dimensional traces, a common local model is a Gaussian peak with a smooth baseline:
[ I(x) = A\exp\left[-\frac{(x - x_0)^2}{2\sigma^2}\right]
- b_0 + b_1x. ]
Here \(x_0\) is the fitted peak center and \(\sigma\) controls width. The full width at half maximum is
For two-dimensional peak fitting in reciprocal space, the separable Gaussian form is
[ I(q{\mathrm{xy}}, q_z) = A\exp\left[ -\frac{1}{2} \left( \frac{(q-\mu}{\mathrm{xy}})^2}{\sigma + \frac{(q_z-\mu_z)^2}{\sigma_z^2} \right) \right]}}^2
- B(q_{\mathrm{xy}}, q_z). ]
The fitted center \((\mu\_{\mathrm{xy}}, \mu_z)\) becomes the peak coordinate passed into Structure Analysis.
Film Optics¶
For X-rays in matter, the refractive index is commonly written as
For small \(\delta\), the critical angle for total external reflection is
The corresponding vertical momentum transfer is
EWALD stores stoichiometry, density, refractive-index delta, and critical angle in the correction state so those values can be reviewed alongside the reciprocal-space transform.
Structure Factors And Simulation¶
For a crystal structure with atoms at fractional positions \(\mathbf{r}\_j\), the structure factor for reflection \(hkl\) is
Reflection intensity is proportional to
with additional experimental weights from orientation spread, footprint, polarization, detector response, and masking. In simulation, a rotated reflection contributes near its predicted detector coordinate:
where \(K\_{\sigma}\) is a peak-shape kernel and \(W(\mathbf{R})\) represents the orientation distribution.
The Ewald-sphere condition can be written as
Equivalently, an excitation error can be defined by
Reflections with small \(|\epsilon\_{hkl}|\) are close to the Ewald sphere and are more likely to appear in the simulated image.
Difference Maps¶
EWALD simulation comparison uses normalized experimental and simulated images. A simple scale/offset fit is
The residual image is
The root-mean-square residual is
where \(\Omega\) is the valid, finite, unmasked comparison region. A lower RMSE means the simulated pattern explains more of the corrected experimental target after normalization.
Practical Reading Guide¶
- Use detector and correction settings to make \(q\_{\mathrm{xy}}\) symmetry and \(q_z\) placement physically plausible before fitting.
- Use ROIs to extract stable local traces rather than fitting broad image regions with mixed phases.
- Use hkl labels and phase tags to constrain Structure Analysis to peaks that should share one reciprocal lattice.
- Use simulation residuals as an image-level check after lattice-level candidate ranking.