Geant4
9.6.p02
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
geant4_9_6_p02
examples
extended
field
field03
src
F03PrimaryGeneratorAction.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
// $Id$
30
//
31
32
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
33
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
34
35
#include "
F03PrimaryGeneratorAction.hh
"
36
#include "
F03DetectorConstruction.hh
"
37
#include "
F03PrimaryGeneratorMessenger.hh
"
38
39
#include "
G4Event.hh
"
40
#include "
G4ParticleGun.hh
"
41
#include "
G4ParticleTable.hh
"
42
#include "
G4ParticleDefinition.hh
"
43
#include "
Randomize.hh
"
44
#include "
G4PhysicalConstants.hh
"
45
#include "
G4SystemOfUnits.hh
"
46
#include "
G4ios.hh
"
47
48
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
49
50
G4String
F03PrimaryGeneratorAction::fgPrimaryParticleName=
"e-"
;
51
52
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
53
54
F03PrimaryGeneratorAction::F03PrimaryGeneratorAction
(
55
F03DetectorConstruction
* det)
56
:
G4VUserPrimaryGeneratorAction
(),
57
fParticleGun(0),
58
fDetector(det),
59
fMessenger(0),
60
fRndmFlag(
"off"
),
61
fXVertex(0.),
62
fYVertex(0.),
63
fZVertex(0.),
64
fVertexDefined(false)
65
{
66
G4int
n_particle = 1;
67
fParticleGun =
new
G4ParticleGun
(n_particle);
68
69
// create a messenger for this class
70
//
71
fMessenger =
new
F03PrimaryGeneratorMessenger
(
this
);
72
73
// default particle kinematic
74
75
G4ParticleTable
* particleTable =
G4ParticleTable::GetParticleTable
();
76
G4String
particleName;
77
G4ParticleDefinition
* particle
78
= particleTable->
FindParticle
(particleName=
"e-"
);
79
fParticleGun->
SetParticleDefinition
(particle);
80
81
fgPrimaryParticleName = particle->
GetParticleName
() ;
82
83
fParticleGun->
SetParticleMomentumDirection
(
G4ThreeVector
(0.,0.,-1.));
84
fParticleGun->
SetParticleEnergy
(1.*
GeV
);
85
86
fZVertex=fDetector->
GetAbsorberZpos
()-0.5*(fDetector->
GetAbsorberThickness
());
87
fParticleGun->
SetParticlePosition
(
G4ThreeVector
(fXVertex,fYVertex,fZVertex));
88
89
}
90
91
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
92
93
F03PrimaryGeneratorAction::~F03PrimaryGeneratorAction
()
94
{
95
delete
fParticleGun;
96
delete
fMessenger;
97
}
98
99
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
100
101
void
F03PrimaryGeneratorAction::GeneratePrimaries
(
G4Event
* anEvent)
102
{
103
//this function is called at the begining of event
104
//
105
fgPrimaryParticleName
106
= fParticleGun->
GetParticleDefinition
()->
GetParticleName
() ;
107
G4double
x0,y0,z0 ;
108
if
(fVertexDefined)
109
{
110
x0 = fXVertex ;
111
y0 = fYVertex ;
112
z0 = fZVertex ;
113
}
114
else
115
{
116
x0 = 0. ;
117
y0 = 0. ;
118
z0 = fDetector->
GetAbsorberZpos
()-0.5*(fDetector->
GetAbsorberThickness
());
119
}
120
G4double
r0, phi0;
121
122
if
(fRndmFlag ==
"on"
)
123
{
124
r0 = (fDetector->
GetAbsorberRadius
())*std::sqrt(
G4UniformRand
());
125
phi0 =
twopi
*
G4UniformRand
();
126
x0 = r0*std::cos(phi0);
127
y0 = r0*std::sin(phi0);
128
}
129
130
fParticleGun->
SetParticlePosition
(
G4ThreeVector
(x0,y0,z0));
131
fParticleGun->
GeneratePrimaryVertex
(anEvent);
132
}
133
134
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
135
136
G4String
F03PrimaryGeneratorAction::GetPrimaryName
()
137
{
138
return
fgPrimaryParticleName ;
139
}
140
141
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
142
143
void
F03PrimaryGeneratorAction::SetXVertex
(
G4double
x
)
144
{
145
fVertexDefined = true ;
146
fXVertex =
x
;
147
G4cout
<<
" X coordinate of the primary vertex = "
<< fXVertex/
mm
148
<<
" mm."
<<
G4endl
;
149
}
150
151
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
152
153
void
F03PrimaryGeneratorAction::SetYVertex
(
G4double
y
)
154
{
155
fVertexDefined = true ;
156
fYVertex =
y
;
157
G4cout
<<
" Y coordinate of the primary vertex = "
<< fYVertex/
mm
158
<<
" mm."
<<
G4endl
;
159
}
160
161
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
162
163
void
F03PrimaryGeneratorAction::SetZVertex
(
G4double
z
)
164
{
165
fVertexDefined = true ;
166
fZVertex =
z
;
167
G4cout
<<
" Z coordinate of the primary vertex = "
<< fZVertex/
mm
168
<<
" mm."
<<
G4endl
;
169
}
170
171
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
Generated on Sat May 25 2013 14:32:25 for Geant4 by
1.8.4