Semianalytic model of electron pulse propagation: Magnetic lenses and rf pulse compression cavities