Reconstruction of electron beam energy spectra for vacuum and gas diodes