Recording particle energy/momenta at last step in the geometry boundary

Hi,

I am trying to calculate the energy/momentum distribution at the last step in the geometry boundary, just before particle exits the boundary.
I am using the following approach for that,
Firstly, I define a geometry in the Detector Construction, with a world volume and my detector geometry contained within (with Physical and Logical volume defined).
In the UserSteppingAction, I define the following, to get to the last step in volume.

const G4StepPoint* endPoint = step->GetPostStepPoint();
G4ParticleDefinition* prim_particle = fPrimary->GetParticleGun()->GetParticleDefinition();
G4bool condition = step->IsLastStepInVolume();

if ((prim_particle == G4MuonMinus::MuonMinus())  && condition == true)
        {
                G4cout << "Step is the last step in the volume" << G4endl;
                energy_mu =  endPoint->GetKineticEnergy(); 
                pX_mu = endPoint->GetMomentum().x();
                posX_mu = endPoint->GetPosition().x();
                .....
        }

The condition always comes out to be false (0 on printing it out), even though there are numerous primary particles being transported out of the volume. (I get the end of step energy and momentum values properly if I remove the condition).

Another approach I tried was using the ‘fGeomBoundary’ as follows:

G4StepPoint* boundarypoint = step->GetPostStepPoint();
G4TouchableHandle touch = boundarypoint->GetTouchableHandle();
  G4VPhysicalVolume* volume = touch->GetVolume();
  G4String name = volume->GetName();

(prints out the volume name just fine).

if ((prim_particle == G4MuonMinus::MuonMinus()) && (boundarypoint->GetStepStatus() == fGeomBoundary))
           {
              G4cout << "Step is the last step in the volume" << G4endl;
                    energy_mu =  boundaryPoint->GetKineticEnergy(); 
                    pX_mu = boundaryPoint->GetMomentum().x();
                    posX_mu = boundaryPoint->GetPosition().x();
                    .....
            }

Here again, I am not getting any values for energy/momenta of outgoing particles.

Thank you for anyone who can help.
Aditya

In the context of TestEm3, I have checked your two tests, whit a geantino.
I attach the macro (can be run in batch or interactively with visualisation), the 2 outputs and the code added in SteppingAction.
aditya.mac.txt (374 Bytes)
aditya.lastStep.txt (2.3 KB)
aditya.fGeomBoundary.txt (2.4 KB)
aditya.stepAction.txt (448 Bytes)

1 Like

Hi Michel,

Thank you so much for checking these.
I’ll have a look at my code again to see what I’m missing.

Aditya

Hi,

I am still unable to debug the issue. My geometry is a simple rock geometry with particles (muons) being propagated via General Particle Source (GPS).
After printing out the tracking information, I get the following for one of the events…

**********************************************************    ***********************************************
    * G4Track Information:   Particle = mu-,   Track ID = 1,   Parent ID = 0
    *********************************************************************************************************

    Step#    X(mm)    Y(mm)    Z(mm) KinE(MeV)  dE(MeV) StepLeng TrackLeng  NextVolume ProcName
        0        0        0        0  1.19e+04        0        0         0  RockBurden initStep
        1     1.47    0.754    -4.92  1.19e+04     2.53     5.19      5.19  RockBurden muIoni
        2     32.8     16.8     -110  1.19e+04     46.3      111       116  RockBurden muIoni
        3     37.8     19.4     -127  1.19e+04     7.34     17.8       134  RockBurden muIoni
.....

260     -280 -2.86e+03 -4.97e+03  2.05e+04      8.8       19  5.74e+03  RockBurden muIoni
  261     -280 -2.86e+03 -4.97e+03  2.05e+04    0.141    0.386  5.74e+03  RockBurden muIoni
  262     -282 -2.88e+03   -5e+03  2.05e+04     13.6     32.6  5.78e+03       World Transportation
  263 -5.69e+04 -5.77e+05   -1e+06  2.05e+04 4.27e-20 1.15e+06  1.16e+06  OutOfWorld Transportation

In the stepping action, I use the command the same way as yours.

if (step->IsLastStepInVolume()) {
	G4cout << "Step is the last step in the volume " << volume->GetName()<< "\n" <<  G4endl;
	energy_mu =  endPoint->GetKineticEnergy();
	G4cout << "Muon energy on exit " << energy_mu << G4endl;
}

