A method includes directing an X-ray beam to be incident at a grazing angle on a location on a surface of the sample. An X-ray fluorescence excited at the location is measured. A reflection angle of the X-ray beam from the surface and a transmission angle of the X-ray beam are measured. An angle of incidence of the X-ray beam on the surface is evaluated using the measured reflection and transmission angles, and the measured X-ray fluorescence is analyzed using the evaluated angle of incidence.