Gain in quantum cascade lasers and superlattices: A quantum transport theory