What is the correct choice of the contour in the case of undamped forced harmonic oscillator? I am interested in finding the Green's function (GF) for the undamped forced harmonic oscillator equation: $$\Big(\frac{d^2}{dx^2}+\omega_0^2\Big)x(t)=f(t).$$ In order to find the GF, start by define it: $$\Big(\frac{d^2}{dx^2}+\omega_0^2\Big)G(t-t')=\delta(t-t').$$ First denoted $\tau\equiv t-t'$ and consider the Fourier transform $$G(\tau)=\frac{1}{\sqrt{2\pi}}\int\limits_{-\infty}^{+\infty}\tilde{G}(\omega)e^{i\omega \tau}d\omega,~ \delta(\tau)=\frac{1}{2\pi}\int\limits_{-\infty}^{+\infty}e^{i\omega\tau}d\omega$$ which redialy gives $$\tilde{G}(\omega)=\frac{\sqrt{2\pi}}{\omega^2-\omega_0^2}\Rightarrow G(\tau)=\int\limits_{-\infty}^{\infty}\frac{e^{i\omega\tau}}{(\omega+\omega_0)(\omega-\omega_0)}d\omega$$ i.e., the integral has simple poles at $\omega=\pm\omega_0$
For $\tau>0$, there are three ways in which a closed semicircular contour can be chosen to enclose the poles.
$1.$ Both the poles $-\omega_0$ and $+\omega_0$ can be included in the contour, by choosing two small semicircular indentations in the lower half-plane around $-\omega_0$ and $+\omega_0$. In this case, the result is $G(\tau)=\frac{1}{\omega_0}\sin(\omega_0\tau)$.
$2.$ Both the poles $-\omega_0$ and $+\omega_0$ can be excluded from the contour, by choosing two small semicircular indentations in the upper half-plane around $-\omega_0$ and $+\omega_0$. In this case, the result is $G(\tau)=0$.
$3.$ The pole $-\omega_0$ is included from the contour while $+\omega_0$ is excluded. In this case, the result is $G(\tau)=\frac{i\pi}{\omega_0}e^{-i\omega_0\tau}$.
$4.$ The pole $+\omega_0$ is included from the contour while $-\omega_0$ is excluded. In this case, the result is $G(\tau)=\frac{i\pi}{\omega_0}e^{+i\omega_0\tau}$.

*

*Which one is the correct choice of contour to find $G(\tau)$ and why?

 A: The issue is that you assume that the small semicircular integral is $0$. If you integrate over an arc segment with radius $r$ and angle $\alpha$ around a simple pole $z_0$, $$\lim_{r\to 0}\int_{C(r,\alpha)}f(z) dz=\alpha i \mathrm{Res}(f,z_0)$$
See for example this answer.
Then if you go around the pole on a semicircle counterclockwise your integral is $\pi i \mathrm{Res}(f,z_0)$, and if you go clockwise is $-\pi i \mathrm{Res}(f,z_0)$. So it does not matter which trajectory you choose, as long you do it correctly.
EDIT
Since there was a question in the comment, I've decided to add a few explanations to this answer. For simplicity of notation, we want to integrate $f(x)$ from $-\infty$ to $\infty$, with two simple poles at $\pm\omega_0$. So we create a contour in the complex plane, made up on a large semicircle $\Gamma$, with radius $R\to\infty$, where we know that the integral of $f(z)$ vanishes. Then on the real line we avoid the poles by making small semicircles, of radius $\epsilon\to 0$ around $\pm\omega_0$. We call these $\gamma_{+,-}^{u,d}$. The $+$ or $-$ sign identify the pole, and $u$ means we avid the pole going above the line, $d$ we go below.
$$\lim_{R\to\infty, \epsilon\to 0}\left(\int_{-R}^{-\omega_0-\epsilon}f(x)dx+\int_{-\omega_0+\epsilon}^{\omega_0-\epsilon}f(x)dx+\int_{\omega_0+\epsilon}^Rf(x)dx\\+\int_\Gamma f(z)dz+\int_{\gamma_+^{u,d}} f(z)dz+\int_{\gamma_-^{u,d}} f(z)dz\right)=2\pi i\sum_{z_i}\mathrm{Res}(f,z_i)$$
Here you have the choice of how you avoid the poles (up or down), but that will change the sum on the right. The first three integrals converge to $\int_{-\infty}^\infty f(x)dx$, the fourth is zero. So
$$\int_{-\infty}^\infty f(x)dx=2\pi i\sum_{z_i}\mathrm{Res}(f,z_i)-\int_{\gamma_+^{u,d}} f(z)dz-\int_{\gamma_-^{u,d}} f(z)dz$$
If you make point $\omega_0$ to be inside the contour, you add it to the sum. But you need to subtract the integral over $\gamma_+^d$, which is $\pi i \mathrm{Res}(f,\omega_0)$. So the net contribution of that pole is $\pi i \mathrm{Res}(f,\omega_0)$. If you avoid the pole going on the upward trajectory, you will not add it to the sum, but the integral on $\gamma_+^d$ is $-\pi i \mathrm{Res}(f,\omega_0)$, so the net contribution is once again $\pi i \mathrm{Res}(f,\omega_0)$. You can do the same for the $-\omega_0$ pole. So in this case
$$\int_{-\infty}^\infty f(x)dx=\pi i\left(\mathrm{Res}(f,-\omega_0)+\mathrm{Res}(f,\omega_0)\right)$$
This is independent of the choice of your contour.
