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: G4NeutronHPInterpolator.hh,v 1.20 2008/08/12 00:42:31 tkoi Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-02 $ |
---|
29 | // |
---|
30 | // 080809 Change interpolation scheme of "histogram", now using LinearLinear |
---|
31 | // For multidimensional interpolations By T. Koi |
---|
32 | // |
---|
33 | #ifndef G4NeutronHPInterpolator_h |
---|
34 | #define G4NeutronHPInterpolator_h 1 |
---|
35 | |
---|
36 | #include "globals.hh" |
---|
37 | #include "G4InterpolationScheme.hh" |
---|
38 | #include "Randomize.hh" |
---|
39 | #include "G4ios.hh" |
---|
40 | #include "G4HadronicException.hh" |
---|
41 | |
---|
42 | |
---|
43 | class G4NeutronHPInterpolator |
---|
44 | { |
---|
45 | public: |
---|
46 | |
---|
47 | G4NeutronHPInterpolator(){} |
---|
48 | ~G4NeutronHPInterpolator() |
---|
49 | { |
---|
50 | // G4cout <<"deleted the interpolator"<<G4endl; |
---|
51 | } |
---|
52 | |
---|
53 | inline G4double Lin(G4double x,G4double x1,G4double x2,G4double y1,G4double y2) |
---|
54 | { |
---|
55 | G4double slope=0, off=0; |
---|
56 | if(x2-x1==0) return (y2+y1)/2.; |
---|
57 | slope = (y2-y1)/(x2-x1); |
---|
58 | off = y2-x2*slope; |
---|
59 | G4double y = x*slope+off; |
---|
60 | return y; |
---|
61 | } |
---|
62 | |
---|
63 | inline G4double Interpolate(G4InterpolationScheme aScheme, |
---|
64 | G4double x, G4double x1, G4double x2, |
---|
65 | G4double y1, G4double y2) const; |
---|
66 | |
---|
67 | G4double |
---|
68 | GetBinIntegral(const G4InterpolationScheme & aScheme, |
---|
69 | const G4double x1,const G4double x2,const G4double y1,const G4double y2); |
---|
70 | |
---|
71 | G4double |
---|
72 | GetWeightedBinIntegral(const G4InterpolationScheme & aScheme, |
---|
73 | const G4double x1,const G4double x2,const G4double y1,const G4double y2); |
---|
74 | |
---|
75 | private: |
---|
76 | |
---|
77 | inline G4double Histogram(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const; |
---|
78 | inline G4double LinearLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const; |
---|
79 | inline G4double LinearLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const; |
---|
80 | inline G4double LogarithmicLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const; |
---|
81 | inline G4double LogarithmicLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const; |
---|
82 | inline G4double Random(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const; |
---|
83 | |
---|
84 | }; |
---|
85 | |
---|
86 | inline G4double G4NeutronHPInterpolator:: |
---|
87 | Interpolate(G4InterpolationScheme aScheme, |
---|
88 | G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const |
---|
89 | { |
---|
90 | G4double result(0); |
---|
91 | G4int theScheme = aScheme; |
---|
92 | theScheme = theScheme%CSTART_; |
---|
93 | switch(theScheme) |
---|
94 | { |
---|
95 | case 1: |
---|
96 | //080809 |
---|
97 | //result = Histogram(x, x1, x2, y1, y2); |
---|
98 | result = LinearLinear(x, x1, x2, y1, y2); |
---|
99 | break; |
---|
100 | case 2: |
---|
101 | result = LinearLinear(x, x1, x2, y1, y2); |
---|
102 | break; |
---|
103 | case 3: |
---|
104 | result = LinearLogarithmic(x, x1, x2, y1, y2); |
---|
105 | break; |
---|
106 | case 4: |
---|
107 | result = LogarithmicLinear(x, x1, x2, y1, y2); |
---|
108 | break; |
---|
109 | case 5: |
---|
110 | result = LogarithmicLogarithmic(x, x1, x2, y1, y2); |
---|
111 | break; |
---|
112 | case 6: |
---|
113 | result = Random(x, x1, x2, y1, y2); |
---|
114 | break; |
---|
115 | default: |
---|
116 | G4cout << "theScheme = "<<theScheme<<G4endl; |
---|
117 | throw G4HadronicException(__FILE__, __LINE__, "G4NeutronHPInterpolator::Carthesian Invalid InterpolationScheme"); |
---|
118 | break; |
---|
119 | } |
---|
120 | return result; |
---|
121 | } |
---|
122 | |
---|
123 | inline G4double G4NeutronHPInterpolator:: |
---|
124 | Histogram(G4double , G4double , G4double , G4double y1, G4double ) const |
---|
125 | { |
---|
126 | G4double result; |
---|
127 | result = y1; |
---|
128 | return result; |
---|
129 | } |
---|
130 | |
---|
131 | inline G4double G4NeutronHPInterpolator:: |
---|
132 | LinearLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const |
---|
133 | { |
---|
134 | G4double slope=0, off=0; |
---|
135 | if(x2-x1==0) return (y2+y1)/2.; |
---|
136 | slope = (y2-y1)/(x2-x1); |
---|
137 | off = y2-x2*slope; |
---|
138 | G4double y = x*slope+off; |
---|
139 | return y; |
---|
140 | } |
---|
141 | |
---|
142 | inline G4double G4NeutronHPInterpolator:: |
---|
143 | LinearLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const |
---|
144 | { |
---|
145 | G4double result; |
---|
146 | if(x==0) result = y1+y2/2.; |
---|
147 | else if(x1==0) result = y1; |
---|
148 | else if(x2==0) result = y2; |
---|
149 | else result = LinearLinear(std::log(x), std::log(x1), std::log(x2), y1, y2); |
---|
150 | return result; |
---|
151 | } |
---|
152 | |
---|
153 | inline G4double G4NeutronHPInterpolator:: |
---|
154 | LogarithmicLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const |
---|
155 | { |
---|
156 | G4double result; |
---|
157 | if(y1==0||y2==0) result = 0; |
---|
158 | else |
---|
159 | { |
---|
160 | result = LinearLinear(x, x1, x2, std::log(y1), std::log(y2)); |
---|
161 | result = std::exp(result); |
---|
162 | } |
---|
163 | return result; |
---|
164 | } |
---|
165 | |
---|
166 | inline G4double G4NeutronHPInterpolator:: |
---|
167 | LogarithmicLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const |
---|
168 | { |
---|
169 | G4double result; |
---|
170 | if(x==0) result = y1+y2/2.; |
---|
171 | else if(x1==0) result = y1; |
---|
172 | else if(x2==0) result = y2; |
---|
173 | if(y1==0||y2==0) result = 0; |
---|
174 | else |
---|
175 | { |
---|
176 | result = LinearLinear(std::log(x), std::log(x1), std::log(x2), std::log(y1), std::log(y2)); |
---|
177 | result = std::exp(result); |
---|
178 | } |
---|
179 | return result; |
---|
180 | } |
---|
181 | |
---|
182 | inline G4double G4NeutronHPInterpolator:: |
---|
183 | Random(G4double , G4double , G4double , G4double y1, G4double y2) const |
---|
184 | { |
---|
185 | G4double result; |
---|
186 | result = y1+G4UniformRand()*(y2-y1); |
---|
187 | return result; |
---|
188 | } |
---|
189 | |
---|
190 | #endif |
---|