On the Trajectory Tracking Control of Hamiltonian Systems