Jpp  16.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JAstronomy.hh
Go to the documentation of this file.
1 #ifndef __JASTRONOMY__
2 #define __JASTRONOMY__
3 
4 #include "JMath/JConstants.hh"
5 
6 /**
7  * \file
8  *
9  * Interface methods for slalib and auxiliary classes and methods for astronomy.
10  * \author mdejong
11  */
12 namespace JASTRONOMY {}
13 namespace JPP { using namespace JASTRONOMY; }
14 
15 namespace JASTRONOMY {
16 
17  extern "C"
18  {
19  // To convert Modified Julian Date to Greenwich Mean Sidereal Time (in rads):
20  double sla_gmst_(double& ut1);
21  double sla_gmsta_(double& ut1, double& part_day);
22 
23  // To calculate the difference between the mean & apparant places of the Equinox (in rads):
24  double sla_eqeqx_(double& ut1);
25 
26  // To convert local equatorial to horizontal coords and vice versa:
27  void sla_de2h_(double& hourangle, double& declination, double& observer_latitude,
28  double& azimuth, double& elevation); // azimuth: [0,2pi], elevation: [-pi/2,pi/2]
29  void sla_dh2e_(double& azimuth, double& elevation, double& observer_latitude,
30  double& hourangle, double& declination); // HA: [-pi,pi], Dec: [-pi/2,pi/2]
31 
32  // To convert equatorial to ecliptic coordinates and vice versa:
33  void sla_eqecl_(double& rightascension, double& declination, double& time,
34  double& ecliptic_longitude, double& ecliptic_latitude);
35  void sla_ecleq_(double& ecliptic_longitude, double& ecliptic_latitude, double& time,
36  double& rightascension, double& declination);
37 
38  // To convert equatorial to galactic coords and vice versa:
39  void sla_eqgal_(double& rightascension, double& declination,
40  double& galactic_longitude, double& galactic_latitude);
41  void sla_galeq_(double& galactic_longitude, double& galactic_latitude,
42  double& rightascension, double& declination);
43 
44  // To convert galactic to supergalactic coords and vice versa:
45  void sla_galsup_(double& galactic_longitude, double& galactic_latitude,
46  double& sgalactic_longitude, double& sgalactic_latitude);
47  void sla_supgal_(double& sgalactic_longitude, double& sgalactic_latitude,
48  double& galactic_longitude, double& galactic_latitude);
49 
50  // To convert Gregorian Calender Date to Modified Julian Date:
51  // (Note: MJD = JD - 2400000.5,
52  // i.e.\ JD = # of days since noon 1st of januari 4713 BC
53  // and MJD = # of days since midnight 17th of november 1858 AD)
54  void sla_caldj_(int& year, int& month, int& day,
55  double& mjd, int& status);
56 
57  // calendar to year, days
58  void sla_clyd_(int& year, int& month, int& day, int& nyears, int& ndays, int&status);
59 
60  // MJD to Gregorian Calendar Date, expressed in single array
61  void sla_djcal_(int& precision, double& mjd, // input : number of decimal places of days in fraction, MJD
62  int result[4], int& status); // output: GCD, status
63 
64  // days to hour, min, sec
65  void sla_dd2tf_(int& ndec, double& day, // input : number of decimal places of seconds, interval in days
66  char sign[1], int result[4]); // output: + or -, hours, minutes, seconds
67 
68  // To obtain the difference in dynamical Terrestial Time and the current time (UT1) in secs, at the current time (UT1):
69  // (Note: instead of the current time (UT1) one can also use current time (UTC) since UTC-UT1 < 0.9 secs
70  double sla_dtt_(double& ut1);
71 
72  // To obtain approx. topocentric apparent (RA & Dec) and angular size of planet/moon/sun from an observer:
73  void sla_rdplan_(double& dtt, int& object, const double& longitude, const double& latitude, // longitude is +/- if east/west of prime meridian
74  double& rightascension, double& declination, double& diam);
75 
76  // To calculate the precession between epochs:
77  void sla_preces_(char *system, double& ep0, double& ep1, double& ra, double& dec, int length);
78  }
79 
80 
81  static const double MJD_EPOCH = 40587.0; // MJD of the Unix Epoch, i.e.\ 00:00 Jan 1 1970 (UTC)
82 
83  static const double NUMBER_OF_SECONDS_PER_HOUR = 60.0 * 60.0;
87 
88 
89  /**
90  * Convert angle to radians.
91  *
92  * \param angle angle [deg]
93  * \return angle [rad]
94  */
95  inline double getRadians(const double angle)
96  {
97  return JMATH::PI * angle / 180.0;
98  }
99 
100 
101  /**
102  * Convert angle to radians.
103  *
104  * \param angle angle [deg]
105  * \param amin arcminutes
106  * \param asec arcseconds
107  * \return angle [rad]
108  */
109  inline double getRadians(const int angle,
110  const int amin,
111  const double asec)
112  {
113  return JMATH::PI * ((double) angle +
114  (double) amin / 60.0 +
115  (double) asec / 3600.0) / 180.0;
116  }
117 
118 
119  /**
120  * Convert hour angle to radians.
121  *
122  * \param hour hour
123  * \param min minutes
124  * \param sec seconds
125  * \return angle [rad]
126  */
127  inline double getHourAngle(const int hour,
128  const int min,
129  const double sec)
130  {
131  double ha = (JMATH::PI * (double) hour / 12.0 +
132  JMATH::PI * (double) min / 720.0 +
133  JMATH::PI * (double) sec / 43200.0);
134 
135  if (ha > JMATH::PI) {
136  ha -= 2*JMATH::PI;
137  }
138 
139  return ha;
140  }
141 
142 
143  /**
144  * Location of astrophysical source.
145  */
147  public:
148 
149  /**
150  * Default constructor.
151  */
153  __declination (0.0),
154  __right_ascension(0.0)
155  {}
156 
157 
158  /**
159  * Constructor.
160  *
161  * \param declination declination
162  * \param right_ascension right ascension
163  */
164  JSourceLocation(const double declination,
165  const double right_ascension) :
166  __declination (declination),
167  __right_ascension(right_ascension)
168  {}
169 
170  const double& getDeclination() const { return __declination; }
171  const double& getRightAscension() const { return __right_ascension; }
172 
173  protected:
176  };
177 
178 
179  /**
180  * Direction of incident neutrino.
181  */
183  public:
184 
185  /**
186  * Default constructor.
187  */
189  __zenith (0.0),
190  __azimuth(0.0)
191  {}
192 
193 
194  /**
195  * Constructor.
196  *
197  * \param zenith zenith
198  * \param azimuth azimuth
199  */
200  JNeutrinoDirection(const double& zenith,
201  const double& azimuth) :
202  __zenith (zenith),
203  __azimuth(azimuth)
204  {}
205 
206  const double& getZenith() const { return __zenith; }
207  const double& getAzimuth() const { return __azimuth; }
208 
209  protected:
210  double __zenith;
211  double __azimuth;
212  };
213 
214 
215  /**
216  * Location of detector.
217  */
219  public:
220 
221  /**
222  * Default constructor.
223  */
225  __latitude (0.0),
226  __longitude(0.0)
227  {}
228 
229 
230  /**
231  * Constructor.
232  *
233  * \param latitude latitude
234  * \param longitude longitude
235  */
236  JGeographicalLocation(const double latitude,
237  const double longitude) :
238  __latitude (latitude),
239  __longitude(longitude)
240  {}
241 
242 
243  /**
244  * Constructor.
245  *
246  * \param degreesNorth degrees North
247  * \param minutesNorth minutes North
248  * \param degreesEast degrees East
249  * \param minutesEast minutes East
250  */
251  JGeographicalLocation(const int degreesNorth,
252  const int minutesNorth,
253  const int degreesEast,
254  const int minutesEast)
255  {
256  __latitude = (degreesNorth + minutesNorth / 60.0) * JMATH::PI / 180.0;
257  __longitude = (degreesEast + minutesEast / 60.0) * JMATH::PI / 180.0;
258  }
259 
260  const double& getLatitude() const { return __latitude; }
261  const double& getLongitude() const { return __longitude; }
262 
263  protected:
264  double __latitude;
265  double __longitude;
266  };
267 
268 
269 
270  /**
271  * Auxiliary class to make coordinate transformations for a specific geographical location of the detector.
272  *
273  * Note: SLALIB ref. system : (x,y,z) = (N,E,up)
274  * ANTARES ref. system for d10_c00_s00 : (x,y,z) = (N,W,up)
275  * ANTARES ref. system for real det. : (x,y,z) = (E,N,up)
276  */
277  class JAstronomy :
278  public JGeographicalLocation
279  {
280  public:
281 
282  /**
283  * Constructor.
284  *
285  * \param location location of detector
286  */
288  JGeographicalLocation(location)
289  {}
290 
291 
292  /**
293  * Get direction pointing to source.
294  *
295  * \param t1 number of seconds since MJD
296  * \param pos source location
297  * \return direction of neutrino
298  */
300  const JSourceLocation& pos) const
301  {
302  double mjd = t1 / NUMBER_OF_SECONDS_PER_DAY; // [days]
303 
304  double longitude = getLongitude();
305  double latitude = getLatitude();
306 
307  // Convert current mjd (UTC) to local sidereal time,
308  // taking into account the Equation of the Equinoxes:
309  // Note: LST = GMST + local longitude, where l.l. is +/- if east/west of prime meridian
310 
311  double gmst = sla_gmst_ (mjd); // gmst = Greenwich mean sidereal time
312  double eqeqx = sla_eqeqx_(mjd); // Note: Equation of the Equinoxes < 1.15 secs
313  double lst = gmst + longitude + eqeqx;
314 
315  // Transform time-independent equatorial coordinates to time-dependent equatorial coordinates (i.e.\ ra->ha):
316 
317  double dec = pos.getDeclination();
318  double ra = pos.getRightAscension();
319  double ha = lst - ra;
320 
321  // Convert time-dependent equatorial coordinates to local horizontal coordinates:
322  // Note: azimuth: [0,2pi] and elevation: [-pi,pi]
323 
324  double azimuth;
325  double elevation;
326 
327  sla_de2h_(ha, dec, latitude, azimuth, elevation);
328 
329  double theta = -elevation + JMATH::PI/2.0;
330  double phi = -azimuth + JMATH::PI/2.0;
331 
332  // invert direction
333 
334  theta = JMATH::PI - theta;
335  phi = phi + JMATH::PI;
336 
337  if (phi > JMATH::PI)
338  phi -= 2.0*JMATH::PI;
339 
340  return JNeutrinoDirection(theta,phi);
341  }
342 
343 
344  /**
345  * Get location of source.
346  *
347  * \param t1 number of seconds since MJD
348  * \param dir direction of neutrino
349  * \return source location
350  */
352  const JNeutrinoDirection& dir) const
353  {
354  double longitude = getLongitude();
355  double latitude = getLatitude();
356 
357  // invert direction
358 
359  double theta = JMATH::PI - dir.getZenith();
360  double phi = dir.getAzimuth() - JMATH::PI;
361 
362  if (phi < 0.0) {
363  phi += 2.0*JMATH::PI;
364  }
365 
366  double elevation = -theta + JMATH::PI/2.0;
367  double azimuth = -phi + JMATH::PI/2.0;
368 
369  // Convert time-dependent equatorial coordinates to local horizontal coordinates:
370  // Note: azimuth: [0,2pi] and elevation: [-pi,pi]
371 
372  double ha;
373  double dec;
374 
375  sla_dh2e_(azimuth, elevation, latitude, ha, dec);
376 
377  // Get current mjd (UTC):
378 
379  double mjd = t1 / NUMBER_OF_SECONDS_PER_DAY; // [days]
380 
381  // Convert current mjd (UTC) to local sidereal time,
382  // taking into account the Equation of the Equinoxes:
383  // Note: LST = GMST + local longitude, where l.l. is +/- if east/west of prime meridian
384 
385  double gmst = sla_gmst_ (mjd); // gmst = Greenwich mean sidereal time
386  double eqeqx = sla_eqeqx_(mjd); // Note: Equation of the Equinoxes < 1.15 secs
387  double lst = gmst + longitude + eqeqx;
388 
389  // Transform time-independent equatorial coordinates to time-dependent equatorial coordinates (i.e.\ ra->ha):
390 
391  double ra = lst - ha;
392 
393  if (ra > JMATH::PI) {
394  ra -= 2.0*JMATH::PI;
395  }
396 
397  return JSourceLocation(dec, ra);
398  }
399  };
400 
401 
402  /**
403  * Dot product.
404  *
405  * \param first neutrino direction
406  * \param second neutrino direction
407  * \return dot product
408  */
409  inline double getDot(const JNeutrinoDirection& first,
410  const JNeutrinoDirection& second)
411  {
412  return
413  cos(first.getZenith()) * cos(second.getZenith()) +
414  sin(first.getZenith()) * sin(second.getZenith()) *
415  cos(first.getAzimuth() - second.getAzimuth());
416  }
417 
418 
419  /**
420  * Dot product.
421  *
422  * \param first source location
423  * \param second source location
424  * \return dot product
425  */
426  inline double getDot(const JSourceLocation& first,
427  const JSourceLocation& second)
428  {
429  return
430  sin(first.getDeclination()) * sin(second.getDeclination()) +
431  cos(first.getDeclination()) * cos(second.getDeclination()) *
432  cos(first.getRightAscension() - second.getRightAscension());
433  }
434 
435 
436  // detector locations
437 
438  static const JGeographicalLocation Antares(42, 48, 06, 10);
439  static const JGeographicalLocation Sicily (36, 16, 16, 06);
440  static const JGeographicalLocation Pylos (36, 33, 16, 06);
441 
442 
443  // source locations
444 
445  static const JSourceLocation galacticCenter(-0.5062816, -1.633335);
446  static const JSourceLocation RXJ1713 (getRadians(-39, -46, 0.0), getHourAngle(17, 13, 7));
447  static const JSourceLocation VELAX (getRadians(-45, -10, -35.2), getHourAngle( 8, 35, 20.66));
448 }
449 
450 #endif
static const JGeographicalLocation Sicily(36, 16, 16, 06)
Direction of incident neutrino.
Definition: JAstronomy.hh:182
JGeographicalLocation(const int degreesNorth, const int minutesNorth, const int degreesEast, const int minutesEast)
Constructor.
Definition: JAstronomy.hh:251
double sla_eqeqx_(double &ut1)
void sla_djcal_(int &precision, double &mjd, int result[4], int &status)
void sla_eqecl_(double &rightascension, double &declination, double &time, double &ecliptic_longitude, double &ecliptic_latitude)
void sla_dh2e_(double &azimuth, double &elevation, double &observer_latitude, double &hourangle, double &declination)
void sla_de2h_(double &hourangle, double &declination, double &observer_latitude, double &azimuth, double &elevation)
JNeutrinoDirection getDirectionOfNeutrino(const double &t1, const JSourceLocation &pos) const
Get direction pointing to source.
Definition: JAstronomy.hh:299
double getDot(const JNeutrinoDirection &first, const JNeutrinoDirection &second)
Dot product.
Definition: JAstronomy.hh:409
Location of detector.
Definition: JAstronomy.hh:218
double getHourAngle(const int hour, const int min, const double sec)
Convert hour angle to radians.
Definition: JAstronomy.hh:127
double sla_gmsta_(double &ut1, double &part_day)
static const JSourceLocation RXJ1713(getRadians(-39,-46, 0.0), getHourAngle(17, 13, 7))
JAstronomy(const JGeographicalLocation &location)
Constructor.
Definition: JAstronomy.hh:287
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Auxiliary class to make coordinate transformations for a specific geographical location of the detect...
Definition: JAstronomy.hh:277
Location of astrophysical source.
Definition: JAstronomy.hh:146
const char *const hourangle
Definition: io_ascii.hh:56
void sla_ecleq_(double &ecliptic_longitude, double &ecliptic_latitude, double &time, double &rightascension, double &declination)
void sla_dd2tf_(int &ndec, double &day, char sign[1], int result[4])
void sla_galsup_(double &galactic_longitude, double &galactic_latitude, double &sgalactic_longitude, double &sgalactic_latitude)
const double & getZenith() const
Definition: JAstronomy.hh:206
const double & getLatitude() const
Definition: JAstronomy.hh:260
const double & getDeclination() const
Definition: JAstronomy.hh:170
void sla_clyd_(int &year, int &month, int &day, int &nyears, int &ndays, int &status)
Mathematical constants.
return result
Definition: JPolint.hh:743
double sla_gmst_(double &ut1)
static const double NUMBER_OF_SECONDS_PER_DAY
Definition: JAstronomy.hh:84
void sla_supgal_(double &sgalactic_longitude, double &sgalactic_latitude, double &galactic_longitude, double &galactic_latitude)
void sla_preces_(char *system, double &ep0, double &ep1, double &ra, double &dec, int length)
const double & getAzimuth() const
Definition: JAstronomy.hh:207
JGeographicalLocation()
Default constructor.
Definition: JAstronomy.hh:224
static const JGeographicalLocation Pylos(36, 33, 16, 06)
void sla_caldj_(int &year, int &month, int &day, double &mjd, int &status)
static const double PI
Mathematical constants.
static const double MJD_EPOCH
Definition: JAstronomy.hh:81
static const JSourceLocation VELAX(getRadians(-45,-10,-35.2), getHourAngle(8, 35, 20.66))
void sla_rdplan_(double &dtt, int &object, const double &longitude, const double &latitude, double &rightascension, double &declination, double &diam)
static const double NUMBER_OF_SECONDS_PER_SEDERIAL_DAY
Definition: JAstronomy.hh:86
static const double NUMBER_OF_SECONDS_PER_HOUR
Definition: JAstronomy.hh:83
void sla_eqgal_(double &rightascension, double &declination, double &galactic_longitude, double &galactic_latitude)
static const JGeographicalLocation Antares(42, 48, 06, 10)
double getRadians(const double angle)
Convert angle to radians.
Definition: JAstronomy.hh:95
double sla_dtt_(double &ut1)
int sign(const T &value)
Get sign of value.
Definition: JLib.hh:20
JNeutrinoDirection()
Default constructor.
Definition: JAstronomy.hh:188
void sla_galeq_(double &galactic_longitude, double &galactic_latitude, double &rightascension, double &declination)
const double & getLongitude() const
Definition: JAstronomy.hh:261
JSourceLocation getLocationOfSource(const double t1, const JNeutrinoDirection &dir) const
Get location of source.
Definition: JAstronomy.hh:351
static const double NUMBER_OF_SECONDS_PER_YEAR
Definition: JAstronomy.hh:85
static const JSourceLocation galacticCenter(-0.5062816,-1.633335)
JSourceLocation()
Default constructor.
Definition: JAstronomy.hh:152
JSourceLocation(const double declination, const double right_ascension)
Constructor.
Definition: JAstronomy.hh:164
JGeographicalLocation(const double latitude, const double longitude)
Constructor.
Definition: JAstronomy.hh:236
JNeutrinoDirection(const double &zenith, const double &azimuth)
Constructor.
Definition: JAstronomy.hh:200
const double & getRightAscension() const
Definition: JAstronomy.hh:171