We consider light scattering from ultracold quantum gas in optical lattices into a cavity. The measurement of photons leaking out of the cavity enables a quantum nondemolition access to various atomic variables. The time resolved light detection projects the motional state to various atom-number squeezed and macroscopic superposition states that strongly depend on the geometry. Modifications of the atomic and light properties at a single quantum trajectory are demonstrated. The quantum structure of final states can be revealed by further observations of the same sample.