I am trying to understand a derivation concerning the number of photons associated with an electromagnetic field which is irradiated on some probe. The point is to get a expression that connects the field amplitude of an laser field to the number of photons per frequency but some steps seem wrong to me. The derivation goes like this and follows closely the derivation given in the book Introduction to Quantum Mechanics A Time Dependent Perspective, Chapter 13.3.2:
The energy U of an electromagnetic E field in vacuum in cgs units is given by
$$
U = \frac{1}{8\pi}\int |\vec E(t)|^2 +|\vec B(t)|^2 dV = \frac{1}{4\pi}\int |\vec E|^2(t)dV
$$
assuming that the B-Field term contributes the same Energy as the E-field term.
The Volume element is now rewritten as $V=Acdt$ where $A$ is an area, $c$ is the speed of light in vacuum and $t$ is a time, assuming that the field is constant on the surface A(t). We obtain
$$
U = \frac{1}{4\pi}\int |\vec E(t)|^2 Acdt.
$$
Now we invoke Parsevals Theorem to obtain
$$
U = \frac{1}{4\pi}\int |\vec {\tilde{E}}(\omega)|^2 Acd\omega.
$$
where $\vec {\tilde{E}}(\omega)$ is the Fourier transform of $\vec E(t)$. Now we compare this with another expression for the energy, based on the knowledge that one photon at frequency $\omega$ holds the energy $\hbar \omega$.
We get
$$U = \int N(\omega)\hbar \omega d\omega $$
where $N(\omega)$ is the number of photons at a given frequency. Comparing both integrals over the frequency gives the identity
$$
N(\omega)\hbar \omega= \frac{1}{4\pi}|\vec {\tilde{E}}(\omega)|^2 Ac
$$
$$N(\omega) = \frac{1}{4\pi \hbar \omega}|\vec {\tilde{E}}(\omega)|^2 Ac$$
My problem is that the Volume integral change to a "time" integral is actually still an integral over the position, i.e. $z(t)=ct$. The volume element in cartesian coordinates is then $dxdydz\rightarrow dxdy \ cdt$. The electric field if written with with all coordinates should look like this $\vec E(x,y,z,t')\rightarrow \vec E(x,y,ct,t')$. The problem is now that the fouriert transform over $t$ is not the same as the fourier transform over $t'$. It holds only for a single plane wave of the type $\vec E(r,t)=E_0 \cos(\omega t - \vec k \cdot \vec r)$ in my opinion.
This is where i need help. Is the derivation valid for other electromagnetic fields or only for single frequency fields ?