Unable to Print Detector index

After attaching the lines as you @weller suggested I got
Debug: StepStatus: 1 IsFirstStepInVolume: 1
Debug: StepStatus: 1 IsFirstStepInVolume: 1
Debug: StepStatus: 1 IsFirstStepInVolume: 1
Debug: StepStatus: 1 IsFirstStepInVolume: 1
Debug: StepStatus: 1 IsFirstStepInVolume: 1
Debug: StepStatus: 1 IsFirstStepInVolume: 1
Debug: StepStatus: 1 IsFirstStepInVolume: 1

so, still duplicate entries of detector id?

yes! @weller still I am getting duplicate entries of detector id.
Debug: StepStatus: 1 IsFirstStepInVolume: 1
Event id: 9998 detector id: 504 trackid: 1
Debug: StepStatus: 1 IsFirstStepInVolume: 1
Event id: 9998 detector id: 404 trackid: 1
Debug: StepStatus: 1 IsFirstStepInVolume: 1
Event id: 9998 detector id: 404 trackid: 1

ok, so it appears that the same track is actually leaving and re-entering the same volume again, and that is happening frequently.

what kind of particles are we talking about? can you identify that in the stepping action? I could imagine optical photons being reflected on the surface being counted twice.

@weller I am using gamma for the simulation.
I actually don’t know how to identify particle in the stepping action. If you kindly suggest how to obtain that would be great. I added the following lines
if (track->GetDefinition() == G4Electron::Definition()) { G4cout << " got an electron!" << G4endl;}
if (track->GetDefinition() == G4Gamma::Definition()) { G4cout << " got a photon!" << G4endl;}

Now I got

Event id: 99945 detector id: 401 trackid: 1
got a photon!
Event id: 99946 detector id: 104 trackid: 1
got a photon!
Event id: 99946 detector id: 103 trackid: 1
got a photon!
Event id: 99946 detector id: 103 trackid: 1
got a photon!
Event id: 99948 detector id: 603 trackid: 1
got a photon!

I could see Event id 99947 also missing ?

I think you are making good progress in understanding what is going on. instead of comparing the definition, you could also simply print the definition directly, but what you did is perfectly fine here.
since it’s gamma also for the duplicates, I think the most reasonable would be to assume it is indeed re-entry. you could verify with verbose output for tracking, but depending on how often that phenomenon occurs, it could be a lot of output

1 Like

@weller let’s assume this as re-entry. As you can see I able to print event id as well as detector id.
If I generate 100000 events then how to count the scattered events i,e different detector id having same event Id?

record each hit in a hitsmap as the detector d and process this map at the end of the event, similar to what is done here: geant4/EventAction.cc at v11.1.1 · Geant4/geant4 · GitHub

instead of calculating the sum of the entries, you would check for more than 1 entry and (at least?) two different ids.

1 Like