source: trunk/MagicSoft/Mars/mpointing/MPointing.h@ 8851

Last change on this file since 8851 was 8829, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 11.4 KB
Line 
1#ifndef MARS_MPointing
2#define MARS_MPointing
3
4#ifndef ROOT_TArrayD
5#include <TArrayD.h>
6#endif
7
8#ifndef ROOT_TVector2
9#include <TVector2.h>
10#endif
11
12#ifndef ROOT_TVector3
13#include <TVector3.h>
14#endif
15
16#ifndef MARS_MParContainer
17#include "MParContainer.h"
18#endif
19
20// ---------------------------------------------------
21
22#define XY TVector2
23
24inline TVector2 Div(const TVector2 &v1, const TVector2 &v2)
25{
26 return TVector2(v1.X()/v2.X(), v1.Y()/v2.Y());
27}
28inline TVector2 Mul(const TVector2 &v1, const TVector2 &v2)
29{
30 return TVector2(v1.X()*v2.X(), v1.Y()*v2.Y());
31}
32
33inline TVector2 operator-(const TVector2 &v) { return TVector2(-v.X(), -v.Y()); }
34
35class AltAz : public XY
36{
37public:
38 AltAz(double alt=0, double az=0) : XY(alt, az) {}
39
40 double Alt() const { return fX; }
41 double Az() const { return fY; }
42
43 void operator*=(double c) { fX*=c; fY*=c; }
44 void operator/=(double c) { fX*=c; fY*=c; }
45
46 void Alt(double d) { fX=d; }
47 void Az(double d) { fY=d; }
48 void operator*=(const XY &c) { fX*=c.X(); fY*=c.Y(); }
49 void operator/=(const XY &c) { fX/=c.X(); fY/=c.Y(); }
50 void operator-=(const AltAz &c) { fX-=c.fX; fY-=c.fY; }
51 void operator+=(const AltAz &c) { fX+=c.fX; fY+=c.fY; }
52
53 AltAz operator/(double c) const { return AltAz(fX/c, fY/c); }
54 AltAz operator*(double c) const { return AltAz(fX*c, fY*c); }
55 AltAz operator*(const XY &c) const { return AltAz(fX*c.X(), fY*c.Y()); }
56 AltAz operator/(const XY &c) const { return AltAz(fX/c.X(), fY/c.Y()); }
57 AltAz operator+(const AltAz &c) const { return AltAz(fX+c.fX, fY+c.fY); }
58 AltAz operator-(const AltAz &c) const { return AltAz(fX-c.fX, fY-c.fY); }
59 AltAz operator-() const { return AltAz(-fX, -fY); }
60
61 ClassDef(AltAz, 0)
62};
63
64class ZdAz : public XY
65{
66public:
67 ZdAz(double zd=0, double az=0) : XY(zd, az) {}
68 ZdAz(const ZdAz &c) : XY(c) {}
69
70 void operator*=(double c) { fX*=c; fY*=c; }
71 void operator/=(double c) { fX*=c; fY*=c; }
72
73 double Zd() const { return fX; }
74 double Az() const { return fY; }
75
76 void Zd(double d) { fX=d; }
77 void Az(double d) { fY=d; }
78 void operator*=(const XY &c) { fX*=c.X(); fY*=c.Y(); }
79 void operator/=(const XY &c) { fX/=c.X(); fY/=c.Y(); }
80 void operator-=(const ZdAz &c) { fX-=c.fX; fY-=c.fY; }
81 void operator+=(const ZdAz &c) { fX+=c.fX; fY+=c.fY; }
82
83 ZdAz operator/(double c) const { return ZdAz(fX/c, fY/c); }
84 ZdAz operator*(double c) const { return ZdAz(fX*c, fY*c); }
85 ZdAz operator*(const XY &c) const { return ZdAz(fX*c.X(), fY*c.Y()); }
86 ZdAz operator/(const XY &c) const { return ZdAz(fX/c.X(), fY/c.Y()); }
87 ZdAz operator+(const ZdAz &c) const { return ZdAz(fX+c.fX, fY+c.fY); }
88 ZdAz operator-(const ZdAz &c) const { return ZdAz(fX-c.fX, fY-c.fY); }
89 ZdAz operator-() const { return ZdAz(-fX, -fY); }
90
91 // MSlewing only?!?
92 double Ratio() const { return fX/fY; }
93 void Round() { fX=(int)(floor(fX+.5)); fY=(int)(floor(fY+.5)); }
94
95 ClassDef(ZdAz, 0)
96};
97
98class RaDec : public XY
99{
100public:
101 RaDec(double ra=0, double dec=0) : XY(ra, dec) {}
102
103 double Ra() const { return fX; }
104 double Dec() const { return fY; }
105
106 void operator*=(double c) { fX*=c; fY*=c; }
107 void operator/=(double c) { fX*=c; fY*=c; }
108
109 void Ra(double x) { fX = x; }
110 void Dec(double y) { fY = y; }
111
112 RaDec operator/(double c) const { return RaDec(fX/c, fY/c); }
113 RaDec operator*(double c) const { return RaDec(fX*c, fY*c); }
114 RaDec operator*(const XY &c) const { return RaDec(fX*c.X(), fY*c.Y()); }
115 RaDec operator+(const RaDec &c) const { return RaDec(fX+c.fX, fY+c.fY); }
116 RaDec operator-(const RaDec &c) const { return RaDec(fX-c.fX, fY-c.fY); }
117 RaDec operator-() const { return RaDec(-fX, -fY); }
118
119 ClassDef(RaDec, 0)
120};
121
122// ---------------------------------------------------
123
124class TMinuit;
125
126class MPointing : public MParContainer
127{
128private:
129 enum {
130 kIA, // [rad] Index Error in Elevation
131 kIE, // [rad] Index Error in Azimuth
132 kFLOP, // [rad] Vertical Sag
133 kAN, // [rad] Az-El Nonperpendicularity
134 kAW, // [rad] Left-Right Collimation Error
135 kNPAE, // [rad] Azimuth Axis Misalignment (N-S)
136 kCA, // [rad] Azimuth Axis Misalignment (E-W)
137 kTF, // [rad] Tube fluxture (sin)
138 kTX, // [rad] Tube fluxture (tan)
139 kECES, // [rad] Nasmyth rotator displacement, horizontal
140 kACES, // [rad] Nasmyth rotator displacement, vertical
141 kECEC, // [rad] Alt/Az Coude Displacement (N-S)
142 kACEC, // [rad] Alt/Az Coude Displacement (E-W)
143 kNRX, // [rad] Elevation Centering Error (sin)
144 kNRY, // [rad] Azimuth Centering Error (sin)
145 kCRX, // [rad] Elevation Centering Error (cos)
146 kCRY, // [rad] Azimuth Centering Error (cos)
147 kMAGIC1, // [rad] Magic Term (what is it?)
148 kMAGIC2, // [rad] Magic Term (what is it?)
149 kPX, // [rad] Starguider calibration fixed offset x
150 kPY, // [rad] Starguider calibration fixed offset y
151 kDX, // [rad] Starguider calibration additional offset dx
152 kDY, // [rad] Starguider calibration additional offset dy
153 kNumPar // Number of elements
154 };
155
156
157 Double_t fIe ; // [rad] Index Error in Elevation
158 Double_t fIa ; // [rad] Index Error in Azimuth
159 Double_t fFlop ; // [rad] Vertical Sag
160 Double_t fNpae ; // [rad] Az-El Nonperpendicularity
161 Double_t fCa ; // [rad] Left-Right Collimation Error
162 Double_t fAn ; // [rad] Azimuth Axis Misalignment (N-S)
163 Double_t fAw ; // [rad] Azimuth Axis Misalignment (E-W)
164 Double_t fTf ; // [rad] Tube fluxture (sin)
165 Double_t fTx ; // [rad] Tube fluxture (tan)
166 Double_t fNrx ; // [rad] Nasmyth rotator displacement, horizontal
167 Double_t fNry ; // [rad] Nasmyth rotator displacement, vertical
168 Double_t fCrx ; // [rad] Alt/Az Coude Displacement (N-S)
169 Double_t fCry ; // [rad] Alt/Az Coude Displacement (E-W)
170 Double_t fEces ; // [rad] Elevation Centering Error (sin)
171 Double_t fAces ; // [rad] Azimuth Centering Error (sin)
172 Double_t fEcec ; // [rad] Elevation Centering Error (cos)
173 Double_t fAcec ; // [rad] Azimuth Centering Error (cos)
174 Double_t fMagic1; // [rad] Magic Term (what is it?)
175 Double_t fMagic2; // [rad] Magic Term (what is it?)
176
177 Double_t fPx; // [rad] Starguider calibration fixed offset x
178 Double_t fPy; // [rad] Starguider calibration fixed offset y
179 Double_t fDx; // [rad] Starguider calibration additional offset dx
180 Double_t fDy; // [rad] Starguider calibration additional offset dy
181
182 Double_t **fCoeff; //!
183 TString *fNames; //!
184 TString *fDescr; //!
185
186 TArrayD fError;
187
188 void Init(const char *name=0, const char *title=0);
189
190 void Clear(Option_t *o="")
191 {
192 for (int i=0; i<kNumPar; i++)
193 {
194 *fCoeff[i] = 0;
195 fError[i] = -1;
196 }
197 }
198
199 static Double_t Sign(Double_t val, Double_t alt);
200 AltAz CalcAnAw(const AltAz &p, Int_t sign) const;
201
202public:
203 MPointing() : fError(kNumPar) { Init(); Clear(); }
204 MPointing(const char *name) : fError(kNumPar) { Init(); Clear(); Load(name); }
205 virtual ~MPointing() { delete [] fNames; delete [] fCoeff; delete [] fDescr; }
206
207 Bool_t Load(const char *name);
208 Bool_t Save(const char *name);
209
210 void Reset();
211
212 ZdAz Correct(const ZdAz &zdaz) const;
213 AltAz Correct(const AltAz &aaz) const;
214 TVector3 Correct(const TVector3 &v) const;
215
216 ZdAz CorrectBack(const ZdAz &zdaz) const;
217 AltAz CorrectBack(const AltAz &aaz) const;
218 TVector3 CorrectBack(const TVector3 &v) const;
219
220 ZdAz operator()(const ZdAz &zdaz) const { return Correct(zdaz); }
221 AltAz operator()(const AltAz &aaz) const { return Correct(aaz); }
222 TVector3 operator()(const TVector3 &v) const { return Correct(v); }
223
224 ZdAz operator()(const ZdAz &zdaz, void (*fcn)(ZdAz &zdaz, Double_t *par)) const
225 {
226 Double_t par[kNumPar];
227 GetParameters(par);
228 ZdAz za = zdaz;
229 fcn(za, par);
230 return za;
231 }
232
233 AltAz operator()(const AltAz &aaz, void (*fcn)(AltAz &aaz, Double_t *par)) const
234 {
235 Double_t par[kNumPar];
236 GetParameters(par);
237 AltAz aa = aaz;
238 fcn(aa, par);
239 return aa;
240 }
241
242 TVector3 operator()(const TVector3 &aaz, void (*fcn)(TVector3 &aaz, Double_t *par)) const
243 {
244 Double_t par[kNumPar];
245 GetParameters(par);
246 TVector3 v = aaz;
247 fcn(v, par);
248 return v;
249 }
250
251 AltAz AddOffsets(const AltAz &aa) const;
252 ZdAz AddOffsets(const ZdAz &zdaz) const
253 {
254 AltAz p(TMath::Pi()/2-zdaz.Zd(), zdaz.Az());
255 AltAz c = AddOffsets(p);
256 return ZdAz(TMath::Pi()/2-c.Alt(), c.Az());
257 }
258 TVector3 AddOffsets(const TVector3 &v) const
259 {
260 AltAz p(TMath::Pi()/2-v.Theta(), v.Phi());
261 AltAz c = AddOffsets(p);
262 TVector3 rc;
263 rc.SetMagThetaPhi(1, TMath::Pi()/2-c.Alt(), c.Az());
264 return rc;
265 }
266
267 AltAz SubtractOffsets(const AltAz &aa) const;
268 ZdAz SubtractOffsets(const ZdAz &zdaz) const
269 {
270 AltAz p(TMath::Pi()/2-zdaz.Zd(), zdaz.Az());
271 AltAz c = SubtractOffsets(p);
272 return ZdAz(TMath::Pi()/2-c.Alt(), c.Az());
273 }
274 TVector3 SubtractOffsets(const TVector3 &v) const
275 {
276 AltAz p(TMath::Pi()/2-v.Theta(), v.Phi());
277 AltAz c = SubtractOffsets(p);
278 TVector3 rc;
279 rc.SetMagThetaPhi(1, TMath::Pi()/2-c.Alt(), c.Az());
280 return rc;
281 }
282
283 void SetParameters(const Double_t *par, Int_t n=kNumPar);
284 void GetParameters(Double_t *par, Int_t n=kNumPar) const;
285
286 void SetParameters(const TArrayD &par)
287 {
288 SetParameters(par.GetArray(), par.GetSize());
289 }
290 void GetParameters(TArrayD &par) const
291 {
292 par.Set(kNumPar);
293 GetParameters(par.GetArray());
294 }
295 void GetError(TArrayD &par) const
296 {
297 par = fError;
298 for (int i=0; i<kNumPar; i++)
299 par[i] *= TMath::RadToDeg();
300 }
301
302 Double_t &operator[](UInt_t i) { return *fCoeff[i]; }
303
304 void SetMinuitParameters(TMinuit &m, Int_t n=-1) const;
305 void GetMinuitParameters(TMinuit &m, Int_t n=-1);
306 void PrintMinuitParameters(TMinuit &m, Int_t n=-1) const;
307
308 const TString &GetVarName(int i) const { return fNames[i]; }
309 const TString &GetDescription(int i) const { return fDescr[i]; }
310
311 /*
312 Double_t GetIe() const { return fIe; }
313 Double_t GetIa() const { return fIa; }
314 Double_t GetCa() const { return fCa; }
315 Double_t GetAn() const { return fAn; }
316 Double_t GetAw() const { return fAw; }
317 Double_t GetNrx() const { return fNrx; }
318 Double_t GetNry() const { return fNry; }
319 Double_t GetCrx() const { return fNrx; }
320 Double_t GetCry() const { return fNry; }
321 Double_t GetEces() const { return fEces; }
322 Double_t GetEcec() const { return fEcec; }
323 Double_t GetAces() const { return fAces; }
324 Double_t GetAcec() const { return fAcec; }
325 Double_t GetNpae() const { return fNpae; }
326 */
327
328 TVector2 GetDxy() const { return TVector2(fDx, fDy)*TMath::RadToDeg(); }
329
330 Double_t GetPx() const { return fPx*TMath::RadToDeg(); }
331 Double_t GetPy() const { return fPy*TMath::RadToDeg(); }
332
333 Bool_t IsPxValid() const { return fError[kPX]>0; }
334 Bool_t IsPyValid() const { return fError[kPY]>0; }
335
336 static const Int_t GetNumPar() { return kNumPar; }
337
338 ClassDef(MPointing, 2) // Pointing Model for MAGIC
339};
340
341#endif
Note: See TracBrowser for help on using the repository browser.