Counting number of detected particle

_Geant4 Version:_geant4-v11.2.0
_Operating System:_win11
_Compiler/Version:_Visual Studio Version 17.3.5
_CMake Version:_cmake-3.28.1

Hi everybody, I am trying to record the number of particles that hit my target and then record these particles how much of them reach to my detector core. I have tried lots of code sample but could not get the result.

Can you guide me on that matter? What classes should I have (such as G4VHitsCollection, G4VHit, G4VSensitiveDetector)? or can I use only EndOfEventAction? Everything massed up sadly.

I am using geant4_pybind.

Have you looked at using G4MultiFunctionalDetector(s) attached to the detector volume(s) together with the appropriate G4PS... primitive scorer classes registered with the multifunctional detector(s)? The scored quantities, like number, flux, etc. can be extracted/persisted as needed in an EndOfEventAction.

Use of these is demonstrated in the B3 and B4d basic examples, with more advanced use in the RE02, RE03 and RE06 examples in extended/runAndEvent.

If more detailed per track/event info is needed, then a full implementation with custom hits, sensitive detectors might be needed, but it depends on exactly what you want to record.

Note that we can’t provide support for geant4_pybind here, though the C++ interfaces should translate across if they are exposed by the binding.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.