A covariance formula for topological events of smooth Gaussian fields