#include <G4PolynomialPDF.hh>
|
| G4PolynomialPDF (size_t n=0, const double *coeffs=nullptr, G4double x1=0, G4double x2=1) |
|
| ~G4PolynomialPDF () |
|
void | SetNCoefficients (size_t n) |
|
size_t | GetNCoefficients () const |
|
void | SetCoefficients (const std::vector< G4double > &v) |
|
G4double | GetCoefficient (size_t i) const |
|
void | SetCoefficient (size_t i, G4double value) |
|
void | SetCoefficients (size_t n, const G4double *coeffs) |
|
void | SetDomain (G4double x1, G4double x2) |
|
void | Normalize () |
|
G4double | Evaluate (G4double x, G4int ddxPower=0) |
|
G4double | GetRandomX () |
|
void | SetTolerance (G4double tolerance) |
|
G4double | GetX (G4double p, G4double x1, G4double x2, G4int ddxPower=0, G4double guess=1.e99, G4bool bisect=true) |
|
G4double | EvalInverseCDF (G4double p) |
|
G4double | Bisect (G4double p, G4double x1, G4double x2) |
|
void | Dump () |
|
Definition at line 49 of file G4PolynomialPDF.hh.
G4PolynomialPDF::G4PolynomialPDF |
( |
size_t |
n = 0 , |
|
|
const double * |
coeffs = nullptr , |
|
|
G4double |
x1 = 0 , |
|
|
G4double |
x2 = 1 |
|
) |
| |
Definition at line 43 of file G4PolynomialPDF.cc.
void SetCoefficients(const std::vector< G4double > &v)
void SetNCoefficients(size_t n)
G4PolynomialPDF::~G4PolynomialPDF |
( |
| ) |
|
Definition at line 363 of file G4PolynomialPDF.cc.
368 if(fz < 0)
return Bisect(
p, z, x2);
G4double GetX(G4double p, G4double x1, G4double x2, G4int ddxPower=0, G4double guess=1.e99, G4bool bisect=true)
G4double Bisect(G4double p, G4double x1, G4double x2)
G4double Evaluate(G4double x, G4int ddxPower=0)
void G4PolynomialPDF::Dump |
( |
| ) |
|
Definition at line 372 of file G4PolynomialPDF.cc.
374 G4cout <<
"G4PolynomialPDF::Dump() - PDF(x) = ";
379 if(i>1)
G4cout <<
"^" << i;
382 G4cout <<
"G4PolynomialPDF::Dump() - Interval: " <<
fX1 <<
" <= x < "
G4GLOB_DLL std::ostream G4cout
G4double GetCoefficient(size_t i) const
size_t GetNCoefficients() const
Definition at line 99 of file G4PolynomialPDF.hh.
G4double GetX(G4double p, G4double x1, G4double x2, G4int ddxPower=0, G4double guess=1.e99, G4bool bisect=true)
Evaluate f(x) ddxPower = -1: f = CDF ddxPower = 0: f = PDF ddxPower = 1: f = (d/dx) PDF ddxPower = 2: f = (d2/dx2) PDF
Definition at line 116 of file G4PolynomialPDF.cc.
123 if(ddxPower < -1 || ddxPower > 2) {
125 G4cout <<
"G4PolynomialPDF::GetX() WARNING: ddxPower " << ddxPower
126 <<
" not implemented" <<
G4endl;
140 else if(ddxPower == 1) {
143 else if(ddxPower == 2) {
G4GLOB_DLL std::ostream G4cout
G4double GetCoefficient(size_t i) const
size_t GetNCoefficients() const
G4double G4PolynomialPDF::GetCoefficient |
( |
size_t |
i | ) |
const |
|
inline |
size_t G4PolynomialPDF::GetNCoefficients |
( |
| ) |
const |
|
inline |
G4double G4PolynomialPDF::GetRandomX |
( |
| ) |
|
Definition at line 192 of file G4PolynomialPDF.cc.
198 G4cout <<
"G4PolynomialPDF::GetRandomX() WARNING: PDF has negative values, returning 0..."
G4GLOB_DLL std::ostream G4cout
G4bool HasNegativeMinimum(G4double x1, G4double x2)
G4double EvalInverseCDF(G4double p)
Find a value of X between x1 and x2 at which f(x) = p. ddxPower = -1: f = CDF ddxPower = 0: f = PDF ddxPower = 1: f = (d/dx) PDF Uses the Newton-Raphson method to find the zero of f(x) - p. If not found in range, returns the nearest boundary
Definition at line 208 of file G4PolynomialPDF.cc.
221 G4cout <<
"G4PolynomialPDF::GetX() WARNING: no PDF defined!" <<
G4endl;
225 if(ddxPower < -1 || ddxPower > 1) {
227 G4cout <<
"G4PolynomialPDF::GetX() WARNING: ddxPower " << ddxPower
228 <<
" not implemented" <<
G4endl;
234 G4cout <<
"G4PolynomialPDF::GetX() WARNING: p is out of range" <<
G4endl;
240 if(x2 <= x1 || x1 < fX1 || x2 >
fX2) {
242 G4cout <<
"G4PolynomialPDF::GetX() WARNING: domain must have fX1 <= x1 < x2 <= fX2. "
243 <<
"You sent x1 = " << x1 <<
", x2 = " << x2 <<
"." <<
G4endl;
258 if(ddxPower == 1) slope *= 2.;
263 else if(value > x2) {
278 if(ddxPower == 1) b *= 2.;
280 if(ddxPower == 1) a *= 3;
281 else if(ddxPower == -1) a *= 0.5;
282 double sqrtFactor = b*b - 4.*a*c;
283 if(sqrtFactor < 0)
return x2;
284 sqrtFactor = sqrt(sqrtFactor)/2./fabs(a);
285 G4double valueMinus = -b/2./a - sqrtFactor;
286 if(valueMinus >= x1 && valueMinus <= x2)
return valueMinus;
287 else if(valueMinus > x2)
return x2;
288 G4double valuePlus = -b/2./a + sqrtFactor;
289 if(valuePlus >= x1 && valuePlus <= x2)
return valuePlus;
290 else if(valuePlus < x1)
return x2;
291 return (x1-valueMinus <= valuePlus-x2) ? x1 : x2;
296 if(guess < x1 || guess > x2) guess = (x2+x1)*0.5;
298 size_t iterations = 0;
311 else if(ddxPower == 0) {
321 if(f == 0)
return guess;
324 G4cout <<
"G4PolynomialPDF::GetX() WARNING: got f != 0 but slope = 0 for ddxPower = "
329 lastChange = - f/dfdx;
331 if(guess + lastChange < x1) {
332 lastChange = x1 - guess;
333 }
else if(guess + lastChange > x2) {
334 lastChange = x2 - guess;
338 lastChange /= (fX2-
fX1);
341 if(iterations > 50) {
344 G4cout <<
"G4PolynomialPDF::GetX() WARNING: got stuck searching for " <<
p
345 <<
" between " << x1 <<
" and " << x2 <<
" with ddxPower = "
347 <<
". Last guess was " << guess <<
"." <<
G4endl;
350 if(ddxPower==-1 && bisect) {
352 G4cout <<
"G4PolynomialPDF::GetX() WARNING: Bisceting and trying again..."
G4double Bisect(G4double p, G4double x1, G4double x2)
G4GLOB_DLL std::ostream G4cout
G4double GetCoefficient(size_t i) const
const XML_Char int const XML_Char * value
size_t GetNCoefficients() const
Definition at line 151 of file G4PolynomialPDF.cc.
156 if(x1 < fX1 || x2 >
fX2 || x2 < x1) {
158 G4cout <<
"G4PolynomialPDF::HasNegativeMinimum() WARNING: Invalid range "
159 << x1 <<
" - " << x2 <<
G4endl;
177 if(xMin < x1) xMin = x1;
178 if(xMin > x2) xMin = x2;
187 extremum >= x2-(x2-x1)*
fTolerance)
return false;
G4double GetX(G4double p, G4double x1, G4double x2, G4int ddxPower=0, G4double guess=1.e99, G4bool bisect=true)
G4GLOB_DLL std::ostream G4cout
G4double GetCoefficient(size_t i) const
G4bool HasNegativeMinimum(G4double x1, G4double x2)
size_t GetNCoefficients() const
G4double Evaluate(G4double x, G4int ddxPower=0)
void G4PolynomialPDF::Normalize |
( |
| ) |
|
Normalize PDF to 1 over domain fX1 to fX2. Double-check that the highest-order coefficient is non-zero.
Definition at line 86 of file G4PolynomialPDF.cc.
104 G4cout <<
"G4PolynomialPDF::Normalize() WARNING: PDF has non-positive area: "
std::vector< G4double > fCoefficients
G4GLOB_DLL std::ostream G4cout
G4double GetCoefficient(size_t i) const
void SetCoefficient(size_t i, G4double value)
size_t GetNCoefficients() const
void G4PolynomialPDF::SetCoefficient |
( |
size_t |
i, |
|
|
G4double |
value |
|
) |
| |
Definition at line 54 of file G4PolynomialPDF.cc.
std::vector< G4double > fCoefficients
const XML_Char int const XML_Char * value
void G4PolynomialPDF::SetCoefficients |
( |
const std::vector< G4double > & |
v | ) |
|
|
inline |
void G4PolynomialPDF::SetCoefficients |
( |
size_t |
n, |
|
|
const G4double * |
coeffs |
|
) |
| |
Definition at line 62 of file G4PolynomialPDF.cc.
void SetNCoefficients(size_t n)
void SetCoefficient(size_t i, G4double value)
size_t GetNCoefficients() const
Definition at line 72 of file G4PolynomialPDF.cc.
76 G4cout <<
"G4PolynomialPDF::SetDomain() WARNING: Invalide domain! "
77 <<
"(x1 = " << x1 <<
", x2 = " << x2 <<
")." <<
G4endl;
G4GLOB_DLL std::ostream G4cout
void G4PolynomialPDF::SetNCoefficients |
( |
size_t |
n | ) |
|
|
inline |
G4bool G4PolynomialPDF::fChanged |
|
protected |
std::vector<G4double> G4PolynomialPDF::fCoefficients |
|
protected |
G4int G4PolynomialPDF::fVerbose |
|
protected |
The documentation for this class was generated from the following files: