The computer-implemented method for inspection of a sample includes
defining a plurality of locations on a surface of the sample, irradiating
the surface at each of the locations with a beam of X-rays, and measuring
an angular distribution of the X-rays that are emitted from the surface
responsively to the beam, so as to produce a respective plurality of
X-ray spectra. The X-ray spectra are analyzed to produce respective
figures-of-merit indicative of a measurement quality of the X-ray spectra
at the respective location. One or more locations are selected out of the
plurality of locations responsively to the figures-of-merit, and a
property of the sample is estimated using the X-ray spectra measured at
the selected location.