Quantum nondemolition measurements and state preparation in quantum gases by light detection.