  We study the potential of the kinematic SZ effect as a probe for cosmology,
focusing on the pairwise method. The main challenge is disentangling the
cosmologically interesting mean pairwise velocity from the cluster optical
depth and the associated uncertainties on the baryonic physics in clusters.
Furthermore, the pairwise kSZ signal might be affected by internal cluster
motions or correlations between velocity and optical depth. We investigate
these effects using the Magneticum cosmological hydrodynamical simulations, one
of the largest simulations of this kind performed to date. We produce tSZ and
kSZ maps with an area of $\simeq 1600~\mathrm{deg}^2$, and the corresponding
cluster catalogues with $M_{500c} \gtrsim 3 \times 10^{13}~h^{-1}M_\odot$ and
$z \lesssim 2$. From these data sets we calibrate a scaling relation between
the average Compton-$y$ parameter and optical depth. We show that this relation
can be used to recover an accurate estimate of the mean pairwise velocity from
the kSZ effect, and that this effect can be used as an important probe of
cosmology. We discuss the impact of theoretical and observational systematic
effects, and find that further work on feedback models is required to interpret
future high-precision measurements of the kSZ effect.
