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