Theory of cavity ring-up spectroscopy