Primary particle count per event

Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!

Geant4 Version: 4.11.2
Operating System: Windows 10
Compiler/Version:
CMake Version:

Hello! I am running some basic GEANT4 simulations and whilst setting them up I had to specifiy the number of events. But where do I specifiy the number of primary particles generated per event? Or where is it possible to check this parameter?

Sincerely,
Michal D.

If you are using G4ParticleGun, the SetNumberOfParticles() function allows you to specify how many primaries you want in each event (the default is 1, of course). All the particles will be identical, of course.

If you are writing your own PrimaryGeneratorAction, you can set it up yourself with a “number of primaries” paramater, and generate a collection of particles.

Dear Mr. Kelsey,

Thank you for your response. I am using G4ParticleGun, but the SetNumberOfParticles() is set to “i”:

inline void SetNumberOfParticles(G4int i)
{ NumberOfParticlesToBeGenerated = i; }

Does thsi mean the default 1 particle per event?

It means that when you, somewhere in your own code (or in the code of a UI command), call the function, the numeric value you put into your function call is assigned to the local variable ‘i’.

If you look at $G4INCLUDE/G4ParticleGun.hh, you will see that one of the constructors includes a parameter to preset the number of particles, and that parameter defaults to 1. So when you instantiate G4ParticleGun, the data member G4ParticleGun::NumberOfParticlesToBeGenerated will be preset to a value of 1. If you never call the SetNumberOfParticles() function at all, that preset value will never be changed.

Your question suggests a certain level of unfamiliarity with the C++ language. In order to understand how the Geant4 code functions, you really do need to have some knolwedge of C++.

2 Likes

I understand sir. Thank you for your time and patience in explaining this to me!

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