Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ParticleHPLabAngularEnergy.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// neutron_hp -- source file
27// J.P. Wellisch, Nov-1996
28// A prototype of the low energy neutron transport model.
29//
30// 080808 Bug fix in serching mu bin and index for theBuff2b by T. Koi
31//
32// P. Arce, June-2014 Conversion neutron_hp to particle_hp
33//
34// E. Mendoza, Nov. 2020 - bug fix
35//
38#include "G4SystemOfUnits.hh"
39#include "Randomize.hh"
40#include "G4Gamma.hh"
41#include "G4Electron.hh"
42#include "G4Positron.hh"
43#include "G4Neutron.hh"
44#include "G4Proton.hh"
45#include "G4Deuteron.hh"
46#include "G4Triton.hh"
47#include "G4He3.hh"
48#include "G4Alpha.hh"
49
50void G4ParticleHPLabAngularEnergy::Init(std::istream & aDataFile)
51{
52 aDataFile >> nEnergies;
53 theManager.Init(aDataFile);
54 theEnergies = new G4double[nEnergies];
55 nCosTh = new G4int[nEnergies];
56 theData = new G4ParticleHPVector * [nEnergies];
57 theSecondManager = new G4InterpolationManager [nEnergies];
58 for(G4int i=0; i<nEnergies; i++)
59 {
60 aDataFile >> theEnergies[i];
61 theEnergies[i]*=eV;
62 aDataFile >> nCosTh[i];
63 theSecondManager[i].Init(aDataFile);
64 theData[i] = new G4ParticleHPVector[nCosTh[i]];
65 G4double label;
66 for(G4int ii=0; ii<nCosTh[i]; ii++)
67 {
68 aDataFile >> label;
69 theData[i][ii].SetLabel(label);
70 theData[i][ii].Init(aDataFile, eV);
71 }
72 }
73}
74
76{
78 G4int Z = static_cast<G4int>(massCode/1000);
79 G4int A = static_cast<G4int>(massCode-1000*Z);
80
81 if(massCode==0)
82 {
84 }
85 else if(A==0)
86 {
88 if(Z==1) result->SetDefinition(G4Positron::Positron());
89 }
90 else if(A==1)
91 {
93 if(Z==1) result->SetDefinition(G4Proton::Proton());
94 }
95 else if(A==2)
96 {
98 }
99 else if(A==3)
100 {
102 if(Z==2) result->SetDefinition(G4He3::He3());
103 }
104 else if(A==4)
105 {
106 result->SetDefinition(G4Alpha::Alpha());
107 if(Z!=2) throw G4HadronicException(__FILE__, __LINE__, "Unknown ion case 1");
108 }
109 else
110 {
111 throw G4HadronicException(__FILE__, __LINE__, "G4ParticleHPLabAngularEnergy: Unknown ion case 2");
112 }
113
114 // get theta, E
115 G4double cosTh, secEnergy;
116 G4int i, it(0);
117 // find the energy bin
118 for(i=0; i<nEnergies; i++)
119 {
120 it = i;
121 if ( anEnergy < theEnergies[i] ) break;
122 }
123
124 if ( it == 0 ) // it marks the energy bin --> we do not extrapolate to low energies, we extrapolate to high energies (??)
125 {
126 //Do not sample between incident neutron energies:
127 //---------------------------------------------------------
128 //CosTheta:
129 G4ParticleHPVector theThVec;
130 theThVec.SetInterpolationManager(theSecondManager[it]);
131 for(i=0; i<nCosTh[it]; i++)
132 {
133 theThVec.SetX(i, theData[it][i].GetLabel());
134 theThVec.SetY(i, theData[it][i].GetIntegral());
135 }
136 cosTh=theThVec.Sample();
137 //---------------------------------------------------------
138
139 //---------------------------------------------------------
140 //Now the secondary energy:
141 G4double x, x1, x2, y1, y2, y, E;
142 G4int i1(0);
143 for(i=1; i<nCosTh[it]; i++)
144 {
145 i1 = i;
146 if(cosTh<theData[it][i].GetLabel()) break;
147 }
148 // now get the prob at this energy for the right theta value
149 x = cosTh;
150 x1 = theData[it][i1-1].GetLabel();
151 x2 = theData[it][i1].GetLabel();
152 G4ParticleHPVector theBuff1a;
153 theBuff1a.SetInterpolationManager(theData[it][i1-1].GetInterpolationManager());
154 for(i=0;i<theData[it][i1-1].GetVectorLength(); i++)
155 {
156 E = theData[it][i1-1].GetX(i);
157 y1 = theData[it][i1-1].GetY(i);
158 y2 = theData[it][i1].GetY(E);
159 y = theInt.Interpolate(theSecondManager[it].GetScheme(i1), x, x1,x2,y1,y2);
160 theBuff1a.SetData(i, E, y);
161 }
162 G4ParticleHPVector theBuff2a;
163 theBuff2a.SetInterpolationManager(theData[it][i1].GetInterpolationManager());
164 for(i=0;i<theData[it][i1].GetVectorLength(); i++)
165 {
166 E = theData[it][i1].GetX(i);
167 y1 = theData[it][i1-1].GetY(E);
168 y2 = theData[it][i1].GetY(i);
169 y = theInt.Interpolate(theSecondManager[it].GetScheme(i1), x, x1,x2,y1,y2);
170 theBuff2a.SetData(i, E, y); // wrong E, right theta.
171 }
172 G4ParticleHPVector theStore;
173 theStore.Merge(&theBuff1a, &theBuff2a);
174 secEnergy = theStore.Sample();
175 currentMeanEnergy = theStore.GetMeanX();
176 //---------------------------------------------------------
177 }
178 else // this is the small big else.
179 {
180 G4double x, x1, x2, y1, y2, y, tmp, E;
181 // integrate the prob for each costh, and select theta.
183 for(i=0;i<nCosTh[it-1]; i++)
184 {
185 run1.SetX(i, theData[it-1][i].GetLabel());
186 run1.SetY(i,theData[it-1][i].GetIntegral());
187 }
189 for(i=0;i<nCosTh[it]; i++)
190 {
191 run2.SetX(i, theData[it][i].GetLabel());
192 run2.SetY(i, theData[it][i].GetIntegral());
193 }
194 // get the distributions for the correct neutron energy
195 x = anEnergy;
196 x1 = theEnergies[it-1];
197 x2 = theEnergies[it];
198 G4ParticleHPVector thBuff1; // to be interpolated as run1.
199 thBuff1.SetInterpolationManager(theSecondManager[it-1]);
200 for(i=0; i<run1.GetVectorLength(); i++)
201 {
202 tmp = run1.GetX(i); //theta
203 y1 = run1.GetY(i); // integral
204 y2 = run2.GetY(tmp);
205 y = theInt.Interpolate(theManager.GetScheme(it), x, x1,x2,y1,y2);
206 thBuff1.SetData(i, tmp, y);
207 }
208 G4ParticleHPVector thBuff2;
209 thBuff2.SetInterpolationManager(theSecondManager[it]);
210 for(i=0; i<run2.GetVectorLength(); i++)
211 {
212 tmp = run2.GetX(i); //theta
213 y1 = run1.GetY(tmp); // integral
214 y2 = run2.GetY(i);
215 y = theInt.Interpolate(theManager.GetScheme(it), x, x1,x2,y1,y2);
216 thBuff2.SetData(i, tmp, y);
217 }
218 G4ParticleHPVector theThVec;
219 theThVec.Merge(&thBuff1 ,&thBuff2); // takes care of interpolation
220 cosTh=theThVec.Sample();
221 /*
222 if(massCode>0.99 && massCode<1.01){theThVec.Dump();}
223 G4double random = (theThVec.GetY(theThVec.GetVectorLength()-1)
224 -theThVec.GetY(0)) *G4UniformRand();
225 G4cout<<" -- "<<theThVec.GetY(theThVec.GetVectorLength()-1)<<" "<<theThVec.GetY(0)<<" ----> "<<random<<G4endl;
226 G4int ith(0);
227 for(i=1;i<theThVec.GetVectorLength(); i++)
228 {
229 ith = i;
230 if(random<theThVec.GetY(i)-theThVec.GetY(0)) break;
231 }
232 {
233 // calculate theta
234 G4double xx, xx1, xx2, yy1, yy2;
235 xx = random;
236 xx1 = theThVec.GetY(ith-1)-theThVec.GetY(0); // integrals
237 xx2 = theThVec.GetY(ith)-theThVec.GetY(0);
238 yy1 = theThVec.GetX(ith-1); // std::cos(theta)
239 yy2 = theThVec.GetX(ith);
240 cosTh = theInt.Interpolate(theSecondManager[it].GetScheme(ith),
241 xx, xx1,xx2,yy1,yy2);
242 }
243 */
244 G4int i1(0), i2(0);
245 // get the indixes of the vectors close to theta for low energy
246 // first it-1 !!!! i.e. low in energy
247 for(i=1; i<nCosTh[it-1]; i++)
248 {
249 i1 = i;
250 if(cosTh<theData[it-1][i].GetLabel()) break;
251 }
252 // now get the prob at this energy for the right theta value
253 x = cosTh;
254 x1 = theData[it-1][i1-1].GetLabel();
255 x2 = theData[it-1][i1].GetLabel();
256 G4ParticleHPVector theBuff1a;
257 theBuff1a.SetInterpolationManager(theData[it-1][i1-1].GetInterpolationManager());
258 for(i=0;i<theData[it-1][i1-1].GetVectorLength(); i++)
259 {
260 E = theData[it-1][i1-1].GetX(i);
261 y1 = theData[it-1][i1-1].GetY(i);
262 y2 = theData[it-1][i1].GetY(E);
263 y = theInt.Interpolate(theSecondManager[it-1].GetScheme(i1), x, x1,x2,y1,y2);
264 theBuff1a.SetData(i, E, y); // wrong E, right theta.
265 }
266 G4ParticleHPVector theBuff2a;
267 theBuff2a.SetInterpolationManager(theData[it-1][i1].GetInterpolationManager());
268 for(i=0;i<theData[it-1][i1].GetVectorLength(); i++)
269 {
270 E = theData[it-1][i1].GetX(i);
271 y1 = theData[it-1][i1-1].GetY(E);
272 y2 = theData[it-1][i1].GetY(i);
273 y = theInt.Interpolate(theSecondManager[it-1].GetScheme(i1), x, x1,x2,y1,y2);
274 theBuff2a.SetData(i, E, y); // wrong E, right theta.
275 }
276 G4ParticleHPVector theStore1;
277 theStore1.Merge(&theBuff1a, &theBuff2a); // wrong E, right theta, complete binning
278
279 // get the indixes of the vectors close to theta for high energy
280 // then it !!!! i.e. high in energy
281 for(i=1; i<nCosTh[it]; i++)
282 {
283 i2 = i;
284 if(cosTh<theData[it][i2].GetLabel()) break;
285 } // sonderfaelle mit i1 oder i2 head on fehlen. @@@@@
286 x1 = theData[it][i2-1].GetLabel();
287 x2 = theData[it][i2].GetLabel();
288 G4ParticleHPVector theBuff1b;
289 theBuff1b.SetInterpolationManager(theData[it][i2-1].GetInterpolationManager());
290 for(i=0;i<theData[it][i2-1].GetVectorLength(); i++)
291 {
292 E = theData[it][i2-1].GetX(i);
293 y1 = theData[it][i2-1].GetY(i);
294 y2 = theData[it][i2].GetY(E);
295 y = theInt.Interpolate(theSecondManager[it].GetScheme(i2), x, x1,x2,y1,y2);
296 theBuff1b.SetData(i, E, y); // wrong E, right theta.
297 }
298 G4ParticleHPVector theBuff2b;
299 theBuff2b.SetInterpolationManager(theData[it][i2].GetInterpolationManager());
300 //080808 i1 -> i2
301 //for(i=0;i<theData[it][i1].GetVectorLength(); i++)
302 for(i=0;i<theData[it][i2].GetVectorLength(); i++)
303 {
304 //E = theData[it][i1].GetX(i);
305 //y1 = theData[it][i1-1].GetY(E);
306 //y2 = theData[it][i1].GetY(i);
307 E = theData[it][i2].GetX(i);
308 y1 = theData[it][i2-1].GetY(E);
309 y2 = theData[it][i2].GetY(i);
310 y = theInt.Interpolate(theSecondManager[it].GetScheme(i2), x, x1,x2,y1,y2);
311 theBuff2b.SetData(i, E, y); // wrong E, right theta.
312 }
313 G4ParticleHPVector theStore2;
314 theStore2.Merge(&theBuff1b, &theBuff2b); // wrong E, right theta, complete binning
315 // now get to the right energy.
316
317 x = anEnergy;
318 x1 = theEnergies[it-1];
319 x2 = theEnergies[it];
320 G4ParticleHPVector theOne1;
322 for(i=0; i<theStore1.GetVectorLength(); i++)
323 {
324 E = theStore1.GetX(i);
325 y1 = theStore1.GetY(i);
326 y2 = theStore2.GetY(E);
327 y = theInt.Interpolate(theManager.GetScheme(it), x, x1,x2,y1,y2);
328 theOne1.SetData(i, E, y); // both correct
329 }
330 G4ParticleHPVector theOne2;
332 for(i=0; i<theStore2.GetVectorLength(); i++)
333 {
334 E = theStore2.GetX(i);
335 y1 = theStore1.GetY(E);
336 y2 = theStore2.GetY(i);
337 y = theInt.Interpolate(theManager.GetScheme(it), x, x1,x2,y1,y2);
338 theOne2.SetData(i, E, y); // both correct
339 }
340 G4ParticleHPVector theOne;
341 theOne.Merge(&theOne1, &theOne2); // both correct, complete binning
342
343 secEnergy = theOne.Sample();
344 currentMeanEnergy = theOne.GetMeanX();
345 }
346
347// now do random direction in phi, and fill the result.
348
349 result->SetKineticEnergy(secEnergy);
350
351 G4double phi = twopi*G4UniformRand();
352 G4double theta = std::acos(cosTh);
353 G4double sinth = std::sin(theta);
354 G4double mtot = result->GetTotalMomentum();
355 G4ThreeVector tempVector(mtot*sinth*std::cos(phi), mtot*sinth*std::sin(phi), mtot*std::cos(theta) );
356 result->SetMomentum(tempVector);
357
358 return result;
359}
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
const G4int Z[17]
const G4double A[17]
#define G4UniformRand()
Definition: Randomize.hh:52
static G4Alpha * Alpha()
Definition: G4Alpha.cc:88
static G4Deuteron * Deuteron()
Definition: G4Deuteron.cc:93
static G4Electron * Electron()
Definition: G4Electron.cc:93
static G4Gamma * Gamma()
Definition: G4Gamma.cc:85
static G4He3 * He3()
Definition: G4He3.cc:93
void Init(G4int aScheme, G4int aRange)
G4InterpolationScheme GetScheme(G4int index) const
static G4Neutron * Neutron()
Definition: G4Neutron.cc:103
G4double Interpolate(G4InterpolationScheme aScheme, G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
void Init(std::istream &aDataFile)
G4ReactionProduct * Sample(G4double anEnergy, G4double massCode, G4double mass)
void SetY(G4int i, G4double x)
void SetX(G4int i, G4double e)
void SetData(G4int i, G4double x, G4double y)
const G4InterpolationManager & GetInterpolationManager() const
void SetLabel(G4double aLabel)
void SetInterpolationManager(const G4InterpolationManager &aManager)
G4double GetY(G4double x)
G4double GetX(G4int i) const
void Merge(G4ParticleHPVector *active, G4ParticleHPVector *passive)
void Init(std::istream &aDataFile, G4int total, G4double ux=1., G4double uy=1.)
G4int GetVectorLength() const
static G4Positron * Positron()
Definition: G4Positron.cc:93
static G4Proton * Proton()
Definition: G4Proton.cc:92
void SetMomentum(const G4double x, const G4double y, const G4double z)
G4double GetTotalMomentum() const
void SetDefinition(const G4ParticleDefinition *aParticleDefinition)
void SetKineticEnergy(const G4double en)
static G4Triton * Triton()
Definition: G4Triton.cc:93