There is spinomesencephalic tract that is used to modulate pain(endorphins) when you hit your finger with a hammer and then put your finger in your mouth or otherwise shake it to reduce pain. Same reason behind dental pain and hitting your head against the wall trying to subdue the dental pain. analogue of spinomesenphalic would be one of those trigeminal nuclei that i forgot its name.