Geant4-11
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4PhysicsVector.icc
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// G4PhysicsVector inline methods implementation
27//
28// Authors:
29// - 02 Dec. 1995, G.Cosmo: Structure created based on object model
30// - 03 Mar. 1996, K.Amako: Implemented the 1st version
31// --------------------------------------------------------------------
32inline G4double G4PhysicsVector::operator[](const std::size_t index) const
33{
34 return dataVector[index];
35}
36
37// ---------------------------------------------------------------
38inline G4double G4PhysicsVector::operator()(const std::size_t index) const
39{
40 return dataVector[index];
41}
42
43// ---------------------------------------------------------------
44inline G4double G4PhysicsVector::Energy(const std::size_t index) const
45{
46 return binVector[index];
47}
48
49// ---------------------------------------------------------------
50inline G4double
51G4PhysicsVector::GetLowEdgeEnergy(const std::size_t index) const
52{
53 return binVector[index];
54}
55
56// ---------------------------------------------------------------
57inline G4double G4PhysicsVector::GetMinEnergy() const
58{
59 return edgeMin;
60}
61
62// ---------------------------------------------------------------
63inline G4double G4PhysicsVector::GetMaxEnergy() const
64{
65 return edgeMax;
66}
67
68// ---------------------------------------------------------------
69inline G4double G4PhysicsVector::GetMinValue() const
70{
71 return (numberOfNodes > 0) ? dataVector[0] : 0.0;
72}
73
74// ---------------------------------------------------------------
75inline G4double G4PhysicsVector::GetMaxValue() const
76{
77 return (numberOfNodes > 0) ? dataVector[numberOfNodes - 1] : 0.0;
78}
79
80// ---------------------------------------------------------------
81inline std::size_t G4PhysicsVector::GetVectorLength() const
82{
83 return numberOfNodes;
84}
85
86// ---------------------------------------------------------------
87inline void G4PhysicsVector::PutValue(std::size_t index, G4double theValue)
88{
89 if(index >= numberOfNodes)
90 {
91 PrintPutValueError(index, theValue, "PutValue(..) ");
92 }
93 else
94 {
95 dataVector[index] = theValue;
96 }
97}
98
99// ---------------------------------------------------------------
100inline G4PhysicsVectorType G4PhysicsVector::GetType() const
101{
102 return type;
103}
104
105// ---------------------------------------------------------------
106inline G4bool G4PhysicsVector::GetSpline() const
107{
108 return useSpline;
109}
110
111// ---------------------------------------------------------------
112inline void G4PhysicsVector::SetVerboseLevel(G4int value)
113{
114 verboseLevel = value;
115}
116
117// ---------------------------------------------------------------
118inline G4double
119G4PhysicsVector::FindLinearEnergy(const G4double rand) const
120{
121 return GetEnergy(rand*dataVector[numberOfNodes - 1]);
122}
123
124// ---------------------------------------------------------------
125inline G4double G4PhysicsVector::Interpolation(const std::size_t idx,
126 const G4double e) const
127{
128 // perform the interpolation
129 const G4double x1 = binVector[idx];
130 const G4double dl = binVector[idx + 1] - x1;
131
132 const G4double y1 = dataVector[idx];
133 const G4double dy = dataVector[idx + 1] - y1;
134
135 // note: all corner cases of the previous methods are covered and eventually
136 // gives b=0/1 that results in y=y0\y_{N-1} if e<=x[0]/e>=x[N-1] or
137 // y=y_i/y_{i+1} if e<x[i]/e>=x[i+1] due to small numerical errors
138 const G4double b = (e - x1) / dl;
139
140 G4double res = y1 + b * dy;
141
142 if(useSpline) // spline interpolation
143 {
144 const G4double c0 = (2.0 - b) * secDerivative[idx];
145 const G4double c1 = (1.0 + b) * secDerivative[idx + 1];
146 res += (b * (b - 1.0)) * (c0 + c1) * (dl * dl * (1.0/6.0));
147 }
148
149 return res;
150}
151
152// ---------------------------------------------------------------
153inline std::size_t G4PhysicsVector::ComputeLogVectorBin(
154 const G4double loge) const
155{
156 return std::min(static_cast<G4int>((loge - logemin) * invdBin), idxmax);
157}
158
159// ---------------------------------------------------------------
160inline std::size_t G4PhysicsVector::GetBin(const G4double e) const
161{
162 std::size_t bin;
163 switch(type)
164 {
165 case T_G4PhysicsLogVector:
166 bin = ComputeLogVectorBin(G4Log(e));
167 break;
168
169 case T_G4PhysicsLinearVector:
170 bin = std::min(static_cast<G4int>((e - edgeMin) * invdBin), idxmax);
171 break;
172
173 default:
174 // Bin location proposed by K.Genser (FNAL)
175 bin = std::lower_bound(binVector.begin(), binVector.end(), e) -
176 binVector.begin() - 1;
177 }
178 return bin;
179}
180
181// ---------------------------------------------------------------
182inline G4double
183G4PhysicsVector::Value(const G4double e, std::size_t& idx) const
184{
185 G4double res;
186 if(idx + 1 < numberOfNodes &&
187 e >= binVector[idx] && e <= binVector[idx+1])
188 {
189 res = Interpolation(idx, e);
190 }
191 else if(e > edgeMin && e < edgeMax)
192 {
193 idx = GetBin(e);
194 res = Interpolation(idx, e);
195 }
196 else if(e <= edgeMin)
197 {
198 res = dataVector[0];
199 idx = 0;
200 }
201 else
202 {
203 res = dataVector[numberOfNodes - 1];
204 idx = idxmax;
205 }
206 return res;
207}
208
209// ---------------------------------------------------------------
210inline G4double G4PhysicsVector::Value(G4double e) const
211{
212 G4double res;
213 if(e > edgeMin && e < edgeMax)
214 {
215 const std::size_t idx = GetBin(e);
216 res = Interpolation(idx, e);
217 }
218 else if(e <= edgeMin)
219 {
220 res = dataVector[0];
221 }
222 else
223 {
224 res = dataVector[numberOfNodes - 1];
225 }
226 return res;
227}
228
229// ---------------------------------------------------------------
230inline G4double G4PhysicsVector::GetValue(G4double e, G4bool&) const
231{
232 return Value(e);
233}
234
235// ---------------------------------------------------------------
236inline G4double
237G4PhysicsVector::LogVectorValue(const G4double e, const G4double loge) const
238{
239 G4double res;
240 if(e > edgeMin && e < edgeMax)
241 {
242 const std::size_t idx = ComputeLogVectorBin(loge);
243 res = Interpolation(idx, e);
244 }
245 else if(e <= edgeMin)
246 {
247 res = dataVector[0];
248 }
249 else
250 {
251 res = dataVector[numberOfNodes - 1];
252 }
253 return res;
254}
255
256// ---------------------------------------------------------------