How to count the number of ionizations by a primary particle?

I want to shoot particles into a volume, count the number of times it ionizes the volume material, and then print the result. I have tried studying the application developer’s guide on hits and have looked at basic example B2 for some hints but I am not enough familiar with either geant4 or c++ to really understand what I should do. Copying some of the code from example B2 might get me partway since it looks like I could collect only hits having track ID 1, but I also want to filter for a single process, and I don’t know how to do that. Can anyone help me?

I would try something like

if (step->GetPreStepPoint()->GetProcessDefinedStep()->GetProcessName()=="eIoni") ...

with the correct process name. My first guess is to do this kind of filtering where you also filter for the track ID.

Sorry, I’m not a physics developer, but as I understand it the energy loss processes do not produce ions. They just calculate the energy loss.

Let’s wait for a response from a em processes developer.

in principle you can use the command suggested (step-> GetPreStepPoint() … etc) to determine how many times you have an ionisation. However, when using a condensed history approach, as in G4 EM Physics Lists (opt0, 1, 2, 3, 4), many interactions are artificially condensed in one single step, therefore this approach is not correct to retrieve the number of ionisations. In reality you will have more! What should be done is to adopt a Track Structure approach, where all ionisations in the medium are modelled one by one. This is possible to do in water only in Geant4, using Geant4-DNA Physics Lists. Please look at this paper and I think you will understand better:


Thank you. For some reason I did not see your response until just now. I will check the reference you mentioned.