Counts for energy bins

hello everyone,
i want to get energy spectrum of gamma rays, the following code makes me to extract the energy of each particle.
my question is how to get number of counts for each energy bin.
if (volume != ScoringVolume ) return;
G4double Energy = step->GetPostStepPoint()->GetKineticEnergy();;
G4cout<<particleName<<" "<<Energy*1000<<G4endl;

Hi, I am interested to this topic, did you get a spectrum count/Energy for a gamma rays source? I would like to get the energy output spectrum for a gamma source Inside a spherical detector. Have you any simple example that worked for you?
Thanks in advance