We consider a nonlinear inversion problem occurring in gamma spectrometry. In that framework, photon energies are converted to electrical pulses which are susceptible to overlap, creating clusters of pulses, referred to as pileup. This phenomenon introduces a distortion that can be a nuisance for the correct identification of the radionuclides. In that application we are interested in the distribution of the individual photon energies, hence, it is necessary to estimate this distribution using the indirect observations of the piled-up electrical pulses. In this paper, we present a new method to correct the pileup phenomenon, based on a nonlinear formula, which is inverted to give a nonparametric estimator of the individual energy distribution. Since the proposed estimator depends on parameters to be chosen carefully by the user, we also detail data-driven selection methods for the associated algorithm. Applications on simulations and real datasets are presented, which shows the efficiency of the proposed method.