Geant4  10.03
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 //
27 // $Id: G4PhysicsVector.icc 98864 2016-08-15 11:53:26Z gcosmo $
28 //
29 //
30 //---------------------------------------------------------------
31 // GEANT 4 class source file
32 //
33 // G4PhysicsVector.icc
34 //
35 // Description:
36 // A physics vector which has values of energy-loss, cross-section,
37 // and other physics values of a particle in matter in a given
38 // range of the energy, momentum, etc.
39 // This class serves as the base class for a vector having various
40 // energy scale, for example like 'log', 'linear', 'free', etc.
41 //
42 //---------------------------------------------------------------
43 
44 inline
45  G4double G4PhysicsVector::operator[](const size_t index) const
46 {
47  return dataVector[index];
48 }
49 
50 //---------------------------------------------------------------
51 
52 inline
53  G4double G4PhysicsVector::operator()(const size_t index) const
54 {
55  return dataVector[index];
56 }
57 
58 //---------------------------------------------------------------
59 
60 inline
61  G4double G4PhysicsVector::Energy(const size_t index) const
62 {
63  return binVector[index];
64 }
65 
66 //---------------------------------------------------------------
67 
68 inline
69  G4double G4PhysicsVector::GetMaxEnergy() const
70 {
71  return edgeMax;
72 }
73 
74 //---------------------------------------------------------------
75 
76 inline
77  size_t G4PhysicsVector::GetVectorLength() const
78 {
79  return numberOfNodes;
80 }
81 
82 //------------------------------------------------
83 
84 inline
85  G4double G4PhysicsVector::LinearInterpolation(size_t idx, G4double e) const
86 {
87  // Linear interpolation is used to get the value. Before this method
88  // is called it is ensured that the energy is inside the bin
89  // 0 < idx < numberOfNodes-1
90 
91  return dataVector[idx] +
92  ( dataVector[idx + 1]-dataVector[idx] ) * (e - binVector[idx])
93  /( binVector[idx + 1]-binVector[idx] );
94 }
95 
96 //---------------------------------------------------------------
97 
98 inline
99  G4double G4PhysicsVector::SplineInterpolation(size_t idx, G4double e) const
100 {
101  // Spline interpolation is used to get the value. Before this method
102  // is called it is ensured that the energy is inside the bin
103  // 0 < idx < numberOfNodes-1
104 
105  static const G4double onesixth = 1.0/6.0;
106 
107  // check bin value
108  G4double x1 = binVector[idx];
109  G4double x2 = binVector[idx + 1];
110  G4double delta = x2 - x1;
111 
112  G4double a = (x2 - e)/delta;
113  G4double b = (e - x1)/delta;
114 
115  // Final evaluation of cubic spline polynomial for return
116  G4double y1 = dataVector[idx];
117  G4double y2 = dataVector[idx + 1];
118 
119  G4double res = a*y1 + b*y2 +
120  ( (a*a*a - a)*secDerivative[idx] +
121  (b*b*b - b)*secDerivative[idx + 1] )*delta*delta*onesixth;
122 
123  return res;
124 }
125 
126 //---------------------------------------------------------------
127 
128 inline
129  G4double G4PhysicsVector::Interpolation(size_t idx, G4double e) const
130 {
131  return useSpline ? SplineInterpolation(idx, e) : LinearInterpolation(idx, e);
132 }
133 
134 //---------------------------------------------------------------
135 
136 inline
137  void G4PhysicsVector::PutValue(size_t index, G4double theValue)
138 {
139  if(index >= numberOfNodes) { PrintPutValueError(index); }
140  dataVector[index] = theValue;
141 }
142 
143 //---------------------------------------------------------------
144 
145 inline
146  G4bool G4PhysicsVector::IsFilledVectorExist() const
147 {
148  return (numberOfNodes > 0) ? true : false;
149 }
150 
151 //---------------------------------------------------------------
152 
153 inline
154  G4PhysicsVectorType G4PhysicsVector::GetType() const
155 {
156  return type;
157 }
158 
159 //---------------------------------------------------------------
160 
161 // Flag useSpline is "true" only if second derivatives are filled
162 inline
163  void G4PhysicsVector::SetSpline(G4bool val)
164 {
165  if(val) {
166  if(0 == secDerivative.size() && 0 < dataVector.size()) {
167  FillSecondDerivatives();
168  }
169  } else {
170  useSpline = false;
171  secDerivative.clear();
172  }
173 }
174 
175 //---------------------------------------------------------------
176 
177 inline
178 void G4PhysicsVector::SetVerboseLevel(G4int value)
179 {
180  verboseLevel = value;
181 }
182 
183 //---------------------------------------------------------------
184 /*
185 inline
186 G4int G4PhysicsVector::GetVerboseLevel() const
187 {
188  return verboseLevel;
189 }
190 */
191 //---------------------------------------------------------------
192 
193 inline
194 size_t G4PhysicsVector::FindBinLocation(G4double theEnergy) const
195 {
196  size_t bin;
197  if(type == T_G4PhysicsLogVector) {
198  bin = size_t(G4Log(theEnergy)/dBin - baseBin);
199  if(bin > 0 && theEnergy < binVector[bin]) { --bin; }
200  else if(theEnergy > binVector[bin+1]) { ++bin; }
201  } else if(type == T_G4PhysicsLinearVector) {
202  bin = size_t( theEnergy/dBin - baseBin );
203  if(bin > 0 && theEnergy < binVector[bin]) { --bin; }
204  else if(theEnergy > binVector[bin+1]) { ++bin; }
205  } else {
206  // Bin location proposed by K.Genser (FNAL)
207  bin = std::lower_bound(binVector.begin(), binVector.end(), theEnergy)
208  - binVector.begin() - 1;
209  }
210  return std::min(bin, numberOfNodes-2);
211 }
212 
213 //---------------------------------------------------------------
214 
215 inline size_t G4PhysicsVector::FindBin(G4double e, size_t idx) const
216 {
217  size_t id = idx;
218  if(e < binVector[1]) {
219  id = 0;
220  } else if(e >= binVector[numberOfNodes-2]) {
221  id = numberOfNodes - 2;
222  } else if(idx >= numberOfNodes || e < binVector[idx]
223  || e > binVector[idx+1]) {
224  id = FindBinLocation(e);
225  }
226  return id;
227 }
228 
229 //---------------------------------------------------------------
230 
231 inline
232  G4double G4PhysicsVector::Value(G4double theEnergy) const
233 {
234  size_t idx=0;
235  return Value(theEnergy, idx);
236 }
237 
238 //---------------------------------------------------------------
239 
240 inline
241  G4double G4PhysicsVector::GetValue(G4double theEnergy, G4bool&) const
242 {
243  size_t idx=0;
244  return Value(theEnergy, idx);
245 }
246 
247 //---------------------------------------------------------------