source: trunk/Cosy/tpoint/TPointStar.cc@ 14586

Last change on this file since 14586 was 14581, checked in by tbretz, 12 years ago
Fixed the GetResidual.
File size: 4.5 KB
Line 
1#include "TPointStar.h"
2
3#include <TMath.h>
4
5#include "MLog.h"
6#include "MLogManip.h"
7
8#include "MPointing.h"
9
10ClassImp(TPointStar);
11
12using namespace std;
13
14void TPointStar::Init(const char *name, const char *title)
15{
16 fName = name ? name : "TPointStar";
17 fTitle = title ? title : "A set of TPoints";
18}
19
20TPointStar::TPointStar(Double_t sel, Double_t saz, Double_t rel, Double_t raz) :
21 fStarAz(saz*TMath::DegToRad()),
22 fStarEl(sel*TMath::DegToRad()),
23 fRawAz(raz*TMath::DegToRad()),
24 fRawEl(rel*TMath::DegToRad()), fMag(-25)
25{
26 Init();
27}
28
29Double_t TPointStar::GetDEl() const { return (fRawEl-fStarEl)*TMath::RadToDeg(); }
30Double_t TPointStar::GetDZd() const { return -GetDEl(); }
31Double_t TPointStar::GetDAz() const { return (fRawAz-fStarAz)*TMath::RadToDeg(); }
32Double_t TPointStar::GetStarEl() const { return fStarEl*TMath::RadToDeg(); }
33Double_t TPointStar::GetStarZd() const { return 90.-fStarEl*TMath::RadToDeg(); }
34Double_t TPointStar::GetStarAz() const { return fStarAz*TMath::RadToDeg(); }
35Double_t TPointStar::GetRawEl() const { return fRawEl*TMath::RadToDeg(); }
36Double_t TPointStar::GetRawAz() const { return fRawAz*TMath::RadToDeg(); }
37Double_t TPointStar::GetRawZd() const { return 90.-fRawEl*TMath::RadToDeg(); }
38
39ZdAz TPointStar::GetStarZdAz() const { return ZdAz(TMath::Pi()/2-fStarEl, fStarAz); }
40AltAz TPointStar::GetStarAltAz() const { return AltAz(fStarEl, fStarAz); }
41
42ZdAz TPointStar::GetRawZdAz() const { return ZdAz(TMath::Pi()/2-fRawEl, fRawAz); }
43AltAz TPointStar::GetRawAltAz() const { return AltAz(fRawEl, fRawAz); }
44
45void TPointStar::AdjustEl(Double_t del) { fStarEl += del*TMath::DegToRad(); }
46void TPointStar::AdjustAz(Double_t daz) { fStarAz += daz*TMath::DegToRad(); }
47
48void TPointStar::Adjust(const MPointing &bend)
49{
50 AltAz p = bend(GetStarAltAz());
51 fStarEl = p.Alt();
52 fStarAz = p.Az();
53}
54
55void TPointStar::AdjustBack(const MPointing &bend)
56{
57 AltAz p = bend.CorrectBack(GetRawAltAz());
58 fRawEl = p.Alt();
59 fRawAz = p.Az();
60}
61
62Double_t TPointStar::GetResidual(Double_t *err) const
63{
64 /*
65 TVector3 v1, v2;
66 v1.SetMagThetaPhi(1, TMath::Pi()/2-fRawEl, fRawAz);
67 v2.SetMagThetaPhi(1, TMath::Pi()/2-fStarEl, fStarAz);
68
69 return v1.Angle(v2)*TMath::RadToDeg();
70 */
71
72 const Double_t del = fRawEl-fStarEl;
73 const Double_t daz = fRawAz-fStarAz;
74
75 const double x = sin(fRawEl) * sin(fStarEl) * cos(fStarAz-fRawAz);
76 const double y = cos(fRawEl) * cos(fStarEl);
77
78 const Double_t d = acos(x + y);
79
80 if (err)
81 {
82 // Error of one pixel in the CCD
83 const Double_t e1 = 32./3600*TMath::DegToRad() * 0.5;
84
85 // Error of one SE unit
86 const Double_t e2 = 360./16384*TMath::DegToRad() * 0.5;
87
88 const Double_t e11 = sin(del)+cos(fRawEl)*sin(fStarEl)*(1-cos(daz));
89 const Double_t e12 = cos(fRawEl)*cos(fStarEl)*sin(daz);
90
91 const Double_t e21 = -sin(del)+sin(fRawEl)*cos(fStarEl)*(1-cos(daz));
92 const Double_t e22 = -cos(fRawEl)*cos(fStarEl)*sin(daz);
93
94 const Double_t err1 = sqrt(1-d*d);
95 const Double_t err2 = (e11*e11 + e12*e12)*e1*e1;
96 const Double_t err3 = (e21*e21 + e22*e22)*e2*e2;
97
98 *err = sqrt(err2+err3)/err1 * TMath::RadToDeg();
99 }
100
101 const Double_t dist = acos(d);
102 return dist * TMath::RadToDeg();
103}
104
105istream &operator>>(istream &fin, TPointStar &set)
106{
107 TString str;
108 do
109 {
110 str.ReadLine(fin);
111 if (!fin)
112 return fin;
113 } while (str[0]=='#');
114
115 Float_t v[4], mag;
116 Int_t n = sscanf(str.Data(), "%f %f %f %f %*f %*f %*f %*f %*f %*f %f", v, v+1, v+2, v+3, &mag);
117 if (n<4)
118 {
119 gLog << err << "Read: ERROR - Not enough numbers" << endl;
120 return fin;
121 }
122 set.fMag = n<5 ? -25 : mag;
123
124 set.fStarAz = v[0]*TMath::DegToRad();
125 set.fStarEl = v[1]*TMath::DegToRad();
126
127 set.fRawAz = v[2]*TMath::DegToRad();
128 set.fRawEl = v[3]*TMath::DegToRad();
129
130 if (fin)
131 {
132 Double_t res, err;
133 res = set.GetResidual(&err);
134 gLog << inf << "Read: " << v[0] << " " << v[1] << " : " << v[2] << " " << v[3] << " : " << v[2]-v[0] << " " << v[3]-v[1] << " : " << res << " " << err << " " << err/res << endl;
135 }
136
137 return fin;
138}
139
140ostream &operator<<(ostream &out, TPointStar &set)
141{
142 out << Form("%8.3f", set.fStarAz*TMath::RadToDeg()) << " ";
143 out << Form("%7.3f", set.fStarEl*TMath::RadToDeg()) << " ";
144 out << Form("%8.3f", set.fRawAz*TMath::RadToDeg()) << " ";
145 out << Form("%7.3f", set.fRawEl*TMath::RadToDeg()) << " ";
146 out << Form("%6.3f", set.fMag);
147
148 return out;
149}
Note: See TracBrowser for help on using the repository browser.