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
PrimaryGeneratorAction.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file PrimaryGeneratorAction.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
//
26
//
29
//
30
31
//---------------------------------------------------------------------------
32
//
33
// ClassName: PrimaryGeneratorAction
34
//
35
// Description: Generate primary beam
36
//
37
// Authors: V.Grichine, V.Ivanchenko
38
//
39
// Modified:
40
//
41
//----------------------------------------------------------------------------
42
//
43
44
#include "PrimaryGeneratorAction.hh"
45
#include "DetectorConstruction.hh"
46
#include "PrimaryGeneratorMessenger.hh"
47
#include "
Randomize.hh
"
48
#include "
G4ParticleGun.hh
"
49
#include "
G4ParticleTable.hh
"
50
#include "
G4ParticleDefinition.hh
"
51
#include "
G4PhysicalConstants.hh
"
52
#include "
G4SystemOfUnits.hh
"
53
54
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
55
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
56
57
PrimaryGeneratorAction::PrimaryGeneratorAction
(
DetectorConstruction
* pDet):
58
fDetector(pDet)
59
{
60
InitializeMe
();
61
}
62
63
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
64
65
void
PrimaryGeneratorAction::InitializeMe
()
66
{
67
fVerbose
=
fDetector
->
GetVerbose
();
68
fMessenger
=
new
PrimaryGeneratorMessenger
(
this
);
69
fParticleGun
=
new
G4ParticleGun
();
70
fCounter
= 0;
71
fX0
= 0.0;
72
fY0
= 0.0;
73
fZ0
= 0.0;
74
fSigmaX
= 1.5*
mm
;
75
fSigmaY
= 1.5*
mm
;
76
fSigmaZ
= 0.0;
77
fSigmaE
= 0.0;
78
fRMax2
= 2.5*2.5*
mm
*
mm
;
79
fSigmaTheta
= 0.0;
80
// fSigmaTheta = 0.17*degree;
81
fMinCosTheta
= 2.0;
82
SetBeamEnergy
(50.0*
MeV
);
83
fPosition
=
G4ThreeVector
(
fX0
,
fY0
,
fZ0
);
84
fDirection
=
G4ThreeVector
(0.0,0.0,1.0);
85
fGauss
=
true
;
86
}
87
88
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
89
90
PrimaryGeneratorAction::~PrimaryGeneratorAction
()
91
{
92
delete
fParticleGun
;
93
delete
fMessenger
;
94
}
95
96
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
97
98
void
PrimaryGeneratorAction::GeneratePrimaries
(
G4Event
* anEvent)
99
{
100
fCounter
++ ;
101
102
// Simulation of beam position
103
G4double
x
=
fX0
;
104
G4double
y
=
fY0
;
105
G4double
z
=
fDetector
->
GetGeneratorPosZ
();
106
do
{
107
if
(0.0 <
fSigmaX
) { x =
G4RandGauss::shoot
(
fX0
,
fSigmaX
); }
108
if
(0.0 <
fSigmaY
) { y =
G4RandGauss::shoot
(
fY0
,
fSigmaY
); }
109
}
while
(x*x + y*y >
fRMax2
);
110
111
fPosition
=
G4ThreeVector
(x,y,z);
112
fParticleGun
->
SetParticlePosition
(
fPosition
);
113
114
// Simulation of beam direction
115
G4double
ux
=
fDirection
.
x
();
116
G4double
uy
=
fDirection
.
y
();
117
G4double
uz =
fDirection
.
z
();
118
119
// Beam particles are uniformly distributed over phi, cosTheta
120
if
(1.0 >
fMinCosTheta
) {
121
uz =
fMinCosTheta
+ (1.0 -
fMinCosTheta
)*
G4UniformRand
() ;
122
ux = std::sqrt((1.0 - uz)*(1.0 + uz)) ;
123
}
else
if
(
fSigmaTheta
> 0.0) {
124
ux =
G4RandGauss::shoot
(0.0,
fSigmaTheta
);
125
uz = std::sqrt((1.0 - ux)*(1.0 + ux));
126
}
127
128
G4double
phi
=
twopi
*
G4UniformRand
() ;
129
uy =
ux
;
130
ux *= std::cos(phi) ;
131
uy *= std::sin(phi) ;
132
fDirection
=
G4ThreeVector
(ux,uy,uz) ;
133
134
fParticleGun
->
SetParticleMomentumDirection
(
fDirection
);
135
136
// Simulation of beam kinetic energy
137
G4double
kinEnergy =
fEnergy
;
138
139
if
(
fGauss
==
"flatE"
) {
140
kinEnergy =
fEnergy
-
fSigmaE
+ 2.*
fSigmaE
*
G4UniformRand
();
141
}
else
if
(0.0 <
fSigmaE
) {
142
kinEnergy =
fEnergy
+
G4RandGauss::shoot
(0.0,
fSigmaE
);
143
}
144
fParticleGun
->
SetParticleEnergy
(kinEnergy);
145
146
if
(
fVerbose
> 0) {
147
G4ParticleDefinition
*
particle
=
fParticleGun
->
GetParticleDefinition
();
148
G4String
particleName = particle->
GetParticleName
() ;
149
G4cout
<<
"Event# "
<<
fCounter
150
<<
" Beam particle is generated by PrimaryGeneratorAction "
151
<<
G4endl
;
152
G4cout
<<
"ParticleName= "
<< particleName
153
<<
" PDGcode= "
<< particle->
GetPDGEncoding
()
154
<< std::setprecision(5)
155
<<
" KinEnergy(GeV)= "
156
<<
fEnergy
/
GeV
157
<<
" x(mm)= "
158
<< x/
mm
159
<<
" y(mm)= "
160
<< y/
mm
161
<<
" z(mm)= "
162
<< z/
mm
163
<<
" ux= "
164
<< ux
165
<<
" uy= "
166
<< uy
167
<<
" uz= "
168
<< uz
169
<<
G4endl
;
170
}
171
172
fParticleGun
->
GeneratePrimaryVertex
(anEvent);
173
}
174
175
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
176
177
void
PrimaryGeneratorAction::SetBeamEnergy
(
G4double
val)
178
{
179
fEnergy
= val;
180
if
(fEnergy<fDetector->GetMaxEnergy())
fDetector
->
SetMaxEnergy
(
fEnergy
);
181
}
182
183
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
184
185
186
geant4
tree
geant4-10.6-release
examples
extended
medical
GammaTherapy
src
PrimaryGeneratorAction.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:24:51
using
1.8.2 with
ECCE GitHub integration