I try to get the output to the function call for IsLastStepInVolume, but it always comes out to be ‘0’

G4bool condition = step->IsLastStepInVolume();
G4cout << "condition is " << condition << G4endl;

Similarily, fGeomBoundary doesn’t seem to work either. Maybe I’m missing something, I can’t quite figure out.
The particles are clearly transporting out of the volume as in the attached document. I don’t quite understand what I’m missing.

Thanks again for the help.

Aditya.

g4_0000.pdf (1.7 MB)

1- Did you try with a geantino ?
2- Are you sure that the volumes do not overlap ?
ps. May I suggest you to try to implement the SteppingVerbose of TestEm examples (but it will not solve the problem !).

Hi Michel,

Yes, I did try with a geantino, it passes straight through the geometry without taking any steps in it.

*********************************************************************************************************
* G4Track Information:   Particle = geantino,   Track ID = 1,   Parent ID = 0
*********************************************************************************************************

Step#    X(mm)    Y(mm)    Z(mm) KinE(MeV)  dE(MeV) StepLeng TrackLeng  NextVolume ProcName
    0 -1.7e+05 -7.3e+04    5e+04   6.8e+03        0        0         0  RockBurden initStep
    1 -1.59e+05 9.34e+03   -5e+04   6.8e+03        0  1.3e+05   1.3e+05       World Transportation
    2 -5.32e+04 7.92e+05   -1e+06   6.8e+03        0 1.24e+06  1.37e+06  OutOfWorld Transportation
Rotated and Translated position (-44228.88199316448,-29116.20538633069,50000)
Final User Defined momentum vector (0,0,-1)

I am using the checkOverlaps boolean in the PVplacement which is fine.

Checking overlaps for volume RockBurden (G4Box) ... OK! 
Checking overlaps for volume Scorer (G4Box) ... OK! 

I did implement SteppingVerbose to see if it gives any further clues.
Do you think I could use this,

fUserDefinedLimit // Step defined by the user Step limit in the logical volume,
…to set a limit on the step coordinate, which when it reaches would give the energy/momenta at that step point?

Many thanks,
Aditya

It seems that even geantino do not see IsLastStepInVolume() test.
If it not too complicated, could you post your SteppingAction class ?

Also, for readability of SteppingVerbose, try to shoot the particle along a given axis.

Michel,

I have attached my SteppingAction file.
Yes, none of the particles see the IsLastStepInVolume() condition, although without it, I can save the energy/momentum values to the Ntuple, but for all steps.

Also, for my purpose, I’m using General Particle Source (GPS) using position, energy and angular distribution to shoot particles through the geometry. Should that make any difference? (I’ll also attach the GPS macro)

Thanks a lot!

AdityaSteppingAction.cc (8.0 KB) GPSmacro.txt (48.2 KB)

The step->IsLastStepInVolume() should be equivalent to testing for

step->GetPostStepPoint()->GetStepStatus() == fGeomBoundary ||
step->GetPostStepPoint()->GetStepStatus() == fWorldBoundary

The former is more compact, and doesn’t require accessing the step point.

1 Like

In your SteppingAction, I see : if (nbsec == 0) return;
where nbsec is the number of secondaries in current step.

1 Like

Hi Michel,

That was it. I don’t know how I forgot to comment that earlier. Thank you so much for your time and effort.

Best Regards
Aditya

Hi, bro

How could you get the inform of G4Track like belong?

Does it in the basic example?

**********************************************************    ***********************************************
    * G4Track Information:   Particle = mu-,   Track ID = 1,   Parent ID = 0
    *********************************************************************************************************

    Step#    X(mm)    Y(mm)    Z(mm) KinE(MeV)  dE(MeV) StepLeng TrackLeng  NextVolume ProcName
        0        0        0        0  1.19e+04        0        0         0  RockBurden initStep
        1     1.47    0.754    -4.92  1.19e+04     2.53     5.19      5.19  RockBurden muIoni
        2     32.8     16.8     -110  1.19e+04     46.3      111       116  RockBurden muIoni
        3     37.8     19.4     -127  1.19e+04     7.34     17.8       134  RockBurden muIoni

OK , I see, it is use /tracking/verbose 1