When headaches strike, many people reach for a painkiller. Probing the reasons behind the pain is often a better idea