When u are on the drug, it keeps you in euphoria that is to say feeling good. So you dont have the headache, when you stop the drug, then the effect goes and you feel headache. Get yourself investigated, go for counselling, practice relaxation techniques (other than drugs) and you should be fine.