Ok, so I have a question about an example problem in my textbook (its long but not difficult to follow. My question is at the bottom after I outline the problem). Consider the situation below in frame $S$. A gamma ray encounters an electron, disappears and creates an electron-positron pair, then the two electrons and single positron move off together with speed $u = 0.8c$
From conservation of energy and momentum: $$E_i = E_{\gamma} + mc^2 = E_f$$
$$p_i = \frac{E_{\gamma}}{c} = p_f$$
Now consider a frame $S'$ that moves with speed $v = 0.8c$ so that the three particles after the pair creation are at rest. In this frame, we know that the invariant rest energy of the system equals the sum of the rest energies of the constituent particles since the particles are not moving relative to one another in $S'$. My book places a big emphasis on the fact that
$$(mc^2)^2 = E^2 - (pc)^2$$
the rest energy in the above formula is not the sum of the rest energies of the particles that form the system. Only when the particles are not moving relative to one another (as in $S'$), can you say that $mc^2$ is $\Sigma_i = m_ic^2$.
Anyways, so in $S'$ after the pair creation, $mc^2 = 3mc^2$ since electrons and positrons have the same mass. My book then goes on to write,
$$(3mc^2)^2 = E^2 - (pc)^2 \\ 9(mc^2)^2 = (E_{\gamma} + mc^2)^2 - (\frac{E_{\gamma}c}{c})^2$$
My Question: In the above formula, for $E$ we substituted $E_{\gamma} + mc^2$ from the conservation laws written earlier. However, this energy was determined in frame $S$. Why didn't my book use the transformation:
$$E' = \gamma(E - vp'_x)$$
Since we are in the $S'$ frame? I have the same question for momentum. Why didn't we use the Lorentz transformation for momentum?
By the way: This was a problem specifically looking at what the energy of the photon $E_{\gamma}$ has to be in order for this particular electron-positron pair to be created. However, my main problem is with the reference frames since summing the rest energies requires us to be in $S'$. Then, $E$ and $p$, in $(mc^2)^2 = E^2 - (pc)^2$ need to be the energy and momentum in $S'$ as well?