Thanks for query,
Excess is always poison.
Sex is in our mind.
you should divert your mind from sex.
Just busy with other activity.stop watching porn films will reduce your masturbation
Your headache after ejeculation has no relation with masturbation.
You should consult your doctor for it.He will rule out other possibility like migrain eye problem hypertension
etc & advise you accordingly.