I have to evaluate the following integral for $a>0$:
$$\int_0^\infty \left( \frac{\sin az}{z^2+1}\right)^2 dz$$
I don't exactly know how to do this kind of integral. But I think I need to use the residue theorem. Maybe I could use the trick $\cos(2a) = 1 - \sin^2(a)$, but that makes the integral much more difficult I think.
Since$$\sin(az)=\frac{e^{iaz}-e^{-iaz}}{2i},$$and since you are integrating an even function, your integral is equal to\begin{multline}-\frac18\int_{-\infty}^\infty\frac{e^{2iaz}+e^{-2iaz}-2}{(z^2+1)^2}\,\mathrm dz=\\=-\frac18\left(\int_{-\infty}^\infty\frac{e^{2iaz}}{(z^2+1)^2}\,\mathrm dz+\int_{-\infty}^\infty\frac{e^{-2iaz}}{(z^2+1)^2}\,\mathrm dz-\int_{-\infty}^\infty\frac2{(z^2+1)^2}\,\mathrm dz\right).\end{multline}Now, let us see how to compute these integrals. First of all, since $a>0$,\begin{align}\int_{-\infty}^\infty\frac{e^{2iaz}}{(z^2+1)^2}\,\mathrm dz&=2\pi i\operatorname{res}\left(i,\frac{e^{2iaz}}{(z^2+1)^2}\right)\\&=2\pi i\left(-\frac14i(2a+1)e^{2a}\right)\\&=\frac12\pi(2a+1)e^{-2a}.\end{align}It is a real number. Since the second integral is the conjugate of the first one, it is equal to the same number. Finally\begin{align}\int_{-\infty}^\infty\frac2{(z^2+1)^2}\,\mathrm dz&=2\pi i\operatorname{res}\left(i,\frac2{(x^2+1)^2}\right)\\&=2\pi i\left(-\frac i2\right)\\&=\pi.\end{align}And so\begin{align}\int_0^\infty\frac{\sin^2(ax)}{(x^2+1)^2}\,\mathrm dx&=-\frac18\left(2\times\frac12\pi(2a+1)e^{-2a}-\pi\right)\\&=\frac18\pi\left(1-(2a+1)e^{-2a}\right).\end{align}