How does GetPosition() command works?

Hello,
I’m new in GEANT4 and interested in neutron shielding simulation. I wanted to score neutron flux at other side of shielding material on Hadr07 example. What i did was creating shielding material and placed neutron source outside of the material. (Fig1) Shielding material has thickness of 20 cm (placed at (0,0,0)). Primary generator placed at (-30cm,0,0).
By changing code on TrackingAction into below command
G4double x = track->GetStep()->GetPostStepPoint()->GetPosition().x()/cm;
if (x < 10
cm ) return;
I thought i can obtain neutron energy spectrum on other side of shielding material. In Fig1 you can see that some neutrons are transmitted through shielding material but result says there’s no neutron counted on the other side of shielding material. Can anyone tell me how this command works?
When i change the range to (x< 0*cm) it gives acceptability result. (Fig2)

GetPosition() works exactly how you are using it. When you call GetPosition().x() it returns a G4double of your x position. It sounds like you are having errors in your recording logic

Do you want to get neutrons that get through your shielding or ones that don’t?

Your source is at -30 cm, and your shielding is at 0 cm (with edges at -10, and 10 cm).

When you return at x < 10, you are stopping before any neutrons hit your shielding.

Are you doing something if you don’t return? How are you recording neutron energy

Hi,
I want to get neutrons that get through my shielding. The reason that return at x<10 is to count neutrons right after get through my shielding. Because shielding edge is at 10cm. Unfortunately, no neutron recorded when condition is x<10 return;

Sure, so your function returns when x < 10, i.e. when a particle reaches your shielding. But what function? What do you expect to happen when you return your function? Stop tracking? If you stop tracking when the particle hit your shielding then you won’t have any particles hitting your shielding. We need more information on what you are doing with the tracking information.

Thanks for replying,
All i need is the neutron energy spectrum on the other side of shielding. Returns to the function when x<10 means stop tracking when position x<10cm (edge of the shielding). I’m not really sure about that :slight_smile:
Hadr06 code was originally like this:
// keep only emerging particles
G4StepStatus status = track->GetStep()->GetPostStepPoint()->GetStepStatus();
if (status != fWorldBoundary) return;
It gives me all neutrons get through my shielding (I need neutrons that get through only one side) and i changed the code.
Since I am not an expert at GEANT4, I’m attaching TrackingAction.cc

TrackingAction.cc (4.9 KB)

I see what you are attempting to do and I don’t see any logical error. You say that when you set it to x < 0 * cm it works. I would suggest having the code output the x value in PostUserTrackingAction and run a few particles and see if you get what you expect

G4cout << x << G4endl;

you should see something like
-30
-10
(something between -10,10) etc.

Its possible something with your units or geometry is defined wrong.

When I use this code on TrackingAction.cc
G4cout << “x is =” << x
<< G4endl;
Running process shows so many different x values. Do you know what is that mean?

Tracks don’t all stop in the same place every time.

Hi, thanks for replying,
Yeah, I understand that. For example, I shot with 10 neutrons and when I set x<10 there’s no neutron counted, But when I set x<0 there’s 3 neutrons counted. As u can see from picture there’s 3 “x” values are more than 10 cm.
I think x<10 would count that neutrons too.

When you say x < 10, you are looking at tracks that stop before hitting your shielding, which is very few. If you want neutrons that get through your shielding, then use x > 10, which is the position at which neutrons first get through your shielding.

I’m guessing you don’t have any tracks < 10 because your world geometry is not interacting with neutrons very much (if at all), which would make sense if it is a vacuum or G4Galactic

Does this position from GetPostion().x() give position with respect to the position of a particle gun or with respect to origin of worldvolume?

Respect to the world.

So particle gun x position is -30. Your detector starts at -10 and goes to 10. So an x position between -10 and 10 means the neutron is interacting with your shielding material.

What you need to do, if you want to record the spectrum of neutrons that make it past your shielding, is to have some logic like this:
if position > 10:
record neutron energy

DetectorConstruction.cc (28.2 KB)
I construct detector this was. In nutshell, there is a world volume, cylinder r= 6 m, h= 8 m. There is a LAr cylinder inside the world of radius 3.5 m. The space between is filled with water. I generate a neutron on the surface of LAr cylinder, radially outward direction. . When I store the position of capture it gives me between -40 to 40 cm. while I am expecting 400 cm at least if this is returning the position with respect to volume.