The Magnus expansion for classical Hamiltonian systems