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 | // |
---|
29 | // ClassName: PrimaryGeneratorAction |
---|
30 | // |
---|
31 | // Description: Generate primary beam |
---|
32 | // |
---|
33 | // Authors: V.Grichine, V.Ivanchenko |
---|
34 | // |
---|
35 | // Modified: |
---|
36 | // |
---|
37 | //---------------------------------------------------------------------------- |
---|
38 | // |
---|
39 | |
---|
40 | #include "PrimaryGeneratorAction.hh" |
---|
41 | #include "DetectorConstruction.hh" |
---|
42 | #include "PrimaryGeneratorMessenger.hh" |
---|
43 | #include "Randomize.hh" |
---|
44 | #include "G4ParticleGun.hh" |
---|
45 | #include "G4ParticleTable.hh" |
---|
46 | #include "G4ParticleDefinition.hh" |
---|
47 | #include "Histo.hh" |
---|
48 | |
---|
49 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
50 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
51 | |
---|
52 | PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction* pDet): |
---|
53 | fDetector(pDet) |
---|
54 | { |
---|
55 | InitializeMe(); |
---|
56 | } |
---|
57 | |
---|
58 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
59 | |
---|
60 | void PrimaryGeneratorAction::InitializeMe() |
---|
61 | { |
---|
62 | theMessenger = new PrimaryGeneratorMessenger(this); |
---|
63 | particleGun = new G4ParticleGun(); |
---|
64 | counter = 0; |
---|
65 | verbose = 0; |
---|
66 | x0 = 0.0; |
---|
67 | y0 = 0.0; |
---|
68 | z0 = 0.0; |
---|
69 | sigmaX = 1.5*mm; |
---|
70 | sigmaY = 1.5*mm; |
---|
71 | sigmaZ = 0.0; |
---|
72 | sigmaE = 0.0; |
---|
73 | rMax2 = 2.5*2.5*mm*mm; |
---|
74 | sigmaTheta = 0.0; |
---|
75 | // sigmaTheta = 0.17*degree; |
---|
76 | minCosTheta = 2.0; |
---|
77 | SetBeamEnergy(50.0*MeV); |
---|
78 | position = G4ThreeVector(x0,y0,z0); |
---|
79 | direction = G4ThreeVector(0.0,0.0,1.0); |
---|
80 | m_gauss = true; |
---|
81 | if(energy < (Histo::GetPointer())->GetMaxEnergy()) |
---|
82 | (Histo::GetPointer())->SetMaxEnergy(energy); |
---|
83 | } |
---|
84 | |
---|
85 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
86 | |
---|
87 | PrimaryGeneratorAction::~PrimaryGeneratorAction() |
---|
88 | { |
---|
89 | delete particleGun; |
---|
90 | delete theMessenger; |
---|
91 | } |
---|
92 | |
---|
93 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
94 | |
---|
95 | void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) |
---|
96 | { |
---|
97 | counter++ ; |
---|
98 | verbose = (Histo::GetPointer())->GetVerbose(); |
---|
99 | |
---|
100 | // Simulation of beam position |
---|
101 | G4double x = x0; |
---|
102 | G4double y = y0; |
---|
103 | G4double z = fDetector->GetGeneratorPosZ(); |
---|
104 | do { |
---|
105 | if(0.0 < sigmaX) x = G4RandGauss::shoot(x0,sigmaX); |
---|
106 | if(0.0 < sigmaY) y = G4RandGauss::shoot(y0,sigmaY); |
---|
107 | } while (x*x + y*y > rMax2); |
---|
108 | |
---|
109 | position = G4ThreeVector(x,y,z); |
---|
110 | particleGun->SetParticlePosition(position); |
---|
111 | |
---|
112 | // Simulation of beam direction |
---|
113 | G4double ux = direction.x(); |
---|
114 | G4double uy = direction.y(); |
---|
115 | G4double uz = direction.z(); |
---|
116 | |
---|
117 | // Beam particles are uniformly distributed over phi, cosTheta |
---|
118 | if(1.0 > minCosTheta) { |
---|
119 | uz = minCosTheta + (1.0 - minCosTheta)*G4UniformRand() ; |
---|
120 | ux = std::sqrt(1.0 - uz*uz) ; |
---|
121 | } else if (sigmaTheta > 0.0) { |
---|
122 | ux = G4RandGauss::shoot(0.0,sigmaTheta); |
---|
123 | uz = std::sqrt(1.0 - ux*ux); |
---|
124 | } |
---|
125 | |
---|
126 | G4double phi = twopi*G4UniformRand() ; |
---|
127 | uy = ux ; |
---|
128 | ux *= std::cos(phi) ; |
---|
129 | uy *= std::sin(phi) ; |
---|
130 | direction = G4ThreeVector(ux,uy,uz) ; |
---|
131 | |
---|
132 | direction = direction.unit(); |
---|
133 | particleGun->SetParticleMomentumDirection(direction); |
---|
134 | G4ParticleDefinition* particle = particleGun->GetParticleDefinition(); |
---|
135 | |
---|
136 | // Simulation of beam kinetic energy |
---|
137 | G4double kinEnergy = energy; |
---|
138 | |
---|
139 | if(m_gauss == "flatE") kinEnergy = energy - sigmaE + 2.*sigmaE*G4UniformRand(); |
---|
140 | else if(0.0 < sigmaE) kinEnergy = energy + G4RandGauss::shoot(0.0,sigmaE); |
---|
141 | |
---|
142 | particleGun->SetParticleEnergy(kinEnergy); |
---|
143 | |
---|
144 | G4String particleName = particle->GetParticleName() ; |
---|
145 | |
---|
146 | if(verbose > 0) { |
---|
147 | G4cout << "Event# " << counter |
---|
148 | << " Beam particle is generated by PrimaryGeneratorAction " |
---|
149 | << G4endl; |
---|
150 | G4cout << "ParticleName= " << particleName |
---|
151 | << " PDGcode= " << particle->GetPDGEncoding() |
---|
152 | << std::setprecision(5) |
---|
153 | << " KinEnergy(GeV)= " |
---|
154 | << energy/GeV |
---|
155 | << " x(mm)= " |
---|
156 | << x/mm |
---|
157 | << " y(mm)= " |
---|
158 | << y/mm |
---|
159 | << " z(mm)= " |
---|
160 | << z/mm |
---|
161 | << " ux= " |
---|
162 | << ux |
---|
163 | << " uy= " |
---|
164 | << uy |
---|
165 | << " uz= " |
---|
166 | << uz |
---|
167 | << G4endl; |
---|
168 | } |
---|
169 | |
---|
170 | particleGun->GeneratePrimaryVertex(anEvent); |
---|
171 | } |
---|
172 | |
---|
173 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
174 | |
---|
175 | void PrimaryGeneratorAction::SetBeamSigmaE(G4double val) |
---|
176 | { |
---|
177 | sigmaE = val; |
---|
178 | } |
---|
179 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
180 | |
---|
181 | void PrimaryGeneratorAction::SetBeamEnergy(G4double val) |
---|
182 | { |
---|
183 | energy = val; |
---|
184 | if(energy < (Histo::GetPointer())->GetMaxEnergy()) |
---|
185 | (Histo::GetPointer())->SetMaxEnergy(energy); |
---|
186 | } |
---|
187 | |
---|
188 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
189 | |
---|
190 | |
---|
191 | |
---|