#include <G4AdjointInterpolator.hh>
Definition at line 53 of file G4AdjointInterpolator.hh.
G4AdjointInterpolator::~G4AdjointInterpolator | ( | ) |
G4double G4AdjointInterpolator::ExponentialInterpolation | ( | G4double & | x, | |
G4double & | x1, | |||
G4double & | x2, | |||
G4double & | y1, | |||
G4double & | y2 | |||
) |
Definition at line 81 of file G4AdjointInterpolator.cc.
Referenced by Interpolation().
00082 { G4double B=(std::log(y2)-std::log(y1)); 00083 B=B/(x2-x1); 00084 G4double A=y1*std::exp(-B*x1); 00085 G4double res=A*std::exp(B*x); 00086 return res; 00087 }
size_t G4AdjointInterpolator::FindPosition | ( | G4double & | x, | |
std::vector< G4double > & | x_vec, | |||
size_t | ind_min = 0 , |
|||
size_t | ind_max = 0 | |||
) |
Definition at line 108 of file G4AdjointInterpolator.cc.
Referenced by G4AdjointCSMatrix::AddData(), FindPositionForLogVector(), Interpolate(), and InterpolateWithIndexVector().
00109 { //most rapid nethod could be used probably 00110 //It is important to put std::vector<G4double>& such that the vector itself is used and not a copy 00111 00112 00113 size_t ndim = x_vec.size(); 00114 size_t ind1 = 0; 00115 size_t ind2 = ndim - 1; 00116 /* if (ind_max >= ind_min){ 00117 ind1=ind_min; 00118 ind2=ind_max; 00119 00120 00121 } 00122 */ 00123 00124 00125 if (ndim >1) { 00126 00127 if (x_vec[0] < x_vec[1] ) { //increasing 00128 do { 00129 size_t midBin = (ind1 + ind2)/2; 00130 if (x < x_vec[midBin]) 00131 ind2 = midBin; 00132 else 00133 ind1 = midBin; 00134 } while (ind2 - ind1 > 1); 00135 } 00136 else { 00137 do { 00138 size_t midBin = (ind1 + ind2)/2; 00139 if (x < x_vec[midBin]) 00140 ind1 = midBin; 00141 else 00142 ind2 = midBin; 00143 } while (ind2 - ind1 > 1); 00144 } 00145 00146 } 00147 00148 return ind1; 00149 }
size_t G4AdjointInterpolator::FindPositionForLogVector | ( | G4double & | x, | |
std::vector< G4double > & | x_vec | |||
) |
Definition at line 153 of file G4AdjointInterpolator.cc.
References FindPosition().
Referenced by InterpolateForLogVector(), and G4VEmAdjointModel::SampleAdjSecEnergyFromCSMatrix().
00154 { //most rapid nethod could be used probably 00155 //It is important to put std::vector<G4double>& such that the vector itself is used and not a copy 00156 return FindPosition(log_x, log_x_vec); 00157 /* 00158 if (log_x_vec.size()>3){ 00159 size_t ind=0; 00160 G4double log_x1=log_x_vec[1]; 00161 G4double d_log =log_x_vec[2]-log_x1; 00162 G4double dind=(log_x-log_x1)/d_log +1.; 00163 if (dind <1.) ind=0; 00164 else if (dind >= double(log_x_vec.size())-2.) ind =log_x_vec.size()-2; 00165 else ind =size_t(dind); 00166 return ind; 00167 00168 } 00169 else return FindPosition(log_x, log_x_vec); 00170 */ 00171 00172 00173 }
G4AdjointInterpolator * G4AdjointInterpolator::GetAdjointInterpolator | ( | ) | [static] |
Definition at line 34 of file G4AdjointInterpolator.cc.
00035 { if(theInstance == 0) { 00036 static G4AdjointInterpolator interpolator; 00037 theInstance = &interpolator; 00038 } 00039 return theInstance; 00040 }
G4AdjointInterpolator * G4AdjointInterpolator::GetInstance | ( | ) | [static] |
Definition at line 43 of file G4AdjointInterpolator.cc.
Referenced by G4AdjointCSMatrix::AddData(), and G4VEmAdjointModel::SampleAdjSecEnergyFromCSMatrix().
00044 { if(theInstance == 0) { 00045 static G4AdjointInterpolator interpolator; 00046 theInstance = &interpolator; 00047 } 00048 return theInstance; 00049 }
G4double G4AdjointInterpolator::Interpolate | ( | G4double & | x, | |
std::vector< G4double > & | x_vec, | |||
std::vector< G4double > & | y_vec, | |||
G4String | InterPolMethod = "Log" | |||
) |
Definition at line 176 of file G4AdjointInterpolator.cc.
References FindPosition(), and Interpolation().
Referenced by G4VEmAdjointModel::SampleAdjSecEnergyFromCSMatrix().
00177 { size_t i=FindPosition(x,x_vec); 00178 //G4cout<<i<<G4endl; 00179 //G4cout<<x<<G4endl; 00180 //G4cout<<x_vec[i]<<G4endl; 00181 return Interpolation( x,x_vec[i],x_vec[i+1],y_vec[i],y_vec[i+1],InterPolMethod); 00182 }
G4double G4AdjointInterpolator::InterpolateForLogVector | ( | G4double & | x, | |
std::vector< G4double > & | x_vec, | |||
std::vector< G4double > & | y_vec | |||
) |
Definition at line 208 of file G4AdjointInterpolator.cc.
References FindPositionForLogVector(), and LinearInterpolation().
Referenced by G4VEmAdjointModel::SampleAdjSecEnergyFromCSMatrix().
00209 { //size_t i=0; 00210 size_t i=FindPositionForLogVector(log_x,log_x_vec); 00211 /*G4cout<<"In interpolate "<<G4endl; 00212 G4cout<<i<<G4endl; 00213 G4cout<<log_x<<G4endl; 00214 G4cout<<log_x_vec[i]<<G4endl; 00215 G4cout<<log_x_vec[i+1]<<G4endl; 00216 G4cout<<log_y_vec[i]<<G4endl; 00217 G4cout<<log_y_vec[i+1]<<G4endl;*/ 00218 00219 G4double log_y=LinearInterpolation(log_x,log_x_vec[i],log_x_vec[i+1],log_y_vec[i],log_y_vec[i+1]); 00220 return log_y; 00221 00222 }
G4double G4AdjointInterpolator::InterpolateWithIndexVector | ( | G4double & | x, | |
std::vector< G4double > & | x_vec, | |||
std::vector< G4double > & | y_vec, | |||
std::vector< size_t > & | index_vec, | |||
G4double | x0, | |||
G4double | dx | |||
) |
Definition at line 186 of file G4AdjointInterpolator.cc.
References FindPosition(), and Interpolation().
00188 { size_t ind=0; 00189 if (x>x0) ind=int((x-x0)/dx); 00190 if (ind >= index_vec.size()-1) ind= index_vec.size()-2; 00191 size_t ind1 = index_vec[ind]; 00192 size_t ind2 = index_vec[ind+1]; 00193 if (ind1 >ind2) { 00194 size_t ind11=ind1; 00195 ind1=ind2; 00196 ind2=ind11; 00197 00198 } 00199 00200 ind=FindPosition(x,x_vec,ind1,ind2); 00201 return Interpolation( x,x_vec[ind],x_vec[ind+1],y_vec[ind],y_vec[ind+1],"Lin"); 00202 00203 }
G4double G4AdjointInterpolator::Interpolation | ( | G4double & | x, | |
G4double & | x1, | |||
G4double & | x2, | |||
G4double & | y1, | |||
G4double & | y2, | |||
G4String | InterPolMethod = "Log" | |||
) |
Definition at line 90 of file G4AdjointInterpolator.cc.
References ExponentialInterpolation(), LinearInterpolation(), and LogarithmicInterpolation().
Referenced by Interpolate(), and InterpolateWithIndexVector().
00091 { 00092 if (InterPolMethod == "Log" ){ 00093 return LogarithmicInterpolation(x,x1,x2,y1,y2); 00094 } 00095 else if (InterPolMethod == "Lin" ){ 00096 return LinearInterpolation(x,x1,x2,y1,y2); 00097 } 00098 else if (InterPolMethod == "Exp" ){ 00099 return ExponentialInterpolation(x,x1,x2,y1,y2); 00100 } 00101 else { 00102 //G4cout<<"The interpolation method that you invoked does not exist!"<<G4endl; 00103 return -1111111111.; 00104 } 00105 }
G4double G4AdjointInterpolator::LinearInterpolation | ( | G4double & | x, | |
G4double & | x1, | |||
G4double & | x2, | |||
G4double & | y1, | |||
G4double & | y2 | |||
) |
Definition at line 63 of file G4AdjointInterpolator.cc.
Referenced by InterpolateForLogVector(), Interpolation(), LogarithmicInterpolation(), and G4VEmAdjointModel::SampleAdjSecEnergyFromCSMatrix().
00064 { G4double res = y1+ (x-x1)*(y2-y1)/(x2-x1); 00065 //G4cout<<"Linear "<<res<<G4endl; 00066 return res; 00067 }
G4double G4AdjointInterpolator::LogarithmicInterpolation | ( | G4double & | x, | |
G4double & | x1, | |||
G4double & | x2, | |||
G4double & | y1, | |||
G4double & | y2 | |||
) |
Definition at line 70 of file G4AdjointInterpolator.cc.
References LinearInterpolation().
Referenced by Interpolation().
00071 { if (y1<=0 || y2<=0 || x1<=0) return LinearInterpolation(x,x1,x2,y1,y2); 00072 G4double B=std::log(y2/y1)/std::log(x2/x1); 00073 //G4cout<<"x1,x2,y1,y2 "<<x1<<'\t'<<x2<<'\t'<<y1<<'\t'<<y2<<'\t'<<G4endl; 00074 G4double A=y1/std::pow(x1,B); 00075 G4double res=A*std::pow(x,B); 00076 // G4cout<<"Log "<<res<<G4endl; 00077 return res; 00078 }