Stochastic theory of emission and absorption of quanta