Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
F01PrimaryGeneratorAction.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: F01PrimaryGeneratorAction.cc 77881 2013-11-29 08:37:53Z 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 
52  G4ParticleDefinition* F01PrimaryGeneratorAction::fgPrimaryParticle = 0;
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
72  fGunMessenger = new F01PrimaryGeneratorMessenger(this);
73 
74  // default particle kinematic
75 
77  G4String particleName;
78  G4ParticleDefinition* particle
79  = particleTable->FindParticle(particleName="e-");
80  fParticleGun->SetParticleDefinition(particle);
81 
82  fgPrimaryParticle = particle;
83 
84  fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,-1.));
85  fParticleGun->SetParticleEnergy(0.5*GeV);
86 
87  fZVertex = fDetector->GetAbsorberZpos() -
88  0.5*(fDetector->GetAbsorberThickness());
89  fParticleGun->SetParticlePosition(G4ThreeVector(fXVertex,fYVertex,fZVertex));
90 
91 }
92 
93 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
94 
96 {
97  delete fParticleGun;
98  delete fGunMessenger;
99 }
100 
101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
102 
104 {
105  // this function is called at the begining of event
106  //
107  fgPrimaryParticle = fParticleGun->GetParticleDefinition();
108 
109  G4double x0,y0,z0;
110  if (fVertexDefined)
111  {
112  x0 = fXVertex;
113  y0 = fYVertex;
114  z0 = fZVertex;
115  }
116  else
117  {
118  x0 = 0.;
119  y0 = 0.;
120  z0 = fDetector->GetAbsorberZpos()-0.5*(fDetector->GetAbsorberThickness());
121  }
122 
123  G4double r0,phi0;
124  if (fRndmFlag == "on")
125  {
126  r0 = (fDetector->GetAbsorberRadius())*std::sqrt(G4UniformRand());
127  phi0 = twopi*G4UniformRand();
128  x0 = r0*std::cos(phi0);
129  y0 = r0*std::sin(phi0);
130  }
131 
132  fParticleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
133  fParticleGun->GeneratePrimaryVertex(anEvent);
134 }
135 
136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
137 
139 {
140  return fgPrimaryParticle->GetParticleName();
141 }
142 
143 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
144 
146 {
147  fVertexDefined = true;
148  fZVertex = z;
149  G4cout << " Z coordinate of the primary vertex = " << fZVertex/mm <<
150  " mm." << G4endl;
151 }
152 
153 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
154 
156 {
157  fVertexDefined = true;
158  fXVertex = x;
159  G4cout << " X coordinate of the primary vertex = " << fXVertex/mm <<
160  " mm." << G4endl;
161 }
162 
163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
164 
166 {
167  fVertexDefined = true;
168  fYVertex = y;
169  G4cout << " Y coordinate of the primary vertex = " << fYVertex/mm <<
170  " mm." << G4endl;
171 }
172 
173 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static constexpr double mm
Definition: G4SIunits.hh:115
CLHEP::Hep3Vector G4ThreeVector
Definition of the F01PrimaryGeneratorAction class.
tuple x
Definition: test.py:50
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
virtual void GeneratePrimaries(G4Event *)
int G4int
Definition: G4Types.hh:78
virtual void GeneratePrimaryVertex(G4Event *evt)
const G4String & GetParticleName() const
Definition of the F01PrimaryGeneratorMessenger class.
static constexpr double twopi
Definition: G4SIunits.hh:76
Definition of the F01DetectorConstruction class.
void SetParticlePosition(G4ThreeVector aPosition)
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
F01PrimaryGeneratorAction(F01DetectorConstruction *)
void SetParticleEnergy(G4double aKineticEnergy)
static G4ParticleTable * GetParticleTable()
G4ParticleDefinition * GetParticleDefinition() const
static constexpr double GeV
Definition: G4SIunits.hh:217
tuple z
Definition: test.py:28
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)