Quantum thermodynamics in Cavity QED