What is in your control is your response to the unexpected. Did you get lost on the trail?
Did the official do something weird or unfair? So what, what do you do now?
Prepare your brain for that. It happens.
The unexpected happens, almost every time.
Expect that at least 3-5 unexpected things are going to happen and move on quickly.
Let go and move on to the task at hand.
I am writing about sport psychology and encouraging you to generalize to other areas of your life, like relationships.
What is the task at hand?
Are you getting distracted by your minor emotions and taking your eyes off the prize?
Are you letting something small derail you? Are you letting your ego get upset by something that is not worth it? When you choose your battles, is this really a wise battle?
Your mental energy is best spent on the task at hand, not arguing with a ref or wishing life were different. Get back on task quickly. Practice that during practice. If there is an unplanned event, get back on track. How quickly can you get your head back in the game?