Track and vertex fitting in an inhomogeneous magnetic field