  Future data from galaxy redshift surveys, combined with high-resolutions maps
of the cosmic microwave background, will enable measurements of the pairwise
kinematic Sunyaev-Zel'dovich (kSZ) signal with unprecedented statistical
significance. This signal probes the matter-velocity correlation function,
scaled by the average optical depth ($\tau$) of the galaxy groups and clusters
in the sample, and is thus of fundamental importance for cosmology. However, in
order to translate pairwise kSZ measurements into cosmological constraints,
external constraints on $\tau$ are necessary. In this work, we present a new
model for the intra-cluster medium, which takes into account star-formation,
feedback, non-thermal pressure, and gas cooling. Our semi-analytic model is
computationally efficient and can reproduce results of recent hydrodynamical
simulations of galaxy cluster formation. By calibrating the model using recent
X-ray measurements of gas density profiles of clusters and $M_{\mathrm{gas}}-M$
relations of groups and clusters, we show that the integrated $\tau$ is
constrained to better than 6% (with a confidence level of 95%), which sets the
tightest constraints on the external prior on the optical depth of groups and
clusters reported in the literature to date. Our strong prior on $\tau$ should
significantly improve cosmological constraints derived from future pairwise kSZ
measurements and shed new insights into the nature of dark energy, modified
gravity, and neutrino mass.
