Résumé : Context. Cool giant and supergiant star atmospheres are characterized by complex velocity fields originating from convection and pulsation processes which are not fully understood yet. The velocity fields impact the formation of spectral lines, which thus contain information on the dynamics of stellar atmospheres. Aims. The tomographic method allows to recover the distribution of the component of the velocity field projected on the line of sight at different optical depths in the stellar atmosphere. The computation of the contribution function to the line depression aims at correctly identifying the depth of formation of spectral lines in order to construct numerical masks probing spectral lines forming at different optical depths. Methods. The tomographic method is applied to one-dimensional (1D) model atmospheres and to a realistic three-dimensional (3D) radiative hydrodynamics simulation performed with CO5BOLD in order to compare their spectral line formation depths and velocity fields. Results. In 1D model atmospheres, each spectral line forms in a restricted range of optical depths. On the other hand, in 3D simulations, the line formation depths are spread in the atmosphere mainly because of temperature and density inhomogeneities. Comparison of cross-correlation function profiles obtained from 3D synthetic spectra with velocities from the 3D simulation shows that the tomographic method correctly recovers the distribution of the velocity component projected on the line of sight in the atmosphere.