Decreasing the Zeeman shift uncertainty by real-time magnetic field compensation