How to stop a neutron with a specific energy to enter to a volume?

Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!

_Geant4 Version:_Geant4v11.2.0
_Operating System:_Windows 11
_Compiler/Version:_VS 2019
_CMake Version:_CMake 3.28

Hello all,
My work consists of calculating the absorbded dose within a 10 mm3 voxel, which is located within a 30x30x15cm3 phantom of water.
Now, I want to limit the neutron that enter the voxel by its energy, i.e. stop all neutrons with energy >=0.5eV in the front of the voxel, for that I’m using the following condition in the SteppingAction:

G4String preVname = step->GetPreStepPoint()->GetPhysicalVolume()->GetName();
G4StepPoint* postStepPoint = step->GetPostStepPoint();
 if (preVname == "Phantom" && postStepPoint->GetStepStatus() == fGeomBoundary)
  {
      if (particleType == G4Neutron::NeutronDefinition() && step->GetTrack()->GetKineticEnergy() >= 0.5*eV)
      {
          step->GetTrack()->SetTrackStatus(fStopAndKill);     
      }
      //else
      //  {
      //    //G4cout << "The neutron energy of ID : " << eventID << " is: " << En << G4endl;
      //    Count++;
      //  }
  }
  // collect energy deposited in this step
  G4double edepStep = step->GetTotalEnergyDeposit();

  if (volume == fScoringVolume)
      fEventAction->AddEdep(edepStep);

Is it correct this condition?
N.B. The simulation become more slow after adding this condition, however a part of neutrons are killed.
Thanks in advance.

Something like this should work. How are you generating your neutrons?

To generate neutrons, I used a source of type plane with the same dimension of the phantom, which emits monoenergetic neutrons randomly, it was positioned in front of the phantom at 2.5m.
Is there another way to limit neutrons by energy?

So you are generating neutrons of one energy, and stopping all neutrons above a different energy? Is your generated energy > 0.5eV? You can kill every neutron with an energy >0.5eV, or just not produce any neutrons above that energy. But if you are looking at a dose from lower energy neutrons produced by higher energy neutrons, then it will stop the higher energy neutrons before they become lower energy neutrons. Why are you trying to limit the energy of neutrons measured in your voxel? One thing you could do is record the energy deposition separately depending on the energy of depositing neutron