12.07.2015 Views

Geant4 User's Guide for Application Developers - Geant4 - CERN

Geant4 User's Guide for Application Developers - Geant4 - CERN

Geant4 User's Guide for Application Developers - Geant4 - CERN

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Getting Started with <strong>Geant4</strong>- Running a Simple ExampleIn Example 2.19, G4ParticleGun is constructed to use as the actual primary particle generator. Methods ofG4ParticleGun are described in the following section. Please note that the primary generator object(s) you constructin your G4VUserPrimaryGeneratorAction concrete class must be deleted in your destructor.2.6.1.2. Generation of an eventG4VUserPrimaryGeneratorAction has a pure virtual method named generatePrimaries(). This method isinvoked at the beginning of each event. In this method, you have to invoke the G4VPrimaryGenerator concreteclass you instantiated via the generatePrimaryVertex() method.You can invoke more than one generator and/or invoke one generator more than once. Mixing up several generatorscan produce a more complicated primary event.2.6.2. G4VPrimaryGenerator<strong>Geant4</strong> provides three G4VPrimaryGenerator concrete classes. Among these G4ParticleGun andG4GeneralParticleSource will be discussed here. The third one is G4HEPEvtInterface, which will be discussedin Section 3.6.2.6.2.1. G4ParticleGunG4ParticleGun is a generator provided by <strong>Geant4</strong>. This class generates primary particle(s) with a given momentumand position. It does not provide any sort of randomizing. The constructor of G4ParticleGun takes an integerwhich causes the generation of one or more primaries of exactly same kinematics. It is a rather frequent user requirementto generate a primary with randomized energy, momentum, and/or position. Such randomization can beachieved by invoking various set methods provided by G4ParticleGun. The invocation of these methods should beimplemented in the generatePrimaries() method of your concrete G4VUserPrimaryGeneratorAction classbe<strong>for</strong>e invoking generatePrimaryVertex() of G4ParticleGun. <strong>Geant4</strong> provides various random numbergeneration methods with various distributions (see Section 3.2).2.6.2.2. Public methods of G4ParticleGunThe following methods are provided by G4ParticleGun, and all of them can be invoked from the generatePrimaries()method in your concrete G4VUserPrimaryGeneratorAction class.• void SetParticleDefinition(G4ParticleDefinition*)• void SetParticleMomentum(G4ParticleMomentum)• void SetParticleMomentumDirection(G4ThreeVector)• void SetParticleEnergy(G4double)• void SetParticleTime(G4double)• void SetParticlePosition(G4ThreeVector)• void SetParticlePolarization(G4ThreeVector)• void SetNumberOfParticles(G4int)2.6.2.3. G4GeneralParticleSourceFor many applications G4ParticleGun is a suitable particle generator. Howevr if you want to generate primaryparticles in more sophisticated manner, you can utilize G4GeneralParticleSource - <strong>Geant4</strong> General ParticleSource module (GPS).Using this tool, you can control the following characteristics of primary particles:• Spectrum: linear, exponential, power-law, Gaussian, blackbody, or piece-wise fits to data.• Angular distribution: unidirectional, isotropic, cosine-law, beam or arbitrary (user defined).• Spatial sampling: on simple 2D or 3D surfaces such as discs, spheres, and boxes.• Multiple sources: multiple independent sources can be used in the same run.Details of in<strong>for</strong>mation on the General Source Particle Module can be found in the documents <strong>Geant4</strong> GeneralParticle Source.17

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!