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 | #include "G4NeutronHPLegendreStore.hh" |
---|
31 | #include "G4NeutronHPVector.hh" |
---|
32 | #include "G4NeutronHPInterpolator.hh" |
---|
33 | #include "G4NeutronHPFastLegendre.hh" |
---|
34 | #include "Randomize.hh" |
---|
35 | #include <iostream> |
---|
36 | |
---|
37 | G4double G4NeutronHPLegendreStore::SampleMax (G4double anEnergy) |
---|
38 | { |
---|
39 | G4double result; |
---|
40 | |
---|
41 | G4int i0; |
---|
42 | G4int low(0), high(0); |
---|
43 | G4NeutronHPFastLegendre theLeg; |
---|
44 | for (i0=0; i0<nEnergy; i0++) |
---|
45 | { |
---|
46 | high = i0; |
---|
47 | if(theCoeff[i0].GetEnergy()>anEnergy) break; |
---|
48 | } |
---|
49 | low = std::max(0, high-1); |
---|
50 | G4NeutronHPInterpolator theInt; |
---|
51 | G4double x, x1, x2; |
---|
52 | x = anEnergy; |
---|
53 | x1 = theCoeff[low].GetEnergy(); |
---|
54 | x2 = theCoeff[high].GetEnergy(); |
---|
55 | G4double theNorm = 0; |
---|
56 | G4double try01=0, try02=0; |
---|
57 | G4double max1, max2, costh; |
---|
58 | max1 = 0; max2 = 0; |
---|
59 | G4int l; |
---|
60 | for(i0=0; i0<601; i0++) |
---|
61 | { |
---|
62 | costh = G4double(i0-300)/300.; |
---|
63 | try01 = 0; |
---|
64 | for(l=0; l<theCoeff[low].GetNumberOfPoly() ; l++) |
---|
65 | { |
---|
66 | try01 += (2.*l+1)/2.*theCoeff[low].GetCoeff(l)*theLeg.Evaluate(l, costh); |
---|
67 | } |
---|
68 | if(try01>max1) max1=try01; |
---|
69 | try02 = 0; |
---|
70 | for(l=0; l<theCoeff[high].GetNumberOfPoly() ; l++) |
---|
71 | { |
---|
72 | try02 += (2.*l+1)/2.*theCoeff[high].GetCoeff(l)*theLeg.Evaluate(l, costh); |
---|
73 | } |
---|
74 | if(try02>max2) max2=try02; |
---|
75 | } |
---|
76 | theNorm = theInt.Interpolate(theManager.GetScheme(high), x, x1, x2, max1, max2); |
---|
77 | |
---|
78 | G4double value, random; |
---|
79 | G4double v1, v2; |
---|
80 | do |
---|
81 | { |
---|
82 | v1 = 0; |
---|
83 | v2 = 0; |
---|
84 | result = 2.*G4UniformRand()-1.; |
---|
85 | for(l=0; l<theCoeff[low].GetNumberOfPoly() ; l++) |
---|
86 | { |
---|
87 | G4double legend = theLeg.Evaluate(l, result); // @@@ done to avoid optimization error on SUN |
---|
88 | v1 += (2.*l+1)/2.*theCoeff[low].GetCoeff(l)*legend; |
---|
89 | } |
---|
90 | for(l=0; l<theCoeff[high].GetNumberOfPoly() ; l++) |
---|
91 | { |
---|
92 | G4double legend = theLeg.Evaluate(l, result); // @@@ done to avoid optimization error on SUN |
---|
93 | v2 += (2.*l+1)/2.*theCoeff[high].GetCoeff(l)*legend; |
---|
94 | } |
---|
95 | v1 = std::max(0.,v1); // Workaround in case one of the distributions is fully non-physical. |
---|
96 | v2 = std::max(0.,v2); |
---|
97 | value = theInt.Interpolate(theManager.GetScheme(high), x, x1, x2, v1, v2); |
---|
98 | random = G4UniformRand(); |
---|
99 | if(0>=theNorm) break; // Workaround for negative cross-section values. @@@@ 31 May 2000 |
---|
100 | } |
---|
101 | while(random>value/theNorm); |
---|
102 | |
---|
103 | return result; |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | G4double G4NeutronHPLegendreStore::SampleElastic (G4double anEnergy) |
---|
108 | { |
---|
109 | G4double result; |
---|
110 | |
---|
111 | G4int i0; |
---|
112 | G4int low(0), high(0); |
---|
113 | G4NeutronHPFastLegendre theLeg; |
---|
114 | for (i0=0; i0<nEnergy; i0++) |
---|
115 | { |
---|
116 | high = i0; |
---|
117 | if(theCoeff[i0].GetEnergy()>anEnergy) break; |
---|
118 | } |
---|
119 | low = std::max(0, high-1); |
---|
120 | G4NeutronHPInterpolator theInt; |
---|
121 | G4double x, x1, x2; |
---|
122 | x = anEnergy; |
---|
123 | x1 = theCoeff[low].GetEnergy(); |
---|
124 | x2 = theCoeff[high].GetEnergy(); |
---|
125 | G4double theNorm = 0; |
---|
126 | G4double try01=0, try02=0, try11=0, try12=0; |
---|
127 | G4double try1, try2; |
---|
128 | G4int l; |
---|
129 | for(l=0; l<theCoeff[low].GetNumberOfPoly(); l++) |
---|
130 | { |
---|
131 | try01 += (2.*l+1)/2.*theCoeff[low].GetCoeff(l)*theLeg.Evaluate(l, -1.); |
---|
132 | try11 += (2.*l+1)/2.*theCoeff[low].GetCoeff(l)*theLeg.Evaluate(l, +1.); |
---|
133 | } |
---|
134 | for(l=0; l<theCoeff[high].GetNumberOfPoly(); l++) |
---|
135 | { |
---|
136 | try02 += (2.*l+1)/2.*theCoeff[high].GetCoeff(l)*theLeg.Evaluate(l, -1.); |
---|
137 | try12 += (2.*l+1)/2.*theCoeff[high].GetCoeff(l)*theLeg.Evaluate(l, +1.); |
---|
138 | } |
---|
139 | try1 = theInt.Interpolate(theManager.GetScheme(high), x, x1, x2, try01, try02); |
---|
140 | try2 = theInt.Interpolate(theManager.GetScheme(high), x, x1, x2, try11, try12); |
---|
141 | theNorm = std::max(try1, try2); |
---|
142 | |
---|
143 | G4double value, random; |
---|
144 | G4double v1, v2; |
---|
145 | do |
---|
146 | { |
---|
147 | v1 = 0; |
---|
148 | v2 = 0; |
---|
149 | result = 2.*G4UniformRand()-1.; |
---|
150 | for(l=0; l<theCoeff[low].GetNumberOfPoly() ; l++) |
---|
151 | { |
---|
152 | G4double legend = theLeg.Evaluate(l, result); // @@@ done to avoid optimization error on SUN |
---|
153 | v1 += (2.*l+1)/2.*theCoeff[low].GetCoeff(l)*legend; |
---|
154 | } |
---|
155 | for(l=0; l<theCoeff[high].GetNumberOfPoly() ; l++) |
---|
156 | { |
---|
157 | G4double legend = theLeg.Evaluate(l, result); // @@@ done to avoid optimization error on SUN |
---|
158 | v2 += (2.*l+1)/2.*theCoeff[high].GetCoeff(l)*legend; |
---|
159 | } |
---|
160 | value = theInt.Interpolate(theManager.GetScheme(high), x, x1, x2, v1, v2); |
---|
161 | random = G4UniformRand(); |
---|
162 | } |
---|
163 | while(random>value/theNorm); |
---|
164 | |
---|
165 | return result; |
---|
166 | } |
---|
167 | |
---|
168 | G4double G4NeutronHPLegendreStore::Sample (G4double energy) // still in interpolation; do not use |
---|
169 | { |
---|
170 | G4int i0; |
---|
171 | G4int low(0), high(0); |
---|
172 | // G4cout << "G4NeutronHPLegendreStore::Sample "<<energy<<" "<<energy<<" "<<nEnergy<<G4endl; |
---|
173 | for (i0=0; i0<nEnergy; i0++) |
---|
174 | { |
---|
175 | // G4cout <<"theCoeff["<<i0<<"].GetEnergy() = "<<theCoeff[i0].GetEnergy()<<G4endl; |
---|
176 | high = i0; |
---|
177 | if(theCoeff[i0].GetEnergy()>energy) break; |
---|
178 | } |
---|
179 | low = std::max(0, high-1); |
---|
180 | // G4cout << "G4NeutronHPLegendreStore::Sample high, low: "<<high<<", "<<low<<G4endl; |
---|
181 | G4NeutronHPVector theBuffer; |
---|
182 | G4NeutronHPInterpolator theInt; |
---|
183 | G4double x1, x2, y1, y2, y; |
---|
184 | x1 = theCoeff[low].GetEnergy(); |
---|
185 | x2 = theCoeff[high].GetEnergy(); |
---|
186 | // G4cout << "the xes "<<x1<<" "<<x2<<G4endl; |
---|
187 | G4double costh=0; |
---|
188 | for(i0=0; i0<601; i0++) |
---|
189 | { |
---|
190 | costh = G4double(i0-300)/300.; |
---|
191 | y1 = Integrate(low, costh); |
---|
192 | y2 = Integrate(high, costh); |
---|
193 | y = theInt.Interpolate(theManager.GetScheme(high), energy, x1, x2, y1, y2); |
---|
194 | theBuffer.SetData(i0, costh, y); |
---|
195 | // G4cout << "Integration "<<low<<" "<<costh<<" "<<y1<<" "<<y2<<" "<<y<<G4endl; |
---|
196 | } |
---|
197 | G4double rand = G4UniformRand(); |
---|
198 | G4int it; |
---|
199 | for (i0=1; i0<601; i0++) |
---|
200 | { |
---|
201 | it = i0; |
---|
202 | if(rand < theBuffer.GetY(i0)/theBuffer.GetY(600)) break; |
---|
203 | // G4cout <<"sampling now "<<i0<<" " |
---|
204 | // << theBuffer.GetY(i0)<<" " |
---|
205 | // << theBuffer.GetY(600)<<" " |
---|
206 | // << rand<<" " |
---|
207 | // << theBuffer.GetY(i0)/theBuffer.GetY(600)<<G4endl;; |
---|
208 | } |
---|
209 | if(it==601) it=600; |
---|
210 | // G4cout << "G4NeutronHPLegendreStore::Sample it "<<rand<<" "<<it<<G4endl; |
---|
211 | G4double norm = theBuffer.GetY(600); |
---|
212 | if(norm==0) return -DBL_MAX; |
---|
213 | x1 = theBuffer.GetY(it)/norm; |
---|
214 | x2 = theBuffer.GetY(it-1)/norm; |
---|
215 | y1 = theBuffer.GetX(it); |
---|
216 | y2 = theBuffer.GetX(it-1); |
---|
217 | // G4cout << "G4NeutronHPLegendreStore::Sample x y "<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<G4endl; |
---|
218 | return theInt.Interpolate(theManager.GetScheme(high), rand, x1, x2, y1, y2); |
---|
219 | } |
---|
220 | |
---|
221 | G4double G4NeutronHPLegendreStore::Integrate(G4int k, G4double costh) // still in interpolation; not used anymore |
---|
222 | { |
---|
223 | G4double result=0; |
---|
224 | G4NeutronHPFastLegendre theLeg; |
---|
225 | // G4cout <<"the COEFFS "<<k<<" "; |
---|
226 | // G4cout <<theCoeff[k].GetNumberOfPoly()<<" "; |
---|
227 | for(G4int l=0; l<theCoeff[k].GetNumberOfPoly() ; l++) |
---|
228 | { |
---|
229 | result += theCoeff[k].GetCoeff(l)*theLeg.Integrate(l, costh); |
---|
230 | // G4cout << theCoeff[k].GetCoeff(l)<<" "; |
---|
231 | } |
---|
232 | // G4cout <<G4endl; |
---|
233 | return result; |
---|
234 | } |
---|