Optical measurement of the longitudinal ion distribution of bunched ion beams in the ESR