That being said, if changing jobs is not an option in the near future, here are some tips:
1. Take pride in what you do. Try to write the most beautiful code. Learn new technologies. Make Easter eggs.
2. Remove friction and sources of frustration. For example if you write tests, you don't have that felling that you might have broken something after you made a change.
3. Communicate. Explain people how you fell. Probably, people don't realize they are disturbing your concentration. Maybe they can send an email or make an appointment.
4. Plan a vacation.
5. Accept things the way they are. If some days you are not as productive that's okay and ultimately not your fault.
6. See the positive.