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

Last change on this file since 1742 was 1680, checked in by rwagner, 22 years ago
*** empty log message ***
File size: 10.1 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// "-"
116//
117void MVPObject::SetObjectByName(char* object)
118{
119 fObjectName=object;
120 fGotName=kTRUE;
121
122// cout<<"OBJ:"<<object<<endl;
123
124 unsigned int delim=0;
125 for (unsigned int i=0; i<strlen(object); i++)
126 if ((object[i]=='+')||(object[i]=='-'))
127 delim=i;
128
129 char ra[6];
130 char de[6];
131
132 unsigned int i;
133 for (i=0; i<=delim; i++)
134 ra[i]=object[i];
135 ra[i-1]=0;
136
137 for (i=delim+1; i<strlen(object); i++)
138 de[i-delim-1]=object[i];
139 de[i-delim-1]=0;
140
141 Float_t RA, Dec;
142
143 sscanf(ra,"%f",&RA);
144 sscanf(de,"%f",&Dec);
145
146// cout<<"OBJd:"<<Dec<<endl; //220
147// cout<<"OBJr:"<<RA<<endl; //1959
148
149 if (object[delim]=='-') Dec*=-1;
150
151 fRA=(Double_t)( fgHrsToRad* ((Int_t)(RA/100) + ( RA-(Int_t)(RA/100)*100)/60 ));
152 fDec=(Double_t)( fgDegToRad* ((Int_t)(Dec/10) + (Dec-(Int_t)(Dec/10)*10 )/10 ));
153
154 // fRA=(Double_t)( fgHrsToRad* ((Int_t)(RA/100) + ((RA / 100)-(Int_t)(RA/100))/60 ));
155// fDec=(Double_t)( fgDegToRad* ((Int_t)(Dec/10) + ((Dec / 10)-(Int_t)(Dec/100))/10 ));
156
157// cout<<"OBJd:"<<fDec/fgDegToRad<<endl;
158// cout<<"OBJr:"<<fRA/fgHrsToRad<<endl;
159
160 fGotRA=kTRUE;
161 fGotDec=kTRUE;
162}
163
164
165// --------------------------------------------------------------------------
166//
167// Sets RA position of object. Position is to be provided in hours, minutes,
168// seconds, and microseconds (if needed)
169//
170void MVPObject::SetRA(Int_t rh, Int_t rm, Int_t rs, Int_t ru)
171{
172 // Rect is a timelike value...
173 fRA = fgHrsToRad*((Double_t)rh + (Double_t)rm/60 + (Double_t)rs/(60*60) + (Double_t)ru/(36000));
174 fBody = 10;
175 fGotRA = kTRUE;
176}
177
178// --------------------------------------------------------------------------
179//
180// Sets Dec position of object. Position is to be provided in degrees,
181// minutes, seconds, and microseconds (if needed)
182//
183void MVPObject::SetDec(Int_t dh, Int_t dm, Int_t ds, Int_t du)
184{
185 // Dec is an anglelike value
186 fDec = fgDegToRad*((Double_t)dh + (Double_t)dm/60 + (Double_t)ds/(60*60) + (Double_t)du/(36000));
187 fBody = 10;
188 fGotDec = kTRUE;
189}
190
191// --------------------------------------------------------------------------
192//
193// Alternatively to providing RA, Dec and Name of an object, you may provide
194// a solar system object (which has no fixed RA, Dec, by the way!) with
195// MVPObject::SetObject.
196// -
197// UInt_t body | Object Sun and Moon will be objects needed at most,
198// 0 | Sun presumably.
199// 1 | Mercury
200// 2 | Venus
201// 3 | Moon
202// 4 | Mars
203// 5 | Jupiter
204// 6 | Saturn
205// 7 | Uranus
206// 8 | Neptune
207// 9 | Pluto
208//
209Bool_t MVPObject::SetObject(UInt_t body)
210{
211 if (body > 9)
212 {
213 *fLog << dbginf << "No solar system object associated with value " << body <<"! Ignoring request." << endl;
214 return kFALSE;
215 }
216 else // We are working on a solar system body.
217 {
218 switch (body)
219 {
220 case 1: fObjectName="Mercury"; break;
221 case 2: fObjectName="Venus"; break;
222 case 3: fObjectName="Moon"; break;
223 case 4: fObjectName="Mars"; break;
224 case 5: fObjectName="Jupiter"; break;
225 case 6: fObjectName="Saturn"; break;
226 case 7: fObjectName="Uranus"; break;
227 case 8: fObjectName="Neptune"; break;
228 case 9: fObjectName="Pluto"; break;
229 default: fObjectName="Sun";
230 }
231 }
232
233 fBody = body;
234 fGotRA = fGotDec = fGotName = kTRUE;
235 return kTRUE;
236}
237
238// --------------------------------------------------------------------------
239//
240// Given RA, Dec or a solar system object as well as an observatory
241// location and a MVPTime, MVPObject::Process() calculates
242// Alt, Az, ZA and (in the case of solar system objects) the apparent
243// object diameter
244//
245Bool_t MVPObject::Process()
246{
247 Double_t diameter = 0.0;
248
249 if (fBody < 10) // We are working on a solar system body.
250 {
251 slaRdplan(fTime->GetMJD(), fBody, fObservatory->GetLongitudeRad(), fObservatory->GetLatitudeRad(), &fRA, &fDec, &diameter);
252 }
253
254 if (fCalcEc) slaEqecl(fRA, fDec, fTime->GetMJD(), &fEcLong, &fEcLat);
255
256 Float_t azimuth;
257 Float_t elevation;
258
259 Float_t hourAngle = (Float_t)UT1ToGMST(fTime->GetMJD()) - fRA;
260
261 // cout << "ha: " << hourAngle << " ra: " << fRA << " dec " << fDec <<endl;
262
263 slaE2h (hourAngle, (Float_t)fDec, (Float_t)fObservatory->GetLatitudeRad(), &azimuth, &elevation);
264
265 fZA = slaZd(hourAngle, fDec, fObservatory->GetLatitudeRad());
266 fAlt = (Double_t)elevation;
267 fAz = (Double_t)azimuth;
268 fDiameter = diameter;
269
270 return kTRUE;
271}
272
273
274// --------------------------------------------------------------------------
275//
276// Returns distance of given object to this object in degrees
277//
278Double_t MVPObject::GetDistance(MVPObject* object)
279{
280 return slaSep(fRA, fDec, object->GetRARad(), object->GetDecRad())/fgDegToRad;
281}
282
283// --------------------------------------------------------------------------
284//
285// Returns distance of given object to this object in radians
286//
287Double_t MVPObject::GetDistanceRad(MVPObject* object)
288{
289 return slaSep(fRA, fDec, object->GetRARad(), object->GetDecRad());
290}
291
292
293// --------------------------------------------------------------------------
294//
295// Converts UT1 (given as MJD) to Greenwich mean star time in radians
296//
297Double_t MVPObject::UT1ToGMST(Double_t ut1)
298{
299 return slaGmst(ut1);
300}
301
302void MVPObject::Print(Option_t *) const
303{
304 *fLog << all;
305 *fLog << "Position of "<< fObjectName <<
306 ": Dec " << fDec/fgDegToRad << " deg, " <<
307 "RA " << fRA/fgHrsToRad << " hrs" << endl;
308 if (fCalcEc) *fLog << "Ecliptic Long: " << fEcLong/fgDegToRad << " deg, " <<
309 "Ecliptic Lat: " << fEcLat/fgDegToRad << " deg, " << endl;
310}
311
312
Note: See TracBrowser for help on using the repository browser.