I have this problem also and Pomodoro technique is a god send. 5 minutes in I am always ready to do something else but then refocus.
Productivity is how many pomodoros I have done on that task. Otherwise, I am just all over the place and nothing quite gets done.