A method for inspection of a sample includes irradiating the sample with a
beam of X-rays and measuring a distribution of the X-rays that are
emitted from the sample responsively to the beam, thereby generating an
X-ray spectrum. An assessment is made of an effect on the spectrum of a
non-uniformity of the beam, and the spectrum is corrected responsively to
the effect.