Longitudinal current profile reconstruction from a wakefield response in plasmas and structures