Get and save neutron energy from track

Hi,everyone!
I’m trying to modify B4c example for my simulation about neutron moderation. If I write code as

G4String particleName = neutron

if ( step → GetTrack() → GetDynamicParticle()
→ GetDefinition → GetParticleName() == particleName)

{
auto en = step->GetTotalEnergy();
}
// This is a part of my
// B4cDetectorSD::ProcessHits(G4Step* step, G4TouchableHistory*) {…}

Can I get neutron energy and save it in en as I expected?
I also want to save the neutron energy in a matrix, can I use matrix in Geant4?

I appreciate for any advice, thanks in advance!