Cavity-aided nondemolition measurements for atom counting and spin squeezing | Synapse