ErrorPropagation.cc
Go to the documentation of this file.
1 
7 #include <utl/config.h>
8 #include "ErrorPropagation.h"
9 #include "ConversionUtil.h"
10 
11 #include <utl/NumericalErrorPropagation.h>
12 #include <utl/AugerException.h>
13 #include <utl/TimeStamp.h>
14 #include <utl/UTCDateTime.h>
15 #include <utl/ModifiedJulianDate.h>
16 #include <utl/Vector.h>
17 #include <utl/AxialVector.h>
18 #include <utl/Point.h>
19 #include <utl/UTMPoint.h>
20 #include <utl/PhysicalConstants.h>
21 #include <utl/AugerUnits.h>
22 #include <utl/CoordinateSystemPtr.h>
23 #include <utl/Transformation.h>
24 #include <utl/Vector.h>
25 
26 #include <evt/Event.h>
27 #include <evt/ShowerFRecData.h>
28 
29 #include <fevt/Eye.h>
30 #include <fevt/EyeRecData.h>
31 
32 #include <det/Detector.h>
33 #include <fdet/FDetector.h>
34 #include <fdet/Eye.h>
35 
36 #include <fwk/LocalCoordinateSystem.h>
37 #include <fwk/CoordinateSystemRegistry.h>
38 
39 #include <iostream>
40 #include <string>
41 
42 using namespace std;
43 using namespace otoa;
44 using namespace otoa::err;
45 using namespace utl;
46 using namespace fwk;
47 
48 
49 std::vector<double>
50 CalculateEquatorialCoordinates::operator()(const std::vector<double>& p)
51  const
52 {
53  if (p.size() != 7) {
54  ostringstream msg;
55  msg << "CalculateEquatorialCoordinates needs 7 parameters, but was called with " << p.size();
56  throw utl::OutOfBoundException(msg.str());
57  }
58 
59  const double julianDay = p[0];
60  const double gmst = p[1];
61  const double easting = p[2]; // = x
62  const double northing = p[3]; // = y
63  const double altitude = p[4]; // = z
64  double theta = p[5];
65  double phi = p[6];
66 
67  const char band = 'H';
68  const int zone = 19;
69  const UTMPoint pt(northing, easting, altitude, zone, band, ReferenceEllipsoid::eWGS84);
70 
71  double latitude;
72  double longitude;
73  double height;
74  boost::tuple<double&, double&, double&>(latitude, longitude, height) =
76 
77  phi += 0.5*kPi; // phi should be -phi
78  // (Auger pointing east, and going to north, west, etc)
79  phi *= -1; // change sign of phi
80  theta = 0.5*kPi - theta; // theta
81 
82  const double sinTheta = sin(theta);
83  const double cosTheta = cos(theta);
84  const double cosPhi = cos(phi);
85  const double sinLatitude = sin(latitude);
86  const double cosLatitude = cos(latitude);
87  const double dec = asin(sinLatitude*sinTheta - cosLatitude*cosTheta*cosPhi);
88  const double secDec = 1 / cos(dec);
89  const double haSin = cosTheta * sin(phi) * secDec;
90  const double haCos = (cosLatitude*sinTheta + sinLatitude*cosTheta*cosPhi) * secDec;
91 
92  const double ha = (haSin < 0) ? 2*kPi - acos(haCos) : acos(haCos);
93 
94  // TODO lives in ConversionUtils.cc, should be in utl along with THIS code (or libnova)
95  const double nutHour = otoa::CalculateNutationCorrection(julianDay);
96  // local sideral time
97  double lmst = fmod(gmst + nutHour, 24.)*15 + longitude/deg;
98 
99  //get the lmst between 0 and 360 degrees
100  if (lmst > 0)
101  lmst -= int(lmst/360)*360;
102  else
103  lmst += 360 - int(lmst/360)*360;
104 
105  double ra = lmst*deg - ha;
106 
107  if (ra < 0)
108  ra += 2*kPi;
109  if (ra > 2*kPi)
110  ra -= 2*kPi;
111 
112  vector<double> result(2);
113  if (-2*kPi <= ra && ra <= 2*kPi) {
114  result[0] = ra;
115  result[1] = dec;
116  }
117 
118  return result;
119 }
120 
121 
122 std::vector<double>
123 CalculateGalacticCoordinates::operator()(const std::vector<double>& p)
124  const
125 {
126  if (p.size() != 7) {
127  ostringstream msg;
128  msg << "CalculateGalacticCoordinates needs 7 parameters, but was called with " << p.size();
129  throw utl::OutOfBoundException(msg.str());
130  }
131 
133  const vector<double> q = calcEqu(p);
134 
135  const double ra = q[0];
136  const double dec = q[1];
137 
138  const double raGalEq = 282.86*deg; // ra of the ascending node
139  const double galLg2000 = 32.933*deg; //
140  const double eqGal = 27.13*deg; // pi/2-angle betweem eq and gal equator
141 
142  const double cosDec = cos(dec);
143  const double sinDec = sin(dec);
144  const double cosEqGal = cos(eqGal);
145  const double galLatitude = asin(sinDec*sin(eqGal) - cosDec*sin(ra - raGalEq)*cosEqGal);
146  const double secGalLatitude = 1 / cos(galLatitude);
147  const double cosLon = cosDec*cos(ra - raGalEq) * secGalLatitude;
148  const double sinLon = (cosDec*sin(ra - raGalEq)*sin(eqGal) + sinDec*cosEqGal) * secGalLatitude;
149 
150  double galLongitude = ((cosLon < 0 && sinLon < 0) || (cosLon > 0 && sinLon < 0)) ?
151  2*kPi - acos(cosLon) + galLg2000 : acos(cosLon) + galLg2000;
152 
153  //while(GLongitude>2*kPi) GLongitude -= 2.0*kPi;
154  galLongitude = fmod(galLongitude, 2*kPi);
155  if (galLongitude < 0)
156  galLongitude += 2*kPi;
157 
158  vector<double> result(2);
159  result[0] = galLongitude;
160  result[1] = galLatitude;
161  return result;
162 }
163 
164 
165 CalculateFdCorePosition::CalculateFdCorePosition(const fevt::Eye& eye) :
166  fEye(eye)
167 { }
168 
169 
170 std::vector<double>
171 CalculateFdCorePosition::operator()(const std::vector<double>& p)
172  const
173 {
174  const double rp = p[0];
175  const double chi0 = p[1];
176  const double sDPtheta = p[2];
177  const double sDPphi = p[3];
178 
179  const ReferenceEllipsoid wgs84(ReferenceEllipsoid::Get(ReferenceEllipsoid::eWGS84));
180  const fdet::Eye& detEye = det::Detector::GetInstance().GetFDetector().GetEye(fEye);
181  const CoordinateSystemPtr eyeCS = detEye.GetEyeCoordinateSystem();
182  const Point eyeposition = detEye.GetPosition();
183 
184  const Vector sdp(1, sDPtheta, sDPphi, eyeCS, Vector::kSpherical);
185 
186  const Vector vertical(0, 0, 1, eyeCS);
187  const Vector horizontalInSDP = Normalized(Cross(sdp, vertical)); // horizontal
188 
189  const Vector coreEyeVec = rp / sin(kPi - chi0) * horizontalInSDP;
190  const Point core = eyeposition + coreEyeVec;
191 
192  // core (first of all do the utm-exception check !!!!)
193  double northing = 0;
194  double easting = 0;
195  // altitude is fixed to local ground altitude
196  try {
197  const utl::UTMPoint pt(core, wgs84);
198  northing = pt.GetNorthing();
199  easting = pt.GetEasting();
200  } catch (UTMPoint::UTMZoneException&) {
201  ERROR("UTMZoneException: fd rec shower invalid");
202  } catch (UTMPoint::UTMException&) {
203  ERROR("UTMException: fd rec shower invalid");
204  }
205 
206  std::vector<double> result(2);
207  result[0] = easting;
208  result[1] = northing;
209 
210  return result;
211 }
212 
213 
215  fEye(eye)
216 { }
217 
218 
219 std::vector<double>
220 CalculateFdArrivalDirection::operator()(const std::vector<double>& p)
221  const
222 {
223  const double chi0 = p[0];
224  const double sDPtheta = p[1];
225  const double sDPphi = p[2];
226 
228  const utl::Point& core = frec.GetCorePosition();
229  const fdet::Eye& detEye = det::Detector::GetInstance().GetFDetector().GetEye(fEye);
230  const CoordinateSystemPtr eyeCS = detEye.GetEyeCoordinateSystem();
231  const CoordinateSystemPtr localCS = LocalCoordinateSystem::Create(core);
232 
233  const Vector sdp(1, sDPtheta, sDPphi, eyeCS, Vector::kSpherical);
234 
235  const Vector vertical(0, 0, 1, eyeCS);
236  const Vector horizontalInSDP = Normalized(Cross(sdp, vertical)); // horizontal
237 
238  const Transformation rot = Transformation::Rotation(-chi0, sdp, eyeCS);
239 
240  const Vector axis = Normalized(rot * horizontalInSDP); // apply rotation
241 
242  vector<double> result(2);
243  result[0] = axis.GetTheta(localCS);
244  result[1] = axis.GetPhi(localCS);
245 
246  return result;
247 }
AxialVector Cross(const Vector &l, const Vector &r)
Definition: OperationsAV.h:25
Point object.
Definition: Point.h:32
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
Definition: BasicVector.h:254
Fluorescence Detector Eye Event.
Definition: FEvent/Eye.h:29
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
Definition: BasicVector.h:248
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
std::vector< double > operator()(const std::vector< double > &p) const
Detector description interface for Eye-related data.
Definition: FDetector/Eye.h:45
double GetNorthing() const
Get the northing.
Definition: UTMPoint.h:206
Report attempts to use invalid UTM zone.
Definition: UTMPoint.h:300
double CalculateNutationCorrection(const double julianDay)
Used by the calculation of the equatorial coordinates. TODO: Move such calculations to utl or use lib...
Exception for reporting variable out of valid range.
constexpr double deg
Definition: AugerUnits.h:140
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Reference ellipsoids for UTM transformations.
utl::CoordinateSystemPtr GetEyeCoordinateSystem() const
Returns the Eye Coordinate system.
constexpr double kPi
Definition: MathConstants.h:24
const Data result[]
Active transformations of geometrical objects.
evt::ShowerFRecData & GetFRecShower()
Reconstructed shower info for this eye.
Definition: EyeRecData.h:323
double GetEasting() const
Get the easting.
Definition: UTMPoint.h:209
AxialVector Normalized(const AxialVector &v)
Definition: AxialVector.h:81
Report problems in UTM handling.
Definition: UTMPoint.h:288
Vector object.
Definition: Vector.h:30
Interface class to access to Fluorescence reconstruction of a Shower.
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
std::vector< double > operator()(const std::vector< double > &p) const
CalculateFdArrivalDirection(const fevt::Eye &eye)
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
boost::tuple< double, double, double > GetGeodeticCoordinates() const
Get geodetic latitude, longitude, height.
Definition: UTMPoint.cc:67
const utl::Point & GetCorePosition() const
Shower core as reconstructed by the FD or FD eye.
utl::Point GetPosition() const
Eye position.
fevt::EyeRecData & GetRecData()
Reconstructed data for this eye.
Definition: FEvent/Eye.cc:130

, generated on Tue Sep 26 2023.