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: G4PhysicsVector.icc,v 1.23 2009/11/18 11:42:03 vnivanch Exp $ |
---|
28 | // GEANT4 tag $Name: global-V09-02-10 $ |
---|
29 | // |
---|
30 | // |
---|
31 | //--------------------------------------------------------------- |
---|
32 | // GEANT 4 class source file |
---|
33 | // |
---|
34 | // G4PhysicsVector.icc |
---|
35 | // |
---|
36 | // Description: |
---|
37 | // A physics vector which has values of energy-loss, cross-section, |
---|
38 | // and other physics values of a particle in matter in a given |
---|
39 | // range of the energy, momentum, etc. |
---|
40 | // This class serves as the base class for a vector having various |
---|
41 | // energy scale, for example like 'log', 'linear', 'free', etc. |
---|
42 | // |
---|
43 | //--------------------------------------------------------------- |
---|
44 | |
---|
45 | inline |
---|
46 | G4double G4PhysicsVector::operator[](const size_t binNumber) const |
---|
47 | { |
---|
48 | return dataVector[binNumber]; |
---|
49 | } |
---|
50 | |
---|
51 | //--------------------------------------------------------------- |
---|
52 | |
---|
53 | inline |
---|
54 | G4double G4PhysicsVector::operator()(const size_t binNumber) const |
---|
55 | { |
---|
56 | return dataVector[binNumber]; |
---|
57 | } |
---|
58 | |
---|
59 | //--------------------------------------------------------------- |
---|
60 | |
---|
61 | inline |
---|
62 | G4double G4PhysicsVector::Energy(const size_t binNumber) const |
---|
63 | { |
---|
64 | return binVector[binNumber]; |
---|
65 | } |
---|
66 | |
---|
67 | //--------------------------------------------------------------- |
---|
68 | |
---|
69 | inline |
---|
70 | size_t G4PhysicsVector::GetVectorLength() const |
---|
71 | { |
---|
72 | return numberOfNodes; |
---|
73 | } |
---|
74 | |
---|
75 | //--------------------------------------------------------------- |
---|
76 | |
---|
77 | inline |
---|
78 | G4double G4PhysicsVector::LinearInterpolation() |
---|
79 | { |
---|
80 | // Linear interpolation is used to get the value. If the give energy |
---|
81 | // is in the highest bin, no interpolation will be Done. Because |
---|
82 | // there is an extra bin hidden from a user at locBin=numberOfBin, |
---|
83 | // the following interpolation is valid even the current locBin= |
---|
84 | // numberOfBin-1. |
---|
85 | |
---|
86 | G4double intplFactor = (lastEnergy-binVector[lastBin]) |
---|
87 | / (binVector[lastBin+1]-binVector[lastBin]); // Interpolation factor |
---|
88 | |
---|
89 | return dataVector[lastBin] + |
---|
90 | ( dataVector[lastBin+1]-dataVector[lastBin] ) * intplFactor; |
---|
91 | } |
---|
92 | |
---|
93 | //--------------------------------------------------------------- |
---|
94 | |
---|
95 | inline |
---|
96 | G4double G4PhysicsVector::SplineInterpolation() |
---|
97 | { |
---|
98 | // Spline interpolation is used to get the value. If the give energy |
---|
99 | // is in the highest bin, no interpolation will be Done. Because |
---|
100 | // there is an extra bin hidden from a user at locBin=numberOfBin, |
---|
101 | // the following interpolation is valid even the current locBin= |
---|
102 | // numberOfBin-1. |
---|
103 | |
---|
104 | if(0 == secDerivative.size() ) { FillSecondDerivatives(); } |
---|
105 | |
---|
106 | // check bin value |
---|
107 | G4double x1 = binVector[lastBin]; |
---|
108 | G4double x2 = binVector[lastBin+1]; |
---|
109 | G4double delta = x2 - x1; |
---|
110 | |
---|
111 | G4double a = (x2 - lastEnergy)/delta; |
---|
112 | G4double b = (lastEnergy - x1)/delta; |
---|
113 | |
---|
114 | // Final evaluation of cubic spline polynomial for return |
---|
115 | G4double y1 = dataVector[lastBin]; |
---|
116 | G4double y2 = dataVector[lastBin+1]; |
---|
117 | |
---|
118 | G4double res = a*y1 + b*y2 + |
---|
119 | ( (a*a*a - a)*secDerivative[lastBin] + |
---|
120 | (b*b*b - b)*secDerivative[lastBin+1] )*delta*delta/6.0; |
---|
121 | |
---|
122 | return res; |
---|
123 | } |
---|
124 | |
---|
125 | //--------------------------------------------------------------- |
---|
126 | |
---|
127 | inline |
---|
128 | G4double G4PhysicsVector::GetValue(G4double theEnergy, G4bool&) |
---|
129 | { |
---|
130 | return Value(theEnergy); |
---|
131 | } |
---|
132 | |
---|
133 | //--------------------------------------------------------------- |
---|
134 | |
---|
135 | inline |
---|
136 | G4double G4PhysicsVector::Value(G4double theEnergy) |
---|
137 | { |
---|
138 | // Use cache for speed up - check if the value 'theEnergy' is same as the |
---|
139 | // last call. If it is same, then use the last bin location. Also the |
---|
140 | // value 'theEnergy' lies between the last energy and low edge of of the |
---|
141 | // bin of last call, then the last bin location is used. |
---|
142 | |
---|
143 | if( theEnergy == lastEnergy ) { |
---|
144 | |
---|
145 | } else if(theEnergy < lastEnergy && theEnergy >= binVector[lastBin]) { |
---|
146 | lastEnergy = theEnergy; |
---|
147 | Interpolation(); |
---|
148 | |
---|
149 | } else if( theEnergy <= edgeMin ) { |
---|
150 | lastBin = 0; |
---|
151 | lastEnergy = edgeMin; |
---|
152 | lastValue = dataVector[0]; |
---|
153 | |
---|
154 | } else if( theEnergy >= edgeMax ){ |
---|
155 | lastBin = numberOfNodes-2; |
---|
156 | lastEnergy = edgeMax; |
---|
157 | lastValue = dataVector[numberOfNodes-1]; |
---|
158 | |
---|
159 | } else { |
---|
160 | lastBin = FindBinLocation(theEnergy); |
---|
161 | if(lastBin >= numberOfNodes-1) {lastBin = numberOfNodes-2;} |
---|
162 | lastEnergy = theEnergy; |
---|
163 | Interpolation(); |
---|
164 | } |
---|
165 | return lastValue; |
---|
166 | } |
---|
167 | |
---|
168 | //--------------------------------------------------------------- |
---|
169 | |
---|
170 | inline |
---|
171 | void G4PhysicsVector::Interpolation() |
---|
172 | { |
---|
173 | if(useSpline) { lastValue = SplineInterpolation(); } |
---|
174 | else { lastValue = LinearInterpolation(); } |
---|
175 | } |
---|
176 | |
---|
177 | //--------------------------------------------------------------- |
---|
178 | |
---|
179 | inline |
---|
180 | void G4PhysicsVector::PutValue(size_t binNumber, G4double theValue) |
---|
181 | { |
---|
182 | dataVector[binNumber] = theValue; |
---|
183 | } |
---|
184 | |
---|
185 | //--------------------------------------------------------------- |
---|
186 | |
---|
187 | inline |
---|
188 | G4bool G4PhysicsVector::IsFilledVectorExist() const |
---|
189 | { |
---|
190 | G4bool status=false; |
---|
191 | |
---|
192 | if(numberOfNodes > 0) { status=true; } |
---|
193 | return status; |
---|
194 | } |
---|
195 | |
---|
196 | //--------------------------------------------------------------- |
---|
197 | |
---|
198 | inline |
---|
199 | void G4PhysicsVector::PutComment(const G4String& theComment) |
---|
200 | { |
---|
201 | comment = theComment; |
---|
202 | } |
---|
203 | |
---|
204 | //--------------------------------------------------------------- |
---|
205 | |
---|
206 | inline |
---|
207 | const G4String& G4PhysicsVector::GetComment() const |
---|
208 | { |
---|
209 | return comment; |
---|
210 | } |
---|
211 | |
---|
212 | //--------------------------------------------------------------- |
---|
213 | |
---|
214 | inline |
---|
215 | G4PhysicsVectorType G4PhysicsVector::GetType() const |
---|
216 | { |
---|
217 | return type; |
---|
218 | } |
---|
219 | |
---|
220 | //--------------------------------------------------------------- |
---|
221 | |
---|
222 | inline |
---|
223 | void G4PhysicsVector::SetSpline(G4bool val) |
---|
224 | { |
---|
225 | useSpline = val; |
---|
226 | } |
---|