1 / 5

Particle Gun

Particle Gun. Makoto Asai (SLAC) Geant4 Tutorial Course. G4VUserPrimaryGeneratorAction. This class is one of mandatory user classes to control the generation of primaries.

cain
Download Presentation

Particle Gun

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Particle Gun Makoto Asai (SLAC) Geant4 Tutorial Course

  2. G4VUserPrimaryGeneratorAction • This class is one of mandatory user classes to control the generation of primaries. • This class itself should NOT generate primaries but invokeGeneratePrimaryVertex() method of primary generator(s) to make primaries. • Constructor • Instantiate primary generator(s) • Set default values to it(them) • GeneratePrimaries() method • Randomize particle-by-particle value(s) • Set these values to primary generator(s) • Never use hard-coded UI commands • Invoke GeneratePrimaryVertex()method of primary generator(s) Particle Gun - M.Asai (SLAC)

  3. Particle Gun vs. General Particle Source • Particle Gun • Simple and naïve • Shoot one track at a time • Easy to handle. • Use set methods to alternate track-by-track or event-by-event values. • General Particle Source • Powerful • Controlled by UI commands. • Almost impossible to control through set methods • Capability of shooting particles from a surface of a volume. • Capability of randomizing kinetic energy, position and/or direction following a user-specified distribution (histogram). • If you need to shoot primary particles from a surface of a volume, either outward or inward, GPS is the choice. • If you need a complicated distribution, not flat or simple Gaussian, GPS is the choice. • Otherwise, use Particle Gun. Particle Gun - M.Asai (SLAC)

  4. What to do and where to do • In the constructor of your UserPrimaryGeneratorAction • Instantiate G4ParticleGun • Set default values by set methods of G4ParticleGun • Particle type, kinetic energy, position and direction • In your macro file or from your interactive terminal session • Set values for a run • Particle type, kinetic energy, position and direction • In the GeneratePrimaries() method of your UserPrimaryGeneratorAction • Shoot random number(s) and prepare track-by-track or event-by-event values • Kinetic energy, position and direction • Use set methods of G4ParticleGun to set such values • Then invoke GeneratePrimaryVertex() method of G4ParticleGun • If you need more than one primary tracks per event, loop over randomization and GeneratePrimaryVertex(). • examples/extended/analysis/A01/src/A01PrimaryGeneratorAction.cc is a good example to start with. Particle Gun - M.Asai (SLAC)

  5. G4VUserPrimaryGeneratorAction void A01PrimaryGeneratorAction:: GeneratePrimaries(G4Event* anEvent) { G4ParticleDefinition* particle; G4int i = (int)(5.*G4UniformRand()); switch(i) { case 0: particle = positron; break; ... } particleGun->SetParticleDefinition(particle); G4double pp = momentum+(G4UniformRand()-0.5)*sigmaMomentum; G4double mass = particle->GetPDGMass(); G4double Ekin = sqrt(pp*pp+mass*mass)-mass; particleGun->SetParticleEnergy(Ekin); G4double angle = (G4UniformRand()-0.5)*sigmaAngle; particleGun->SetParticleMomentumDirection (G4ThreeVector(sin(angle),0.,cos(angle))); particleGun->GeneratePrimaryVertex(anEvent); } • You can repeat this for generating more than one primary particles. Particle Gun - M.Asai (SLAC)

More Related