Geant4-11
Public Member Functions | Private Member Functions
G4ParticleHPInterpolator Class Reference

#include <G4ParticleHPInterpolator.hh>

Public Member Functions

 G4ParticleHPInterpolator ()
 
G4double GetBinIntegral (const G4InterpolationScheme &aScheme, const G4double x1, const G4double x2, const G4double y1, const G4double y2)
 
G4double GetWeightedBinIntegral (const G4InterpolationScheme &aScheme, const G4double x1, const G4double x2, const G4double y1, const G4double y2)
 
G4double Interpolate (G4InterpolationScheme aScheme, G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
 
G4double Interpolate2 (G4InterpolationScheme aScheme, G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
 
G4double Lin (G4double x, G4double x1, G4double x2, G4double y1, G4double y2)
 
 ~G4ParticleHPInterpolator ()
 

Private Member Functions

G4double Histogram (G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
 
G4double LinearLinear (G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
 
G4double LinearLogarithmic (G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
 
G4double LogarithmicLinear (G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
 
G4double LogarithmicLogarithmic (G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
 
G4double Random (G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
 

Detailed Description

Definition at line 44 of file G4ParticleHPInterpolator.hh.

Constructor & Destructor Documentation

◆ G4ParticleHPInterpolator()

G4ParticleHPInterpolator::G4ParticleHPInterpolator ( )
inline

Definition at line 48 of file G4ParticleHPInterpolator.hh.

48{}

◆ ~G4ParticleHPInterpolator()

G4ParticleHPInterpolator::~G4ParticleHPInterpolator ( )
inline

Definition at line 49 of file G4ParticleHPInterpolator.hh.

50 {
51 // G4cout <<"deleted the interpolator"<<G4endl;
52 }

Member Function Documentation

◆ GetBinIntegral()

G4double G4ParticleHPInterpolator::GetBinIntegral ( const G4InterpolationScheme aScheme,
const G4double  x1,
const G4double  x2,
const G4double  y1,
const G4double  y2 
)

Definition at line 35 of file G4ParticleHPInterpolator.cc.

38 { // inline again later on @@@@
39 G4double result = 0;
40 if(aScheme==HISTO||aScheme==CHISTO||aScheme==UHISTO)
41 {
42 result = y1*(x2-x1);
43 }
44 else if(aScheme==LINLIN||aScheme==CLINLIN||aScheme==ULINLIN)
45 {
46 result = 0.5*(y2+y1)*(x2-x1);
47 }
48 else if(aScheme==LINLOG||aScheme==CLINLOG||aScheme==ULINLOG)
49 {
50 if(x1==0) result = y1;
51 else if(x2==0) result = y2;
52 else
53 {
54 G4double b = (y2-y1)/(G4Log(x2)-G4Log(x1));
55 G4double a = y1 - b*G4Log(x1);
56 result = (a-b)*(x2-x1) + b*(x2*G4Log(x2)-x1*G4Log(x1));
57 }
58 }
59 else if(aScheme==LOGLIN||aScheme==CLOGLIN||aScheme==ULOGLIN)
60 {
61 if ( y1==0||y2==0 ) {
62 result =0;
63 } else {
64 // G4double b = (std::log(y2)-std::log(y1))/(x2-x1);
65 // G4double a = std::log(y1) - b*x1;
66 //***************************************************************
67 //EMendoza:
68 //result = (std::exp(a)/b)*(std::exp(b*x2)-std::exp(b*x1));
69 //***************************************************************
70 if ( y1!=y2 ) {
71 result = (x2-x1)*(y2-y1)/G4Log(y2/y1);
72 } else {
73 result = y2*(x2-x1);
74 }
75 //***************************************************************
76 }
77 }
78 else if(aScheme==LOGLOG||aScheme==CLOGLOG||aScheme==ULOGLOG)
79 {
80 if(x1==0) result = y1;
81 else if(x2==0) result = y2;
82 else if(y1==0||y2==0) result =0;
83 else
84 {
85 G4double b = (G4Log(y2)-G4Log(y1))/(G4Log(x2)-G4Log(x1));
86 G4double a = G4Log(y1) - b*G4Log(x1);;
87 result = (G4Exp(a)/(b+1))*(G4Pow::GetInstance()->powA(x2,b+1)-G4Pow::GetInstance()->powA(x1,b+1));
88 }
89 }
90 else
91 {
92 throw G4HadronicException(__FILE__, __LINE__, "Unknown interpolation scheme in G4ParticleHPVector::Integrate");
93 }
94 return result;
95 }
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition: G4Exp.hh:179
G4double G4Log(G4double x)
Definition: G4Log.hh:226
double G4double
Definition: G4Types.hh:83
static G4Pow * GetInstance()
Definition: G4Pow.cc:41
G4double powA(G4double A, G4double y) const
Definition: G4Pow.hh:230

References CHISTO, CLINLIN, CLINLOG, CLOGLIN, CLOGLOG, G4Exp(), G4Log(), G4Pow::GetInstance(), HISTO, LINLIN, LINLOG, LOGLIN, LOGLOG, G4Pow::powA(), UHISTO, ULINLIN, ULINLOG, ULOGLIN, and ULOGLOG.

Referenced by G4ParticleHPVector::GetMeanX(), G4ParticleHPVector::IntegrateAndNormalise(), and G4ParticleHPContAngularPar::Sample().

◆ GetWeightedBinIntegral()

G4double G4ParticleHPInterpolator::GetWeightedBinIntegral ( const G4InterpolationScheme aScheme,
const G4double  x1,
const G4double  x2,
const G4double  y1,
const G4double  y2 
)

Definition at line 96 of file G4ParticleHPInterpolator.cc.

99 { // inline again later on @@@@
100 G4double result = 0;
101 if(aScheme==HISTO||aScheme==CHISTO||aScheme==UHISTO)
102 {
103 result = 0.5*y1*(x2*x2-x1*x1);
104 }
105 else if(aScheme==LINLIN||aScheme==CLINLIN||aScheme==ULINLIN)
106 {
107 // G4double b = (y2-y1)/(x2-x1);
108 // G4double a = y1 - b*x1;
109 // result = 0.5*a*(x2*x2-x1*x1) + (b/3.)*(x2*x2*x2-x1*x1*x1);
110 // Factor out x2-x1 to avoid divide by zero
111
112 result = (y1*x2 - y2*x1)*(x2 + x1)/2. + (y2-y1)*(x2*x2 + x2*x1 + x1*x1)/3.;
113 }
114 else if(aScheme==LINLOG||aScheme==CLINLOG||aScheme==ULINLOG)
115 {
116 if(x1==0) result = y1;
117 else if(x2==0) result = y2;
118 else
119 {
120 G4double b = (y2-y1)/(G4Log(x2)-G4Log(x1));
121 G4double a = y1 - b*G4Log(x1);
122 result = ( x2*x2/2. * (a-b/2.+b*G4Log(x2)) )
123 -( x1*x1/2. * (a-b/2.+b*G4Log(x1)) );
124 }
125 }
126 else if(aScheme==LOGLIN||aScheme==CLOGLIN||aScheme==ULOGLIN)
127 {
128 if(y1==0||y2==0) result = 0;
129 else
130 {
131 G4double b = (G4Log(y2)-G4Log(y1))/(x2-x1);
132 G4double a = G4Log(y1) - b*x1;
133 result = G4Exp(a)/(b*b)*( G4Exp(b*x2)*(b*x2-1.) - G4Exp(b*x1)*(b*x1-1.) );
134 }
135 }
136 else if(aScheme==LOGLOG||aScheme==CLOGLOG||aScheme==ULOGLOG)
137 {
138 if(x1==0) result = y1;
139 else if(x2==0) result = y2;
140 else if(y1==0||y2==0) result = 0;
141 else
142 {
143 G4double b = (G4Log(y2)-G4Log(y1))/(G4Log(x2)-G4Log(x1));
144 G4double a = G4Log(y1) - b*G4Log(x1);;
145 result = G4Exp(a)/(b+2.)*( G4Pow::GetInstance()->powA(x2, b+2.) - G4Pow::GetInstance()->powA(x1, b+2) );
146 }
147 }
148 else
149 {
150 throw G4HadronicException(__FILE__, __LINE__, "Unknown interpolation scheme in G4ParticleHPVector::Integrate");
151 }
152 return result;
153 }

References CHISTO, CLINLIN, CLINLOG, CLOGLIN, CLOGLOG, G4Exp(), G4Log(), G4Pow::GetInstance(), HISTO, LINLIN, LINLOG, LOGLIN, LOGLOG, G4Pow::powA(), UHISTO, ULINLIN, ULINLOG, ULOGLIN, and ULOGLOG.

Referenced by G4ParticleHPVector::GetMeanX(), and G4ParticleHPContAngularPar::Sample().

◆ Histogram()

G4double G4ParticleHPInterpolator::Histogram ( G4double  x,
G4double  x1,
G4double  x2,
G4double  y1,
G4double  y2 
) const
inlineprivate

Definition at line 162 of file G4ParticleHPInterpolator.hh.

164{
165 G4double result;
166 result = y1;
167 return result;
168}

Referenced by Interpolate2().

◆ Interpolate()

G4double G4ParticleHPInterpolator::Interpolate ( G4InterpolationScheme  aScheme,
G4double  x,
G4double  x1,
G4double  x2,
G4double  y1,
G4double  y2 
) const
inline

Definition at line 90 of file G4ParticleHPInterpolator.hh.

93{
94 G4double result(0);
95 G4int theScheme = aScheme;
96 theScheme = theScheme%CSTART_;
97 switch(theScheme)
98 {
99 case 1:
100 //080809
101 //result = Histogram(x, x1, x2, y1, y2);
102 result = LinearLinear(x, x1, x2, y1, y2);
103 break;
104 case 2:
105 result = LinearLinear(x, x1, x2, y1, y2);
106 break;
107 case 3:
108 result = LinearLogarithmic(x, x1, x2, y1, y2);
109 break;
110 case 4:
111 result = LogarithmicLinear(x, x1, x2, y1, y2);
112 break;
113 case 5:
114 result = LogarithmicLogarithmic(x, x1, x2, y1, y2);
115 break;
116 case 6:
117 result = Random(x, x1, x2, y1, y2);
118 break;
119 default:
120 G4cout << "theScheme = "<<theScheme<<G4endl;
121 throw G4HadronicException(__FILE__, __LINE__, "G4ParticleHPInterpolator::Carthesian Invalid InterpolationScheme");
122 break;
123 }
124 return result;
125}
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4double LinearLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
G4double LogarithmicLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
G4double LinearLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
G4double Random(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
G4double LogarithmicLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const

References CSTART_, G4cout, G4endl, LinearLinear(), LinearLogarithmic(), LogarithmicLinear(), LogarithmicLogarithmic(), and Random().

Referenced by G4ParticleHPContAngularPar::BuildByInterpolation(), G4ParticleHPAngularP::GetCosTh(), G4ParticleHPVector::GetXsec(), G4ParticleHPPartial::GetY(), G4ParticleHPVector::Merge(), G4ParticleHPDiscreteTwoBody::Sample(), G4ParticleHPLabAngularEnergy::Sample(), G4ParticleHPContAngularPar::Sample(), G4ParticleHPLegendreStore::Sample(), G4ParticleHPPartial::Sample(), G4ParticleHPLegendreStore::SampleDiscreteTwoBody(), G4ParticleHPLegendreStore::SampleElastic(), and G4ParticleHPLegendreStore::SampleMax().

◆ Interpolate2()

G4double G4ParticleHPInterpolator::Interpolate2 ( G4InterpolationScheme  aScheme,
G4double  x,
G4double  x1,
G4double  x2,
G4double  y1,
G4double  y2 
) const
inline

Definition at line 127 of file G4ParticleHPInterpolator.hh.

130{
131 G4double result(0);
132 G4int theScheme = aScheme;
133 theScheme = theScheme%CSTART_;
134 switch(theScheme)
135 {
136 case 1:
137 result = Histogram(x, x1, x2, y1, y2);
138 break;
139 case 2:
140 result = LinearLinear(x, x1, x2, y1, y2);
141 break;
142 case 3:
143 result = LinearLogarithmic(x, x1, x2, y1, y2);
144 break;
145 case 4:
146 result = LogarithmicLinear(x, x1, x2, y1, y2);
147 break;
148 case 5:
149 result = LogarithmicLogarithmic(x, x1, x2, y1, y2);
150 break;
151 case 6:
152 result = Random(x, x1, x2, y1, y2);
153 break;
154 default:
155 G4cout << "theScheme = "<<theScheme<<G4endl;
156 throw G4HadronicException(__FILE__, __LINE__, "G4ParticleHPInterpolator::Carthesian Invalid InterpolationScheme");
157 break;
158 }
159 return result;
160}
G4double Histogram(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const

References CSTART_, G4cout, G4endl, Histogram(), LinearLinear(), LinearLogarithmic(), LogarithmicLinear(), LogarithmicLogarithmic(), and Random().

Referenced by G4ParticleHPContAngularPar::BuildByInterpolation().

◆ Lin()

G4double G4ParticleHPInterpolator::Lin ( G4double  x,
G4double  x1,
G4double  x2,
G4double  y1,
G4double  y2 
)
inline

Definition at line 54 of file G4ParticleHPInterpolator.hh.

55 {
56 G4double slope=0, off=0;
57 if(x2-x1==0) return (y2+y1)/2.;
58 slope = (y2-y1)/(x2-x1);
59 off = y2-x2*slope;
60 G4double y = x*slope+off;
61 return y;
62 }

Referenced by G4ParticleHPVector::Get50percentBorder(), G4ParticleHPVector::SampleLin(), and G4ParticleHPVector::ThinOut().

◆ LinearLinear()

G4double G4ParticleHPInterpolator::LinearLinear ( G4double  x,
G4double  x1,
G4double  x2,
G4double  y1,
G4double  y2 
) const
inlineprivate

Definition at line 170 of file G4ParticleHPInterpolator.hh.

172{
173 G4double slope=0, off=0;
174 if(x2-x1==0) return (y2+y1)/2.;
175 slope = (y2-y1)/(x2-x1);
176 off = y2-x2*slope;
177 G4double y = x*slope+off;
178 return y;
179}

Referenced by Interpolate(), Interpolate2(), LinearLogarithmic(), LogarithmicLinear(), and LogarithmicLogarithmic().

◆ LinearLogarithmic()

G4double G4ParticleHPInterpolator::LinearLogarithmic ( G4double  x,
G4double  x1,
G4double  x2,
G4double  y1,
G4double  y2 
) const
inlineprivate

Definition at line 181 of file G4ParticleHPInterpolator.hh.

183{
184 G4double result;
185 if(x==0) result = y1+y2/2.;
186 else if(x1==0) result = y1;
187 else if(x2==0) result = y2;
188 else result = LinearLinear(G4Log(x), G4Log(x1), G4Log(x2), y1, y2);
189 return result;
190}

References G4Log(), and LinearLinear().

Referenced by Interpolate(), and Interpolate2().

◆ LogarithmicLinear()

G4double G4ParticleHPInterpolator::LogarithmicLinear ( G4double  x,
G4double  x1,
G4double  x2,
G4double  y1,
G4double  y2 
) const
inlineprivate

Definition at line 192 of file G4ParticleHPInterpolator.hh.

194{
195 G4double result;
196 if(y1==0||y2==0) result = 0;
197 else
198 {
199 result = LinearLinear(x, x1, x2, G4Log(y1), G4Log(y2));
200 result = G4Exp(result);
201 }
202 return result;
203}

References G4Exp(), G4Log(), and LinearLinear().

Referenced by Interpolate(), and Interpolate2().

◆ LogarithmicLogarithmic()

G4double G4ParticleHPInterpolator::LogarithmicLogarithmic ( G4double  x,
G4double  x1,
G4double  x2,
G4double  y1,
G4double  y2 
) const
inlineprivate

Definition at line 205 of file G4ParticleHPInterpolator.hh.

207{
208 if(x==0) return y1+y2/2.;
209 else if(x1==0) return y1;
210 else if(x2==0) return y2;
211 G4double result;
212 if(y1==0||y2==0) result = 0;
213 else
214 {
215 result = LinearLinear(G4Log(x), G4Log(x1), G4Log(x2), G4Log(y1), G4Log(y2));
216 result = G4Exp(result);
217 }
218 return result;
219}

References G4Exp(), G4Log(), and LinearLinear().

Referenced by Interpolate(), and Interpolate2().

◆ Random()

G4double G4ParticleHPInterpolator::Random ( G4double  x,
G4double  x1,
G4double  x2,
G4double  y1,
G4double  y2 
) const
inlineprivate

Definition at line 221 of file G4ParticleHPInterpolator.hh.

223{
224 G4double result;
225 result = y1+G4UniformRand()*(y2-y1);
226 return result;
227}
#define G4UniformRand()
Definition: Randomize.hh:52

References G4UniformRand.

Referenced by Interpolate(), and Interpolate2().


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