# Primary particle count per event

**URL:** <https://geant4-forum.web.cern.ch/t/primary-particle-count-per-event/13329>\
**Category:** Particles, Track, Event, Run and Biasing\
**Created:** [December 10, 2024, 9:05am UTC](https://geant4-forum.web.cern.ch/t/primary-particle-count-per-event/13329 "2024-12-10T09:05:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichalD](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/michald/32/9379_2.png) [@MichalD](https://geant4-forum.web.cern.ch/u/MichalD)\
**Post date:** [December 10, 2024, 9:05am UTC](https://geant4-forum.web.cern.ch/t/primary-particle-count-per-event/13329/1 "2024-12-10T09:05:54Z")

</div>

Please fill out the following information to help in answering your question, and also see [tips for posting code snippets](https://geant4-forum.web.cern.ch/t/how-to-post-code-snippets/9944). 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.

---

<div class="post-metadata">

**Author:** ![mkelsey](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/mkelsey/32/49_2.png) [@mkelsey](https://geant4-forum.web.cern.ch/u/mkelsey)\
**Post date:** [December 10, 2024, 4:01pm UTC](https://geant4-forum.web.cern.ch/t/primary-particle-count-per-event/13329/2 "2024-12-10T16:01:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MichalD](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/michald/32/9379_2.png) [@MichalD](https://geant4-forum.web.cern.ch/u/MichalD)\
**Post date:** [December 10, 2024, 4:59pm UTC](https://geant4-forum.web.cern.ch/t/primary-particle-count-per-event/13329/3 "2024-12-10T16:59:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mkelsey](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/mkelsey/32/49_2.png) [@mkelsey](https://geant4-forum.web.cern.ch/u/mkelsey)\
**Post date:** [December 10, 2024, 6:41pm UTC](https://geant4-forum.web.cern.ch/t/primary-particle-count-per-event/13329/4 "2024-12-10T18:41:23Z")

</div>

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++.

---

<div class="post-metadata">

**Author:** ![MichalD](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/michald/32/9379_2.png) [@MichalD](https://geant4-forum.web.cern.ch/u/MichalD)\
**Post date:** [December 11, 2024, 1:26pm UTC](https://geant4-forum.web.cern.ch/t/primary-particle-count-per-event/13329/5 "2024-12-11T13:26:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://geant4-forum.web.cern.ch/uploads/default/original/1X/ce519a43ebdf7ac48a98a03c6ad6eea013b68c46.png) [@system](https://geant4-forum.web.cern.ch/u/system)\
**Post date:** [December 18, 2024, 1:27pm UTC](https://geant4-forum.web.cern.ch/t/primary-particle-count-per-event/13329/6 "2024-12-18T13:27:00Z")

</div>

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