Step action tends to happen at certain point

I am new to Geant4, trying to write a small program to simulate protons in liquid argon. And I am trying to plot a dedx plot and other properties, code is available here if you like to have a look at.

I’d expect a smooth curve with one peak at end(Bragg Peak), while I got:

There is a strange peak at near z=5 position, when investing this strange peak, I found my program seem to be more likely to record events at z=5.

I changed my code to store where the step occurs at UserSteppingAction() and draw a histogram for all stored step->GetPostStepPoint()->GetPosition().z() value.

I get (that is a histogram for z coordinate on each step)
(sorry that I can only put ONE image in a post, this is a link to the histogram)

You can see a peak at near z=5.(and smaller one at z=10)

I don’t expect anything special for that position, but why there is a peak indicating that it is more likely to record events at certain position.

Could anyone help me to figure out my problem, is this from my misunderstanding of Geant4 or that is the mechanism?

PLUS: physics list is QBBC

I cannot reproduce your problem with example TestEm11, even by relaxing various constraints on the step size. I joint macro and plot. I played with AutomaticStepSize, setCut, physicsList.
Have you something special at z=5 cm ? a volume boundary ?
karuboniru.mac.txt (627 Bytes)

1 Like

So, there must be something to do with my code, I am going to check TestEm11 to see the difference, Thanks!

I found the trick:

in TestEm11:

 G4StepPoint* prePoint  = step->GetPreStepPoint();
 G4StepPoint* postPoint = step->GetPostStepPoint(); 
 G4ThreeVector P1 = prePoint ->GetPosition();
 G4ThreeVector P2 = postPoint->GetPosition();
 G4ThreeVector point = P1 + G4UniformRand()*(P2 - P1);

this is equal to averaging energy loss to a range of a step, starting point to stopping point. my problem comes from extremely long step being cut, and this way just avoid the problem to be hurtful.

After doing the same thing in my code:

The peak at beginning is from nuclear reaction, after removing nuclear reaction:
One pic limit again!