testFDetector.cc
Go to the documentation of this file.
1 #include <map>
2 #include <sstream>
3 
4 #include <det/Detector.h>
5 #include <fdet/FDetector.h>
6 #include <fdet/Eye.h>
7 #include <fdet/Telescope.h>
8 #include <fdet/Mirror.h>
9 #include <fdet/Filter.h>
10 #include <fdet/Corrector.h>
11 #include <fdet/Camera.h>
12 #include <fdet/Pixel.h>
13 #include <fdet/Channel.h>
14 #include <fwk/CentralConfig.h>
15 #include <utl/TimeStamp.h>
16 #include <utl/UTCDateTime.h>
17 #include <utl/TabulatedFunction.h>
18 #include <utl/Reader.h>
19 #include <utl/Point.h>
20 #include <utl/CoordinateSystem.h>
21 #include <utl/ErrorLogger.h>
22 #include <utl/AugerUnits.h>
23 #include <fwk/CoordinateSystemRegistry.h>
24 
25 #include <cppunit/extensions/HelperMacros.h>
26 #include <tst/Verify.h>
27 
28 using namespace det;
29 using namespace fdet;
30 using namespace std;
31 using namespace fwk;
32 using namespace utl;
33 using namespace tst;
34 
35 class FDetectorTest : public CppUnit::TestFixture {
36 
37  CPPUNIT_TEST_SUITE(FDetectorTest);
38  CPPUNIT_TEST_EXCEPTION(testNotCommissioned, NonExistentComponentException);
39  CPPUNIT_TEST_EXCEPTION(testNoSuchEye, NonExistentComponentException);
40  CPPUNIT_TEST(testGetEyeByName);
41  CPPUNIT_TEST(testEyeList);
42  CPPUNIT_TEST(testCommissionedTelescopeList);
43  CPPUNIT_TEST(testCommissionedTelescopeListLaterTimestamp);
44  CPPUNIT_TEST(testGetPixelCalibTime1);
45  CPPUNIT_TEST(testGetPixelCalibTime2);
46  CPPUNIT_TEST(testGetPixelCalibTime3); // NB. this test sets commission time after HEAT was deployed
47  CPPUNIT_TEST(testGetPixelCalibNullEndTime);
48  CPPUNIT_TEST(testPixelStatus);
49  CPPUNIT_TEST(testReadFullTelescope);
50  CPPUNIT_TEST(testGetTimeOffset);
51  CPPUNIT_TEST(testVirtualEye);
52 
53  // add a test for corrector ring.
54 
55  CPPUNIT_TEST_SUITE_END();
56 
57 private:
58 
59 public:
60  void setUp() {
61  ErrorLogger::GetInstance().SetVerbosity(Verbosity::eVerbose);
62 
63  // CentralConfig must be created first.
64  //
65  CentralConfig::GetInstance(BOOTSTRAPFILE);
66 
67  // Create a detector
68  //
69  // Detector::GetInstance();
70  }
71 
72  void tearDown() {
73  }
74 
76  Detector& theDet = Detector::GetInstance();
77  theDet.Update(UTCDateTime(2000,4,1,1).GetTimeStamp());
78  tst::Expected();
79  theDet.GetFDetector().GetEye(1).GetTelescope(3);
80  }
81 
83  const FDetector& theFDet = Detector::GetInstance().GetFDetector();
84  Detector::GetInstance().Update(UTCDateTime(2005,1,1,1).GetTimeStamp());
85  CPPUNIT_ASSERT(Verify<Equal>( (int)theFDet.GetEye("Los Morados").GetId(), 2));
86  }
87 
88  void testNoSuchEye() {
89  const FDetector& theFDet = Detector::GetInstance().GetFDetector();
90  Detector::GetInstance().Update(UTCDateTime(2005,1,1,1).GetTimeStamp());
91  tst::Expected();
92  theFDet.GetEye("San Martin");
93  }
94 
95  void testEyeList() {
96  const FDetector& theFDet = Detector::GetInstance().GetFDetector();
97 
98  Detector::GetInstance().Update(UTCDateTime(2005,1,2,1).GetTimeStamp());
99 
100  int numEyes = 0; // == physical eyes
101  for (FDetector::EyeIterator eyeIt = theFDet.EyesBegin();
102  eyeIt != theFDet.EyesEnd(); ++eyeIt)
103  ++numEyes;
104  CPPUNIT_ASSERT(Verify<Equal>(numEyes, 5));
105 
106  int numPhysicalEyes = 0;
108  eyeIt != theFDet.EyesEnd(fdet::FDetComponentSelector::ePhysical); ++eyeIt)
109  ++numPhysicalEyes;
110  CPPUNIT_ASSERT(Verify<Equal>(numPhysicalEyes, 5));
111 
112  int numEyesTotal = 0;
114  eyeIt != theFDet.EyesEnd(fdet::FDetComponentSelector::eAll); ++eyeIt)
115  ++numEyesTotal;
116  CPPUNIT_ASSERT(Verify<Equal>(numEyesTotal, 7));
117 
118  int numVirtualEyes = 0;
120  eyeIt != theFDet.EyesEnd(fdet::FDetComponentSelector::eVirtual); ++eyeIt)
121  ++numVirtualEyes;
122  CPPUNIT_ASSERT(Verify<Equal>(numVirtualEyes, 2));
123  }
124 
125  void
127  {
128  const Eye& eye = Detector::GetInstance().GetFDetector().GetEye(1);
129  Detector::GetInstance().Update(UTCDateTime(2005,1,2,1).GetTimeStamp());
130  int numTels = 0;
131  for (Eye::TelescopeIterator tIt = eye.TelescopesBegin();
132  tIt != eye.TelescopesEnd(); ++tIt)
133  ++numTels;
134 
135  CPPUNIT_ASSERT(Verify<Equal>(numTels, 6));
136 
137  // for eye2 at timestamp 2005, eye 3 should be uncommissioned in test file
138  //
139  const Eye& eye2 = Detector::GetInstance().GetFDetector().GetEye(2);
140  Detector::GetInstance().Update(UTCDateTime(2005,1,1,1).GetTimeStamp());
141  for (Eye::TelescopeIterator tIt = eye2.TelescopesBegin();
142  tIt != eye2.TelescopesEnd(); ++tIt)
143  CPPUNIT_ASSERT(Verify<Not<Equal> >(tIt->GetId(), 3U));
144  }
145 
147 
148  // test eye2 at timestample 2010, when all 3 eyes should be commissioned in test file
149  //
150  Detector::GetInstance().Update(UTCDateTime(2010,1,1,1).GetTimeStamp());
151  const Eye& theEye2 = Detector::GetInstance().GetFDetector().GetEye(2);
152  int numTels=0;
153  for (Eye::TelescopeIterator telIt = theEye2.TelescopesBegin() ;
154  telIt != theEye2.TelescopesEnd(); ++telIt)
155  ++numTels;
156  CPPUNIT_ASSERT(Verify<Equal>(numTels, 6));
157 
158  }
159 
161  Detector::GetInstance().Update(UTCDateTime(2001,5,2).GetTimeStamp());
162  const Pixel& pix =
163  Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetTelescope(1).GetPixel(1);
164 
166  CPPUNIT_ASSERT(Verify<CloseTo>(calib.Y(425.*nanometer), 1001.));
167  CPPUNIT_ASSERT(Verify<CloseTo>(calib.Y(450.*nanometer), 2001.));
168  CPPUNIT_ASSERT(Verify<CloseTo>(calib.Y(475.*nanometer), 3001.));
169  }
170 
172  Detector::GetInstance().Update(UTCDateTime(2006,1,2).GetTimeStamp());
173  const Pixel& pix =
174  Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetTelescope(1).GetPixel(1);
176 
177  CPPUNIT_ASSERT(Verify<CloseTo>(calib.Y(425.*nanometer), 4001.));
178  CPPUNIT_ASSERT(Verify<CloseTo>(calib.Y(450.*nanometer), 5001.));
179  CPPUNIT_ASSERT(Verify<CloseTo>(calib.Y(475.*nanometer), 6001.));
180 
181  Detector::GetInstance().Update(UTCDateTime(2006,1,3).GetTimeStamp()); // should not reread db
183 
184  CPPUNIT_ASSERT(Verify<CloseTo>(calib2.Y(425.*nanometer), 4001.));
185  CPPUNIT_ASSERT(Verify<CloseTo>(calib2.Y(450.*nanometer), 5001.));
186  CPPUNIT_ASSERT(Verify<CloseTo>(calib2.Y(475.*nanometer), 6001.));
187 
188  Detector::GetInstance().Update(UTCDateTime(2006,1,3).GetTimeStamp()); // should reread db
189 
190  const Pixel& pix3 =
191  Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetTelescope(1).GetPixel(10);
192  const TabulatedFunction& calib3 = pix3.GetEndToEndCalibrationConstant();
193  CPPUNIT_ASSERT(Verify<CloseTo>(calib3.Y(425.*nanometer), 4010.));
194  CPPUNIT_ASSERT(Verify<CloseTo>(calib3.Y(450.*nanometer), 5010.));
195  CPPUNIT_ASSERT(Verify<CloseTo>(calib3.Y(475.*nanometer), 6010.));
196 
197  Detector::GetInstance().Update(UTCDateTime(2006,1,4).GetTimeStamp()); // should not reread db
198 
199  const TabulatedFunction& calib4 = pix3.GetEndToEndCalibrationConstant();
200  CPPUNIT_ASSERT(Verify<CloseTo>(calib4.Y(425.*nanometer), 4010.));
201  CPPUNIT_ASSERT(Verify<CloseTo>(calib4.Y(450.*nanometer), 5010.));
202  CPPUNIT_ASSERT(Verify<CloseTo>(calib4.Y(475.*nanometer), 6010.));
203  }
204 
206 
207  Detector::GetInstance().Update(UTCDateTime(2012,1,1).GetTimeStamp());
208 
209  // Get HEAT telescope by name and number
210 
211  const Pixel& pixHeatByName =
212  Detector::GetInstance().GetFDetector().GetEye("Heat").GetTelescope(1).GetPixel(1);
213 
214  const TabulatedFunction& calibHeatByName = pixHeatByName.GetEndToEndCalibrationConstant();
215 
216  CPPUNIT_ASSERT(Verify<CloseTo>(calibHeatByName.Y(425.*nanometer), 98765.0));
217 
218  const Pixel& pixHeatByNumber =
219  Detector::GetInstance().GetFDetector().GetEye(5).GetTelescope(1).GetPixel(1);
220  const TabulatedFunction& calibHeatByNumber = pixHeatByNumber.GetEndToEndCalibrationConstant();
221 
222  CPPUNIT_ASSERT(Verify<CloseTo>(calibHeatByNumber.Y(425.*nanometer), 98765.0));
223 
224  }
225 
227  Detector::GetInstance().Update(UTCDateTime(2006,1,2).GetTimeStamp());
228  const Pixel& pix =
229  Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetTelescope(1).GetPixel(1);
230  const double timeOffset = pix.GetTimeOffset();
231  CPPUNIT_ASSERT(Verify<CloseTo>(timeOffset, 1234.));
232  }
233 
235 
236  Detector::GetInstance().Update(UTCDateTime(2001,5,2).GetTimeStamp());
237  const Telescope& tel =
238  Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetTelescope(1);
239 
240  for (unsigned int i = tel.GetFirstPixelId();
241  i != tel.GetLastPixelId(); ++i) {
242  const Pixel& aPix = tel.GetPixel(i);
243  /*const TabulatedFunction& calVsLambda = */aPix.GetEndToEndCalibrationConstant();
244  }
245  }
246 
248 
249  Detector::GetInstance().Update(UTCDateTime(2007,1,2).GetTimeStamp());
250  const Pixel& pix1 =
251  Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetTelescope(1).GetPixel(1);
252  const TabulatedFunction& calib1 = pix1.GetEndToEndCalibrationConstant();
253  CPPUNIT_ASSERT(Verify<CloseTo>(calib1.Y(425.*nanometer), 7001.));
254  CPPUNIT_ASSERT(Verify<CloseTo>(calib1.Y(450.*nanometer), 8001.));
255  CPPUNIT_ASSERT(Verify<CloseTo>(calib1.Y(475.*nanometer), 9001.));
256 
257  Detector::GetInstance().Update(UTCDateTime(2008,1,2).GetTimeStamp());
258  const Pixel& pix2 =
259  Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetTelescope(1).GetPixel(2);
260  const TabulatedFunction& calib2 = pix2.GetEndToEndCalibrationConstant();
261  CPPUNIT_ASSERT(Verify<CloseTo>(calib2.Y(425.*nanometer), 13002.));
262  CPPUNIT_ASSERT(Verify<CloseTo>(calib2.Y(450.*nanometer), 14002.));
263  CPPUNIT_ASSERT(Verify<CloseTo>(calib2.Y(475.*nanometer), 15002.));
264 
265  Detector::GetInstance().Update(UTCDateTime(2009,1,2).GetTimeStamp());
266  const Pixel& pix3 =
267  Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetTelescope(1).GetPixel(3);
268  const TabulatedFunction& calib3 = pix3.GetEndToEndCalibrationConstant();
269  CPPUNIT_ASSERT(Verify<CloseTo>(calib3.Y(425.*nanometer), 16003.));
270  CPPUNIT_ASSERT(Verify<CloseTo>(calib3.Y(450.*nanometer), 17003.));
271  CPPUNIT_ASSERT(Verify<CloseTo>(calib3.Y(475.*nanometer), 18003.));
272  }
273 
275  Detector::GetInstance().Update(UTCDateTime(2006,1,2).GetTimeStamp());
276  const Telescope& tel =
277  Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetTelescope(1);
278 
279  for (unsigned int i = tel.GetFirstPixelId() ;
280  i <= tel.GetLastPixelId() ; ++i) {
281  const Pixel& pix = tel.GetPixel(i);
282 
283  // In the test DB, each 100'th pixel has status set to 1, rest are 0
284  CPPUNIT_ASSERT(Verify<Equal>((bool)pix.GetStatus(), i%100 == 1));
285  }
286  }
287 
288  void testVirtualEye() {
289  Detector::GetInstance().Update(UTCDateTime(2009,6,2).GetTimeStamp());
290  const Eye& eye = Detector::GetInstance().GetFDetector().GetEye("Coihueco");
291  const Telescope& tel =
292  Detector::GetInstance().GetFDetector().GetEye("Los Morados").GetTelescope(3);
293 
294  const Eye& veye = Detector::GetInstance().GetFDetector().GetEye("Virtual Eye 1");
295  const Telescope& vtel = veye.GetTelescope(1);
296 
297  CPPUNIT_ASSERT(!eye.IsVirtual());
298  CPPUNIT_ASSERT(veye.IsVirtual());
299  CPPUNIT_ASSERT(!tel.IsVirtual());
300  CPPUNIT_ASSERT(vtel.IsVirtual());
301 
302  CPPUNIT_ASSERT(Verify<Equal>(veye.GetParentPhysicalId(), eye.GetParentPhysicalId()));
303  CPPUNIT_ASSERT(Verify<Equal>(veye.GetParentPhysicalIdString(), eye.GetParentPhysicalIdString()));
304 
305  const CoordinateSystemPtr siteCS = Detector::GetInstance().GetSiteCoordinateSystem();
306 
307  CPPUNIT_ASSERT(Verify<Equal>(eye.GetId(), (unsigned int)4));
308  CPPUNIT_ASSERT(Verify<Equal>(veye.GetId(), (unsigned int)6));
309  CPPUNIT_ASSERT(Verify<Equal>(veye.GetName(), string("Virtual Eye 1")));
310  CPPUNIT_ASSERT(Verify<CloseTo>(veye.GetPosition().GetX(siteCS), eye.GetPosition().GetX(siteCS)));
311  CPPUNIT_ASSERT(Verify<CloseTo>(veye.GetPosition().GetY(siteCS), eye.GetPosition().GetY(siteCS)));
312  CPPUNIT_ASSERT(Verify<CloseTo>(veye.GetPosition().GetZ(siteCS), eye.GetPosition().GetZ(siteCS)));
313 
314  CPPUNIT_ASSERT(Verify<Equal>(vtel.GetParentPhysicalId(), tel.GetParentPhysicalId()));
315  CPPUNIT_ASSERT(Verify<Equal>(vtel.GetParentPhysicalIdString(), tel.GetParentPhysicalIdString()));
316  CPPUNIT_ASSERT(Verify<Equal>(vtel.GetParentPhysicalEyeId(), tel.GetParentPhysicalEyeId()));
317  CPPUNIT_ASSERT(Verify<Equal>(vtel.GetParentPhysicalEyeIdString(), tel.GetParentPhysicalEyeIdString()));
318 
319  CPPUNIT_ASSERT(Verify<Equal>(tel.GetId(), (unsigned int)3));
320  CPPUNIT_ASSERT(Verify<Equal>(vtel.GetId(), (unsigned int)1));
321  CPPUNIT_ASSERT(Verify<Equal>(tel.GetEyeId(), (unsigned int)2));
322  CPPUNIT_ASSERT(Verify<Equal>(vtel.GetEyeId(), (unsigned int)6));
323  CPPUNIT_ASSERT(Verify<CloseTo>(vtel.GetPosition().GetX(siteCS), tel.GetPosition().GetX(siteCS)));
324  CPPUNIT_ASSERT(Verify<CloseTo>(vtel.GetPosition().GetY(siteCS), tel.GetPosition().GetY(siteCS)));
325  CPPUNIT_ASSERT(Verify<CloseTo>(vtel.GetPosition().GetZ(siteCS), tel.GetPosition().GetZ(siteCS)));
326  }
327 };
328 
329 
331 
332 
333 // Configure (x)emacs for this file ...
334 // Local Variables:
335 // mode:c++
336 // compile-command: "make -C .. testFDetector -k"
337 // End:
Status GetStatus() const
Get the pixel status flag.
void Update()
void testGetEyeByName()
void Update(const utl::TimeStamp &time, const bool invData=true, const bool invComp=true, const bool forceRadio=false)
Update detector: deletes currently constructed stations and sets new time.
Definition: Detector.cc:179
void testCommissionedTelescopeList()
void testVirtualEye()
void testCommissionedTelescopeListLaterTimestamp()
const utl::TabulatedFunction & GetEndToEndCalibrationConstant() const
end to end calibration function
void testEyeList()
unsigned int GetFirstPixelId() const
const std::string & GetParentPhysicalEyeIdString() const
Class to hold collection (x,y) points and provide interpolation between them.
unsigned int GetParentPhysicalEyeId() const
unsigned int GetEyeId() const
Traditional name.
Definition: Verbosity.h:17
Base class for exceptions trying to access non-existing components.
const Eye & GetEye(const unsigned int eyeId) const
Find eye by numerical Id.
Definition: FDetector.cc:68
EyeIterator EyesBegin(const FDetComponentSelector::Type type=FDetComponentSelector::ePhysical) const
iterator pointing to first eye of given type (ePhysical, eVirtual, eAll)
Definition: FDetector.h:72
Detector description interface for Eye-related data.
Definition: FDetector/Eye.h:45
void testGetPixelCalibTime1()
void testGetPixelCalibNullEndTime()
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
Detector description interface for FDetector-related data.
Definition: FDetector.h:44
#define U
constexpr double nanometer
Definition: AugerUnits.h:102
const Pixel & GetPixel(const unsigned int pixelId) const
Get Pixel by id, throw utl::NonExistentComponentException if n.a.
Definition: Test.h:180
const std::string & GetParentPhysicalIdString() const
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
unsigned int GetLastPixelId() const
boost::filter_iterator< FDetComponentSelector, AllEyeIterator > EyeIterator
Definition: FDetector.h:69
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
unsigned int GetParentPhysicalId() const
TelescopeIterator TelescopesBegin() const
Beginning of the collection of telescopes.
Definition: FDetector/Eye.h:79
bool Verify(const Predicate &pred, const T &lhs, const T &rhs)
Test condition by evaluating a predicate and print on failure.
Definition: Verify.h:38
const Telescope & GetTelescope(const unsigned int telescopeId) const
Find Telescope by numerical Id.
void testGetTimeOffset()
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
unsigned int GetId() const
Eye numerical Id.
void Expected()
Print `Expected&#39; for expected failures.
Definition: Verify.h:85
const fdet::FDetector & GetFDetector() const
Definition: Detector.cc:131
void testReadFullTelescope()
const Telescope & GetTelescope() const
Access the telescope this Pixel belongs to.
boost::filter_iterator< TelIsCommissioned, InternalConstTelescopeIterator > TelescopeIterator
An iterator over telescopes.
Definition: FDetector/Eye.h:76
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
Detector description interface for Telescope-related data.
void testNotCommissioned()
void testPixelStatus()
bool IsVirtual() const
Returns whether this telescope belongs to a virtual eye.
unsigned int GetParentPhysicalId() const
Description of a pixel.
utl::Point GetPosition() const
const std::string & GetParentPhysicalIdString() const
TelescopeIterator TelescopesEnd() const
End of the collection of telescopes.
Definition: FDetector/Eye.h:83
double GetTimeOffset() const
pixel time offset
void testGetPixelCalibTime3()
void testNoSuchEye()
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:212
void testGetPixelCalibTime2()
double Y(const double x) const
Get or interpolate the Y value that corresponds to parameter x.
unsigned int GetId() const
utl::Point GetPosition() const
Eye position.
const std::string & GetName() const
Eye name.
bool IsVirtual() const
Returns whether this eye is a virtual eye.
EyeIterator EyesEnd(const FDetComponentSelector::Type type=FDetComponentSelector::ePhysical) const
iterator pointing to end of available eyes of given type (ePhysical, eVirtual, eAll) ...
Definition: FDetector.h:76

, generated on Tue Sep 26 2023.