source: trunk/source/global/management/include/G4PhysicsVector.icc @ 869

Last change on this file since 869 was 850, checked in by garnier, 16 years ago

geant4.8.2 beta

File size: 6.9 KB
Line 
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.14 2008/09/05 18:04:45 vnivanch Exp $
28// GEANT4 tag $Name: HEAD $
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// Modified:
44// 05 Sep. 2008, V.Ivanchenko : added protections for zero-length vector
45//---------------------------------------------------------------
46
47inline
48 G4double G4PhysicsVector::operator[](const size_t binNumber) const
49{
50  return dataVector[binNumber];
51}
52
53//---------------------------------------------------------------
54
55inline
56 G4double G4PhysicsVector::operator()(const size_t binNumber) const
57{
58  return dataVector[binNumber];
59}
60
61//---------------------------------------------------------------
62
63inline
64 size_t G4PhysicsVector::GetVectorLength() const
65{
66  return numberOfBin;
67}
68
69//---------------------------------------------------------------
70
71inline
72 G4double G4PhysicsVector::LinearInterpolation()
73{
74  // Linear interpolation is used to get the value. If the give energy
75  // is in the highest bin, no interpolation will be Done. Because
76  // there is an extra bin hidden from a user at locBin=numberOfBin,
77  // the following interpolation is valid even the current locBin=
78  // numberOfBin-1.
79
80  G4double intplFactor = (lastEnergy-binVector[lastBin])
81     / (binVector[lastBin+1]-binVector[lastBin]); // Interpolation factor
82
83  return dataVector[lastBin] +
84         ( dataVector[lastBin+1]-dataVector[lastBin] ) * intplFactor;
85}
86
87//---------------------------------------------------------------
88
89inline
90 G4double G4PhysicsVector::SplineInterpolation()
91{
92  // Spline interpolation is used to get the value. If the give energy
93  // is in the highest bin, no interpolation will be Done. Because
94  // there is an extra bin hidden from a user at locBin=numberOfBin,
95  // the following interpolation is valid even the current locBin=
96  // numberOfBin-1.
97
98  if( !secDerivative ) { FillSecondDerivatives(); }
99
100  // check bin value
101  G4double delta = binVector[lastBin+1] - binVector[lastBin];
102
103  G4double a = (binVector[lastBin+1] - lastEnergy)/delta;
104  G4double b = (lastEnergy - binVector[lastBin])/delta;
105   
106  // Final evaluation of cubic spline polynomial for return   
107  G4double y1 = dataVector[lastBin];
108  G4double y2 = dataVector[lastBin+1];
109
110  G4double res = a*y1 + b*y2 +
111        ((a*a*a - a)*secDerivative[lastBin] +
112         (b*b*b - b)*secDerivative[lastBin+1])*delta*delta/6.0  ;
113
114  return res;
115}
116
117//---------------------------------------------------------------
118
119inline
120 G4double G4PhysicsVector::GetValue(G4double theEnergy, G4bool&)
121{
122  // Use cache for speed up - check if the value 'theEnergy' is same as the
123  // last call. If it is same, then use the last bin location. Also the
124  // value 'theEnergy' lies between the last energy and low edge of of the
125  // bin of last call, then the last bin location is used.
126
127  if( theEnergy == lastEnergy ) {
128
129  } else if( theEnergy <= edgeMin ) {
130     lastBin = 0;
131     lastEnergy = theEnergy;
132     lastValue  = dataVector[0];
133
134  } else if(theEnergy < lastEnergy && theEnergy >= binVector[lastBin]) {
135     lastEnergy = theEnergy;
136     Interpolation();
137
138  } else if(theEnergy < lastEnergy && theEnergy >= binVector[lastBin-1]) {
139     lastBin--;
140     lastEnergy = theEnergy;
141     Interpolation();
142
143  } else if( theEnergy >= edgeMax ){
144     lastBin = numberOfBin-1;
145     lastEnergy = edgeMax;
146     lastValue  = dataVector[lastBin];
147
148  } else {
149     lastBin = FindBinLocation(theEnergy);
150     lastEnergy = theEnergy;
151     Interpolation();
152  }
153  return lastValue;       
154}
155
156//---------------------------------------------------------------
157
158inline
159 void G4PhysicsVector::Interpolation()
160{
161  if(useSpline) { lastValue = SplineInterpolation(); }
162  else          { lastValue = LinearInterpolation(); }
163}
164
165//---------------------------------------------------------------
166
167inline
168 void G4PhysicsVector::PutValue(size_t binNumber, G4double theValue)
169{
170  if(binNumber < numberOfBin) {
171    dataVector[binNumber] = theValue;
172
173    // Fill the bin which is hidden to user with theValue. This is to
174    // handle correctly when Energy=theEmax in getValue.
175
176    if(binNumber==numberOfBin-1) { dataVector[binNumber+1] = theValue; }
177  }
178}
179
180//---------------------------------------------------------------
181
182inline
183 G4bool G4PhysicsVector::IsFilledVectorExist() const
184{
185  G4bool status=false;
186
187  if(numberOfBin > 0) { status=true; }
188  return status;
189}
190
191//---------------------------------------------------------------
192
193inline
194 void G4PhysicsVector::PutComment(const G4String& theComment)
195{
196  comment = theComment;
197}
198
199//---------------------------------------------------------------
200
201inline
202 const G4String& G4PhysicsVector::GetComment() const
203{
204  return comment;
205}
206
207//---------------------------------------------------------------
208
209inline
210 G4PhysicsVectorType G4PhysicsVector::GetType() const
211{
212  return type;
213}
214
215//---------------------------------------------------------------
216
217inline
218 void G4PhysicsVector::SetSpline(G4bool val)
219{
220  useSpline = val;
221}
Note: See TracBrowser for help on using the repository browser.