  Off-resonant interaction of fluctuating photons in a resonator with a qubit
increases the qubit dephasing rate. We use this effect to measure a small
average number of intracavity photons that are coherently or thermally driven.
For spectral resolution, we do this by subjecting the qubit to a
Carr-Purcell-Meiboom-Gill (CPMG) sequence and record the qubit dephasing rate
for various periods between qubit $\pi$-pulses. The recorded data is then
analyzed with formulas for the photon-induced dephasing rate that we have
derived for the non-Gaussian noise regime with an arbitrary ratio
$2\chi/\kappa$, where $2\chi$ is the qubit frequency shift due to a single
photon and $\kappa$ is the resonator decay rate. We show that the presented
CPMG dephasing rate formulas agree well with experimental results and
demonstrate measurement of thermal and coherent photon populations at the level
of a few $10^{-4}$.
