Beam tracing for migration and inversion