Which solution shauld i use of ion definition?

I want to record ion kinetic energy, so first i need to query the particle is ion,
the code like this:

how to write ion definition?

Do you care which ion it is? If not, then you can test

if (step->GetTrack()->GetDefinition()->IsGeneralIon()) { ... }

(see G4ParticleDefinition.hh). If you are looking for a specific nucleus, then you should put step->GetTrack()->GetDefinition() into a local G4ParticleDefintion* variable, and fetch atomic number and atomic mass.

@ mkelsey,thanks!

Should it work the same as (step->GetTrack()->GetParticleDefinition() == G4Ions::IonsDefinition())?