  (abridged) The observed properties of supermassive black holes suggest a
fundamental link between their assembly and the formation of their host
spheroids. We model the growth and activity of black holes in galaxies using
LambdaCDM cosmological hydrodynamic simulations by following the evolution of
the baryonic mass component in galaxy potential wells. We find that the
observed steep relation between black hole mass and spheroid velocity
dispersion, M_BH propto \sigma^4, is reproduced if the gas mass in bulges is
linearly proportional to the black hole mass. In this model, black hole growth
saturates because of the competition with star-formation and feedback, both of
which determine the gas fraction available for accretion. Unless other
processes also operate, we predict that the M_BH-sigma$ relation is not set in
primordial structures but is fully established at low redshifts, $z \approxlt
2$, and is shallower at earlier times. We find that that central black hole
masses are related to their dark matter halos simply via M_BH ~ M_DM^4/3. We
assume that galaxies undergo a quasar phase with a typical lifetime, t_Q ~
2\times 10^7 yr and show that star-formation regulated depletion of gas in
spheroids can explain the decrease of the quasar population at redshift z<3 in
the optical blue band. However, with the simplest assumption of a redshift
independent quasar lifetime, the model overpredicts optical quasar numbers at
high redshifts although it yields the observed evolution of number density of
X-ray quasars over the redshift range 1 < z< 6. Finally, we find that the
majority of black hole mass is assembled in galaxies by z ~ 3 and that the
black hole accretion rate density peaks in rough correspondence to the star
formation rate density at z ~ 4-5.
