Geant4  10.02.p01
F02PrimaryGeneratorAction.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 //
28 //
29 //
30 // $Id: F02PrimaryGeneratorAction.cc 77893 2013-11-29 08:57:22Z gcosmo $
31 //
32 //
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
35 
37 
40 
41 #include "G4Event.hh"
42 #include "G4ParticleGun.hh"
43 #include "G4ParticleTable.hh"
44 #include "G4ParticleDefinition.hh"
45 
46 #include "Randomize.hh"
47 #include "G4SystemOfUnits.hh"
48 #include "G4PhysicalConstants.hh"
49 
50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
51 
53 
54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55 
59  fParticleGun(0),
60  fDetector(det),
61  fGunMessenger(0),
62  fRndmFlag("off"),
63  fXVertex(0.),
64  fYVertex(0.),
65  fZVertex(0.),
66  fVertexDefined(false)
67 {
68  G4int n_particle = 1;
69  fParticleGun = new G4ParticleGun(n_particle);
70 
71  // create a messenger for this class
73 
74  // default particle kinematic
75 
77  G4String particleName;
78  G4ParticleDefinition* particle
79  = particleTable->FindParticle(particleName="proton");
81 
82  fgPrimaryParticle = particle;
83 
86 
87  fZVertex = 0. ; // -0.5*(fDetector->GetAbsorberThickness());
89 
90 }
91 
92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
93 
95 {
96  delete fParticleGun;
97  delete fGunMessenger;
98 }
99 
100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
101 
103 {
104  // this function is called at the begining of event
105  //
107 
108  G4double x0,y0,z0;
109  if (fVertexDefined)
110  {
111  x0 = fXVertex;
112  y0 = fYVertex;
113  z0 = fZVertex;
114  }
115  else
116  {
117  x0 = 0.;
118  y0 = 0.;
119  z0 = 0.; // -0.5*(fDetector->GetWorldSizeZ());
120  }
121 
122  G4double r0,phi0;
123  if (fRndmFlag == "on")
124  {
125  r0 = (fDetector->GetAbsorberRadius())*std::sqrt(G4UniformRand());
126  phi0 = twopi*G4UniformRand();
127  x0 = r0*std::cos(phi0);
128  y0 = r0*std::sin(phi0);
129  }
130 
133 }
134 
135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
136 
138 {
140 }
141 
142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
143 
145 {
146  fVertexDefined = true;
147  fXVertex = x;
148  G4cout << " X coordinate of the primary vertex = " << fXVertex/mm <<
149  " mm." << G4endl;
150 }
151 
152 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
153 
155 {
156  fVertexDefined = true;
157  fYVertex = y;
158  G4cout << " Y coordinate of the primary vertex = " << fYVertex/mm <<
159  " mm." << G4endl;
160 }
161 
162 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
163 
165 {
166  fVertexDefined = true;
167  fZVertex = z;
168  G4cout << " Z coordinate of the primary vertex = " << fZVertex/mm <<
169  " mm." << G4endl;
170 }
171 
172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
F02PrimaryGeneratorAction(F02DetectorConstruction *)
Definition of the F02PrimaryGeneratorAction class.
CLHEP::Hep3Vector G4ThreeVector
G4double z
Definition: TRTMaterials.hh:39
Definition of the F02PrimaryGeneratorMessenger class.
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
int G4int
Definition: G4Types.hh:78
virtual void GeneratePrimaryVertex(G4Event *evt)
F02DetectorConstruction * fDetector
const G4String & GetParticleName() const
virtual void GeneratePrimaries(G4Event *)
Definition of the F02DetectorConstruction class.
void SetParticlePosition(G4ThreeVector aPosition)
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
static const double twopi
Definition: G4SIunits.hh:75
static const double GeV
Definition: G4SIunits.hh:214
static G4ParticleDefinition * fgPrimaryParticle
void SetParticleEnergy(G4double aKineticEnergy)
F02PrimaryGeneratorMessenger * fGunMessenger
static G4ParticleTable * GetParticleTable()
const G4double x[NPOINTSGL]
G4ParticleDefinition * GetParticleDefinition() const
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
static const double mm
Definition: G4SIunits.hh:114
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
const G4double r0