ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
F01PrimaryGeneratorAction.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file F01PrimaryGeneratorAction.cc
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
//
31
//
32
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34
35
#include "
F01PrimaryGeneratorAction.hh
"
36
37
#include "
F01DetectorConstruction.hh
"
38
#include "
F01PrimaryGeneratorMessenger.hh
"
39
40
#include "
G4Event.hh
"
41
#include "
G4ParticleGun.hh
"
42
#include "
G4ParticleTable.hh
"
43
#include "
G4ParticleDefinition.hh
"
44
45
#include "
Randomize.hh
"
46
#include "
G4SystemOfUnits.hh
"
47
#include "
G4PhysicalConstants.hh
"
48
49
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50
51
G4ParticleDefinition
*
F01PrimaryGeneratorAction::fgPrimaryParticle
= 0;
52
53
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54
55
F01PrimaryGeneratorAction::F01PrimaryGeneratorAction
(
56
F01DetectorConstruction
* det)
57
:
G4VUserPrimaryGeneratorAction
(),
58
fParticleGun(0),
59
fDetector(det),
60
fGunMessenger(0),
61
fRndmFlag(
"off"
),
62
fXVertex(0.),
63
fYVertex(0.),
64
fZVertex(0.),
65
fVertexDefined(
false
)
66
{
67
G4int
n_particle = 1;
68
fParticleGun
=
new
G4ParticleGun
(n_particle);
69
70
// create a messenger for this class
71
fGunMessenger
=
new
F01PrimaryGeneratorMessenger
(
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
fgPrimaryParticle
=
particle
;
82
83
fParticleGun
->
SetParticleMomentumDirection
(
G4ThreeVector
(0.,0.,-1.));
84
fParticleGun
->
SetParticleEnergy
(0.5*
GeV
);
85
86
fZVertex
=
fDetector
->
GetAbsorberZpos
() -
87
0.5*(
fDetector
->
GetAbsorberThickness
());
88
fParticleGun
->
SetParticlePosition
(
G4ThreeVector
(
fXVertex
,
fYVertex
,
fZVertex
));
89
90
}
91
92
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
93
94
F01PrimaryGeneratorAction::~F01PrimaryGeneratorAction
()
95
{
96
delete
fParticleGun
;
97
delete
fGunMessenger
;
98
}
99
100
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
101
102
void
F01PrimaryGeneratorAction::GeneratePrimaries
(
G4Event
* anEvent)
103
{
104
// this function is called at the begining of event
105
//
106
fgPrimaryParticle
=
fParticleGun
->
GetParticleDefinition
();
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 =
fDetector
->
GetAbsorberZpos
()-0.5*(
fDetector
->
GetAbsorberThickness
());
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
131
fParticleGun
->
SetParticlePosition
(
G4ThreeVector
(x0,y0,z0));
132
fParticleGun
->
GeneratePrimaryVertex
(anEvent);
133
}
134
135
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
136
137
G4String
F01PrimaryGeneratorAction::GetPrimaryName
()
138
{
139
return
fgPrimaryParticle
->
GetParticleName
();
140
}
141
142
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
143
144
void
F01PrimaryGeneratorAction::SetZVertex
(
G4double
z
)
145
{
146
fVertexDefined
=
true
;
147
fZVertex
=
z
;
148
G4cout
<<
" Z coordinate of the primary vertex = "
<<
fZVertex
/
mm
<<
149
" mm."
<<
G4endl
;
150
}
151
152
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
153
154
void
F01PrimaryGeneratorAction::SetXVertex
(
G4double
x
)
155
{
156
fVertexDefined
=
true
;
157
fXVertex
=
x
;
158
G4cout
<<
" X coordinate of the primary vertex = "
<<
fXVertex
/
mm
<<
159
" mm."
<<
G4endl
;
160
}
161
162
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
163
164
void
F01PrimaryGeneratorAction::SetYVertex
(
G4double
y
)
165
{
166
fVertexDefined
=
true
;
167
fYVertex
=
y
;
168
G4cout
<<
" Y coordinate of the primary vertex = "
<<
fYVertex
/
mm
<<
169
" mm."
<<
G4endl
;
170
}
171
172
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
geant4
tree
geant4-10.6-release
examples
extended
field
field01
src
F01PrimaryGeneratorAction.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:25:04
using
1.8.2 with
ECCE GitHub integration