Characterization of nonideal quantum non-demolition measurements