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
GammaRayTelPrimaryGeneratorAction.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file GammaRayTelPrimaryGeneratorAction.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
//
27
// ------------------------------------------------------------
28
// GEANT 4 class implementation file
29
// CERN Geneva Switzerland
30
//
31
//
32
// ------------ GammaRayTelPrimaryGeneratorAction ------
33
// by G.Santin, F.Longo & R.Giannitrapani (13 nov 2000)
34
//
35
// ************************************************************
36
37
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
38
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
39
40
#include "
G4RunManager.hh
"
41
#include "
GammaRayTelPrimaryGeneratorAction.hh
"
42
43
#include "
GammaRayTelDetectorConstruction.hh
"
44
#include "
GammaRayTelPrimaryGeneratorMessenger.hh
"
45
46
#include "
G4PhysicalConstants.hh
"
47
#include "
G4SystemOfUnits.hh
"
48
#include "
G4Event.hh
"
49
#include "
G4ParticleGun.hh
"
50
#include "
G4GeneralParticleSource.hh
"
51
#include "
G4ParticleTable.hh
"
52
#include "
G4ParticleDefinition.hh
"
53
#include "
Randomize.hh
"
54
55
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
56
57
GammaRayTelPrimaryGeneratorAction::GammaRayTelPrimaryGeneratorAction
()
58
// :rndmFlag("off"),nSourceType(0),nSpectrumType(0),sourceGun(false)
59
{
60
GammaRayTelDetector
=
static_cast<
const
GammaRayTelDetectorConstruction
*
>
61
(
G4RunManager::GetRunManager
()->
GetUserDetectorConstruction
());
62
63
//create a messenger for this class
64
65
gunMessenger
=
new
GammaRayTelPrimaryGeneratorMessenger
(
this
);
66
67
rndmFlag
=
"off"
;
68
nSourceType
= 0;
69
nSpectrumType
= 0;
70
sourceGun
=
false
;
71
dVertexRadius
= 15.*
cm
;
72
73
G4int
n_particle = 1;
74
75
particleGun
=
new
G4ParticleGun
(n_particle);
76
// default particle kinematic
77
78
G4ParticleTable
* particleTable =
G4ParticleTable::GetParticleTable
();
79
G4String
particleName;
80
G4ParticleDefinition
*
particle
81
= particleTable->
FindParticle
(particleName=
"e-"
);
82
particleGun
->
SetParticleDefinition
(particle);
83
particleGun
->
SetParticleMomentumDirection
(
G4ThreeVector
(0.,0.,-1.));
84
particleGun
->
SetParticleEnergy
(30.*
MeV
);
85
G4double
position
= 0.5*(
GammaRayTelDetector
->
GetWorldSizeZ
());
86
particleGun
->
SetParticlePosition
(
G4ThreeVector
(0.*
cm
,0.*
cm
,position));
87
particleSource
=
new
G4GeneralParticleSource
();
88
89
}
90
91
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
92
93
GammaRayTelPrimaryGeneratorAction::~GammaRayTelPrimaryGeneratorAction
()
94
{
95
96
delete
particleGun
;
97
delete
particleSource
;
98
delete
gunMessenger
;
99
}
100
101
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
102
103
void
GammaRayTelPrimaryGeneratorAction::GeneratePrimaries
(
G4Event
* anEvent)
104
{
105
if
(
sourceGun
)
106
{
107
108
G4cout
<<
"Using G4ParticleGun ... "
<<
G4endl
;
109
110
//this function is called at the begining of event
111
//
112
G4double
z0
= 0.5*(
GammaRayTelDetector
->
GetWorldSizeZ
());
113
G4double
x0 = 0.*
cm
, y0 = 0.*
cm
;
114
115
G4ThreeVector
pos0;
116
G4ThreeVector
vertex0 =
G4ThreeVector
(x0,y0,z0);
117
G4ThreeVector
dir0 =
G4ThreeVector
(0.,0.,-1.);
118
119
G4double
theta
,
phi
;
120
G4double
y
= 0.;
121
G4double
f
= 0.;
122
G4double
theta0=0.;
123
G4double
phi0=0.;
124
125
switch
(
nSourceType
) {
126
case
0:
127
particleGun
->
SetParticlePosition
(vertex0);
128
particleGun
->
SetParticleMomentumDirection
(dir0);
129
break
;
130
case
1:
131
// GS: Generate random position on the 4PIsphere to create a unif. distrib.
132
// GS: on the sphere
133
phi =
G4UniformRand
() *
twopi
;
134
do
{
135
y =
G4UniformRand
()*1.0;
136
theta =
G4UniformRand
() *
pi
;
137
f = std::sin(theta);
138
}
while
(y > f);
139
vertex0 =
G4ThreeVector
(1.,0.,0.);
140
vertex0.
setMag
(
dVertexRadius
);
141
vertex0.
setTheta
(theta);
142
vertex0.
setPhi
(phi);
143
particleGun
->
SetParticlePosition
(vertex0);
144
145
dir0 =
G4ThreeVector
(1.,0.,0.);
146
do
{
147
phi =
G4UniformRand
() *
twopi
;
148
do
{
149
y =
G4UniformRand
()*1.0;
150
theta =
G4UniformRand
() *
pi
;
151
f = std::sin(theta);
152
}
while
(y > f);
153
dir0.
setPhi
(phi);
154
dir0.
setTheta
(theta);
155
}
while
(vertex0.
dot
(dir0) >= -0.7 * vertex0.
mag
());
156
particleGun
->
SetParticleMomentumDirection
((
G4ParticleMomentum
)dir0);
157
158
break
;
159
case
2:
160
// GS: Generate random position on the upper semi-sphere z>0 to create a unif. distrib.
161
// GS: on a plane
162
phi =
G4UniformRand
() *
twopi
;
163
do
{
164
y =
G4UniformRand
()*1.0;
165
theta =
G4UniformRand
() *
halfpi
;
166
f = std::sin(theta) * std::cos(theta);
167
}
while
(y > f);
168
vertex0 =
G4ThreeVector
(1.,0.,0.);
169
170
G4double
xy =
GammaRayTelDetector
->
GetWorldSizeXY
();
171
G4double
z
=
GammaRayTelDetector
->
GetWorldSizeZ
();
172
173
if
(
dVertexRadius
> xy*0.5)
174
{
175
G4cout
<<
"vertexRadius too big "
<<
G4endl
;
176
G4cout
<<
"vertexRadius setted to "
<< xy*0.45 <<
G4endl
;
177
dVertexRadius
= xy*0.45;
178
}
179
180
if
(
dVertexRadius
> z*0.5)
181
{
182
G4cout
<<
"vertexRadius too high "
<<
G4endl
;
183
G4cout
<<
"vertexRadius setted to "
<< z*0.45 <<
G4endl
;
184
dVertexRadius
= z*0.45;
185
}
186
187
188
vertex0.
setMag
(
dVertexRadius
);
189
vertex0.
setTheta
(theta);
190
vertex0.
setPhi
(phi);
191
192
// GS: Get the user defined direction for the primaries and
193
// GS: Rotate the random position according to the user defined direction for the particle
194
195
dir0 =
particleGun
->
GetParticleMomentumDirection
();
196
if
(dir0.
mag
() > 0.001)
197
{
198
theta0 = dir0.
theta
();
199
phi0 = dir0.
phi
();
200
}
201
202
if
(theta0!=0.)
203
{
204
G4ThreeVector
rotationAxis(1.,0.,0.);
205
rotationAxis.
setPhi
(phi0+
halfpi
);
206
vertex0.
rotate
(theta0+
pi
,rotationAxis);
207
}
208
particleGun
->
SetParticlePosition
(vertex0);
209
break
;
210
}
211
212
213
G4double
pEnergy = 100*
MeV
;
214
215
switch
(
nSpectrumType
) {
216
case
0:
// Uniform energy (1-10 GeV)
217
y =
G4UniformRand
();
218
pEnergy = y*9.0*
GeV
+ 1.0*
GeV
;
219
G4cout
<< pEnergy/
GeV
<<
" LIN"
<<
G4endl
;
220
break
;
221
case
1:
// Logaritmic energy
222
y =
G4UniformRand
();
223
pEnergy = std::pow(10,y)*
GeV
;
224
G4cout
<< pEnergy/
GeV
<<
" LOG"
<<
G4endl
;
225
break
;
226
case
2:
// Power Law (-4)
227
do
{
228
y =
G4UniformRand
()*100000.0;
229
pEnergy =
G4UniformRand
() * 10. *
GeV
;
230
f = std::pow(pEnergy * (1/
GeV
), -4.);
231
}
while
(y > f);
232
// particleGun->SetParticleEnergy(pEnergy);
233
break
;
234
case
3:
// Monochromatic
235
pEnergy =
particleGun
->
GetParticleEnergy
();
236
//100 * MeV;
237
G4cout
<< pEnergy <<
" MONO"
<<
G4endl
;
238
break
;
239
}
240
particleGun
->
SetParticleEnergy
(pEnergy);
241
G4cout
<<
particleGun
->
GetParticleDefinition
()->
GetParticleName
() <<
G4endl
;
242
particleGun
->
GeneratePrimaryVertex
(anEvent);
243
}
244
else
245
{
246
particleSource
->
GeneratePrimaryVertex
(anEvent);
247
}
248
249
}
250
251
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
252
253
254
255
256
257
258
259
geant4
tree
geant4-10.6-release
examples
advanced
gammaray_telescope
src
GammaRayTelPrimaryGeneratorAction.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:24:58
using
1.8.2 with
ECCE GitHub integration