testTabulatedFunctionComplexLgAmpPhase.cc
Go to the documentation of this file.
1 
8 #include <iostream>
9 
10 #include <tst/Verify.h>
11 
12 #include <utl/ComplexLgAmpPhase.h>
13 #include <utl/TabulatedFunctionComplexLgAmpPhase.h>
14 #include <utl/AugerException.h>
15 #include <utl/AugerUnits.h>
16 
17 #include <cppunit/extensions/HelperMacros.h>
18 
19 using namespace std;
20 using namespace utl;
21 using namespace tst;
22 
26 class testTabulatedFunctionComplexLgAmpPhase : public CppUnit::TestFixture {
27 
28  CPPUNIT_TEST_SUITE(testTabulatedFunctionComplexLgAmpPhase);
29  CPPUNIT_TEST(testInterpolation);
30  CPPUNIT_TEST(testMultiplication);
31  CPPUNIT_TEST_SUITE_END();
32 
33 private:
34 
35 public:
36  void
38  {
39  }
40 
41  void
43  {
44  }
45 
46  void
48  {
49  // configure the tests
50  const unsigned int numpoints = 10;
51  const unsigned int numcheckpoints = 100;
52  const double phasestepsize = 50.*degree;
53 
54  // create our working TabulatedFunctionComplexLgAmpPhase
56 
57  // fill in some test data
58  for (unsigned int i=0; i<=numpoints; ++i)
59  tfc1.PushBack(double(i),ComplexLgAmpPhase(double(numpoints*i),double(phasestepsize*i)));
60 
61  // test number of entries
62  CPPUNIT_ASSERT(Verify<Equal>(tfc1.GetNPoints(),numpoints+1));
63 
64  // now test if interpolated values are ok
65  for (unsigned int i=0; i<numcheckpoints; ++i) {
66  double point = double(i*numpoints/double(numcheckpoints));
67  CPPUNIT_ASSERT(Verify<CloseTo>(tfc1.Y(point).GetLgAmplitude(), double(numpoints*point))); // amplitude
68  CPPUNIT_ASSERT(Verify<CloseTo>(tfc1.Y(point).GetPhase(), double(phasestepsize*point))); // phase
69  }
70  }
71 
72  void
74  {
75  // configure the tests
76  const unsigned int numpoints = 10;
77  const unsigned int numcheckpoints = 100;
78  const double phasestepsize = 50.*degree;
79  const double offset = 2.0;
80  const unsigned int densityfactor = 2;
81 
82  // create our working TabulatedFunctionComplexLgAmpPhasees
85 
86  // fill in some test data
87  for (unsigned int i=0; i<=numpoints; ++i)
88  tfc1.PushBack(double(i),ComplexLgAmpPhase(double(numpoints*i),double(phasestepsize*i)));
89  for (unsigned int i=0; i<=numpoints*densityfactor; ++i)
90  tfc2.PushBack(double(offset+i/double(densityfactor)),ComplexLgAmpPhase(double(numpoints*i),double(phasestepsize*i)));
91 
93  tfc3*=tfc2;
94 
96  tfc4*=tfc1;
97 
98  // screen output for debugging purposes
99  cout << "TFC1:\n";
100  for (TabulatedFunctionComplexLgAmpPhase::Iterator it = tfc1.Begin(); it != tfc1.End(); ++it)
101  cout << it->X() << "\t" << it->Y().GetLgAmplitude() << "\t" << it->Y().GetPhase()/degree << endl;
102  cout << "\n" << endl;
103 
104  cout << "TFC2:\n";
105  for (TabulatedFunctionComplexLgAmpPhase::Iterator it = tfc2.Begin(); it != tfc2.End(); ++it)
106  cout << it->X() << "\t" << it->Y().GetLgAmplitude() << "\t" << it->Y().GetPhase()/degree << endl;
107  cout << "\n" << endl;
108 
109  cout << "TFC3:\n";
110  for (TabulatedFunctionComplexLgAmpPhase::Iterator it = tfc3.Begin(); it != tfc3.End(); ++it)
111  cout << it->X() << "\t" << it->Y().GetLgAmplitude() << "\t" << it->Y().GetPhase()/degree << endl;
112  cout << "\n" << endl;
113 
114  cout << "TFC4:\n";
115  for (TabulatedFunctionComplexLgAmpPhase::Iterator it = tfc4.Begin(); it != tfc4.End(); ++it)
116  cout << it->X() << "\t" << it->Y().GetLgAmplitude() << "\t" << it->Y().GetPhase()/degree << endl;
117  cout << "\n" << endl;
118 
119  // now test if interpolated values are ok
120  cout << "TFC3 versus manual multiplication:" << endl;
121  for (unsigned int i=0; i<numcheckpoints; ++i) {
122  double point = double(offset+i*(numpoints-offset)/double(numcheckpoints));
123  CPPUNIT_ASSERT(Verify<CloseTo>(tfc3.Y(point).GetLgAmplitude(),tfc4.Y(point).GetLgAmplitude())); // compare amplitudes of the two multiplied TFCs
124  CPPUNIT_ASSERT(Verify<CloseTo>(tfc3.Y(point).GetPhase(),tfc4.Y(point).GetPhase())); // compare amplitudes of the two multiplied TFCs
125  cout << point << "\t" << tfc3.Y(point).GetLgAmplitude() << "\t" << tfc3.Y(point).GetPhase()/degree << "\tversus\t";
126  cout << point << "\t" << (tfc1.Y(point)*tfc2.Y(point)).GetLgAmplitude() << "\t" << (tfc1.Y(point)*tfc2.Y(point)).GetPhase()/degree << "\n";
127  CPPUNIT_ASSERT(Verify<CloseTo>(tfc3.Y(point).GetLgAmplitude(),(tfc1.Y(point)*tfc2.Y(point)).GetLgAmplitude())); // compare amplitudes of tfc3 with manual multiplication
128  CPPUNIT_ASSERT(Verify<CloseTo>(tfc3.Y(point).GetPhase(),(tfc1.Y(point)*tfc2.Y(point)).GetPhase())); // compare amplitudes of tfc3 with manual multiplication
129  }
130  }
131 
132 /*
133  void
134  testBinException()
135  {
136  }
137 */
138 
139 };
140 
142 
143 // Configure (x)emacs for this file ...
144 // Local Variables:
145 // mode: c++
146 // End:
const double degree
double GetPhase() const
Get the phase in radians, can be bigger than 2*pi.
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
Class to hold collection (x,y) points and provide interpolation between them, where y are complex num...
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.
double GetLgAmplitude() const
Get log10(amplitude)
void PushBack(const double x, const utl::ComplexLgAmpPhase &y)

, generated on Tue Sep 26 2023.