Step method for counting incident particles on volume

Dear experts,

I’m writing a code that shall count the number of electrons and positrons hitting a CCD volume inside a geometry. The count shall NOT consider any secondaries that might be produced in the volume, but only the ones that reach it. For that I’m using G4SteppingManager, and I’d appreciate any feedbacks on my approach if possible.

So, for G4SteppingManager I take the volumes at the PreStepPoint and PostStepPoint and check if the step “enters” the volume. There, I retrieve the kinetic energy of the particle and store it in a ROOT ntuple, so later I can apply any energy filters that I like.

What I’m not entirely sure is if my conditionals are correct:

    auto volPreStep = step->GetPreStepPoint()->GetTouchableHandle()->GetVolume();
    auto volPostStep = step->GetPostStepPoint()->GetTouchableHandle()->GetVolume();

    G4double electronEkinetic = 0;
    G4double positronEkinetic = 0;

    if(step->GetTrack()->GetDefinition()->GetParticleName() == "e-"){
        electronEkinetic = step->GetTrack()->GetKineticEnergy();
    else if(step->GetTrack()->GetDefinition()->GetParticleName() == "e+"){
        positronEkinetic = step->GetTrack()->GetKineticEnergy();
    if(volPreStep != fGeometry->GetCCD() && volPostStep == fGeometry->GetCCD()){
        fEventAction->AddCCD(electronEkinetic, positronEkinetic);

The methods GetCCD() and AddCCD() are similar to the ones from example B4a.

I could’ve used the multifunctional detector with primitive scorers, but my fear is that those might count the secondaries as well.

Any feedback on my conditionals to get only the incident electrons and positrons would be much appreciated :slight_smile: And thanks in advance.

_Geant4 Version:_10.7.3
_Operating System:_GNU_Linux Debian 12
_Compiler/Version:_GCC 10.4
_CMake Version:_3.25.1

There are two things to consider here…

The first is what do you want to do with the particles after you count them and second is the efficiency of your code.

So let’s start with the particles after they have been counted.

  • You may kill them (and their secondaries)
  • You may continue propagating them into other volumes

In general only counting the energies of e+ and the e- at a boundary crossing may introduce artifacts in your analysis as they may have entered “briefly” via a corner and maybe they would not deposited their full energy into your volume.

Now into the efficiency of your code:

  • Maybe you want to check for GetPDGEncoding() which is an int instead of a string for faster comparisons
  • Also maybe you want to check whether any of the particles is crossing into your volume before doing other operations… this one is less important though.

My two cents,


1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.