How to Generate Primary Action
How to Generate a Primary Action[edit | edit source]
G4userPrimaryGeneratorAction is one of the mandatory classes available for deriving your own concrete class. In your concrete class, you have to specify how a primary event should be generated. Actual generation of primary particles will be done by concrete classes of G4VPrimaryGenerator.
void S1PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) {
Selection of the Generator[edit | edit source]
In the constructor of your G4VUserPrimaryGeneratorAction, you should instantiate the primary generator(s). If necessary, you need to set some initial conditions for the generator(s). This is an example of a constructor
S1PrimaryGeneratorAction::S1PrimaryGeneratorAction()
- G4VUserPrimaryGeneratorAction(),
//inside this constructor you should have some code calling your generator(s)
G4Primary Generator[edit | edit source]
G4ParticleGun is a generator provided by Geant4. We called This class generates primary particle(s) with a given momentum and position. It does not provide any sort of randomizing. The constructor of G4ParticleGun takes an integer which causes the generation of one or more primaries of exactly same kinematics. It is a rather frequent user requirement to generate a primary with randomized energy, momentum, and/or position. Such randomization can be achieved by invoking various set methods provided by G4ParticleGun. Geant4 provides various random number generation methods with various distributions (see Section 3.2). Within your Primary Generator Action you must establish your conditions of your experiment {Example}
- establish a random position on both top and bottom of your geometry within your envelope
xtop = (G4UniformRand()*(Variables->getGeometryX()*0.5)); ytop = (G4UniformRand()*(Variables->getGeometryY()*0.5)); xbottom = (G4UniformRand()*(Variables->getGeometrytX()*0.5)); ybottom = = (G4UniformRand()*(Variables->getGeometryY()*0.5));
- establish how far below the bottom geometry the particles should start
G4double bottomOfBottomGeo = (Variables->getGeoZ()*-0.5)+Variables->getBottomGeoPos(); zinitial = (bottomOfBottomGeo - 1.0);
- establish the components of the vector to fire along to hit both random points
baseX = (xtop-xbottom); baseY = (ytop-ybottom); heightZ = (Variables->getTopGeoPos() - Variables->getBottomGeoPos());
G4ParticleGun Generator[edit | edit source]
G4ParticleGun is a generator provided by Geant4. This class generates primary particle(s) with a given momentum and position. It does not provide any sort of randomizing. The constructor of G4ParticleGun takes an integer which causes the generation of one or more primaries of exactly same kinematics. It is a rather frequent user requirement to generate a primary with randomized energy, momentum, and/or position. G4ParticleGun is normally found in one of your constructors within your PrimaryGeneratorAction.
fParticleGun = new G4ParticleGun(n_particle);
Next you must decribe the default Particle Kinematics:
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); G4String particleName = "nameofparticlehere"; G4ParticleDefinition* particle = particleTable->FindParticle(particleName); fParticleGun->SetParticleDefinition(particle);