Introduction to GEANT4
From UCL HEP PBT Wiki
m |
m |
||
Line 394: | Line 394: | ||
== <span style="color:#000080"> Generate primary particles </span> == | == <span style="color:#000080"> Generate primary particles </span> == | ||
- | <span style="color:#ff0000"> G4VUserPrimaryGeneratorAction </span> | + | You derive your own class from <span style="color:#ff0000"> G4VUserPrimaryGeneratorAction </span> base class. |
- | + | Actual generation of primary particles is done via classes <span style="color:#ff0000"> G4ParticleGun </span> and <span style="color:#ff0000"> G4GeneralParticleSource </span>. | |
* <span style="color:#ff0000"> G4ParticleGun </span> is used to simulate a beam of particles. It shoots a primary particle of a certain energy and direction from a given point at a given time. | * <span style="color:#ff0000"> G4ParticleGun </span> is used to simulate a beam of particles. It shoots a primary particle of a certain energy and direction from a given point at a given time. | ||
* <span style="color:#ff0000"> G4GeneralParticleSource </span> simulates a beam of particles and the primary vertex is randomly chosen on surface of a given volume with pre-defined energy spectra, spatial and angular distribution. | * <span style="color:#ff0000"> G4GeneralParticleSource </span> simulates a beam of particles and the primary vertex is randomly chosen on surface of a given volume with pre-defined energy spectra, spatial and angular distribution. | ||
+ | |||
+ | |||
+ | <u> Simple example of <span style="color:#ff0000"> MyPrimaryGeneratorAction </span> using particle gun </u> | ||
+ | |||
+ | |||
+ | |||
+ | <span style="color:#800000"> class MyPrimaryGeneratorAction:public G4VUserPrimaryGeneratorAction { </span> | ||
+ | |||
+ | |||
+ | <span style="color:#800000"> public: </span> | ||
+ | |||
+ | <span style="color:#800000"> MyPrimaryGeneratorAction( </span> | ||
+ | |||
+ | <span style="color:#800000"> const G4String& particleName = "proton", </span> | ||
+ | |||
+ | <span style="color:#800000"> G4double energy = 1.*CLHEP::MeV, </span> | ||
+ | |||
+ | <span style="color:#800000"> G4ThreeVector position= G4ThreeVector(0,0,0), </span> | ||
+ | |||
+ | <span style="color:#800000"> G4ThreeVector momentumDirection = G4ThreeVector(0,0,1)); </span> | ||
+ | |||
+ | <span style="color:#800000"> ~MyPrimaryGeneratorAction(); </span> | ||
+ | |||
+ | <span style="color:#800000"> virtual void GeneratePrimaries(G4Event*); </span> | ||
+ | |||
+ | |||
+ | <span style="color:#800000"> private: </span> | ||
+ | |||
+ | <span style="color:#800000"> G4ParticleGun* fParticleGun; }; </span> | ||
+ | |||
+ | |||
+ | <u> Simple example of <span style="color:#ff0000"> MyPrimaryGeneratorAction </span> using general particle source </u> | ||
+ | |||
+ | |||
== <span style="color:#000080"> Optional user classes </span> == | == <span style="color:#000080"> Optional user classes </span> == |