Automatic characterization of layers stacks from reflectivity measurements. Application to the study of the validity conditions of grazing X-rays reflectometry