X-ray and gamma fluxes from the high intensity laser-plasma interaction are extremely short, well beyond temporal resolution of any detectors. If laser pulses come repetitively, the single photon counting technique allows to accumulate the photon spectra, however, its relation to the spectrum of the initial fast electron population in plasma is not straightforward. We present efficient and fast approach based on the Geant4 package that significantly reduces computer time needed to re-construct the high energy tail of electron spectrum from experimental data accounting for the pileup effect. Here, we first tabulate gamma spectrum from monoenergetic electron bunches of different energy for a given experimental setup, and then compose the simulated spectrum. To account for the pileups, we derive analytical formula to reverse the data. We also consider errors coming from the approximation of the initial electron spectrum by the sum of monoenergetic impacts, the finite range of the electron spectrum, etc. and give estimates on how to choose modelling parameters to minimize the approximation errors. Finally, we present an example of the experimental data treatment for the case of laser-solid interaction using 50 fs laser pulse with intensity above 1018 W/cm2.