- Timestamp:
- Jun 18, 2010, 11:42:07 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/global/management/include/G4PhysicsVector.icc
r1193 r1315 25 25 // 26 26 // 27 // $Id: G4PhysicsVector.icc,v 1.2 3 2009/11/18 11:42:03 vnivanchExp $28 // GEANT4 tag $Name: g lobal-V09-02-10$27 // $Id: G4PhysicsVector.icc,v 1.28 2010/05/28 05:13:43 kurasige Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // … … 44 44 45 45 inline 46 G4double G4PhysicsVector::GetLastEnergy() const 47 { 48 return cache->lastEnergy; 49 } 50 51 inline 52 G4double G4PhysicsVector::GetLastValue() const 53 { 54 return cache->lastValue; 55 } 56 57 inline 58 size_t G4PhysicsVector::GetLastBin() const 59 { 60 return cache->lastBin; 61 } 62 63 inline 46 64 G4double G4PhysicsVector::operator[](const size_t binNumber) const 47 65 { 66 return dataVector[binNumber]; 67 } 68 69 //--------------------------------------------------------------- 70 71 inline 72 G4double G4PhysicsVector::operator()(const size_t binNumber) const 73 { 48 74 return dataVector[binNumber]; 49 75 } … … 52 78 53 79 inline 54 G4double G4PhysicsVector::operator()(const size_t binNumber) const55 {56 return dataVector[binNumber];57 }58 59 //---------------------------------------------------------------60 61 inline62 80 G4double G4PhysicsVector::Energy(const size_t binNumber) const 63 81 { … … 76 94 77 95 inline 78 G4double G4PhysicsVector::LinearInterpolation() 96 G4double G4PhysicsVector::GetValue(G4double theEnergy, G4bool&) 97 { 98 return Value(theEnergy); 99 } 100 101 //------------------------------------------------ 102 103 inline 104 G4double G4PhysicsVector::LinearInterpolation(G4int lastBin) 79 105 { 80 106 // Linear interpolation is used to get the value. If the give energy … … 84 110 // numberOfBin-1. 85 111 86 G4double intplFactor = ( lastEnergy-binVector[lastBin])87 / (binVector[lastBin +1]-binVector[lastBin]); // Interpolationfactor112 G4double intplFactor = (cache->lastEnergy-binVector[lastBin]) 113 / (binVector[lastBin + 1]-binVector[lastBin]); // Interpol. factor 88 114 89 115 return dataVector[lastBin] + 90 ( dataVector[lastBin +1]-dataVector[lastBin] ) * intplFactor;91 } 92 93 //--------------------------------------------------------------- 94 95 inline 96 G4double G4PhysicsVector::SplineInterpolation( )116 ( dataVector[lastBin + 1]-dataVector[lastBin] ) * intplFactor; 117 } 118 119 //--------------------------------------------------------------- 120 121 inline 122 G4double G4PhysicsVector::SplineInterpolation(G4int lastBin) 97 123 { 98 124 // Spline interpolation is used to get the value. If the give energy … … 106 132 // check bin value 107 133 G4double x1 = binVector[lastBin]; 108 G4double x2 = binVector[lastBin +1];134 G4double x2 = binVector[lastBin + 1]; 109 135 G4double delta = x2 - x1; 110 136 111 G4double a = (x2 - lastEnergy)/delta;112 G4double b = ( lastEnergy - x1)/delta;137 G4double a = (x2 - cache->lastEnergy)/delta; 138 G4double b = (cache->lastEnergy - x1)/delta; 113 139 114 140 // Final evaluation of cubic spline polynomial for return 115 141 G4double y1 = dataVector[lastBin]; 116 G4double y2 = dataVector[lastBin +1];142 G4double y2 = dataVector[lastBin + 1]; 117 143 118 144 G4double res = a*y1 + b*y2 + 119 145 ( (a*a*a - a)*secDerivative[lastBin] + 120 (b*b*b - b)*secDerivative[lastBin +1] )*delta*delta/6.0;146 (b*b*b - b)*secDerivative[lastBin + 1] )*delta*delta/6.0; 121 147 122 148 return res; … … 125 151 //--------------------------------------------------------------- 126 152 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(); } 153 inline 154 void G4PhysicsVector::Interpolation(G4int lastBin) 155 { 156 if(useSpline) { cache->lastValue = SplineInterpolation(lastBin); } 157 else { cache->lastValue = LinearInterpolation(lastBin); } 175 158 } 176 159
Note: See TracChangeset
for help on using the changeset viewer.