@mkelsey In my detector construction I only made boxes. And, I attached logicBox (which is my LV) as my ScoringVolume. There is no volume other than boxes.
I just want to count the scattered events (which scattered from one LV to another LV). So for a particular event id I must have different detector id.
since you are using the user stepping action, this method is called for every single step.
so also for the step where particles are leaving the world volume, and also for the initial step placing the particle into the world. this could be the -1 and 0 prints!?
i did not see any filtering for the fScoringVolume in your usersteppingaction. maybe this would help to make further progress?
@weller I just want to count the scattered events (which scattered from one LV to another LV). So for a particular event id I must have different detector id.
How should I approach then?
I personally prefer to use sensitive detector instead of usersteppingaction, because then you don’t need to discard all the steps
that are not within the volumes that you attached the SD to.
since you want to only record each volume
once, get rid of the duplicates from multiple steps in the same volume, e.g. like so: Multiple Steps on geometricBoundary
you would need to keep track of the copyID of the visited volumes somehow. you could use the „hitsmap“ for this, and then process the map at the end of each event to check for multiple entries.
inspiration can be found here: geant4/EventAction.cc at v11.1.1 · Geant4/geant4 · GitHub
Geant4 is flexible. You could do this in several different ways. You get to choose which method you like best, and then implement it.
Create a proper SensitiveDetector class, attach it to your “scoring volume” in the ConstructSDandField() function of your detector construction class. That will guarantee that only steps within your desired volume(s) get counted.
Use the UserSteppingAction, but include a test yourself on whether the volume associated with the step (with the PostStepPoint) is the volume you care about. That’s what you’re missing in your current code.
Use Geant4’s built in scorers, which you can configure with macro commands. I believe that you can attach scorers to specific volumes, and request that specific quantities be accumulated. You won’t get an N-tuple, and you won’t be able to analyze cross correlations, but you will get the spectra in each volume.
After get rid of the duplicates from multiple steps in the same volume I am getting :
Event id: 9994 detector id: 306 Event id: 9995 detector id: 407 Event id: 9995 detector id: 402 Event id: 9995 detector id: 402
Here for Event No 9995 I have two different detector id. But value of energy deposition in each volume gets changed for a given event which is obvious. But @weller I noticed there is a repetition of Event id and detector id for many cases . Why?
How close together are your individual detector volumes, and what material is between them? How likely is it to get scattering from A to B and back to A?
Yes there is a possibility to get scattering from A to B and back to A. Material used here is Germanium. But I can see the repetition happens other than scattered events also. This repetition coming not more than twice, like
Event id: 99390 detector id: 302
Event id: 99390 detector id: 302
But I stopped the multiple steps in the same volume. @mkelsey If there is a scattering from A to B and back to A then I shouldn’t get
Event id: 99953 detector id: 106
Event id: 99953 detector id: 107
Event id: 99953 detector id: 107
I should get
Event id: 99953 detector id: 106
Event id: 99953 detector id: 107
Event id: 99953 detector id: 106
Am I correct?
duplicate hits could be that secondaries are produced and also hit a/the SD.
I think secondaries should have a distinct trackID, print that as well and see if it clarifies.
in this case that could be the same bug as in the linked post. try filtering also for IsFirstStepInVolume, as suggested in Multiple Steps on geometricBoundary
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;}
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
@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?