The disturbing thoughts or images are called obsessions, and the rituals that are performed to try to prevent or get rid of them are called compulsions. There is no pleasure in carrying out the rituals you are drawn to, only temporary relief from the anxiety that grows when you don't perform them.