1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Bretz, 11/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MAstro
|
---|
28 | // ------
|
---|
29 | //
|
---|
30 | ////////////////////////////////////////////////////////////////////////////
|
---|
31 | #include "MAstro.h"
|
---|
32 |
|
---|
33 | #include <iostream>
|
---|
34 |
|
---|
35 | #include <TArrayD.h> // TArrayD
|
---|
36 | #include <TVector3.h> // TVector3
|
---|
37 |
|
---|
38 | #include "MTime.h" // MTime::GetGmst
|
---|
39 | #include "MString.h"
|
---|
40 |
|
---|
41 | #include "MAstroCatalog.h" // FIXME: replace by MVector3!
|
---|
42 |
|
---|
43 | using namespace std;
|
---|
44 |
|
---|
45 | ClassImp(MAstro);
|
---|
46 |
|
---|
47 | Double_t MAstro::Trunc(Double_t val)
|
---|
48 | {
|
---|
49 | // dint(A) - truncate to nearest whole number towards zero (double)
|
---|
50 | return val<0 ? TMath::Ceil(val) : TMath::Floor(val);
|
---|
51 | }
|
---|
52 |
|
---|
53 | Double_t MAstro::Round(Double_t val)
|
---|
54 | {
|
---|
55 | // dnint(A) - round to nearest whole number (double)
|
---|
56 | return val<0 ? TMath::Ceil(val-0.5) : TMath::Floor(val+0.5);
|
---|
57 | }
|
---|
58 |
|
---|
59 | Double_t MAstro::Hms2Sec(Int_t deg, UInt_t min, Double_t sec, Char_t sgn)
|
---|
60 | {
|
---|
61 | const Double_t rc = TMath::Sign((60.0 * (60.0 * (Double_t)TMath::Abs(deg) + (Double_t)min) + sec), (Double_t)deg);
|
---|
62 | return sgn=='-' ? -rc : rc;
|
---|
63 | }
|
---|
64 |
|
---|
65 | Double_t MAstro::Dms2Rad(Int_t deg, UInt_t min, Double_t sec, Char_t sgn)
|
---|
66 | {
|
---|
67 | // pi/(180*3600): arcseconds to radians
|
---|
68 | //#define DAS2R 4.8481368110953599358991410235794797595635330237270e-6
|
---|
69 | return Hms2Sec(deg, min, sec, sgn)*TMath::Pi()/(180*3600)/**DAS2R*/;
|
---|
70 | }
|
---|
71 |
|
---|
72 | Double_t MAstro::Hms2Rad(Int_t hor, UInt_t min, Double_t sec, Char_t sgn)
|
---|
73 | {
|
---|
74 | // pi/(12*3600): seconds of time to radians
|
---|
75 | //#define DS2R 7.2722052166430399038487115353692196393452995355905e-5
|
---|
76 | return Hms2Sec(hor, min, sec, sgn)*TMath::Pi()/(12*3600)/**DS2R*/;
|
---|
77 | }
|
---|
78 |
|
---|
79 | Double_t MAstro::Dms2Deg(Int_t deg, UInt_t min, Double_t sec, Char_t sgn)
|
---|
80 | {
|
---|
81 | return Hms2Sec(deg, min, sec, sgn)/3600.;
|
---|
82 | }
|
---|
83 |
|
---|
84 | Double_t MAstro::Hms2Deg(Int_t hor, UInt_t min, Double_t sec, Char_t sgn)
|
---|
85 | {
|
---|
86 | return Hms2Sec(hor, min, sec, sgn)/240.;
|
---|
87 | }
|
---|
88 |
|
---|
89 | Double_t MAstro::Dms2Hor(Int_t deg, UInt_t min, Double_t sec, Char_t sgn)
|
---|
90 | {
|
---|
91 | return Hms2Sec(deg, min, sec, sgn)/54000.;
|
---|
92 | }
|
---|
93 |
|
---|
94 | Double_t MAstro::Hms2Hor(Int_t hor, UInt_t min, Double_t sec, Char_t sgn)
|
---|
95 | {
|
---|
96 | return Hms2Sec(hor, min, sec, sgn)/3600.;
|
---|
97 | }
|
---|
98 |
|
---|
99 | void MAstro::Day2Hms(Double_t day, Char_t &sgn, UShort_t &hor, UShort_t &min, UShort_t &sec)
|
---|
100 | {
|
---|
101 | /* Handle sign */
|
---|
102 | sgn = day<0?'-':'+';
|
---|
103 |
|
---|
104 | /* Round interval and express in smallest units required */
|
---|
105 | Double_t a = Round(86400. * TMath::Abs(day)); // Days to seconds
|
---|
106 |
|
---|
107 | /* Separate into fields */
|
---|
108 | const Double_t ah = Trunc(a/3600.);
|
---|
109 | a -= ah * 3600.;
|
---|
110 | const Double_t am = Trunc(a/60.);
|
---|
111 | a -= am * 60.;
|
---|
112 | const Double_t as = Trunc(a);
|
---|
113 |
|
---|
114 | /* Return results */
|
---|
115 | hor = (UShort_t)ah;
|
---|
116 | min = (UShort_t)am;
|
---|
117 | sec = (UShort_t)as;
|
---|
118 | }
|
---|
119 |
|
---|
120 | void MAstro::Rad2Hms(Double_t rad, Char_t &sgn, UShort_t °, UShort_t &min, UShort_t &sec)
|
---|
121 | {
|
---|
122 | Day2Hms(rad/(TMath::Pi()*2), sgn, deg, min, sec);
|
---|
123 | }
|
---|
124 |
|
---|
125 | void MAstro::Rad2Dms(Double_t rad, Char_t &sgn, UShort_t °, UShort_t &min, UShort_t &sec)
|
---|
126 | {
|
---|
127 | Rad2Hms(rad*15, sgn, deg, min, sec);
|
---|
128 | }
|
---|
129 |
|
---|
130 | void MAstro::Deg2Dms(Double_t d, Char_t &sgn, UShort_t °, UShort_t &min, UShort_t &sec)
|
---|
131 | {
|
---|
132 | Day2Hms(d/24, sgn, deg, min, sec);
|
---|
133 | }
|
---|
134 |
|
---|
135 | void MAstro::Deg2Hms(Double_t d, Char_t &sgn, UShort_t °, UShort_t &min, UShort_t &sec)
|
---|
136 | {
|
---|
137 | Day2Hms(d/360, sgn, deg, min, sec);
|
---|
138 | }
|
---|
139 |
|
---|
140 | void MAstro::Hor2Dms(Double_t h, Char_t &sgn, UShort_t °, UShort_t &min, UShort_t &sec)
|
---|
141 | {
|
---|
142 | Day2Hms(h*15/24, sgn, deg, min, sec);
|
---|
143 | }
|
---|
144 |
|
---|
145 | void MAstro::Hor2Hms(Double_t h, Char_t &sgn, UShort_t °, UShort_t &min, UShort_t &sec)
|
---|
146 | {
|
---|
147 | Day2Hms(h/24, sgn, deg, min, sec);
|
---|
148 | }
|
---|
149 |
|
---|
150 | void MAstro::Day2Hm(Double_t day, Char_t &sgn, UShort_t &hor, Double_t &min)
|
---|
151 | {
|
---|
152 | /* Handle sign */
|
---|
153 | sgn = day<0?'-':'+';
|
---|
154 |
|
---|
155 | /* Round interval and express in smallest units required */
|
---|
156 | Double_t a = Round(86400. * TMath::Abs(day)); // Days to seconds
|
---|
157 |
|
---|
158 | /* Separate into fields */
|
---|
159 | const Double_t ah = Trunc(a/3600.);
|
---|
160 | a -= ah * 3600.;
|
---|
161 |
|
---|
162 | /* Return results */
|
---|
163 | hor = (UShort_t)ah;
|
---|
164 | min = a/60.;
|
---|
165 | }
|
---|
166 |
|
---|
167 | void MAstro::Rad2Hm(Double_t rad, Char_t &sgn, UShort_t °, Double_t &min)
|
---|
168 | {
|
---|
169 | Day2Hm(rad/(TMath::Pi()*2), sgn, deg, min);
|
---|
170 | }
|
---|
171 |
|
---|
172 | void MAstro::Rad2Dm(Double_t rad, Char_t &sgn, UShort_t °, Double_t &min)
|
---|
173 | {
|
---|
174 | Rad2Hm(rad*15, sgn, deg, min);
|
---|
175 | }
|
---|
176 |
|
---|
177 | void MAstro::Deg2Dm(Double_t d, Char_t &sgn, UShort_t °, Double_t &min)
|
---|
178 | {
|
---|
179 | Day2Hm(d/24, sgn, deg, min);
|
---|
180 | }
|
---|
181 |
|
---|
182 | void MAstro::Deg2Hm(Double_t d, Char_t &sgn, UShort_t °, Double_t &min)
|
---|
183 | {
|
---|
184 | Rad2Hm(d/360, sgn, deg, min);
|
---|
185 | }
|
---|
186 |
|
---|
187 | void MAstro::Hor2Dm(Double_t h, Char_t &sgn, UShort_t °, Double_t &min)
|
---|
188 | {
|
---|
189 | Day2Hm(h*15/24, sgn, deg, min);
|
---|
190 | }
|
---|
191 |
|
---|
192 | void MAstro::Hor2Hm(Double_t h, Char_t &sgn, UShort_t °, Double_t &min)
|
---|
193 | {
|
---|
194 | Day2Hm(h/24, sgn, deg, min);
|
---|
195 | }
|
---|
196 |
|
---|
197 | TString MAstro::GetStringDeg(Double_t deg, const char *fmt)
|
---|
198 | {
|
---|
199 | Char_t sgn;
|
---|
200 | UShort_t d, m, s;
|
---|
201 | Deg2Dms(deg, sgn, d, m, s);
|
---|
202 |
|
---|
203 | MString str;
|
---|
204 | str.Print(fmt, sgn, d, m ,s);
|
---|
205 | return str;
|
---|
206 | }
|
---|
207 |
|
---|
208 | TString MAstro::GetStringHor(Double_t deg, const char *fmt)
|
---|
209 | {
|
---|
210 | Char_t sgn;
|
---|
211 | UShort_t h, m, s;
|
---|
212 | Hor2Hms(deg, sgn, h, m, s);
|
---|
213 |
|
---|
214 | MString str;
|
---|
215 | str.Print(fmt, sgn, h, m ,s);
|
---|
216 | return str;
|
---|
217 | }
|
---|
218 |
|
---|
219 | // --------------------------------------------------------------------------
|
---|
220 | //
|
---|
221 | // Interpretes a string ' - 12 30 00.0' or '+ 12 30 00.0'
|
---|
222 | // as floating point value -12.5 or 12.5. If interpretation is
|
---|
223 | // successfull kTRUE is returned, otherwise kFALSE. ret is not
|
---|
224 | // touched if interpretation was not successfull. The successfull
|
---|
225 | // interpreted part is removed from the TString.
|
---|
226 | //
|
---|
227 | Bool_t MAstro::String2Angle(TString &str, Double_t &ret)
|
---|
228 | {
|
---|
229 | Char_t sgn;
|
---|
230 | Int_t d, len;
|
---|
231 | UInt_t m;
|
---|
232 | Float_t s;
|
---|
233 |
|
---|
234 | // Skip whitespaces before %c and after %f
|
---|
235 | int n=sscanf(str.Data(), " %c %d %d %f %n", &sgn, &d, &m, &s, &len);
|
---|
236 |
|
---|
237 | if (n!=4 || (sgn!='+' && sgn!='-'))
|
---|
238 | return kFALSE;
|
---|
239 |
|
---|
240 | str.Remove(0, len);
|
---|
241 |
|
---|
242 | ret = Dms2Deg(d, m, s, sgn);
|
---|
243 | return kTRUE;
|
---|
244 | }
|
---|
245 |
|
---|
246 | // --------------------------------------------------------------------------
|
---|
247 | //
|
---|
248 | // Interpretes a string '-12:30:00.0', '12:30:00.0' or '+12:30:00.0'
|
---|
249 | // as floating point value -12.5, 12.5 or 12.5. If interpretation is
|
---|
250 | // successfull kTRUE is returned, otherwise kFALSE. ret is not
|
---|
251 | // touched if interpretation was not successfull.
|
---|
252 | //
|
---|
253 | Bool_t MAstro::Coordinate2Angle(const TString &str, Double_t &ret)
|
---|
254 | {
|
---|
255 | Char_t sgn = str[0]=='-' ? '-' : '+';
|
---|
256 | Int_t d;
|
---|
257 | UInt_t m;
|
---|
258 | Float_t s;
|
---|
259 |
|
---|
260 | const int n=sscanf(str[0]=='+'||str[0]=='-' ? str.Data()+1 : str.Data(), "%d:%d:%f", &d, &m, &s);
|
---|
261 |
|
---|
262 | if (n!=3)
|
---|
263 | return kFALSE;
|
---|
264 |
|
---|
265 | ret = Dms2Deg(d, m, s, sgn);
|
---|
266 | return kTRUE;
|
---|
267 | }
|
---|
268 |
|
---|
269 | // --------------------------------------------------------------------------
|
---|
270 | //
|
---|
271 | // Returns val=-12.5 as string '-12:30:00'
|
---|
272 | //
|
---|
273 | TString MAstro::Angle2Coordinate(Double_t val)
|
---|
274 | {
|
---|
275 | Char_t sgn;
|
---|
276 | UShort_t d,m,s;
|
---|
277 |
|
---|
278 | Deg2Dms(val, sgn, d, m, s);
|
---|
279 |
|
---|
280 | return Form("%c%02d:%02d:%02d", sgn, d, m, s);
|
---|
281 | }
|
---|
282 |
|
---|
283 | // --------------------------------------------------------------------------
|
---|
284 | //
|
---|
285 | // Return year y, month m and day d corresponding to Mjd.
|
---|
286 | //
|
---|
287 | void MAstro::Mjd2Ymd(UInt_t mjd, UShort_t &y, Byte_t &m, Byte_t &d)
|
---|
288 | {
|
---|
289 | // Express day in Gregorian calendar
|
---|
290 | const ULong_t jd = mjd + 2400001;
|
---|
291 | const ULong_t n4 = 4*(jd+((6*((4*jd-17918)/146097))/4+1)/2-37);
|
---|
292 | const ULong_t nd10 = 10*(((n4-237)%1461)/4)+5;
|
---|
293 |
|
---|
294 | y = n4/1461L-4712;
|
---|
295 | m = ((nd10/306+2)%12)+1;
|
---|
296 | d = (nd10%306)/10+1;
|
---|
297 | }
|
---|
298 |
|
---|
299 | // --------------------------------------------------------------------------
|
---|
300 | //
|
---|
301 | // Return Mjd corresponding to year y, month m and day d.
|
---|
302 | //
|
---|
303 | Int_t MAstro::Ymd2Mjd(UShort_t y, Byte_t m, Byte_t d)
|
---|
304 | {
|
---|
305 | // Month lengths in days
|
---|
306 | static int months[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
---|
307 |
|
---|
308 | // Validate month
|
---|
309 | if (m<1 || m>12)
|
---|
310 | return -1;
|
---|
311 |
|
---|
312 | // Allow for leap year
|
---|
313 | months[1] = (y%4==0 && (y%100!=0 || y%400==0)) ? 29 : 28;
|
---|
314 |
|
---|
315 | // Validate day
|
---|
316 | if (d<1 || d>months[m-1])
|
---|
317 | return -1;
|
---|
318 |
|
---|
319 | // Precalculate some values
|
---|
320 | const Byte_t lm = 12-m;
|
---|
321 | const ULong_t lm10 = 4712 + y - lm/10;
|
---|
322 |
|
---|
323 | // Perform the conversion
|
---|
324 | return 1461L*lm10/4 + (306*((m+9)%12)+5)/10 - (3*((lm10+188)/100))/4 + d - 2399904;
|
---|
325 | }
|
---|
326 |
|
---|
327 | // --------------------------------------------------------------------------
|
---|
328 | //
|
---|
329 | // Convert a mjd to a number yymmdd. The century is just cuts away, e.g.
|
---|
330 | // 54393 --> 71020 (2007/10/20)
|
---|
331 | // 50741 --> 971020 (1997/10/20)
|
---|
332 | // 17868 --> 71020 (1907/10/20)
|
---|
333 | //
|
---|
334 | UInt_t MAstro::Mjd2Yymmdd(UInt_t mjd)
|
---|
335 | {
|
---|
336 | UShort_t y;
|
---|
337 | Byte_t m, d;
|
---|
338 | Mjd2Ymd(mjd, y, m, d);
|
---|
339 |
|
---|
340 | return d + m*100 + (y%100)*10000;
|
---|
341 | }
|
---|
342 |
|
---|
343 | // --------------------------------------------------------------------------
|
---|
344 | //
|
---|
345 | // Convert a yymmdd number to mjd. The century is defined as 2000 for
|
---|
346 | // yy<70, 1900 elsewise.
|
---|
347 | // 71020 --> 54393 (2007/10/20)
|
---|
348 | // 971020 --> 50741 (1997/10/20)
|
---|
349 | //
|
---|
350 | UInt_t MAstro::Yymmdd2Mjd(UInt_t yymmdd)
|
---|
351 | {
|
---|
352 | const Byte_t dd = yymmdd%100;
|
---|
353 | const Byte_t mm = (yymmdd/100)%100;
|
---|
354 | const UShort_t yy = (yymmdd/10000)%100;
|
---|
355 |
|
---|
356 | return Ymd2Mjd(yy + (yy<70 ? 2000 : 1900), mm, dd);
|
---|
357 | }
|
---|
358 |
|
---|
359 | // --------------------------------------------------------------------------
|
---|
360 | //
|
---|
361 | // theta0, phi0 [rad]: polar angle/zenith distance, azimuth of 1st object
|
---|
362 | // theta1, phi1 [rad]: polar angle/zenith distance, azimuth of 2nd object
|
---|
363 | // AngularDistance [rad]: Angular distance between two objects
|
---|
364 | //
|
---|
365 | Double_t MAstro::AngularDistance(Double_t theta0, Double_t phi0, Double_t theta1, Double_t phi1)
|
---|
366 | {
|
---|
367 | TVector3 v0(1);
|
---|
368 | v0.Rotate(phi0, theta0);
|
---|
369 |
|
---|
370 | TVector3 v1(1);
|
---|
371 | v1.Rotate(phi1, theta1);
|
---|
372 |
|
---|
373 | return v0.Angle(v1);
|
---|
374 | }
|
---|
375 |
|
---|
376 | // --------------------------------------------------------------------------
|
---|
377 | //
|
---|
378 | // Calls MTime::GetGmst() Better use MTime::GetGmst() directly
|
---|
379 | //
|
---|
380 | Double_t MAstro::UT2GMST(Double_t ut1)
|
---|
381 | {
|
---|
382 | return MTime(ut1).GetGmst();
|
---|
383 | }
|
---|
384 |
|
---|
385 | // --------------------------------------------------------------------------
|
---|
386 | //
|
---|
387 | // RotationAngle
|
---|
388 | //
|
---|
389 | // calculates the angle for the rotation of the sky coordinate system
|
---|
390 | // with respect to the local coordinate system. This is identical
|
---|
391 | // to the rotation angle of the sky image in the camera.
|
---|
392 | //
|
---|
393 | // sinl [rad]: sine of observers latitude
|
---|
394 | // cosl [rad]: cosine of observers latitude
|
---|
395 | // theta [rad]: polar angle/zenith distance
|
---|
396 | // phi [rad]: rotation angle/azimuth
|
---|
397 | //
|
---|
398 | // Return sin/cos component of angle
|
---|
399 | //
|
---|
400 | // The convention is such, that the rotation angle is -pi/pi if
|
---|
401 | // right ascension and local rotation angle are counted in the
|
---|
402 | // same direction, 0 if counted in the opposite direction.
|
---|
403 | //
|
---|
404 | // (In other words: The rotation angle is 0 when the source culminates)
|
---|
405 | //
|
---|
406 | // Using vectors it can be done like:
|
---|
407 | // TVector3 v, p;
|
---|
408 | // v.SetMagThetaPhi(1, theta, phi);
|
---|
409 | // p.SetMagThetaPhi(1, TMath::Pi()/2-latitude, 0);
|
---|
410 | // v = v.Cross(l));
|
---|
411 | // v.RotateZ(-phi);
|
---|
412 | // v.Rotate(-theta)
|
---|
413 | // rho = TMath::ATan2(v(2), v(1));
|
---|
414 | //
|
---|
415 | // For more information see TDAS 00-11, eqs. (18) and (20)
|
---|
416 | //
|
---|
417 | void MAstro::RotationAngle(Double_t sinl, Double_t cosl, Double_t theta, Double_t phi, Double_t &sin, Double_t &cos)
|
---|
418 | {
|
---|
419 | const Double_t sint = TMath::Sin(theta);
|
---|
420 | const Double_t cost = TMath::Cos(theta);
|
---|
421 |
|
---|
422 | const Double_t snlt = sinl*sint;
|
---|
423 | const Double_t cslt = cosl*cost;
|
---|
424 |
|
---|
425 | const Double_t sinp = TMath::Sin(phi);
|
---|
426 | const Double_t cosp = TMath::Cos(phi);
|
---|
427 |
|
---|
428 | const Double_t v1 = sint*sinp;
|
---|
429 | const Double_t v2 = cslt - snlt*cosp;
|
---|
430 |
|
---|
431 | const Double_t denom = TMath::Sqrt(v1*v1 + v2*v2);
|
---|
432 |
|
---|
433 | sin = cosl*sinp / denom; // y-component
|
---|
434 | cos = (snlt-cslt*cosp) / denom; // x-component
|
---|
435 | }
|
---|
436 |
|
---|
437 | // --------------------------------------------------------------------------
|
---|
438 | //
|
---|
439 | // RotationAngle
|
---|
440 | //
|
---|
441 | // calculates the angle for the rotation of the sky coordinate system
|
---|
442 | // with respect to the local coordinate system. This is identical
|
---|
443 | // to the rotation angle of the sky image in the camera.
|
---|
444 | //
|
---|
445 | // sinl [rad]: sine of observers latitude
|
---|
446 | // cosl [rad]: cosine of observers latitude
|
---|
447 | // theta [rad]: polar angle/zenith distance
|
---|
448 | // phi [rad]: rotation angle/azimuth
|
---|
449 | //
|
---|
450 | // Return angle [rad] in the range -pi, pi
|
---|
451 | //
|
---|
452 | // The convention is such, that the rotation angle is -pi/pi if
|
---|
453 | // right ascension and local rotation angle are counted in the
|
---|
454 | // same direction, 0 if counted in the opposite direction.
|
---|
455 | //
|
---|
456 | // (In other words: The rotation angle is 0 when the source culminates)
|
---|
457 | //
|
---|
458 | // Using vectors it can be done like:
|
---|
459 | // TVector3 v, p;
|
---|
460 | // v.SetMagThetaPhi(1, theta, phi);
|
---|
461 | // p.SetMagThetaPhi(1, TMath::Pi()/2-latitude, 0);
|
---|
462 | // v = v.Cross(l));
|
---|
463 | // v.RotateZ(-phi);
|
---|
464 | // v.Rotate(-theta)
|
---|
465 | // rho = TMath::ATan2(v(2), v(1));
|
---|
466 | //
|
---|
467 | // For more information see TDAS 00-11, eqs. (18) and (20)
|
---|
468 | //
|
---|
469 | Double_t MAstro::RotationAngle(Double_t sinl, Double_t cosl, Double_t theta, Double_t phi)
|
---|
470 | {
|
---|
471 | const Double_t snlt = sinl*TMath::Sin(theta);
|
---|
472 | const Double_t cslt = cosl*TMath::Cos(theta);
|
---|
473 |
|
---|
474 | const Double_t sinp = TMath::Sin(phi);
|
---|
475 | const Double_t cosp = TMath::Cos(phi);
|
---|
476 |
|
---|
477 | return TMath::ATan2(cosl*sinp, snlt-cslt*cosp);
|
---|
478 | }
|
---|
479 |
|
---|
480 | // --------------------------------------------------------------------------
|
---|
481 | //
|
---|
482 | // Estimates the time at which a source culminates.
|
---|
483 | //
|
---|
484 | // ra: right ascension [rad]
|
---|
485 | // elong: observers longitude [rad]
|
---|
486 | // mjd: modified julian date (utc)
|
---|
487 | //
|
---|
488 | // return time in [-12;12]
|
---|
489 | //
|
---|
490 | Double_t MAstro::EstimateCulminationTime(Double_t mjd, Double_t elong, Double_t ra)
|
---|
491 | {
|
---|
492 | // startime at 1.1.2000 for greenwich 0h
|
---|
493 | const Double_t gmt0 = 6.664520;
|
---|
494 |
|
---|
495 | // difference of startime for greenwich for two calendar days [h]
|
---|
496 | const Double_t d0 = 0.06570982224;
|
---|
497 |
|
---|
498 | // mjd of greenwich 1.1.2000 0h
|
---|
499 | const Double_t mjd0 = 51544;
|
---|
500 |
|
---|
501 | // mjd today
|
---|
502 | const Double_t mjd1 = TMath::Floor(mjd);
|
---|
503 |
|
---|
504 | // scale between star-time and sun-time
|
---|
505 | const Double_t scale = 1;//1.00273790926;
|
---|
506 |
|
---|
507 | const Double_t UT = (ra-elong)*RadToHor() - (gmt0 + d0 * (mjd1-mjd0))/scale;
|
---|
508 |
|
---|
509 | return fmod(2412 + UT, 24) - 12;
|
---|
510 | }
|
---|
511 |
|
---|
512 | // --------------------------------------------------------------------------
|
---|
513 | //
|
---|
514 | // Kepler - solve the equation of Kepler
|
---|
515 | //
|
---|
516 | Double_t MAstro::Kepler(Double_t m, Double_t ecc)
|
---|
517 | {
|
---|
518 | m *= TMath::DegToRad();
|
---|
519 |
|
---|
520 | Double_t delta = 0;
|
---|
521 | Double_t e = m;
|
---|
522 | do {
|
---|
523 | delta = e - ecc * sin(e) - m;
|
---|
524 | e -= delta / (1 - ecc * cos(e));
|
---|
525 | } while (fabs(delta) > 1e-6);
|
---|
526 |
|
---|
527 | return e;
|
---|
528 | }
|
---|
529 |
|
---|
530 | // --------------------------------------------------------------------------
|
---|
531 | //
|
---|
532 | // GetMoonPhase - calculate phase of moon as a fraction:
|
---|
533 | // Returns -1 if calculation failed
|
---|
534 | //
|
---|
535 | Double_t MAstro::GetMoonPhase(Double_t mjd)
|
---|
536 | {
|
---|
537 | /****** Calculation of the Sun's position. ******/
|
---|
538 |
|
---|
539 | // date within epoch
|
---|
540 | const Double_t epoch = 44238; // 1980 January 0.0
|
---|
541 | const Double_t day = mjd - epoch;
|
---|
542 | if (day<0)
|
---|
543 | {
|
---|
544 | cout << "MAstro::GetMoonPhase - Day before Jan 1980" << endl;
|
---|
545 | return -1;
|
---|
546 | }
|
---|
547 |
|
---|
548 | // mean anomaly of the Sun
|
---|
549 | const Double_t n = fmod(day*360/365.2422, 360);
|
---|
550 |
|
---|
551 | const Double_t elonge = 278.833540; // ecliptic longitude of the Sun at epoch 1980.0
|
---|
552 | const Double_t elongp = 282.596403; // ecliptic longitude of the Sun at perigee
|
---|
553 |
|
---|
554 | // convert from perigee co-ordinates to epoch 1980.0
|
---|
555 | const Double_t m = fmod(n + elonge - elongp + 360, 360);
|
---|
556 |
|
---|
557 | // solve equation of Kepler
|
---|
558 | const Double_t eccent = 0.016718; // eccentricity of Earth's orbit
|
---|
559 | const Double_t k = Kepler(m, eccent);
|
---|
560 | const Double_t ec0 = sqrt((1 + eccent) / (1 - eccent)) * tan(k / 2);
|
---|
561 | // true anomaly
|
---|
562 | const Double_t ec = 2 * atan(ec0) * TMath::RadToDeg();
|
---|
563 |
|
---|
564 | // Sun's geocentric ecliptic longitude
|
---|
565 | const Double_t lambdasun = fmod(ec + elongp + 720, 360);
|
---|
566 |
|
---|
567 |
|
---|
568 | /****** Calculation of the Moon's position. ******/
|
---|
569 |
|
---|
570 | // Moon's mean longitude.
|
---|
571 | const Double_t mmlong = 64.975464; // moon's mean lonigitude at the epoch
|
---|
572 | const Double_t ml = fmod(13.1763966*day + mmlong + 360, 360);
|
---|
573 | // Moon's mean anomaly.
|
---|
574 | const Double_t mmlongp = 349.383063; // mean longitude of the perigee at the epoch
|
---|
575 | const Double_t mm = fmod(ml - 0.1114041*day - mmlongp + 720, 360);
|
---|
576 | // Evection.
|
---|
577 | const Double_t ev = 1.2739 * sin((2 * (ml - lambdasun) - mm)*TMath::DegToRad());
|
---|
578 | // Annual equation.
|
---|
579 | const Double_t sinm = TMath::Sin(m*TMath::DegToRad());
|
---|
580 | const Double_t ae = 0.1858 * sinm;
|
---|
581 | // Correction term.
|
---|
582 | const Double_t a3 = 0.37 * sinm;
|
---|
583 | // Corrected anomaly.
|
---|
584 | const Double_t mmp = (mm + ev - ae - a3)*TMath::DegToRad();
|
---|
585 | // Correction for the equation of the centre.
|
---|
586 | const Double_t mec = 6.2886 * sin(mmp);
|
---|
587 | // Another correction term.
|
---|
588 | const Double_t a4 = 0.214 * sin(2 * mmp);
|
---|
589 | // Corrected longitude.
|
---|
590 | const Double_t lp = ml + ev + mec - ae + a4;
|
---|
591 | // Variation.
|
---|
592 | const Double_t v = 0.6583 * sin(2 * (lp - lambdasun)*TMath::DegToRad());
|
---|
593 | // True longitude.
|
---|
594 | const Double_t lpp = lp + v;
|
---|
595 | // Age of the Moon in degrees.
|
---|
596 | const Double_t age = (lpp - lambdasun)*TMath::DegToRad();
|
---|
597 |
|
---|
598 | // Calculation of the phase of the Moon.
|
---|
599 | return (1 - TMath::Cos(age)) / 2;
|
---|
600 | }
|
---|
601 |
|
---|
602 | // --------------------------------------------------------------------------
|
---|
603 | //
|
---|
604 | // Calculate the Period to which the time belongs to. The Period is defined
|
---|
605 | // as the number of synodic months ellapsed since the first full moon
|
---|
606 | // after Jan 1st 1980 (which was @ MJD=44240.37917)
|
---|
607 | //
|
---|
608 | Double_t MAstro::GetMoonPeriod(Double_t mjd)
|
---|
609 | {
|
---|
610 | const Double_t synmonth = 29.53058868; // synodic month (new Moon to new Moon)
|
---|
611 | const Double_t epoch0 = 44240.37917; // First full moon after 1980/1/1
|
---|
612 |
|
---|
613 | const Double_t et = mjd-epoch0; // Ellapsed time
|
---|
614 | return et/synmonth;
|
---|
615 | }
|
---|
616 |
|
---|
617 | // --------------------------------------------------------------------------
|
---|
618 | //
|
---|
619 | // To get the moon period as defined for MAGIC observation we take the
|
---|
620 | // nearest integer mjd, eg:
|
---|
621 | // 53257.8 --> 53258
|
---|
622 | // 53258.3 --> 53258
|
---|
623 | // Which is the time between 13h and 12:59h of the following day. To
|
---|
624 | // this day-period we assign the moon-period at midnight. To get
|
---|
625 | // the MAGIC definition we now substract 284.
|
---|
626 | //
|
---|
627 | // For MAGIC observation period do eg:
|
---|
628 | // GetMagicPeriod(53257.91042)
|
---|
629 | // or
|
---|
630 | // MTime t;
|
---|
631 | // t.SetMjd(53257.91042);
|
---|
632 | // GetMagicPeriod(t.GetMjd());
|
---|
633 | // or
|
---|
634 | // MTime t;
|
---|
635 | // t.Set(2004, 1, 1, 12, 32, 11);
|
---|
636 | // GetMagicPeriod(t.GetMjd());
|
---|
637 | //
|
---|
638 | // To get a floating point magic period use
|
---|
639 | // GetMoonPeriod(mjd)-284
|
---|
640 | //
|
---|
641 | Int_t MAstro::GetMagicPeriod(Double_t mjd)
|
---|
642 | {
|
---|
643 | const Double_t mmjd = (Double_t)TMath::Nint(mjd);
|
---|
644 | const Double_t period = GetMoonPeriod(mmjd);
|
---|
645 |
|
---|
646 | return (Int_t)TMath::Floor(period)-284;
|
---|
647 | }
|
---|
648 |
|
---|
649 | // --------------------------------------------------------------------------
|
---|
650 | //
|
---|
651 | // Returns right ascension and declination [rad] of the sun at the
|
---|
652 | // given mjd (ra, dec).
|
---|
653 | //
|
---|
654 | // returns the mean longitude [rad].
|
---|
655 | //
|
---|
656 | // from http://xoomer.alice.it/vtomezzo/sunriset/formulas/index.html
|
---|
657 | //
|
---|
658 | Double_t MAstro::GetSunRaDec(Double_t mjd, Double_t &ra, Double_t &dec)
|
---|
659 | {
|
---|
660 | const Double_t T = (mjd-51544.5)/36525;// + (h-12)/24.0;
|
---|
661 |
|
---|
662 | const Double_t T2 = T<0 ? -T*T : T*T;
|
---|
663 | const Double_t T3 = T*T*T;
|
---|
664 |
|
---|
665 | // Find the ecliptic longitude of the Sun
|
---|
666 |
|
---|
667 | // Geometric mean longitude of the Sun
|
---|
668 | const Double_t L = 280.46646 + 36000.76983*T + 0.0003032*T2;
|
---|
669 |
|
---|
670 | // mean anomaly of the Sun
|
---|
671 | Double_t g = 357.52911 + 35999.05029*T - 0.0001537*T2;
|
---|
672 | g *= TMath::DegToRad();
|
---|
673 |
|
---|
674 | // Longitude of the moon's ascending node
|
---|
675 | Double_t omega = 125.04452 - 1934.136261*T + 0.0020708*T2 + T3/450000;
|
---|
676 | omega *= TMath::DegToRad();
|
---|
677 |
|
---|
678 | const Double_t coso = cos(omega);
|
---|
679 | const Double_t sino = sin(omega);
|
---|
680 |
|
---|
681 | // Equation of the center
|
---|
682 | const Double_t C = (1.914602 - 0.004817*T - 0.000014*T2)*sin(g) +
|
---|
683 | (0.019993 - 0.000101*T)*sin(2*g) + 0.000289*sin(3*g);
|
---|
684 |
|
---|
685 | // True longitude of the sun
|
---|
686 | const Double_t tlong = L + C;
|
---|
687 |
|
---|
688 | // Apperent longitude of the Sun (ecliptic)
|
---|
689 | Double_t lambda = tlong - 0.00569 - 0.00478*sino;
|
---|
690 | lambda *= TMath::DegToRad();
|
---|
691 |
|
---|
692 | // Obliquity of the ecliptic
|
---|
693 | Double_t obliq = 23.4392911 - 0.01300416667*T - 0.00000016389*T2 + 0.00000050361*T3 + 0.00255625*coso;
|
---|
694 | obliq *= TMath::DegToRad();
|
---|
695 |
|
---|
696 | // Find the RA and DEC of the Sun
|
---|
697 | const Double_t sinl = sin(lambda);
|
---|
698 |
|
---|
699 | ra = atan2(cos(obliq) * sinl, cos(lambda));
|
---|
700 | dec = asin(sin(obliq) * sinl);
|
---|
701 |
|
---|
702 | return L*TMath::DegToRad();
|
---|
703 | }
|
---|
704 |
|
---|
705 | // --------------------------------------------------------------------------
|
---|
706 | //
|
---|
707 | // Returns right ascension and declination [rad] of the moon at the
|
---|
708 | // given mjd (ra, dec).
|
---|
709 | //
|
---|
710 | void MAstro::GetMoonRaDec(Double_t mjd, Double_t &ra, Double_t &dec)
|
---|
711 | {
|
---|
712 | // Mean Moon orbit elements as of 1990.0
|
---|
713 | const Double_t l0 = 318.351648 * TMath::DegToRad();
|
---|
714 | const Double_t P0 = 36.340410 * TMath::DegToRad();
|
---|
715 | const Double_t N0 = 318.510107 * TMath::DegToRad();
|
---|
716 | const Double_t i = 5.145396 * TMath::DegToRad();
|
---|
717 |
|
---|
718 | Double_t sunra, sundec, g;
|
---|
719 | {
|
---|
720 | const Double_t T = (mjd-51544.5)/36525;// + (h-12)/24.0;
|
---|
721 | const Double_t T2 = T<0 ? -T*T : T*T;
|
---|
722 |
|
---|
723 | GetSunRaDec(mjd, sunra, sundec);
|
---|
724 |
|
---|
725 | // mean anomaly of the Sun
|
---|
726 | g = 357.52911 + 35999.05029*T - 0.0001537*T2;
|
---|
727 | g *= TMath::DegToRad();
|
---|
728 | }
|
---|
729 |
|
---|
730 | const Double_t sing = sin(g)*TMath::DegToRad();
|
---|
731 |
|
---|
732 | const Double_t D = (mjd-47891) * TMath::DegToRad();
|
---|
733 | const Double_t l = 13.1763966*D + l0;
|
---|
734 | const Double_t MMoon = l -0.1114041*D - P0; // Moon's mean anomaly M
|
---|
735 | const Double_t N = N0 -0.0529539*D; // Moon's mean ascending node longitude
|
---|
736 |
|
---|
737 | const Double_t C = l-sunra;
|
---|
738 | const Double_t Ev = 1.2739 * sin(2*C-MMoon) * TMath::DegToRad();
|
---|
739 | const Double_t Ae = 0.1858 * sing;
|
---|
740 | const Double_t A3 = 0.37 * sing;
|
---|
741 | const Double_t MMoon2 = MMoon+Ev-Ae-A3; // corrected Moon anomaly
|
---|
742 |
|
---|
743 | const Double_t Ec = 6.2886 * sin(MMoon2) * TMath::DegToRad(); // equation of centre
|
---|
744 | const Double_t A4 = 0.214 * sin(2*MMoon2)* TMath::DegToRad();
|
---|
745 | const Double_t l2 = l+Ev+Ec-Ae+A4; // corrected Moon's longitude
|
---|
746 |
|
---|
747 | const Double_t V = 0.6583 * sin(2*(l2-sunra)) * TMath::DegToRad();
|
---|
748 | const Double_t l3 = l2+V; // true orbital longitude;
|
---|
749 |
|
---|
750 | const Double_t N2 = N -0.16*sing;
|
---|
751 |
|
---|
752 | ra = fmod( N2 + atan2( sin(l3-N2)*cos(i), cos(l3-N2) ), TMath::TwoPi() );
|
---|
753 | dec = asin(sin(l3-N2)*sin(i) );
|
---|
754 | }
|
---|
755 |
|
---|
756 | // --------------------------------------------------------------------------
|
---|
757 | //
|
---|
758 | // Return Euqation of time in hours for given mjd
|
---|
759 | //
|
---|
760 | Double_t MAstro::GetEquationOfTime(Double_t mjd)
|
---|
761 | {
|
---|
762 | Double_t ra, dec;
|
---|
763 | const Double_t L = fmod(GetSunRaDec(mjd, ra, dec), TMath::TwoPi());
|
---|
764 |
|
---|
765 | if (L-ra>TMath::Pi())
|
---|
766 | ra += TMath::TwoPi();
|
---|
767 |
|
---|
768 | return 24*(L - ra)/TMath::TwoPi();
|
---|
769 | }
|
---|
770 |
|
---|
771 | // --------------------------------------------------------------------------
|
---|
772 | //
|
---|
773 | // Returns noon time (the time of the highest altitude of the sun)
|
---|
774 | // at the given mjd and at the given observers longitude [deg]
|
---|
775 | //
|
---|
776 | // The maximum altitude reached at noon time is
|
---|
777 | // altmax = 90.0 + dec - latit;
|
---|
778 | // if (dec > latit)
|
---|
779 | // altmax = 90.0 + latit - dec;
|
---|
780 | // dec=Declination of the sun
|
---|
781 | //
|
---|
782 | Double_t MAstro::GetNoonTime(Double_t mjd, Double_t longit)
|
---|
783 | {
|
---|
784 | const Double_t equation = GetEquationOfTime(TMath::Floor(mjd));
|
---|
785 | return 12. + equation - longit/15;
|
---|
786 | }
|
---|
787 |
|
---|
788 | // --------------------------------------------------------------------------
|
---|
789 | //
|
---|
790 | // Returns the time (in hours) between noon (the sun culmination)
|
---|
791 | // and the sun being at height alt[deg] (90=zenith, 0=horizont)
|
---|
792 | //
|
---|
793 | // civil twilight: 0deg to -6deg
|
---|
794 | // nautical twilight: -6deg to -12deg
|
---|
795 | // astronom twilight: -12deg to -18deg
|
---|
796 | //
|
---|
797 | // latit is the observers latitude in rad
|
---|
798 | //
|
---|
799 | // returns -1 in case the sun doesn't reach this altitude.
|
---|
800 | // (eg. alt=0: Polarnight or -day)
|
---|
801 | //
|
---|
802 | // To get the sun rise/set:
|
---|
803 | // double timediff = MAstro::GetTimeFromNoonToAlt(mjd, latit*TMath::DegToRad(), par[0]);
|
---|
804 | // double noon = MAstro::GetNoonTime(mjd, longit);
|
---|
805 | // double N = TMath::Floor(mjd)+noon/24.;
|
---|
806 | // double risetime = N-timediff/24.;
|
---|
807 | // double settime = N+timediff/24.;
|
---|
808 | //
|
---|
809 | Double_t MAstro::GetTimeFromNoonToAlt(Double_t mjd, Double_t latit, Double_t alt)
|
---|
810 | {
|
---|
811 | Double_t ra, dec;
|
---|
812 | GetSunRaDec(mjd, ra, dec);
|
---|
813 |
|
---|
814 | const Double_t h = alt*TMath::DegToRad();
|
---|
815 |
|
---|
816 | const Double_t arg = (sin(h) - sin(latit)*sin(dec))/(cos(latit)*cos(dec));
|
---|
817 |
|
---|
818 | return TMath::Abs(arg)>1 ? -1 : 12*acos(arg)/TMath::Pi();
|
---|
819 | }
|
---|
820 |
|
---|
821 | // --------------------------------------------------------------------------
|
---|
822 | //
|
---|
823 | // Returns the time of the sunrise/set calculated before and after
|
---|
824 | // the noon of floor(mjd) (TO BE IMPROVED)
|
---|
825 | //
|
---|
826 | // Being longit and latit the longitude and latitude of the observer
|
---|
827 | // in deg and alt the hight above or below the horizont in deg.
|
---|
828 | //
|
---|
829 | // civil twilight: 0deg to -6deg
|
---|
830 | // nautical twilight: -6deg to -12deg
|
---|
831 | // astronom twilight: -12deg to -18deg
|
---|
832 | //
|
---|
833 | // A TArrayD(2) is returned with the the mjd of the sunrise in
|
---|
834 | // TArray[0] and the mjd of the sunset in TArrayD[1].
|
---|
835 | //
|
---|
836 | TArrayD MAstro::GetSunRiseSet(Double_t mjd, Double_t longit, Double_t latit, Double_t alt)
|
---|
837 | {
|
---|
838 | const Double_t timediff = MAstro::GetTimeFromNoonToAlt(mjd, latit*TMath::DegToRad(), alt);
|
---|
839 | const Double_t noon = MAstro::GetNoonTime(mjd, longit);
|
---|
840 |
|
---|
841 | const Double_t N = TMath::Floor(mjd)+noon/24.;
|
---|
842 |
|
---|
843 | const Double_t rise = timediff<0 ? N-0.5 : N-timediff/24.;
|
---|
844 | const Double_t set = timediff<0 ? N+0.5 : N+timediff/24.;
|
---|
845 |
|
---|
846 | TArrayD rc(2);
|
---|
847 | rc[0] = rise;
|
---|
848 | rc[1] = set;
|
---|
849 | return rc;
|
---|
850 | }
|
---|
851 |
|
---|
852 | // --------------------------------------------------------------------------
|
---|
853 | //
|
---|
854 | // Returns the distance in x,y between two polar-vectors (eg. Alt/Az, Ra/Dec)
|
---|
855 | // projected on aplain in a distance dist. For Magic this this the distance
|
---|
856 | // of the camera plain (1700mm) dist also determins the unit in which
|
---|
857 | // the TVector2 is returned.
|
---|
858 | //
|
---|
859 | // v0 is the reference vector (eg. the vector to the center of the camera)
|
---|
860 | // v1 is the vector to which we determin the distance on the plain
|
---|
861 | //
|
---|
862 | // (see also MStarCamTrans::Loc0LocToCam())
|
---|
863 | //
|
---|
864 | TVector2 MAstro::GetDistOnPlain(const TVector3 &v0, TVector3 v1, Double_t dist)
|
---|
865 | {
|
---|
866 | v1.RotateZ(-v0.Phi());
|
---|
867 | v1.RotateY(-v0.Theta());
|
---|
868 | v1.RotateZ(-TMath::Pi()/2); // exchange x and y
|
---|
869 | v1 *= dist/v1.Z();
|
---|
870 |
|
---|
871 | return v1.XYvector(); //TVector2(v1.Y(), -v1.X());//v1.XYvector();
|
---|
872 | }
|
---|
873 |
|
---|
874 | // --------------------------------------------------------------------------
|
---|
875 | //
|
---|
876 | // Calculate the absolute misspointing from the nominal zenith angle nomzd
|
---|
877 | // and the deviations in zd (devzd) and az (devaz).
|
---|
878 | // All values given in deg, the return value, too.
|
---|
879 | //
|
---|
880 | Double_t MAstro::GetDevAbs(Double_t nomzd, Double_t devzd, Double_t devaz)
|
---|
881 | {
|
---|
882 | const Double_t pzd = nomzd * TMath::DegToRad();
|
---|
883 | const Double_t azd = devzd * TMath::DegToRad();
|
---|
884 | const Double_t aaz = devaz * TMath::DegToRad();
|
---|
885 |
|
---|
886 | const double el = TMath::Pi()/2-pzd;
|
---|
887 |
|
---|
888 | const double dphi2 = aaz/2.;
|
---|
889 | const double cos2 = TMath::Cos(dphi2)*TMath::Cos(dphi2);
|
---|
890 | const double sin2 = TMath::Sin(dphi2)*TMath::Sin(dphi2);
|
---|
891 | const double d = TMath::Cos(azd)*cos2 - TMath::Cos(2*el)*sin2;
|
---|
892 |
|
---|
893 | return TMath::ACos(d)*TMath::RadToDeg();
|
---|
894 | }
|
---|
895 |
|
---|
896 | // --------------------------------------------------------------------------
|
---|
897 | //
|
---|
898 | // Returned is the offset (number of days) which must be added to
|
---|
899 | // March 1st of the given year, eg:
|
---|
900 | //
|
---|
901 | // Int_t offset = GetDayOfEaster(2004);
|
---|
902 | //
|
---|
903 | // MTime t;
|
---|
904 | // t.Set(year, 3, 1);
|
---|
905 | // t.SetMjd(t.GetMjd()+offset);
|
---|
906 | //
|
---|
907 | // cout << t << endl;
|
---|
908 | //
|
---|
909 | // If the date coudn't be calculated -1 is returned.
|
---|
910 | //
|
---|
911 | // The minimum value returned is 21 corresponding to March 22.
|
---|
912 | // The maximum value returned is 55 corresponding to April 25.
|
---|
913 | //
|
---|
914 | // --------------------------------------------------------------------------
|
---|
915 | //
|
---|
916 | // Gauss'sche Formel zur Berechnung des Osterdatums
|
---|
917 | // Wann wird Ostern gefeiert? Wie erfährt man das Osterdatum für ein
|
---|
918 | // bestimmtes Jahr, ohne in einen Kalender zu schauen?
|
---|
919 | //
|
---|
920 | // Ostern ist ein "bewegliches" Fest. Es wird am ersten Sonntag nach dem
|
---|
921 | // ersten Frühlingsvollmond gefeiert. Damit ist der 22. März der früheste
|
---|
922 | // Termin, der 25. April der letzte, auf den Ostern fallen kann. Von
|
---|
923 | // diesem Termin hängen auch die Feste Christi Himmelfahrt, das 40 Tage
|
---|
924 | // nach Ostern, und Pfingsten, das 50 Tage nach Ostern gefeiert wird, ab.
|
---|
925 | //
|
---|
926 | // Von Carl Friedrich Gauß (Mathematiker, Astronom und Physiker;
|
---|
927 | // 1777-1855) stammt ein Algorithmus, der es erlaubt ohne Kenntnis des
|
---|
928 | // Mondkalenders die Daten der Osterfeste für die Jahre 1700 bis 2199 zu
|
---|
929 | // bestimmen.
|
---|
930 | //
|
---|
931 | // Gib eine Jahreszahl zwischen 1700 und 2199 ein:
|
---|
932 | //
|
---|
933 | // Und so funktioniert der Algorithmus:
|
---|
934 | //
|
---|
935 | // Es sei:
|
---|
936 | //
|
---|
937 | // J die Jahreszahl
|
---|
938 | // a der Divisionsrest von J/19
|
---|
939 | // b der Divisionsrest von J/4
|
---|
940 | // c der Divisionsrest von J/7
|
---|
941 | // d der Divisionsrest von (19*a + M)/30
|
---|
942 | // e der Divisionsrest von (2*b + 4*c + 6*d + N)/7
|
---|
943 | //
|
---|
944 | // wobei M und N folgende Werte annehmen:
|
---|
945 | //
|
---|
946 | // für die Jahre M N
|
---|
947 | // 1583-1599 22 2
|
---|
948 | // 1600-1699 22 2
|
---|
949 | // 1700-1799 23 3
|
---|
950 | // 1800-1899 23 4
|
---|
951 | // 1900-1999 24 5
|
---|
952 | // 2000-2099 24 5
|
---|
953 | // 2100-2199 24 6
|
---|
954 | // 2200-2299 25 0
|
---|
955 | // 2300-2399 26 1
|
---|
956 | // 2400-2499 25 1
|
---|
957 | //
|
---|
958 | // Dann fällt Ostern auf den
|
---|
959 | // (22 + d + e)ten März
|
---|
960 | //
|
---|
961 | // oder den
|
---|
962 | // (d + e - 9)ten April
|
---|
963 | //
|
---|
964 | // Beachte:
|
---|
965 | // Anstelle des 26. Aprils ist immer der 19. April zu setzen,
|
---|
966 | // anstelle des 25. Aprils immer dann der 18. April, wenn d=28 und a>10.
|
---|
967 | //
|
---|
968 | // Literatur:
|
---|
969 | // Schüler-Rechenduden
|
---|
970 | // Bibliographisches Institut
|
---|
971 | // Mannheim, 1966
|
---|
972 | //
|
---|
973 | // --------------------------------------------------------------------------
|
---|
974 | //
|
---|
975 | // Der Ostersonntag ist ein sog. unregelmäßiger Feiertag. Alle anderen
|
---|
976 | // unregelmäßigen Feiertage eines Jahres leiten sich von diesem Tag ab:
|
---|
977 | //
|
---|
978 | // * Aschermittwoch ist 46 Tage vor Ostern.
|
---|
979 | // * Pfingsten ist 49 Tage nach Ostern.
|
---|
980 | // * Christi Himmelfahrt ist 10 Tage vor Pfingsten.
|
---|
981 | // * Fronleichnam ist 11 Tage nach Pfingsten.
|
---|
982 | //
|
---|
983 | // Man muß also nur den Ostersonntag ermitteln, um alle anderen
|
---|
984 | // unregelmäßigen Feiertage zu berechnen. Doch wie geht das?
|
---|
985 | //
|
---|
986 | // Dazu etwas Geschichte:
|
---|
987 | //
|
---|
988 | // Das 1. Kirchenkonzil im Jahre 325 hat festgelegt:
|
---|
989 | //
|
---|
990 | // * Ostern ist stets am ersten Sonntag nach dem ersten Vollmond des
|
---|
991 | // Frühlings.
|
---|
992 | // * Stichtag ist der 21. März, die "Frühlings-Tagundnachtgleiche".
|
---|
993 | //
|
---|
994 | // Am 15.10.1582 wurde von Papst Gregor XIII. der bis dahin gültige
|
---|
995 | // Julianische Kalender reformiert. Der noch heute gültige Gregorianische
|
---|
996 | // Kalender legt dabei folgendes fest:
|
---|
997 | //
|
---|
998 | // Ein Jahr hat 365 Tage und ein Schaltjahr wird eingefügt, wenn das Jahr
|
---|
999 | // durch 4 oder durch 400, aber nicht durch 100 teilbar ist. Hieraus
|
---|
1000 | // ergeben sich die zwei notwendigen Konstanten, um den Ostersonntag zu
|
---|
1001 | // berechnen:
|
---|
1002 | //
|
---|
1003 | // 1. Die Jahreslänge von und bis zum Zeitpunkt der
|
---|
1004 | // Frühlings-Tagundnachtgleiche: 365,2422 mittlere Sonnentage
|
---|
1005 | // 2. Ein Mondmonat: 29,5306 mittlere Sonnentage
|
---|
1006 | //
|
---|
1007 | // Mit der "Osterformel", von Carl Friedrich Gauß (1777-1855) im Jahre 1800
|
---|
1008 | // entwickelt, läßt sich der Ostersonntag für jedes Jahr von 1583 bis 8202
|
---|
1009 | // berechnen.
|
---|
1010 | //
|
---|
1011 | // Der früheste mögliche Ostertermin ist der 22. März. (Wenn der Vollmond
|
---|
1012 | // auf den 21. März fällt und der 22. März ein Sonntag ist.)
|
---|
1013 | //
|
---|
1014 | // Der späteste mögliche Ostertermin ist der 25. April. (Wenn der Vollmond
|
---|
1015 | // auf den 21. März fällt und der 21. März ein Sonntag ist.)
|
---|
1016 | //
|
---|
1017 | Int_t MAstro::GetEasterOffset(UShort_t year)
|
---|
1018 | {
|
---|
1019 | if (year<1583 || year>2499)
|
---|
1020 | {
|
---|
1021 | cout << "MAstro::GetDayOfEaster - Year " << year << " not between 1700 and 2199" << endl;
|
---|
1022 | return -1;
|
---|
1023 | }
|
---|
1024 |
|
---|
1025 | Int_t M=0;
|
---|
1026 | Int_t N=0;
|
---|
1027 | switch (year/100)
|
---|
1028 | {
|
---|
1029 | case 15:
|
---|
1030 | case 16: M=22; N=2; break;
|
---|
1031 | case 17: M=23; N=3; break;
|
---|
1032 | case 18: M=23; N=4; break;
|
---|
1033 | case 19:
|
---|
1034 | case 20: M=24; N=5; break;
|
---|
1035 | case 21: M=24; N=6; break;
|
---|
1036 | case 22: M=25; N=0; break;
|
---|
1037 | case 23: M=26; N=1; break;
|
---|
1038 | case 24: M=25; N=1; break;
|
---|
1039 | }
|
---|
1040 |
|
---|
1041 | const Int_t a = year%19;
|
---|
1042 | const Int_t b = year%4;
|
---|
1043 | const Int_t c = year%7;
|
---|
1044 | const Int_t d = (19*a + M)%30;
|
---|
1045 | const Int_t e = (2*b + 4*c + 6*d + N)%7;
|
---|
1046 |
|
---|
1047 | if (e==6 && d==28 && a>10)
|
---|
1048 | return 48;
|
---|
1049 |
|
---|
1050 | if (d+e==35)
|
---|
1051 | return 49;
|
---|
1052 |
|
---|
1053 | return d + e + 21;
|
---|
1054 | }
|
---|