9 #include <utl/TabulatedFunction.h>
10 #include <utl/TabulatedFunctionErrors.h>
11 #include <utl/MultiTabulatedFunction.h>
12 #include <utl/MultiTabulatedFunctionErrors.h>
13 #include <utl/AugerException.h>
27 const double aX[] = { 1.1, 2.3, 4.2, 4.5, 6.7, 8.333, 12.12, 13.45 };
28 const double aY[] = { 5.7, 3.3, 6.3, 11.1, 1.1, -18.4, -20.7, 44.3 };
31 const double a2X[] = { 1, 2, 4, 3, 5, 6, 7, 8, 9, 10 };
32 const double a2Y[] = { 1, 2, 4, 3, 5, 6, 7, 8, 9, 10 };
35 const std::vector<double> vecX(aX, aX + aN);
36 const std::vector<double> vecY(aY, aY + aN);
37 const std::vector<double> vec2X(a2X, a2X + a2N);
38 const std::vector<double> vec2Y(a2Y, a2Y + a2N);
43 const double tx[] = { 2.11, 5.6, 2.7, 8.333, 9 };
45 cout <<
"Test points TF:\n";
46 for (
int i = 0; i < tN; ++i)
47 cout <<
"x= " << setw(5) << tx[i] <<
" y= " << setw(5) << TF.
Y(tx[i]) <<
'\n';
50 const double t2x[] = { 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5 };
52 cout <<
"Test points TF2:\n";
53 for (
int i = 0; i < t2N; ++i)
54 cout <<
"x= " << setw(3) << t2x[i] <<
" y= " << setw(5) << TF2.
Y(t2x[i]) <<
'\n';
57 double a3X[] = { 1, 3, 5 };
58 double a3Y[] = { 1, 9, 25 };
60 const std::vector<double> vec3X(a3X, a3X + a3N);
61 const std::vector<double> vec3Y(a3Y, a3Y + a3N);
64 cout <<
"Test points TF3:\n";
65 for (
double xVal = 1.0; xVal <= 5.0; xVal += 0.1)
66 cout <<
"x= " << setw(3) << xVal <<
" y= " << setw(5) << TF3.
Y(xVal) <<
'\n';
69 cout <<
"Test points TF3 - interpolation order 1:\n";
70 for (
double xVal = 1.0; xVal <= 5.0 ; xVal += 0.1)
71 cout <<
"x= " << setw(3) << xVal <<
" y= " << setw(5) << TF3.
InterpolateY(xVal, 1) <<
'\n';
74 cout <<
"Test points TF3 - interpolation order 2:\n";
75 for (
double xVal = 1.0; xVal <= 5.0 ; xVal += 0.1)
76 cout <<
"x= " << setw(3) << xVal <<
" y= " << setw(5) << TF3.
InterpolateY(xVal, 2) <<
'\n';
78 cout << endl <<
"Testing operator[]..." << endl
79 << TF[0].X() <<
" " << TF[0].
Y() << endl
80 << endl <<
"Testing iterator" << endl;
86 cout << it->
X() <<
" " << it->
Y() << endl;
88 cout << endl <<
"Testing operator[]..." << endl;
89 for (
unsigned int i = 0; i < TF.
GetNPoints(); ++i)
90 cout << TF[i].X() <<
" " << TF[i].
Y() << endl;
93 << endl <<
"Testing PushBack..." << endl;
104 cout << it->
X() <<
" " << it->
Y() << endl;
107 cout << endl <<
"Testing const iterator" << endl;
112 it != cf.
End(); ++it)
113 cout << it->
X() <<
" " << it->
Y() << endl;
127 for (
unsigned int i = 0; i < tab.
GetNPoints(); ++i)
128 cout << tab[i].X() <<
" " << tab[i].
Y() << endl;
130 cout <<
"Testing TabulatedFunctionError" << endl;
142 cout <<
" iterator " << endl;
145 it != tberr.
End(); ++it)
146 cout <<
"x " << it->
X() <<
" +- " << it->XErr()
147 <<
", y " << it->
Y() <<
" +- " << it->YErr() << endl;
150 cout <<
"Y(16.5)= " << tberr.
Y(16.5) << endl;
151 cout <<
"Y(11.5)= " << tberr.
Y(11.5) << endl;
153 for (
int i = 0; i < 3; ++i)
154 cout <<
"x " << tberr[i].X() <<
" +- " << tberr[i].XErr()
155 <<
", y " << tberr[i].
Y() <<
" +- " << tberr[i].YErr() << endl;
157 cout <<
"Test MultiTabulatedFunction..." << endl;
166 cout <<
"x " << fp[0].X() <<endl;
169 cout <<
"x " << fp2[0].X() <<
" +- " << fp2[0].XErr() << endl;
171 cout <<
"Test copy ctor" << endl;
174 cout <<
"x " << fpcopy1[0].X() << endl;
178 cout <<
"x " << fpcopy2[0].X() <<
" +- " << fpcopy2[0].XErr() << endl;
181 const std::vector<double> sX(1, 1.0);
182 const std::vector<double> sY(1, 10.0);
184 cout <<
"tabulated func initialzed with one pair" << endl;
187 cout <<
" STF(1.0) " << STF.
Y(1.0) << endl;
189 cout <<
"message " << ex.
GetMessage() << endl;
193 cout <<
" STF(0.5) " << STF.
Y(0.5) << endl;
195 cout <<
"caught expected exception " << ex.GetExceptionName() << endl;
198 cout <<
"checking FindX and FindY methods" << endl;
201 cout << it->
X() <<
" == " << tberr.
FindY(it->
Y())->X() <<
"?\t"
202 << it->
Y() <<
" == " << tberr.
FindX(it->
X())->Y() <<
"?" << endl;
207 cout <<
"pushing the same point twice " << endl;
213 cout <<
"pushed 3 points, got " << crap.
GetNPoints() <<
'\n'
unsigned int GetNPoints() const
Base class for all exceptions used in the auger offline code.
Class to hold collection (x,y) points and provide interpolation between them.
void AddTabulatedFunction(const int label)
void PushBack(const double x, const double y)
int main(int argc, char *argv[])
TabulatedFunction & GetTabulatedFunction(const int label=0)
Returns the TabulatedFunction for /par source, throws an exception if na.
A collection of TabulatedFunctionErrors, which provides methods to access different sources...
void PushBack(const double x, const double xErr, const double y, const double yErr)
TabulatedFunctionErrors & GetTabulatedFunctionErrors(const int label=0)
Returns the TabulatedFunctionErrors for /par source.
double InterpolateY(const double x, const unsigned int polyDegree) const
Interpolate the Y value with a polyDegree polynomial.
const double & GetX(const unsigned int idx) const
A collection of TabulatedFunction.
ConstIteratorErr FindX(const double x) const
void AddTabulatedFunctionErrors(const int label)
double Y(const double x) const
Get or interpolate the Y value that corresponds to parameter x.
ConstIteratorErr FindY(const double y) const
const std::string & GetMessage() const
Retrieve the message from the exception.