Pressure in Scott Dodelson's book Modern Cosmology I am completely at a loss in deriving the equation 2.62 given in Scott Dodelson's Modern Cosmology book. That is the following expression for the pressure of Fermi-Dirac and Bose-Einstein distributions,
$$P_i= g_i\int \frac{d^3p}{(2\pi)^3} f_i(\vec{x},\vec{p}) \frac{p^2}{3E(p)},$$
where
$$
f_i(\vec{x},\vec{p}) = \frac{1}{e^{(E-\mu)/T}\pm 1}.
$$
 I am rather weak in statistical physics and to derive this expression I don't even have clue for where to begin. So please answer on how to derive this. A full derivation may not be needed, hints on where to begin and what quantities to compute will also work. Or even a reference to books, papers are also welcome.
 A: Think of the energy density and the pressure as the diagonal elements of the stress-energy tensor of an isotropic gas, for an observer locally at rest. Each element $T^{\alpha\alpha}$ represents the flux of the $\alpha$-component of the energy-momentum vectors of all particles in the $\alpha$-direction (see also this question). In other words, we can write
$$
T^{\alpha\alpha}(\vec{x}) = \int v^\alpha p^\alpha\, n(\vec{x},\vec{p})\,\text{d}^3\vec{p},
$$
where $v^\alpha = (c,\vec{v})$ is the velocity vector, $p^\alpha = (E/c,\vec{p})$ is the energy-momentum vector, and
$$n(\vec{x},\vec{p}) = \frac{g}{(2\pi\hbar)^3}\frac{1}{e^{[E(p)-\mu]/kT}\pm 1} =
\frac{g}{(2\pi\hbar)^3}f(\vec{x},p)$$
is the phase-space number density. Therefore,
$$\begin{align}
T^{00} &= \rho c^2 = \frac{g}{(2\pi\hbar)^3}\int E(p)\, f(\vec{x},p)\,\text{d}^3\vec{p},\\
T^{11} &= \frac{g}{(2\pi\hbar)^3}\int v_xp_x\, f(\vec{x},p)\,\text{d}^3\vec{p},\\
T^{22} &= \frac{g}{(2\pi\hbar)^3}\int v_yp_y\, f(\vec{x},p)\,\text{d}^3\vec{p},\\
T^{33} &= \frac{g}{(2\pi\hbar)^3}\int v_zp_z\, f(\vec{x},p)\,\text{d}^3\vec{p}.
\end{align}$$
Since the distribution is isotropic in $p$, we have $T^{11} = T^{22} = T^{33} = P$, so that
$$
P = \frac{1}{3}\left(T^{11} + T^{22} + T^{33} \right) =
\frac{g}{(2\pi\hbar)^3}\int \frac{1}{3}\vec{v}\cdot\vec{p}\; f(\vec{x},p)\,\text{d}^3\vec{p}.
$$
Finally, from
$$
E = \frac{mc^2}{\sqrt{1-v^2/c^2}},\qquad \vec{p} = \frac{m\vec{v}}{\sqrt{1-v^2/c^2}},
$$
we find $\vec{v} = \vec{p}c^2/E$, and
$$
P = \frac{g}{(2\pi\hbar)^3}\int \frac{p^2c^2}{3E(p)}\, f(\vec{x},p)\,\text{d}^3\vec{p}.
$$
