00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00030
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00050
00051 #include "G4PhysicsOrderedFreeVector.hh"
00052
00054
00056
00058
00060
00061 G4PhysicsOrderedFreeVector::G4PhysicsOrderedFreeVector(G4double *Energies,
00062 G4double *Values,
00063 size_t VectorLength)
00064 : G4PhysicsVector()
00065 {
00066 type = T_G4PhysicsOrderedFreeVector;
00067
00068 for (size_t i = 0 ; i < VectorLength ; i++)
00069 {
00070 InsertValues(Energies[i], Values[i]);
00071 }
00072 }
00073
00074 G4PhysicsOrderedFreeVector::G4PhysicsOrderedFreeVector()
00075 : G4PhysicsVector()
00076 {
00077 type = T_G4PhysicsOrderedFreeVector;
00078 }
00079
00081
00083
00084 G4PhysicsOrderedFreeVector::~G4PhysicsOrderedFreeVector() {}
00085
00087
00089
00090 void G4PhysicsOrderedFreeVector::InsertValues(G4double energy, G4double value)
00091 {
00092 std::vector<G4double>::iterator binLoc =
00093 std::lower_bound(binVector.begin(), binVector.end(), energy);
00094
00095 size_t binIdx = binLoc - binVector.begin();
00096
00097 std::vector<G4double>::iterator dataLoc = dataVector.begin() + binIdx;
00098
00099 binVector.insert(binLoc, energy);
00100 dataVector.insert(dataLoc, value);
00101
00102 numberOfNodes++;
00103 edgeMin = binVector.front();
00104 edgeMax = binVector.back();
00105 }
00106
00107 G4double G4PhysicsOrderedFreeVector::GetLowEdgeEnergy(size_t binNumber) const
00108 {
00109 return binVector[binNumber];
00110 }
00111
00112 G4double G4PhysicsOrderedFreeVector::GetEnergy(G4double aValue)
00113 {
00114
00115 if (aValue <= GetMinValue()) {
00116 return GetMinLowEdgeEnergy();
00117 } else if (aValue >= GetMaxValue()) {
00118 return GetMaxLowEdgeEnergy();
00119 } else {
00120 size_t closestBin = FindValueBinLocation(aValue);
00121 G4double theEnergy = LinearInterpolationOfEnergy(aValue, closestBin);
00122
00123 return theEnergy;
00124 }
00125 }
00126
00127 size_t G4PhysicsOrderedFreeVector::FindValueBinLocation(G4double aValue)
00128 {
00129 G4int n1 = 0;
00130 G4int n2 = numberOfNodes/2;
00131 G4int n3 = numberOfNodes - 1;
00132 while (n1 != n3 - 1) {
00133 if (aValue > dataVector[n2])
00134 { n1 = n2; }
00135 else
00136 { n3 = n2; }
00137 n2 = n1 + (n3 - n1 + 1)/2;
00138 }
00139 return (size_t)n1;
00140 }
00141
00142 G4double G4PhysicsOrderedFreeVector::LinearInterpolationOfEnergy(G4double aValue,
00143 size_t theLocBin)
00144 {
00145 G4double intplFactor = (aValue-dataVector[theLocBin])
00146 / (dataVector[theLocBin+1]-dataVector[theLocBin]);
00147
00148 return binVector[theLocBin] +
00149 ( binVector[theLocBin+1]-binVector[theLocBin] ) * intplFactor;
00150 }
00151
00152
00153 size_t G4PhysicsOrderedFreeVector::FindBinLocation(G4double theEnergy) const
00154 {
00155 G4int n1 = 0;
00156 G4int n2 = numberOfNodes/2;
00157 G4int n3 = numberOfNodes - 1;
00158 while (n1 != n3 - 1)
00159 {
00160 if (theEnergy > binVector[n2])
00161 { n1 = n2; }
00162 else
00163 { n3 = n2; }
00164 n2 = n1 + (n3 - n1 + 1)/2;
00165 }
00166 return (size_t)n1;
00167 }