Evaluating $\int_0^{\pi/2} \frac{a}{a^2+\cos^2 \theta} \, d\theta$ I want to evaluate 
$$
\int_0^{\pi/2} \frac{a}{a^2+\cos^2 \theta} \, d\theta
$$
and here is what Wolfram alpha gave me:
$$
\int_0^{\pi/2} \frac{a}{a^2+\cos^2 \theta} \, d\theta=\frac{\tan^{-1} \left(\frac{a \tan x}{\sqrt{a^2+1}}\right)}{\sqrt{1+a^2}}
$$
Seeing the answer, I substituted $\cos \theta = \tan x$ hoping something good would happen, but in the end it didn't lead anywhere, assuming I didn't make any mistake. But after that I'm knid of hopelessly lost.
What's the magic trick here?

$$\int_0^{\pi/2} \frac{a}{a^2+\cos^2 \theta} d\theta=\int_0^{\pi/2} \frac{a\sec^2 \theta}{a^2\sec^2 \theta + 1} d\theta$$
$$=\int_0^{\pi/2} \frac{a\sec^2 \theta}{a^2(1 + \tan^2 \theta) + 1} d\theta=\int_0^{\pi/2} \frac{a\sec^2 \theta}{a^2 + 1 + a^2 \tan^2 \theta} d\theta$$
Put $a\tan \theta = x$, $ a \sec^2 \theta d\theta = dx$,
$$=\int_0^{\infty} \frac{1}{a^2 + 1 + x^2} dx =\frac{1}{\sqrt{a^2 + 1}}\arctan \frac{x}{\sqrt{a^2 + 1}} \biggl|_0^{\infty} =\frac{\pi}{2\sqrt{a^2 + 1}}$$
