There's a pump-up answer something along the lines of Hashem put me in here because it'll help me grow the most, He still loves me, I'm still a tzadik, even though I have this one problem it doesn't negate everything else I do and my many positive qualities, this is a "normal" problem, etc. etc. (The highly recommended book,
The battle of the generation, is chock-full of helpful, cheerful, inspiring things like that.)
It's hard for me to give that pump-up answer because I don't really feel it. I also feel like I managed to screw myself up into someone pretty messed up. At low times I feel disgusted with myself.
What works for me is to not think about the past at all. However I got here, and however low "here" is, all I gotta do right now is pull myself out of the hole however I can. That's it.