When particles exit the world, the PostStepPoint is in a volume which does not exist. You may put this as a condition together with the fact that the particle should be a photon. It should work.
I wrote OutWorld in the code because I don’t have volumes called “OutWorld”…I think you meant this…
I compiled and runned the application, I didn’t get errors, but I don’t get photons out the world, so I dont’ know if I didnt’ understand your words (i.e. I wrote a wrong code) or really there aren’ photons out the world
Maybe I was wrong because I invented the name OutWorld, but there is a specific name to use ? Or other code?
In order for a volume to have a name, it must exist. If the volume does not exist, then it does not have a name. In particular, if the volume does not exist, that means that it’s pointer is zero.
Try if (!step->GetTrack()->GetNextVolume())
this means if the next volume does not exist… @mkelsey is right.
Another solution is to define a dummy volume with sizes just slightly smaller than the World. When a photon goes from that volume to the world, you count it. I do not know your set-up but I would suggest to have the world made of vacuum, so you are sure that there is no chance for the photons to be backscattered.
I’m studying the muon production in electron positron annihilation to maximize the muon production and minimize the muon emittance of produced muons. Then I’ve a 45GeV positron beam hitting a multi targets. The world is constituted by vacuum. I defined the vacuum in this way
My first supervisor asked me to study also the irradiated energy by photons that don’t enter in the targets; then, my second supervisor (the second supervisor is the expert of Geant4) suggested me to count photons outgoing the world to be sure to get just photons that don’t enter again in the multi targets.
I am happy that now the code is working as you would like. Make sure it works. Have some tests to check that the results are correct by a software point of view. Please mark the discussion thread with “solution”.
Those are two opposite logical expressions. You may find this chart handy.
Let X mean “step->GetTrack()->GetNextVolume()” below (to save typing). If the volume exists, then X is non-zero; if the volume does not exist, then X is zero.
(!X) is true (1) if X is zero, and false (0) if X is non-zero.
(!X == 0) is true if (!X) is zero, which happens (above) if X is non-zero.
So your code is requiring that X be non-zero, which is exactly the opposite of testing for zero.
Given that I modified the code to get muons outgoling the second target, the code if(!step->GetTrack()->GetNextVolume() ) {
was inside the if (volume == fScoringVolume2) {
that’s the reason because I didn’t get particles outgoing the world! then, I moved the if(!step->GetTrack()->GetNextVolume() ) { out of the if (volume == fScoringVolume2) { and it worked!