How to detect particle without killing it

Hey,

is it possible to detect a particle (i do it in the stepping action) without killing it immediately?
I want to compare how many particles are absorbed passing through different materials and count the number of particles in between the layers.

1 Like

Stepping action is used to “observe” what is happening during the smallest unit of simulation: inspect what process has happened, where the particle is, does it enter/exit some volume, what/if energy was deposited, etc. If a particle is killed by a process that was just invoked, you can access all the information that I guess you seek (what particle, which volume).

Thanks for your answer!
That is what I also thought. I count particles leaving a volume and then delete them, because if I don’t, I count them (somehow?) several times, or at least that’s what I think because the number of counts is significally higher if I don’t kill them. Maybe because they bounce back and forth?
Can I somehow make sure that I count each particle only once without killing it?

How about score the particle with trackID?

How do you mean?
I think the trackID is updated each time a new primary particle is created giving it a trackID of 1.

Sorry, seems I misunderstand what you want.

If you want how many (primary?) particles are absorbed by the material, you can try:
step->PreStepPoint->StepStatus == fGeomBoundary /* if step is just entering a geometry */
step->PostStepPoint->StepStatus==fGeomBoundary /* if step is just exiting a geometry */

Then you can score all the enter and exit of each step in steppingAction.

2 Likes

Yes, this is the best method to implement. This way you don’t have to kill the particle and don’t have duplication of the data. Just make sure the interface is defined properly either entering the volume or exiting the volume as implemented beautifully by Saluta.
Best,
Ananta

Hey, thanks for the idea.
I want to count primary as well as secondary particles.
First I want to count how many particles leave an orb. If I use
ParticleLeftOrb = step->GetPostStepPoint()->GetStepStatus() == fGeomBoundary && step->GetPreStepPoint()->GetPhysicalVolume()->GetName() == “Orb” ;
Strangely if I then kill the particle with
step->GetTrack()->SetTrackStatus(fStopAndKill);
around 1% more(!) particles are counted compared to the case when I just count without killing the particles. I would have expected no difference or maybe less counts. Do you have an idea how this can happen?

Sorry for a late reply.
I have no clear idea for why it happened. How about try more simulation primary number to eliminate the statistical fluctuation?

Hey thanks. It works now, I think there was something wrong with my DetectorConstruction and thus the way I counted it.

Wouldn’t it be “easier” to simply replace fStopAndKill with fAlive?