Why is it that when one in considering contour integration of a real function, such as $$ \int_{-\infty}^{\infty} \frac{dx}{1+x^2}$$ the contour in the complex plane used is the following:
Furthermore, what are the general strategies for choosing a contour when integrating a real function using the method of residues? For example, what contour would be used for the function $$\int_{0}^{\infty} \frac{dx}{1+x^2}.$$ Or for the function $$\int_{0}^{\pi} \frac{d \theta}{(a+b \cos\theta)^2}.$$ (Notice how the limits of integration changed). I am also curious how the position of the residues in $\mathbb{C}$ affect a contour. My complex analysis book tends to pull a contour out of thin air with out any appeal to intuition. Any help would really be great! Thank you.