The 4th Century monk Evagrius teaches that doing charity work can calm the mind and rid it of nightmares. Quoting Proverbs he writes:
“If you sit down, you will not be afraid; when you lie down, your sleep will be sweet. And you will not be afraid of alarm coming upon you, nor of approaching attacks of the ungodly (Proverbs 3:24-25):
By this we know that compassion dispels the terrifying visions that befall us at night.
everything that is able to pacify the aroused irascibility, have the same effect, since these visions of terror tend to arise from the provocation of irascibility. […]
[One of these fathers] delivered a certain brother from the disquieting specters by which he was visited in the night by ordering him to minister to the sick and to fast while he did it. When asked about his rationale from employing this procedure, he replied:
‘Such afflictions are extinguished by no other remedy so well as by mercy.’”
(Dragon’s Wine and Angel’s Bread by Gabriel Bunge, pp 91, 90)