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

#include <G4ParticleHPInterpolator.hh>

Public Member Functions

 G4ParticleHPInterpolator ()=default
 
 ~G4ParticleHPInterpolator ()=default
 
G4double Lin (G4double x, G4double x1, G4double x2, G4double y1, 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 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)
 

Detailed Description

Definition at line 43 of file G4ParticleHPInterpolator.hh.

Constructor & Destructor Documentation

◆ G4ParticleHPInterpolator()

G4ParticleHPInterpolator::G4ParticleHPInterpolator ( )
default

◆ ~G4ParticleHPInterpolator()

G4ParticleHPInterpolator::~G4ParticleHPInterpolator ( )
default

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 36 of file G4ParticleHPInterpolator.cc.

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

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 99 of file G4ParticleHPInterpolator.cc.

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

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

◆ Interpolate()

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

Definition at line 83 of file G4ParticleHPInterpolator.hh.

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

Referenced by G4ParticleHPContAngularPar::BuildByInterpolation(), G4ParticleHPAngularP::GetCosTh(), G4ParticleHPVector::GetXsec(), G4ParticleHPVector::GetXsec(), G4ParticleHPPartial::GetY(), G4ParticleHPVector::Merge(), G4ParticleHPContAngularPar::Sample(), G4ParticleHPDiscreteTwoBody::Sample(), G4ParticleHPLabAngularEnergy::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 120 of file G4ParticleHPInterpolator.hh.

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

Referenced by G4ParticleHPContAngularPar::BuildByInterpolation().

◆ Lin()

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

Definition at line 49 of file G4ParticleHPInterpolator.hh.

50 {
51 G4double slope = 0, off = 0;
52 if (x2 - x1 == 0) return (y2 + y1) / 2.;
53 slope = (y2 - y1) / (x2 - x1);
54 off = y2 - x2 * slope;
55 G4double y = x * slope + off;
56 return y;
57 }

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


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