10 #if !defined(__clang_major__) || __clang_major__ < 5
11 # include <ext/algorithm>
13 #include <utl/TabulatedFunctionComplexLgAmpPhase.h>
15 #include <utl/AugerException.h>
16 #include <utl/ErrorLogger.h>
26 TabulatedFunctionComplexLgAmpPhase::FillTable(
const Array& xValues,
29 const unsigned int xSize = xValues.size();
31 if (xSize != yValues.size()) {
33 err <<
"Size of x and y arrays are different.";
41 if (is_sorted(fX.begin(), fX.end()))
45 for (
unsigned int i = 0; i < xSize; ++i) {
46 unsigned int mini = i;
48 for (
unsigned int j = i+1; j < xSize; ++j) {
49 const double x = fX[j];
56 swap(fX[i], fX[mini]);
57 swap(fY[i], fY[mini]);
69 WARNING(
"Refusing to push the same x value twice.");
81 TabulatedFunctionComplexLgAmpPhase::Y(
double x)
84 const unsigned int size = fX.size();
88 msg <<
"No points in table.";
96 if (x < fX[0] || x > fX[size-1]) {
98 if (x < fX[0] && (fX[0] - x) / (fX[1] - fX[2]) < fBoundaryTolerance)
100 else if (x > fX[size-1] &&
101 (x - fX[size-1]) / (fX[size-1] - fX[size-2]) < fBoundaryTolerance)
104 boost::format err(
"Value x=%.10f is out of table bounds [%.10f, %.12f].");
105 err % x % fX[0] % fX[size-1];
112 const Array::const_iterator xBegin = fX.begin();
113 const Array::const_iterator xIt = upper_bound(xBegin, fX.end(), x);
114 int index = xIt - xBegin - 1;
115 const double x1 = fX[index];
120 const double x2 = fX[index];
128 TabulatedFunctionComplexLgAmpPhase::FindX(
const double x)
131 const Array::const_iterator xBegin = fX.begin();
132 const Array::const_iterator xEnd = fX.end();
133 const Array::const_iterator xIt = lower_bound(xBegin, xEnd, x);
134 if (xIt != xEnd && x == *xIt) {
135 const ArrayComplex::const_iterator yIt = fY.begin() + (xIt - xBegin);
146 const ArrayComplex::const_iterator yIt = find(fY.begin(), fY.end(), y);
147 const Array::const_iterator xIt = (yIt != fY.end()) ?
148 fX.begin() + (yIt - fY.begin()) : fX.end();
156 const Array::iterator xIt = lower_bound(fX.begin(), fX.end(), x);
157 const ArrayComplex::iterator yIt = fY.begin() + (xIt - fX.begin());
158 const Array::iterator ixIt = fX.insert(xIt, x);
159 const ArrayComplex::iterator iyIt = fY.insert(yIt, y);
165 TabulatedFunctionComplexLgAmpPhase::IsInValidRange(
const double x)
168 return fX.front() <= x && x <= fX.back();
182 TabulatedFunctionComplexLgAmpPhase::Pow(
const double power)
184 for (ArrayComplex::iterator it = YBegin(); it != YEnd(); ++it)
194 if (this->GetNPoints()<2) {
196 err <<
"LHS TabulatedFunctionComplexLgAmpPhase has less than 2 elements, cannot be multiplied.";
203 err <<
"RHS TabulatedFunctionComplexLgAmpPhase has less than 2 elements, cannot be multiplied.";
209 const double commonstart =
max(*XBegin(),*rhs.
XBegin());
210 const double commonend = min(this->GetX(this->GetNPoints()-1),rhs.
GetX(rhs.
GetNPoints()-1));
227 Array::const_iterator lxIt = XBegin();
228 while (*lxIt < commonstart)
232 Array::const_iterator rxIt = rhs.
XBegin();
233 while (*rxIt < commonstart)
244 tempX.push_back(*lxIt);
252 tempX.push_back(*lxIt);
258 tempX.push_back(*rxIt);
261 }
while ((*lxIt < commonend) || (*rxIt < commonend));
266 tempX.push_back(commonend);
269 tempY.reserve(tempX.size());
270 for (Array::const_iterator xIt = tempX.begin(); xIt != tempX.end(); ++xIt)
271 tempY.push_back(this->Y(*xIt)*rhs.
Y(*xIt));
void swap(utl::Trace< T > &t1, utl::Trace< T > &t2)
double Interpolate(const double dx, const double dy, const double x)
const phoenix::function< PowerToImpl > power
Exception for reporting variable out of valid range.
std::vector< double > Array
Class to hold collection (x,y) points and provide interpolation between them, where y are complex num...
double abs(const SVector< n, T > &v)
#define WARNING(message)
Macro for logging warning messages.
A class to store complex numbers which are internally represented by log10(amplitude) and phase (and ...
utl::ComplexLgAmpPhase Y(const double x) const
Get or interpolate the Y value that corresponds to parameter x.
Array::iterator XBegin()
begin of array of X
unsigned int GetNPoints() const
const double & GetX(const unsigned int idx) const
std::vector< utl::ComplexLgAmpPhase > ArrayComplex
#define ERROR(message)
Macro for logging error messages.
TabulatedPDF::Array Array
TabulatedFunctionComplexLgAmpPhase::ArrayComplex ArrayComplex