1. A method for inspection of a sample, comprising: irradiating the sample with a beam of X-rays; measuring a distribution of the X-rays that are emitted from the sample responsively to the beam, thereby generating an X-ray spectrum; and applying a multi-step analysis to the spectrum so as to determine one or more physical properties of a simulated model of the sample, the analysis comprising: spectrally analyzing the spectrum so as to determine one or more characteristic frequencies; and fitting the simulated model to the spectrum by an iterative optimization process beginning from an initial condition determined by the one or more characteristic frequencies.