Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4AdjointInterpolator Class Reference

#include <G4AdjointInterpolator.hh>

Public Member Functions

 ~G4AdjointInterpolator ()
 
G4double LinearInterpolation (G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
 
G4double LogarithmicInterpolation (G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
 
G4double ExponentialInterpolation (G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
 
G4double Interpolation (G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2, G4String InterPolMethod="Log")
 
size_t FindPosition (G4double &x, std::vector< G4double > &x_vec, size_t ind_min=0, size_t ind_max=0)
 
size_t FindPositionForLogVector (G4double &x, std::vector< G4double > &x_vec)
 
G4double Interpolate (G4double &x, std::vector< G4double > &x_vec, std::vector< G4double > &y_vec, G4String InterPolMethod="Log")
 
G4double InterpolateWithIndexVector (G4double &x, std::vector< G4double > &x_vec, std::vector< G4double > &y_vec, std::vector< size_t > &index_vec, G4double x0, G4double dx)
 
G4double InterpolateForLogVector (G4double &x, std::vector< G4double > &x_vec, std::vector< G4double > &y_vec)
 

Static Public Member Functions

static G4AdjointInterpolatorGetAdjointInterpolator ()
 
static G4AdjointInterpolatorGetInstance ()
 

Detailed Description

Definition at line 53 of file G4AdjointInterpolator.hh.

Constructor & Destructor Documentation

◆ ~G4AdjointInterpolator()

G4AdjointInterpolator::~G4AdjointInterpolator ( )

Definition at line 58 of file G4AdjointInterpolator.cc.

59{;
60}

Member Function Documentation

◆ ExponentialInterpolation()

G4double G4AdjointInterpolator::ExponentialInterpolation ( G4double x,
G4double x1,
G4double x2,
G4double y1,
G4double y2 
)

Definition at line 81 of file G4AdjointInterpolator.cc.

82{ G4double B=(std::log(y2)-std::log(y1));
83 B=B/(x2-x1);
84 G4double A=y1*std::exp(-B*x1);
85 G4double res=A*std::exp(B*x);
86 return res;
87}
double G4double
Definition: G4Types.hh:64

Referenced by Interpolation().

◆ FindPosition()

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.

109{ //most rapid nethod could be used probably
110 //It is important to put std::vector<G4double>& such that the vector itself is used and not a copy
111
112
113 size_t ndim = x_vec.size();
114 size_t ind1 = 0;
115 size_t ind2 = ndim - 1;
116 /* if (ind_max >= ind_min){
117 ind1=ind_min;
118 ind2=ind_max;
119
120
121 }
122 */
123
124
125 if (ndim >1) {
126
127 if (x_vec[0] < x_vec[1] ) { //increasing
128 do {
129 size_t midBin = (ind1 + ind2)/2;
130 if (x < x_vec[midBin])
131 ind2 = midBin;
132 else
133 ind1 = midBin;
134 } while (ind2 - ind1 > 1);
135 }
136 else {
137 do {
138 size_t midBin = (ind1 + ind2)/2;
139 if (x < x_vec[midBin])
140 ind1 = midBin;
141 else
142 ind2 = midBin;
143 } while (ind2 - ind1 > 1);
144 }
145
146 }
147
148 return ind1;
149}

Referenced by G4AdjointCSMatrix::AddData(), FindPositionForLogVector(), Interpolate(), and InterpolateWithIndexVector().

◆ FindPositionForLogVector()

size_t G4AdjointInterpolator::FindPositionForLogVector ( G4double x,
std::vector< G4double > &  x_vec 
)

Definition at line 153 of file G4AdjointInterpolator.cc.

154{ //most rapid nethod could be used probably
155 //It is important to put std::vector<G4double>& such that the vector itself is used and not a copy
156 return FindPosition(log_x, log_x_vec);
157 /*
158 if (log_x_vec.size()>3){
159 size_t ind=0;
160 G4double log_x1=log_x_vec[1];
161 G4double d_log =log_x_vec[2]-log_x1;
162 G4double dind=(log_x-log_x1)/d_log +1.;
163 if (dind <1.) ind=0;
164 else if (dind >= double(log_x_vec.size())-2.) ind =log_x_vec.size()-2;
165 else ind =size_t(dind);
166 return ind;
167
168 }
169 else return FindPosition(log_x, log_x_vec);
170 */
171
172
173}
size_t FindPosition(G4double &x, std::vector< G4double > &x_vec, size_t ind_min=0, size_t ind_max=0)

Referenced by InterpolateForLogVector(), and G4VEmAdjointModel::SampleAdjSecEnergyFromCSMatrix().

◆ GetAdjointInterpolator()

G4AdjointInterpolator * G4AdjointInterpolator::GetAdjointInterpolator ( )
static

Definition at line 34 of file G4AdjointInterpolator.cc.

35{ if(theInstance == 0) {
36 static G4AdjointInterpolator interpolator;
37 theInstance = &interpolator;
38 }
39 return theInstance;
40}

◆ GetInstance()

G4AdjointInterpolator * G4AdjointInterpolator::GetInstance ( )
static

Definition at line 43 of file G4AdjointInterpolator.cc.

44{ if(theInstance == 0) {
45 static G4AdjointInterpolator interpolator;
46 theInstance = &interpolator;
47 }
48 return theInstance;
49}

Referenced by G4AdjointCSMatrix::AddData(), and G4VEmAdjointModel::SampleAdjSecEnergyFromCSMatrix().

◆ Interpolate()

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.

177{ size_t i=FindPosition(x,x_vec);
178 //G4cout<<i<<G4endl;
179 //G4cout<<x<<G4endl;
180 //G4cout<<x_vec[i]<<G4endl;
181 return Interpolation( x,x_vec[i],x_vec[i+1],y_vec[i],y_vec[i+1],InterPolMethod);
182}
G4double Interpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2, G4String InterPolMethod="Log")

Referenced by G4VEmAdjointModel::SampleAdjSecEnergyFromCSMatrix().

◆ InterpolateForLogVector()

G4double G4AdjointInterpolator::InterpolateForLogVector ( G4double x,
std::vector< G4double > &  x_vec,
std::vector< G4double > &  y_vec 
)

Definition at line 208 of file G4AdjointInterpolator.cc.

209{ //size_t i=0;
210 size_t i=FindPositionForLogVector(log_x,log_x_vec);
211 /*G4cout<<"In interpolate "<<G4endl;
212 G4cout<<i<<G4endl;
213 G4cout<<log_x<<G4endl;
214 G4cout<<log_x_vec[i]<<G4endl;
215 G4cout<<log_x_vec[i+1]<<G4endl;
216 G4cout<<log_y_vec[i]<<G4endl;
217 G4cout<<log_y_vec[i+1]<<G4endl;*/
218
219 G4double log_y=LinearInterpolation(log_x,log_x_vec[i],log_x_vec[i+1],log_y_vec[i],log_y_vec[i+1]);
220 return log_y;
221
222}
G4double LinearInterpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
size_t FindPositionForLogVector(G4double &x, std::vector< G4double > &x_vec)

Referenced by G4VEmAdjointModel::SampleAdjSecEnergyFromCSMatrix().

◆ InterpolateWithIndexVector()

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.

188{ size_t ind=0;
189 if (x>x0) ind=int((x-x0)/dx);
190 if (ind >= index_vec.size()-1) ind= index_vec.size()-2;
191 size_t ind1 = index_vec[ind];
192 size_t ind2 = index_vec[ind+1];
193 if (ind1 >ind2) {
194 size_t ind11=ind1;
195 ind1=ind2;
196 ind2=ind11;
197
198 }
199
200 ind=FindPosition(x,x_vec,ind1,ind2);
201 return Interpolation( x,x_vec[ind],x_vec[ind+1],y_vec[ind],y_vec[ind+1],"Lin");
202
203}

◆ Interpolation()

G4double G4AdjointInterpolator::Interpolation ( G4double x,
G4double x1,
G4double x2,
G4double y1,
G4double y2,
G4String  InterPolMethod = "Log" 
)

Definition at line 90 of file G4AdjointInterpolator.cc.

91{
92 if (InterPolMethod == "Log" ){
93 return LogarithmicInterpolation(x,x1,x2,y1,y2);
94 }
95 else if (InterPolMethod == "Lin" ){
96 return LinearInterpolation(x,x1,x2,y1,y2);
97 }
98 else if (InterPolMethod == "Exp" ){
99 return ExponentialInterpolation(x,x1,x2,y1,y2);
100 }
101 else {
102 //G4cout<<"The interpolation method that you invoked does not exist!"<<G4endl;
103 return -1111111111.;
104 }
105}
G4double ExponentialInterpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
G4double LogarithmicInterpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)

Referenced by Interpolate(), and InterpolateWithIndexVector().

◆ LinearInterpolation()

G4double G4AdjointInterpolator::LinearInterpolation ( G4double x,
G4double x1,
G4double x2,
G4double y1,
G4double y2 
)

Definition at line 63 of file G4AdjointInterpolator.cc.

64{ G4double res = y1+ (x-x1)*(y2-y1)/(x2-x1);
65 //G4cout<<"Linear "<<res<<G4endl;
66 return res;
67}

Referenced by InterpolateForLogVector(), Interpolation(), LogarithmicInterpolation(), and G4VEmAdjointModel::SampleAdjSecEnergyFromCSMatrix().

◆ LogarithmicInterpolation()

G4double G4AdjointInterpolator::LogarithmicInterpolation ( G4double x,
G4double x1,
G4double x2,
G4double y1,
G4double y2 
)

Definition at line 70 of file G4AdjointInterpolator.cc.

71{ if (y1<=0 || y2<=0 || x1<=0) return LinearInterpolation(x,x1,x2,y1,y2);
72 G4double B=std::log(y2/y1)/std::log(x2/x1);
73 //G4cout<<"x1,x2,y1,y2 "<<x1<<'\t'<<x2<<'\t'<<y1<<'\t'<<y2<<'\t'<<G4endl;
74 G4double A=y1/std::pow(x1,B);
75 G4double res=A*std::pow(x,B);
76 // G4cout<<"Log "<<res<<G4endl;
77 return res;
78}

Referenced by Interpolation().


The documentation for this class was generated from the following files: