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;