testMeasuredDBMieModel.cc
Go to the documentation of this file.
1 
10 #include <cppunit/extensions/HelperMacros.h>
11 
12 #include <det/Detector.h>
13 #include <fdet/FDetector.h>
14 #include <fdet/Eye.h>
15 
16 #include <fwk/CoordinateSystemRegistry.h>
17 
18 #include <atm/AerosolDB.h>
19 #include <atm/AttenuationResult.h>
20 #include <atm/ScatteringResult.h>
21 #include <atm/MeasuredDBMieModel.h>
22 
23 #include <fwk/CentralConfig.h>
24 
25 #include <utl/TimeStamp.h>
26 #include <utl/UTCDateTime.h>
27 #include <utl/ErrorLogger.h>
28 #include <utl/Point.h>
29 #include <utl/TabulatedFunctionErrors.h>
30 #include <utl/ReferenceEllipsoid.h>
31 
32 #include <tst/Verify.h>
33 
34 #include <iostream>
35 
36 using namespace std;
37 using namespace det;
38 using namespace fdet;
39 using namespace atm;
40 using namespace fwk;
41 using namespace utl;
42 using namespace tst;
43 
44 
45 class testMeasuredDBMieModel : public CppUnit::TestFixture {
46 
47  CPPUNIT_TEST_SUITE(testMeasuredDBMieModel);
48 
49  CPPUNIT_TEST(testZoneSelection);
50  CPPUNIT_TEST(testAttenuation);
51  CPPUNIT_TEST(testLambdaDependence);
52  CPPUNIT_TEST(testScattering);
53  // Disable out-of-bound check (temporarily I home) as corrections
54  // for bug report 418 prevent out-of-bound conditions by construction.
55  // CPPUNIT_TEST_EXCEPTION(testOutOfBound, OutOfBoundException);
56  CPPUNIT_TEST(testHasData);
57  CPPUNIT_TEST_EXCEPTION(testNoData, NoDataForModelException);
58  CPPUNIT_TEST(testNoDataMultipleCalls); // checks bug 456
59  CPPUNIT_TEST(testUncertainty);
60 
61  CPPUNIT_TEST_SUITE_END();
62 
63 public:
64  void
66  {
67  CentralConfig::GetInstance(BOOTSTRAPFILE);
68  ErrorLogger::GetInstance().SetVerbosity(Verbosity::eVerbose);
69  }
70 
71  void tearDown() { }
72 
73  void
75  {
76  Detector::GetInstance().Update(UTCDateTime(2005,1,1,0,0,0).GetTimeStamp());
77  const Atmosphere& theAtm = Detector::GetInstance().GetAtmosphere();
78 
79  vector<double> wlength;
80  wlength.push_back(300*nanometer);
81  wlength.push_back(355*nanometer);
82  wlength.push_back(400*nanometer);
83 
84  // Los Leones
85  //
87  CSll(Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetLocalCoordinateSystem() );
88 
89  Point All(0, 0, 0, CSll);
90  Point Bll(0, 0, 9000*m, CSll);
91 
92  AttenuationResult AttABll = theAtm.EvaluateMieAttenuation(All, Bll, wlength);
93  CPPUNIT_ASSERT(Verify<CloseTo>(AttABll.GetTransmissionFactor().Y(355*nanometer),0.979985, 1e-5));
94 
95  // Coihueco
97  CSco(Detector::GetInstance().GetFDetector().GetEye("Coihueco").GetLocalCoordinateSystem() );
98 
99  Point Aco(0, 0, 0, CSco);
100  Point Bco(0, 0, 9000*m, CSco);
101 
102  AttenuationResult AttABco = theAtm.EvaluateMieAttenuation(Aco, Bco, wlength);
103  CPPUNIT_ASSERT(Verify<CloseTo>(AttABco.GetTransmissionFactor().Y(355.*nanometer),0.391086 , 1e-5));
104  }
105 
106  void
108  {
109  Detector::GetInstance().Update(UTCDateTime(2005,1,1,0,0,0).GetTimeStamp());
110 
112  CSll(Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetLocalCoordinateSystem() );
113 
114  ReferenceEllipsoid wgs84(ReferenceEllipsoid::Get(ReferenceEllipsoid::eWGS84));
115 
116  //
117  // To test scattering and attenuation we define several
118  // points in the sky and compute scattering/attenuation between
119  // different pairs. Points are also defined in >1 coordinate system
120  // to ensure that the calculations are not CS dependent.
121  //
122  // 5 points are defined, arranged as indicated (schematically) below.
123  //
124  // C
125  //
126  //
127  //
128  //
129  // B D E
130  //
131  // A -------- z=0 in local CS ----------
132  //
133 
134  Point All(0, 0, 0, CSll);
135  Point Bll(0, 0, 2600*m, CSll);
136  Point Cll(0, 0, 9000*m, CSll);
137  Point Dll(0, 2000*m, 2600*m, CSll);
138  Point Ell(0, 9000*m, 2600*m, CSll);
139 
140  CoordinateSystemPtr CSst( Detector::GetInstance().GetSiteCoordinateSystem() );
141  Point Cst(0, 0, 10000*m, CSst);
142 
143  vector<double> wlength;
144  wlength.push_back(300*nanometer);
145  wlength.push_back(355*nanometer);
146  wlength.push_back(400*nanometer);
147 
148  const Atmosphere& theAtm = Detector::GetInstance().GetAtmosphere();
149 
150  AttenuationResult attABll = theAtm.EvaluateMieAttenuation(All,
151  Bll,
152  wlength);
153  CPPUNIT_ASSERT(Verify<CloseTo>(attABll.GetTransmissionFactor().Y(355*nanometer), 0.981456, 1e-3));
154 
155  AttenuationResult attACll = theAtm.EvaluateMieAttenuation(All,
156  Cll,
157  wlength);
158  CPPUNIT_ASSERT(Verify<CloseTo>(attACll.GetTransmissionFactor().Y(300*nanometer), 0.979984, 1e-3));
159 
160  AttenuationResult attADll = theAtm.EvaluateMieAttenuation(All,
161  Dll,
162  wlength);
163  CPPUNIT_ASSERT(Verify<CloseTo>(attADll.GetTransmissionFactor().Y(300*nanometer), 0.976664, 1e-3));
164 
165 
166  // Following two checks need some additional attention.
167  // Not clear if MeasuredDBMieModel handles case of
168  // points close together in height in the correct way
169  //
170  AttenuationResult attBDll = theAtm.EvaluateMieAttenuation(Bll,
171  Dll,
172  wlength);
173  CPPUNIT_ASSERT(Verify<CloseTo>(attBDll.GetTransmissionFactor().Y(300*nanometer), 0.997001, 1e-3));
174 
175  AttenuationResult attBEll = theAtm.EvaluateMieAttenuation(Bll,
176  Ell,
177  wlength);
178  CPPUNIT_ASSERT(Verify<CloseTo>(attBEll.GetTransmissionFactor().Y(300*nanometer), 0.986609, 1e-3));
179 
180 
181 // // Set parameters to check bug 397
182 // //
183 // CoordinateSystemPtr
184 // csLL(Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetEyeCoordinateSystem() );
185 // Point Pa(0.*m, 0.*m, 0.*m, csLL);
186 // Point Pb(0.*m, 0.*m, 11000.*m, csLL);
187 // AttenuationResult attPaPb = theAtm.EvaluateMieAttenuation(Pa, Pb, wlength);
188 
189 // cout << "tansmission fact " << attPaPb.GetTransmissionFactor().Y(300.*nanometer) << endl;
190 
191  }
192 
193  void
195  {
196  Detector::GetInstance().Update(UTCDateTime(2005,1,1,0,0,0).GetTimeStamp());
197  const Atmosphere& theAtm = Detector::GetInstance().GetAtmosphere();
198 
199  // Coihueco
201  CSco(Detector::GetInstance().GetFDetector().GetEye("Coihueco").GetLocalCoordinateSystem() );
202 
203  Point Aco(0, 0, 0*m, CSco);
204  Point Bco(0, 0, 200*m, CSco);
205 
206  vector<double> wlength;
207  wlength.push_back(300*nanometer);
208  wlength.push_back(355*nanometer);
209  wlength.push_back(400*nanometer);
210 
211  AttenuationResult att = theAtm.EvaluateMieAttenuation(Aco,
212  Bco,
213  wlength);
214 
215  CPPUNIT_ASSERT(Verify<CloseTo>( log(att.GetTransmissionFactor().Y(375*nanometer)),
216  log(att.GetTransmissionFactor().Y(355*nanometer)) * pow(375./355.,-1.2), 1e-3));
217 
218  CPPUNIT_ASSERT(Verify<CloseTo>( log(att.GetTransmissionFactor().Y(345.*nanometer)),
219  log(att.GetTransmissionFactor().Y(355.*nanometer)) * pow(345./355.,-1.2), 1e-3));
220  }
221 
222  void
224  {
225  Detector::GetInstance().Update(UTCDateTime(2005,1,1,0,0,0).GetTimeStamp());
226  const Atmosphere& theAtm = Detector::GetInstance().GetAtmosphere();
228  CSll(Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetLocalCoordinateSystem() );
229 
230  vector<double> wlength;
231  wlength.push_back(300*nanometer);
232  wlength.push_back(355*nanometer);
233  wlength.push_back(400*nanometer);
234 
235  Point pointA(0, 0, 0 , CSll);
236  Point pointB(0, 0, 1400*m, CSll);
237  Point pointC(0, 600*m, 1600*m, CSll);
238 
239  // vary angle
240  //
241  ScatteringResult scatAB1 =
242  theAtm.EvaluateMieScattering(pointA, pointB,
243  20*degree, 1*km, wlength);
244  CPPUNIT_ASSERT(Verify<CloseTo>(1e8*scatAB1.GetScatteringFactor().Y(400*nanometer), 0.856146, 1e-5));
245 
246  ScatteringResult scatAB2 =
247  theAtm.EvaluateMieScattering(pointA, pointB,
248  30*degree, 1*km, wlength);
249  CPPUNIT_ASSERT(Verify<CloseTo>(1e8*scatAB2.GetScatteringFactor().Y(400*nanometer), 0.430129, 1e-5));
250 
251  ScatteringResult scatAB3 =
252  theAtm.EvaluateMieScattering(pointA, pointB,
253  40*degree, 1*km, wlength);
254  CPPUNIT_ASSERT(Verify<CloseTo>(1e9*scatAB3.GetScatteringFactor().Y(400*nanometer), 2.33831, 1e-5));
255 
256  ScatteringResult scatAB4 =
257  theAtm.EvaluateMieScattering(pointA, pointB,
258  60*degree, 1*km, wlength);
259  CPPUNIT_ASSERT(Verify<CloseTo>(1e9*scatAB4.GetScatteringFactor().Y(400*nanometer), 0.852745, 1e-5));
260 
261  // vary distance
262  //
263  ScatteringResult scatAB5 =
264  theAtm.EvaluateMieScattering(pointA, pointB,
265  30*degree, 10*km, wlength);
266  CPPUNIT_ASSERT(Verify<CloseTo>(1e11*scatAB5.GetScatteringFactor().Y(400*nanometer),
267  4.30129, 1e-5));
268 
269  ScatteringResult scatAB6 =
270  theAtm.EvaluateMieScattering(pointA, pointB,
271  60*degree, 10*km, wlength);
272  CPPUNIT_ASSERT(Verify<CloseTo>(1e11*scatAB6.GetScatteringFactor().Y(400*nanometer),
273  0.852745, 1e-5));
274 
275 
276  // new pair of points (at same altitude)
277  // These need to be checked - not sure if MeasuredDBMieModel is doing this
278  // in the best way
279  //
280  ScatteringResult scatBC1 =
281  theAtm.EvaluateMieScattering(pointB, pointC,
282  40*degree, 1*km, wlength);
283  CPPUNIT_ASSERT(Verify<CloseTo>(1e8*scatBC1.GetScatteringFactor().Y(400*nanometer),
284  0.0441425, 1e-5));
285 
286  ScatteringResult scatBC2 =
287  theAtm.EvaluateMieScattering(pointB, pointC,
288  50*degree, 1*km, wlength);
289  CPPUNIT_ASSERT(Verify<CloseTo>(1e8*scatBC2.GetScatteringFactor().Y(400*nanometer),
290  0.0259341, 1e-5));
291 
292  ScatteringResult scatBC3 =
293  theAtm.EvaluateMieScattering(pointB, pointC,
294  60*degree, 1*km, wlength);
295  CPPUNIT_ASSERT(Verify<CloseTo>(1e10*scatBC3.GetScatteringFactor().Y(400*nanometer),
296  1.60981, 1e-5));
297 
298  ScatteringResult scatBC4 =
299  theAtm.EvaluateMieScattering(pointB, pointC,
300  90*degree, 1*km, wlength);
301  CPPUNIT_ASSERT(Verify<CloseTo>(1e10*scatBC4.GetScatteringFactor().Y(400*nanometer),
302  0.477644, 1e-5));
303 
304  // vary wavelengths
305  //
306  CPPUNIT_ASSERT(Verify<CloseTo>(1e8*scatAB1.GetScatteringFactor().Y(300*nanometer), 0.856146, 1e-5));
307  CPPUNIT_ASSERT(Verify<CloseTo>(1e8*scatAB1.GetScatteringFactor().Y(355*nanometer), 0.856146, 1e-5));
308 
309  // check angle returned
310  //
311  CPPUNIT_ASSERT(Verify<CloseTo>(scatAB1.GetScatteringAngle(), 20*degree));
312  CPPUNIT_ASSERT(Verify<CloseTo>(scatAB2.GetScatteringAngle(), 30*degree));
313  }
314 
315  void
317  {
318  Detector::GetInstance().Update(UTCDateTime(2005,1,1,0,0,0).GetTimeStamp());
319  const Atmosphere& theAtm = Detector::GetInstance().GetAtmosphere();
321  CSll(Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetLocalCoordinateSystem() );
322 
323  vector<double> wlength;
324  wlength.push_back(300*nanometer);
325  wlength.push_back(355*nanometer);
326  wlength.push_back(400*nanometer);
327 
328  Point A(0, 0, 0, CSll);
329  Point B(0, 0, 500*km, CSll);
330 
331  AttenuationResult AttABll = theAtm.EvaluateMieAttenuation(A, B, wlength);
332  AttABll.GetTransmissionFactor().Y(355*nanometer);
333  }
334 
335  void
337  {
338  Detector::GetInstance().Update(TimeStamp(123)); // no data exists for this time
339  const Atmosphere& theAtm = Detector::GetInstance().GetAtmosphere();
341  CSll(Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetLocalCoordinateSystem() );
342 
343  vector<double> wlength;
344  wlength.push_back(300*nanometer);
345  wlength.push_back(355*nanometer);
346  wlength.push_back(400*nanometer);
347 
348  Point A(0, 0, 0, CSll);
349  Point B(0, 0, 1*km, CSll);
350 
351  AttenuationResult AttABll = theAtm.EvaluateMieAttenuation(A, B, wlength);
352  }
353 
354  void
356  {
357  // Test HasData method at the level of the MieModel
358  //
359 
360  Detector::GetInstance().Update(TimeStamp(123));
361  MeasuredDBMieModel mieModelWithoutData;
362  mieModelWithoutData.Init();
363  CPPUNIT_ASSERT(Verify<Equal>(mieModelWithoutData.HasData(), false));
364 
365  Detector::GetInstance().Update(UTCDateTime(2005,1,1,0,0,0).GetTimeStamp());
366  MeasuredDBMieModel mieModelWithData;
367  mieModelWithData.Init();
368  CPPUNIT_ASSERT(Verify<Equal>(mieModelWithData.HasData(), true));
369  }
370 
371  void
373  {
374  Detector::GetInstance().Update(TimeStamp(123)); // no data exists for this time
375  const Atmosphere& theAtm = Detector::GetInstance().GetAtmosphere();
377  CSll(Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetLocalCoordinateSystem() );
378 
379  vector<double> wlength;
380  wlength.push_back(300*nanometer);
381  wlength.push_back(355*nanometer);
382  wlength.push_back(400*nanometer);
383 
384  Point A(0, 0, 0, CSll);
385  Point B(0, 0, 1*km, CSll);
386 
387  // check for bug 456
388  //
389  int numExceptions = 0;
390  for (int i=0 ; i<5 ; i++){
391  try {
392  AttenuationResult AttABll = theAtm.EvaluateMieAttenuation(A, B, wlength);
393  } catch (NoDataForModelException& ex) {
394  numExceptions++;
395  // should catch multiple NoDataForModelExceptions
396  }
397  }
398  CPPUNIT_ASSERT(Verify<Equal>(numExceptions, 5));
399  }
400 
402  Detector::GetInstance().Update(UTCDateTime(2005,1,1,0,0,0).GetTimeStamp());
403 
405  CSll(Detector::GetInstance().GetFDetector().GetEye("Los Leones").GetLocalCoordinateSystem() );
406 
407  ReferenceEllipsoid wgs84(ReferenceEllipsoid::Get(ReferenceEllipsoid::eWGS84));
408 
409  Point All(0, 0, 0, CSll);
410  Point Bll(0, 0, 2600*m, CSll);
411 
412  vector<double> wlength;
413  wlength.push_back(300*nanometer);
414  wlength.push_back(355*nanometer);
415  wlength.push_back(400*nanometer);
416 
417  const Atmosphere& theAtm = Detector::GetInstance().GetAtmosphere();
418  AttenuationResult attABll = theAtm.EvaluateMieAttenuation(All,
419  Bll,
420  wlength);
421  CPPUNIT_ASSERT(Verify<CloseTo>(attABll.GetTransmissionFactor().Y(355*nanometer), 0.9814559317));
422  theAtm.SetUncertaintyBound(Atmosphere::eMie, 1);
423  attABll = theAtm.EvaluateMieAttenuation(All,
424  Bll,
425  wlength);
426  CPPUNIT_ASSERT(Verify<CloseTo>(attABll.GetTransmissionFactor().Y(355*nanometer), 0.9796204908));
427  theAtm.SetUncertaintyBound(Atmosphere::eMie, -1);
428  attABll = theAtm.EvaluateMieAttenuation(All,
429  Bll,
430  wlength);
431  CPPUNIT_ASSERT(Verify<CloseTo>(attABll.GetTransmissionFactor().Y(355*nanometer), 0.9832947194));
432 
433  }
434 
435 };
436 
437 
439 
440 
441 // Configure (x)emacs for this file ...
442 // Local Variables:
443 // mode:c++
444 // compile-command: "make -C .. -k"
445 // End:
double GetScatteringAngle() const
Get calculated scattering angle.
Top of the interface to Atmosphere information.
const double degree
Point object.
Definition: Point.h:32
atm::AttenuationResult EvaluateMieAttenuation(const utl::Point &xInit, const utl::Point &xFinal, const std::vector< double > &wLength) const
const utl::TabulatedFunctionErrors & GetTransmissionFactor() const
Transmission factor.
Traditional name.
Definition: Verbosity.h:17
double pow(const double x, const unsigned int i)
Class for computing aerosol scattering and attenuation using database measurements.
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
Exception to use in a atmosphere model cannot find data it needs.
constexpr double nanometer
Definition: AugerUnits.h:102
Class holding the output of the ScatteringResult function.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Reference ellipsoids for UTM transformations.
bool HasData() const
Determine if the DB tables are full or if an update is needed.
const double km
void Init()
Initialize model using an XML card.
const utl::TabulatedFunctionErrors & GetScatteringFactor() const
Scattering factor.
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
double Y(const double x) const
Get or interpolate the Y value that corresponds to parameter x.
constexpr double m
Definition: AugerUnits.h:121
void SetUncertaintyBound(const ModelWithUncertainty model, const double nSigma) const
alter Model &quot;model&quot; by &quot;nSigma&quot; standard deviations
Class describing the Atmospheric attenuation.
atm::ScatteringResult EvaluateMieScattering(const utl::Point &xA, const utl::Point &xB, const double angle, const double distance, const std::vector< double > &xLength) const

, generated on Tue Sep 26 2023.