9 #include <det/Detector.h>
11 #include <fdet/FDetector.h>
14 #include <atm/NonParametricXMLMieModel.h>
15 #include <atm/ScatteringResult.h>
16 #include <atm/AttenuationResult.h>
18 #include <fwk/CentralConfig.h>
19 #include <fwk/CoordinateSystemRegistry.h>
21 #include <utl/Point.h>
22 #include <utl/AugerUnits.h>
23 #include <utl/MathConstants.h>
24 #include <utl/Reader.h>
25 #include <utl/ErrorLogger.h>
26 #include <utl/Vector.h>
27 #include <utl/ReferenceEllipsoid.h>
28 #include <utl/TabulatedFunctionErrors.h>
29 #include <utl/RandomSamplerFromPDF.h>
43 CentralConfig::GetInstance()->
GetTopBranch(
"NonParametricXMLMieModel");
48 vector<double> height;
64 const double dh = height[1] - height[0];
65 const int N = height.size();
69 alpha.push_back(vaod[0] / dh);
70 for (
int i = 1; i < N; ++i)
71 alpha.push_back((vaod[i] - vaod[i-1]) / dh);
75 for (
int i = 1; i < N; ++i)
76 alpha.push_back((vaod[i] - vaod[i-1]) / dh);
77 vaod.erase(vaod.begin());
78 height.erase(height.begin());
97 NonParametricXMLMieModel::SetPhaseFunction(
const PhaseFunction& phaseFunc)
107 NonParametricXMLMieModel::EvaluateMieScattering(
const utl::Point& xA,
110 const double distance,
111 const vector<double>& wLength)
115 const double fractionError = 0;
116 const double wError = 0;
118 for (std::vector<double>::const_iterator it = wLength.begin();
119 it != wLength.end(); ++it) {
120 const double value = EvaluateMieScattering(xA, xB, angle, distance, *it);
121 frac.
PushBack(*it, wError, value, fractionError);
132 NonParametricXMLMieModel::EvaluateMieScattering(
const utl::Point& xA,
135 const double distance,
141 const double fractionError = 0;
142 const double wError = 0;
144 const unsigned int nWl = attenuation.
GetNPoints();
145 for (
unsigned int iWl = 0; iWl < nWl; ++iWl) {
146 const double wl = attenuation.
GetX(iWl);
147 const double value = EvaluateMieScattering(xA, xB, angle, distance, wl, attenuation.
GetY(iWl));
148 frac.
PushBack(wl, wError, value, fractionError);
159 NonParametricXMLMieModel::EvaluateMieScattering(
const utl::Point& xA,
162 const double distance,
163 const double wLength)
167 const double mAtt = EvaluateMieAttenuation(xA, xB, wLength);
168 return EvaluateMieScattering(xA, xB, angle, distance, wLength, mAtt);
176 NonParametricXMLMieModel::EvaluateMieScattering(
const utl::Point& xA,
179 const double distance,
180 const double wLength,
181 const double mieAttenuation)
184 const double xphs = EvaluateScatteringAngle(xA, angle, wLength);
185 return (1 - mieAttenuation) * xphs /
pow(distance, 2);
194 NonParametricXMLMieModel::EvaluateMieAttenuation(
const utl::Point& xInit,
196 const std::vector<double>& wLength)
200 const double wError = 0;
201 const double mieAttError = 0;
203 for (std::vector<double>::const_iterator wlIter = wLength.begin();
204 wlIter != wLength.end(); ++wlIter) {
205 const double mieAtt = EvaluateMieAttenuation(xInit, xFinal, *wlIter);
206 attenuation.
PushBack(*wlIter, wError, mieAtt, mieAttError);
218 NonParametricXMLMieModel::EvaluateMieAttenuation(
const utl::Point& xInit,
220 const double wLength)
228 const double hMin = fVAODVsHeight->XFront();
229 const double hMax = fVAODVsHeight->XBack();
231 const double distance = (xFinal - xInit).GetMag();
232 const double deltaHeight =
abs(hFinal - hInit);
233 const double cosTheta = deltaHeight / distance;
234 double averageHeight = min(hInit, hFinal) + 0.5 * deltaHeight;
248 if (averageHeight < hMin)
249 averageHeight = hMin;
250 if (averageHeight > hMax)
251 averageHeight = hMax;
256 if (deltaHeight > 1 *
m) {
257 const double vaodInit = fVAODVsHeight->InterpolateY(hInit,3);
258 const double vaodFinal = fVAODVsHeight->InterpolateY(hFinal,3);
259 vaodSlant =
abs(vaodFinal - vaodInit) / cosTheta;
261 const double alpha = fAlphaVsHeight->Y(hInit);
262 vaodSlant = distance*alpha;
266 const double arg = -vaodSlant *
pow(wLength/355./
nanometer, -fGamma);
268 if (arg < std::numeric_limits<double>::max_exponent10 *
kLn10)
279 NonParametricXMLMieModel::GetVerticalAerosolOpticalDepth(
const unsigned int eyeId,
280 const double altitude)
283 const double hMax = fVAODVsHeight->XBack();
286 if (altitude >= hMax) {
288 warn <<
"Requested VAOD at " << altitude /
km <<
" km at eye " << eyeId
289 <<
", but VAOD profile only goes to " << hMax /
km <<
"km."
290 <<
" Returning heighest measured VAOD.";
293 VAOD = fVAODVsHeight->YBack();
296 VAOD = fVAODVsHeight->InterpolateY(altitude, 3);
307 NonParametricXMLMieModel::GetAttenuationLength(
const utl::Point&
p,
308 const double wLength)
315 const double hMin = fAlphaVsHeight->XFront();
316 const double hMax = fAlphaVsHeight->XBack();
324 const double alpha = fAlphaVsHeight->Y(height);
325 return 1. / (alpha *
pow(wLength / 355. /
nanometer, -fGamma));
333 NonParametricXMLMieModel::EvaluateScatteringAngle(
const Point& ,
338 const int nbin = fPF.size();
339 const double binSize =
kPi / (nbin - 1);
340 int ibin = int(angle / binSize);
344 else if (ibin > nbin)
347 return exp(log(fPF[ibin]) +
348 (angle - binSize * ibin) * log(fPF[ibin+1] / fPF[ibin]) / binSize);
std::vector< double > PhaseFunction
Phase function table (arbitrary angular binning between 0, 180 degrees)
Branch GetTopBranch() const
unsigned int GetNPoints() const
const utl::TabulatedFunctionErrors & GetTransmissionFactor() const
Transmission factor.
void swap(utl::TabulatedFunction &t1, utl::TabulatedFunction &t2)
Class to hold collection (x,y) points and provide interpolation between them.
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
static const ReferenceEllipsoid & Get(const EllipsoidID theID)
Get known ellipsoid by registered ID.
double pow(const double x, const unsigned int i)
constexpr double nanometer
Class holding the output of the ScatteringResult function.
Class representing a document branch.
Reference ellipsoids for UTM transformations.
double abs(const SVector< n, T > &v)
Triple PointToLatitudeLongitudeHeight(const Point &thePoint) const
Convert Point to Lat/Long/Height.
void PushBack(const double x, const double xErr, const double y, const double yErr)
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
const double & GetY(const unsigned int idx) const
const double & GetX(const unsigned int idx) const
Class describing the Atmospheric attenuation.