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

Last change on this file since 1038 was 921, checked in by garnier, 17 years ago

en test de gl2ps. Problemes de libraries

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