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
advanced
microbeam
src
MicrobeamPrimaryGeneratorAction.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
//
26
// -------------------------------------------------------------------
27
// $Id$
28
// -------------------------------------------------------------------
29
30
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
31
32
#include "
G4SystemOfUnits.hh
"
33
#include "
G4Event.hh
"
34
#include "
G4ParticleTable.hh
"
35
#include "
Randomize.hh
"
36
37
#include "
MicrobeamPrimaryGeneratorAction.hh
"
38
#include "
MicrobeamDetectorConstruction.hh
"
39
40
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
41
42
MicrobeamPrimaryGeneratorAction::MicrobeamPrimaryGeneratorAction
(
MicrobeamDetectorConstruction
* DC)
43
:Detector(DC)
44
{
45
particleGun =
new
G4ParticleGun
(1);
46
}
47
48
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
49
50
MicrobeamPrimaryGeneratorAction::~MicrobeamPrimaryGeneratorAction
()
51
{
52
delete
particleGun;
53
}
54
55
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
56
57
void
MicrobeamPrimaryGeneratorAction::GeneratePrimaries
(
G4Event
* anEvent)
58
{
59
G4int
numEvent;
60
numEvent=anEvent->
GetEventID
()+1;
61
G4double
x0,y0,z0,theta,phi,xMom0,yMom0,zMom0,e0;
62
63
// INITIAL BEAM POSITION
64
65
z0=-10000*
mm
;
66
x0=10*
mm
;
67
y0=10*
mm
;
68
69
G4double
sizeMax = 0.5*
micrometer
;
// INITIAL BEAM POSITION UNIFORMLY SPREAD ON A DISK
70
while
(! (std::sqrt(x0*x0+y0*y0)<= sizeMax) )
71
{
72
x0 =
CLHEP::RandFlat::shoot
(-sizeMax,sizeMax);
73
y0 =
CLHEP::RandFlat::shoot
(-sizeMax,sizeMax);
74
}
75
76
// INITIAL BEAM ENERGY
77
78
e0= G4RandGauss::shoot(3*
MeV
,5.0955
e
-5*
MeV
);
// AIFIRA ENERGY RESOLUTION
79
80
// INITIAL BEAM DIVERGENCE
81
82
do
{
83
theta=std::acos(1-
G4UniformRand
()*(1.0-std::cos(1.1
e
-6)))*
rad
;
84
}
85
while
(theta>1.1
e
-6*
rad
);
86
87
phi=CLHEP::twopi*
G4UniformRand
()*
rad
;
88
89
xMom0=std::sin(theta)*std::cos(phi);
90
yMom0=std::sin(theta)*std::sin(phi);
91
zMom0=std::cos(theta);
92
93
// VERBOSE
94
95
G4cout
96
<<
"-> Event # "
<< numEvent
97
<<
" generated "
98
<<
G4endl
;
99
100
/*
101
G4cout
102
<< "-> Event # " << numEvent
103
<< " : THETA from Z axis (mrad) = " << theta*1000
104
<< " -- PHI (deg) = " << phi*180/CLHEP::pi
105
<< " -- x0 (um) = " << x0/micrometer
106
<< " -- y0 (um) = " << y0/micrometer
107
<< " -- z0 (m) = " << z0/m
108
<< " -- e0 (MeV) = " << e0/MeV
109
<< G4endl;
110
*/
111
112
particleGun->
SetParticleEnergy
(e0);
113
114
particleGun->
SetParticleMomentumDirection
(
G4ThreeVector
(xMom0,yMom0,zMom0));
115
116
particleGun->
SetParticlePosition
(
G4ThreeVector
(x0,y0,z0));
117
118
G4ParticleDefinition
* particle=
119
G4ParticleTable::GetParticleTable
()->
FindParticle
(
"alpha"
);
120
121
particleGun->
SetParticleDefinition
(particle);
122
123
particleGun->
GeneratePrimaryVertex
(anEvent);
124
125
}
126
127
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
128
129
Generated on Sat May 25 2013 14:32:14 for Geant4 by
1.8.4