Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/extended/electromagnetic/TestEm1/src/PrimaryGeneratorAction.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 /// \file electromagnetic/TestEm1/src/PrimaryGeneratorAction.cc
27 /// \brief Implementation of the PrimaryGeneratorAction class
28 //
29 // $Id: PrimaryGeneratorAction.cc 76293 2013-11-08 13:11:23Z gcosmo $
30 //
31 
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 
35 #include "PrimaryGeneratorAction.hh"
36 
37 #include "DetectorConstruction.hh"
38 #include "PrimaryGeneratorMessenger.hh"
39 
40 #include "G4Event.hh"
41 #include "G4ParticleTable.hh"
42 #include "G4ParticleDefinition.hh"
43 #include "G4SystemOfUnits.hh"
44 #include "Randomize.hh"
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
50  fParticleGun(0),
51  fDetector(det),
52  fRndmBeam(0),
53  fGunMessenger(0)
54 
55 {
56  fParticleGun = new G4ParticleGun(1);
58  fRndmBeam = 0.;
59 
60  //create a messenger for this class
61  fGunMessenger = new PrimaryGeneratorMessenger(this);
62 }
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 
67 {
68  delete fParticleGun;
69  delete fGunMessenger;
70 }
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
75 {
76  G4ParticleDefinition* particle
78  fParticleGun->SetParticleDefinition(particle);
79  fParticleGun->SetParticleMomentumDirection(G4ThreeVector(1.,0.,0.));
80  fParticleGun->SetParticleEnergy(100*MeV);
81  G4double position = 0.*cm;
82  if (front) position = -0.5*(fDetector->GetSize());
83  fParticleGun->SetParticlePosition(G4ThreeVector(position,0.*cm,0.*cm));
84 }
85 
86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
87 
89 {
90  //this function is called at the begining of event
91  //
92  //randomize the beam, if requested.
93  if (fRndmBeam > 0.)
94  {
95  G4ThreeVector oldPosition = fParticleGun->GetParticlePosition();
96  G4double rbeam = 0.5*(fDetector->GetSize())*fRndmBeam;
97  G4double x0 = oldPosition.x();
98  G4double y0 = oldPosition.y() + (2*G4UniformRand()-1.)*rbeam;
99  G4double z0 = oldPosition.z() + (2*G4UniformRand()-1.)*rbeam;
100  fParticleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
101  fParticleGun->GeneratePrimaryVertex(anEvent);
102  fParticleGun->SetParticlePosition(oldPosition);
103  }
104  else fParticleGun->GeneratePrimaryVertex(anEvent);
105 }
106 
107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
108 
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
CLHEP::Hep3Vector G4ThreeVector
double x() const
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
G4ThreeVector GetParticlePosition()
int G4int
Definition: G4Types.hh:78
virtual void GeneratePrimaryVertex(G4Event *evt)
double z() const
void SetParticlePosition(G4ThreeVector aPosition)
#define G4UniformRand()
Definition: Randomize.hh:87
void SetParticleEnergy(G4double aKineticEnergy)
static G4ParticleTable * GetParticleTable()
double y() const
double G4double
Definition: G4Types.hh:76
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)