I’m trying to change my particles position back to the initial (0, 0, 0) after they interacted with something. My problem is that, when I call the G4Track’s SetPosition function in my sensitivedetector’s “ProcessHits” function, it does not work.
I found this thread on my issue, but unfortunately it does not solve my issue.
If anyone could help me in this, that would be greatly appreciated. Thank you in advance for any tips or ideas!
With best regards,
In that thread, Peter Gumplinger’s post is relevant:
One of the, perhaps hidden, doctrines of Geant4 framework architecture is that the user canNOT modify parameters of the current G4Track directly(!), for example in UserSteppingAction.
I second Miguel’s suggestion that you may want to reflect your tracks when they reach the end of your implemented, to be repeated, geometry if the geometry is symmetric wrt that boundary. G4OpBoundary has the necessary code to follow.
You can also write a ‘process’ (derived from G4VProcess) in which you test whether the track has arrived at your boundary and then you ‘stopandkill’ the current track and put a secondary clone at the opposite geometry (start) boundary. I suggest you do not modify the current track in such a radical way as to transpose its position - far away. I am afraid that the G4Navigator will be ‘confused’. It’s better to clone it, give the clone a position, and then the G4Navigator ‘knows’ that it needs to re-seed its geometry memory.
Basically, “don’t do that.” The G4Navigator, which is what handles all of the transport of particles through the geometry, uses a cache in order to avoid having to figure out from scratch the position-volume relationship of the track.
If you manually “push” a track to some arbitrary position in the geometry, the Navigator’s cache will be wrong, and it will either do something non-physical, or notice the problem and throw an error.
If you’re wanting to kill the track after an interaction, you can do that either with a custom process or with a UserStackingAction. With the process, you can both kill the track and create a new one (as a secondary) at the point you desire.
You might also explain the underneath problem of why you want to reset the track to (0,0,0). Maybe there is an other solution to your case.
a clean way to change energy, time, position of a track is to implement your custom Geant4 process which will do this and using standard G4VProcess interface.
Thank all of you for the helpful answers. I will discover the custom G4VProcess way. Is there any example by any chance where I could start?