Getting particles out of the world

Hello, I use this code

if(NextVol && ThisVol->GetName()=="Envelope2" && NextVol->GetName()=="World" && step->GetTrack()->GetParentID()!=00 && (step->GetTrack()->GetDynamicParticle()->GetPDGcode()==13 || step->GetTrack()->GetDynamicParticle()->GetPDGcode()==-13 )) {

to get muons outogoing my second target called “Envelope2”, now I need to get photons out of my world

how can I do it?
Thank you.

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.

Thank you @guatelli
I wrote this code

if(NextVol && ThisVol->GetName()=="World" && NextVol->GetName()=="OutWorld" && step->GetTrack()->GetParentID()!=00 && step->GetTrack()->GetDynamicParticle()->GetPDGcode()==22) {

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?

Do you know what this means?

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.

1 Like

Thank you @mkelsey
I wrote

if( step->GetTrack()->GetNextVolume()==0 ) {

but I stil don’t get particles…,is the code wrong?

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.

Thank you @guatell this code worked!

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

G4double atomicNumber = 1.;
 G4double massOfMole = 1.008*g/mole;
 G4double density = 1.e-25*g/cm3;
 G4double temperature = 2.73*kelvin;
 G4double pressure = 3.e-18*pascal;
 G4Material* world_mat = new G4Material("interGalactic", atomicNumber, massOfMole, density, kStateGas, temperature, pressure);

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.

Dear Fausto

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”.

Kind Regards

thank you @guatelli, I flagged the solution

Sorry @guatelli I just noticed that you wrote [quote=“guatelli, post:6, topic:3935, full:true”]

Try if (!step->GetTrack()->GetNextVolume())
[/quote]

Instead, for error, when I tried the code I wrote if (!step->GetTrack()->GetNextVolume()==0) and I got photons.

Looking the error, today I changed the code writing if (!step->GetTrack()->GetNextVolume()) as you wrote, but in this way I don’t get photons!

Is it the same if I write if (!step->GetTrack()->GetNextVolume()==0) or is it wrong?
I.e. I’m selecting photons outgoing the world in this way

if(!step->GetTrack()->GetNextVolume()==0 && step->GetTrack()->GetParentID()!=00 && step->GetTrack()->GetDynamicParticle()->GetPDGcode()==22 ) {

but now I don’t know if it’s correct to use GetNextVolume()==0, because you just wrote GetNextVolume()

Thank you

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.

Thank you @mkelsey then, unfortunately it was just an error in the code.

writing if (!step->GetTrack()->GetNextVolume()) as @guatelli wrote, I don’t get photons out of the world…

anyway, looking the visualization there are trajectories looking like to go out of the world

and being an e+e- interaction, most of them should be photons

Sorry @guatelli and @mkelsey! I understood the problem!

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!

ok. good . I am happy you solved it.

Cheers

Susanna

1 Like