How to focus only on the problem at hand? I am a PhD student designing algorithms for mathematical problems. I have the very bad habit of loosing my track on research problems. Suppose I am working on problem X, then, in the next week, I will start looking at Y,Z and other problems. Due to this, I feel tired at the end of the day with very less productivity with respect to X. I have always fear in my mind of failing, and that's why I try to look at other problems simultaneously. I don't know if it is okay for a PhD student (after mid-stage) to do this kind of things.

Question: How to focus only on the problem at hand?
You are "guilty" of a particular type of procrastination (in turn a type of  avoidance behavior), in which you avoid working on your (self-assigned) task by working on some other task. Ergo, the usual strategies to counter procrastination apply. There are several examples on this site and elsewhere online; my preferred method is to combine the pomodoro technique with a progess tracker.


Pomodoro technique : Work on your task during limited and manageable time periods by setting a timer, e.g. 25 minutes, then force yourself to take a break of at least five minutes even if it completely disrupts your flow. This limits fear and thus avoidance, and it creates motivation to get back to work after the break. Don't allow yourself to work on your side-gigs until four (or so) pomodori are completed, but then go ahead and indulge.
Progess tracker: Use a 'done' list, an online habit tracker, a spreadsheet or whatever works to track each completed pomodoro. This creates motivation, by seeing your success, in particular if you accomplish not  to break a streak, and facilitates habituation.


If your problem to focus disappears, you may want to be more liberal with the breaks between pomodori, so they don't disturb your flow, use a single pomodoro just to get you started, or do away with them all together.

As a side remark, it's good to work on several projects, but you should prioritize and stick to priorities.