source: trunk/MagicSoft/Mars/mtemp/MVPObject.cc@ 3330

Last change on this file since 3330 was 1745, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 9.3 KB
Line 
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): Robert Wagner <mailto:magicsoft@rwagner.de> 10/2002
19!
20! Copyright: MAGIC Software Development, 2000-2002
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26// //
27// MVPObject //
28// //
29// Class used by the visibility plotter to convert RA/Dec to Alt/Az //
30// //
31// This class represents an object and is used with the Visibility //
32// macro. It must be provided with its RA/Dec coordinates and an //
33// object name (cf. MVPObject::SetRA, MVPObject::SetDec, and //
34// MVPObject::SetName). Alternatively, you can require the MVPObject //
35// to be a solar system object like the Sun, Mars or the Moon //
36// (cf. MVPObject::SetObject). //
37// //
38// MVPObject is ready to be used in a Mars Eventloop. You must provide //
39// an Observatory Location as well as a time at which the position //
40// of the MVPObject is to be calculated. MVPObject::PreProcess //
41// checks the existence of the required containers and also makes sure //
42// all necessary setters have been called. MVPObject::Process //
43// then calculates the Alt/Az position of the object, as well as the //
44// Zenith angle and the object diameter (Solar system objects). //
45// //
46// The astronomical algorithms used are taken from SLALIB 2.4-8. //
47// //
48/////////////////////////////////////////////////////////////////////////////
49#include "MVPObject.h"
50
51#include <TMath.h>
52
53#include "MLog.h"
54#include "MLogManip.h"
55#include "MParList.h"
56
57#include "../../slalib/slalib.h"
58
59ClassImp(MVPObject);
60
61// --------------------------------------------------------------------------
62//
63// Default constructor.
64//
65MVPObject::MVPObject(const char *name, const char *title) : fDiameter(0), fCalcEc(kFALSE), fUT1(52000), fBody(10), fGotRA(kFALSE), fGotDec(kFALSE), fGotName(kFALSE)
66{
67 fName = name ? name : "MVPObject";
68 fTitle = title ? title : "Task to calculate Alt, Az of a given object";
69
70 fgDegToRad=2*TMath::Pi()/360;
71 fgHrsToRad=2*TMath::Pi()/24;
72}
73
74MVPObject::~MVPObject()
75{
76 //Destructor: nothing special yet.
77}
78
79// --------------------------------------------------------------------------
80//
81// Check if necessary containers exist in the parameter list already.
82// We need an ObservatoryLocation and a MVPTime object.
83//
84Bool_t MVPObject::PreProcess(MParList *pList)
85{
86 fObservatory = (MObservatoryLocation*)pList->FindObject("MObservatoryLocation");
87 if (!fObservatory)
88 {
89 *fLog << dbginf << "MObservatoryLocation not found... aborting." << endl;
90 return kFALSE;
91 }
92
93 fTime = (MVPTime*)pList->FindObject("MVPTime");
94 if (!fTime)
95 {
96 *fLog << dbginf << "MVPTime not found... aborting." << endl;
97 return kFALSE;
98 }
99
100 if (!fGotRA || !fGotDec || !fGotName)
101 {
102 *fLog << dbginf << "Object information is not complete." << endl;
103 return kFALSE;
104 }
105
106 return kTRUE;
107}
108
109// --------------------------------------------------------------------------
110//
111// Sets coordinates from object name. Instead of providing RA, Dec and Name
112// of an object, you may also just provide the object name in the from
113// HHMMsDDT, where RA is given in hours and minutes and Declination is
114// given by degrees DD and tenths of degrees T. "s" may be "+" or
115// "-", eg. "1959+650"
116//
117void MVPObject::SetObjectByName(const char *object)
118{
119 fObjectName=object;
120 fGotName=kTRUE;
121
122 Int_t ra, dec;
123 sscanf(object, "%d%d", &ra, &dec);
124
125 fRA = fgHrsToRad * (0.01*ra + (r%100)/60.);
126 fDec = fgDegToRad * 0.1 * dec;
127
128 fGotRA=kTRUE;
129 fGotDec=kTRUE;
130}
131
132
133// --------------------------------------------------------------------------
134//
135// Sets RA position of object. Position is to be provided in hours, minutes,
136// seconds, and microseconds (if needed)
137//
138void MVPObject::SetRA(Int_t rh, Int_t rm, Int_t rs, Int_t ru)
139{
140 // Rect is a timelike value...
141 fRA = fgHrsToRad*((Double_t)rh + (Double_t)rm/60 + (Double_t)rs/(60*60) + (Double_t)ru/(36000));
142 fBody = 10;
143 fGotRA = kTRUE;
144}
145
146// --------------------------------------------------------------------------
147//
148// Sets Dec position of object. Position is to be provided in degrees,
149// minutes, seconds, and microseconds (if needed)
150//
151void MVPObject::SetDec(Int_t dh, Int_t dm, Int_t ds, Int_t du)
152{
153 // Dec is an anglelike value
154 fDec = fgDegToRad*((Double_t)dh + (Double_t)dm/60 + (Double_t)ds/(60*60) + (Double_t)du/(36000));
155 fBody = 10;
156 fGotDec = kTRUE;
157}
158
159// --------------------------------------------------------------------------
160//
161// Alternatively to providing RA, Dec and Name of an object, you may provide
162// a solar system object (which has no fixed RA, Dec, by the way!) with
163// MVPObject::SetObject.
164// -
165// UInt_t body | Object Sun and Moon will be objects needed at most,
166// 0 | Sun presumably.
167// 1 | Mercury
168// 2 | Venus
169// 3 | Moon
170// 4 | Mars
171// 5 | Jupiter
172// 6 | Saturn
173// 7 | Uranus
174// 8 | Neptune
175// 9 | Pluto
176//
177Bool_t MVPObject::SetObject(UInt_t body)
178{
179 if (body > 9)
180 {
181 *fLog << dbginf << "No solar system object associated with value " << body <<"! Ignoring request." << endl;
182 return kFALSE;
183 }
184 else // We are working on a solar system body.
185 {
186 switch (body)
187 {
188 case 1: fObjectName="Mercury"; break;
189 case 2: fObjectName="Venus"; break;
190 case 3: fObjectName="Moon"; break;
191 case 4: fObjectName="Mars"; break;
192 case 5: fObjectName="Jupiter"; break;
193 case 6: fObjectName="Saturn"; break;
194 case 7: fObjectName="Uranus"; break;
195 case 8: fObjectName="Neptune"; break;
196 case 9: fObjectName="Pluto"; break;
197 default: fObjectName="Sun";
198 }
199 }
200
201 fBody = body;
202 fGotRA = fGotDec = fGotName = kTRUE;
203 return kTRUE;
204}
205
206// --------------------------------------------------------------------------
207//
208// Given RA, Dec or a solar system object as well as an observatory
209// location and a MVPTime, MVPObject::Process() calculates
210// Alt, Az, ZA and (in the case of solar system objects) the apparent
211// object diameter
212//
213Bool_t MVPObject::Process()
214{
215 Double_t diameter = 0.0;
216
217 if (fBody < 10) // We are working on a solar system body.
218 {
219 slaRdplan(fTime->GetMJD(), fBody, fObservatory->GetLongitudeRad(), fObservatory->GetLatitudeRad(), &fRA, &fDec, &diameter);
220 }
221
222 if (fCalcEc) slaEqecl(fRA, fDec, fTime->GetMJD(), &fEcLong, &fEcLat);
223
224 Float_t azimuth;
225 Float_t elevation;
226
227 Float_t hourAngle = (Float_t)UT1ToGMST(fTime->GetMJD()) - fRA;
228
229 // cout << "ha: " << hourAngle << " ra: " << fRA << " dec " << fDec <<endl;
230
231 slaE2h (hourAngle, (Float_t)fDec, (Float_t)fObservatory->GetLatitudeRad(), &azimuth, &elevation);
232
233 fZA = slaZd(hourAngle, fDec, fObservatory->GetLatitudeRad());
234 fAlt = (Double_t)elevation;
235 fAz = (Double_t)azimuth;
236 fDiameter = diameter;
237
238 return kTRUE;
239}
240
241
242// --------------------------------------------------------------------------
243//
244// Returns distance of given object to this object in degrees
245//
246Double_t MVPObject::GetDistance(MVPObject* object)
247{
248 return slaSep(fRA, fDec, object->GetRARad(), object->GetDecRad())/fgDegToRad;
249}
250
251// --------------------------------------------------------------------------
252//
253// Returns distance of given object to this object in radians
254//
255Double_t MVPObject::GetDistanceRad(MVPObject* object)
256{
257 return slaSep(fRA, fDec, object->GetRARad(), object->GetDecRad());
258}
259
260
261// --------------------------------------------------------------------------
262//
263// Converts UT1 (given as MJD) to Greenwich mean star time in radians
264//
265Double_t MVPObject::UT1ToGMST(Double_t ut1)
266{
267 return slaGmst(ut1);
268}
269
270void MVPObject::Print(Option_t *) const
271{
272 *fLog << all;
273 *fLog << "Position of "<< fObjectName <<
274 ": Dec " << fDec/fgDegToRad << " deg, " <<
275 "RA " << fRA/fgHrsToRad << " hrs" << endl;
276 if (fCalcEc) *fLog << "Ecliptic Long: " << fEcLong/fgDegToRad << " deg, " <<
277 "Ecliptic Lat: " << fEcLat/fgDegToRad << " deg, " << endl;
278}
279
280
Note: See TracBrowser for help on using the repository browser.