Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/extended/electromagnetic/TestEm3/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/TestEm3/src/PrimaryGeneratorAction.cc
27 /// \brief Implementation of the PrimaryGeneratorAction class
28 //
29 // $Id: PrimaryGeneratorAction.cc 67268 2013-02-13 11:38:40Z ihrivnac $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "PrimaryGeneratorAction.hh"
35 
36 #include "PrimaryGeneratorMessenger.hh"
37 #include "DetectorConstruction.hh"
38 #include "HistoManager.hh"
39 
40 #include "G4Event.hh"
41 #include "G4ParticleGun.hh"
42 #include "G4ParticleTable.hh"
43 #include "G4ParticleDefinition.hh"
44 #include "G4SystemOfUnits.hh"
45 #include "Randomize.hh"
46 
47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
48 
51  fParticleGun(0),
52  fDetector(det),
53  fRndmBeam(0.),
54  fGunMessenger(0)
55 {
56  G4int n_particle = 1;
57  fParticleGun = new G4ParticleGun(n_particle);
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 {
77  G4String particleName;
78  G4ParticleDefinition* particle
79  = particleTable->FindParticle(particleName="e-");
80  fParticleGun->SetParticleDefinition(particle);
81  fParticleGun->SetParticleMomentumDirection(G4ThreeVector(1.,0.,0.));
82  fParticleGun->SetParticleEnergy(1.*GeV);
83  G4double position = -0.5*(fDetector->GetWorldSizeX());
84  fParticleGun->SetParticlePosition(G4ThreeVector(position,0.*cm,0.*cm));
85 }
86 
87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
88 
90 {
91  //this function is called at the begining of event
92  //
93  //randomize the beam, if requested.
94  if (fRndmBeam > 0.)
95  {
96  G4ThreeVector oldPosition = fParticleGun->GetParticlePosition();
97  G4double rbeam = 0.5*(fDetector->GetCalorSizeYZ())*fRndmBeam;
98  G4double x0 = oldPosition.x();
99  G4double y0 = oldPosition.y() + (2*G4UniformRand()-1.)*rbeam;
100  G4double z0 = oldPosition.z() + (2*G4UniformRand()-1.)*rbeam;
101  fParticleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
102  fParticleGun->GeneratePrimaryVertex(anEvent);
103  fParticleGun->SetParticlePosition(oldPosition);
104  }
105  else fParticleGun->GeneratePrimaryVertex(anEvent);
106 }
107 
108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
109 
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)