Since neither your body nor your psyche is a machine, you don't.
However, what you might know is when you start to feel like being yourself again, confident and optimistic. I doubt that your wife would get extremely upset in case your penis fell short of doing a proper pull-up, would she? From what I've heard, relationships in that particular time require some extra attentiveness and affection. It's not all about intercourse. Show her some appreciation, something that makes her feel good about herself (and your little one, of course). In the bedroom, you'll surely find some ways to restore some sexual activity. Focus on your goals - that is, being a father and all. Don't think of your days as trying not to masturbate but as making an attempt to free yourself from generally unhealthy behavior.
Hope that's not all bogus...all the best!