source: trunk/MagicSoft/Cosy/gui/MGAccuracy.cc@ 7788

Last change on this file since 7788 was 7788, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 6.4 KB
Line 
1//
2// This File contains the definition of the MGCoordinates-class
3//
4// Author: Thomas Bretz
5// Version: V1.0 (1-8-2000)
6
7#include "MGAccuracy.h"
8
9#include <iostream.h> // cout
10
11#include <TArc.h>
12#include <TLine.h>
13#include <TText.h>
14#include <TWbox.h>
15#include <TList.h>
16#include <TGaxis.h>
17#include <TGraph.h>
18#include <TCanvas.h>
19
20#include "coord.h"
21#include "MTime.h"
22#include "MAstro.h"
23
24ClassImp(MGAccuracy);
25
26void MGAccuracy::DrawCoordinateSystem()
27{
28 TWbox box;
29 box.DrawWbox(-145*2, 145*2, -15*2, 120*2, 18, 2, 1);
30
31 TText text;
32 text.SetTextAlign(22); // centered, centered (s.TAttText)
33 text.DrawText(-80*2, 132.5*2, "Ctrl Deviation [min]");
34
35
36 TArc arc;
37 arc.SetFillStyle(4000); // transparent
38 arc.SetFillColor(39);
39 arc.SetLineColor(3); // green
40 arc.SetLineStyle(2); // dashed (s. TAttLine)
41 arc.DrawArc(0, 0, 79.1/2.); // 0.5se
42
43 arc.SetLineColor(5); // yellow
44 arc.DrawArc(0, 0, 79.1); // 1.0se
45
46 arc.SetLineColor(2); // red
47 arc.DrawArc(0, 0, 79.1*2.); // 2.0se
48
49
50 text.SetTextAlign(11); // left, bottom (s.TAttText)
51 text.SetTextColor(3);
52 text.DrawText(220, -220, "0.5se");
53
54 text.SetTextColor(5);
55 text.DrawText(220, -250, "1.0se");
56
57 text.SetTextColor(2);
58 text.DrawText(220, -280, "2.0se");
59
60
61 TLine line;
62 line.DrawLine(-65*4, 0, 65*4, 0);
63 line.DrawLine( 0, -65*4, 0, 65*4);
64
65 //
66 // Can be replaced by TGaxis axe; in a later root version
67 // than 3.01/06. I talked to Rene
68 //
69 TGaxis *axe;
70 axe = new TGaxis(-60*4, 0, 60*4, 0, -4, 4, 30204, "+-N");
71 axe->SetTitle("Az"); // \xb0
72 axe->SetBit(kCanDelete);
73 axe->Draw();
74
75 axe = new TGaxis( 0, -60*4, 0, 60*4, -4, 4, 304, "+-N");
76 axe->SetTitle("Zd"); // \xb0
77 axe->SetLabelOffset(-0.02);
78 axe->SetBit(kCanDelete);
79 axe->Draw();
80}
81
82void MGAccuracy::InitText()
83{
84 fTxt = new TText(280, 280, "0' / 0'");
85 fTxt->SetTextAlign(33); // right, top
86 fTxt->SetTextColor(10);
87 fTxt->Draw();
88
89 fList->Add(fTxt);
90}
91
92void MGAccuracy::InitBar()
93{
94 fBar = new TLine(0, 0, 0, 0);
95 fBar->SetLineColor(kBlack);
96 fBar->SetLineStyle(1);
97 fBar->SetLineWidth(5);
98 fBar->Draw();
99
100 fList->Add(fBar);
101}
102
103void MGAccuracy::InitCross()
104{
105 fLin1 = new TLine(0, 0, 0, 0);
106 fLin2 = new TLine(0, 0, 0, 0);
107
108 fLin1->SetLineColor(10); // white (s. TAttFill)
109 fLin2->SetLineColor(10); // white
110 fLin1->SetLineStyle(1); // solid (s. TAttLine)
111 fLin2->SetLineStyle(1);
112
113 fLin1->SetLineWidth(2);
114 fLin2->SetLineWidth(2);
115
116 fLin1->Draw();
117 fLin2->Draw();
118
119 fList->Add(fLin1);
120 fList->Add(fLin2);
121}
122
123MGAccuracy::MGAccuracy(const TGWindow* p, const UInt_t w)
124: MGEmbeddedCanvas("Accuracy", p, w, 300)
125{
126 // FIXME: Overload MapWindow in newer Root versions to remove
127 // the contents of the graph!
128 fGraph = new TGraph;
129 fGraph->SetPoint(0, 0, 0);
130 fGraph->SetLineColor(kBlue);
131 fGraph->SetMarkerColor(kBlue);
132 fGraph->SetMarkerStyle(kFullDotMedium);
133 fGraph->Draw("LP");
134 fList->Add(fGraph);
135 //fGraph->SetNameTitle("AccVsT", "Accuracy vs Min of Time");
136 //fGraph->Draw("APL");
137 //fGraph->SetMarkerSize(2);
138
139 DrawCoordinateSystem();
140
141 InitText();
142 InitCross();
143 InitBar();
144
145 InitCanvas();
146
147 SetNoContextMenu();
148
149 MTime t(-1);
150 fTime = t.GetAxisTime();
151}
152
153MGAccuracy::~MGAccuracy()
154{
155 // cout << "MGAccuracy destroyed." << endl;
156}
157
158// dist [deg]
159void MGAccuracy::UpdateText(Float_t dist)
160{
161 dist *= 3600.; // [sec]
162
163 int rs = (int)floor(fmod(dist, 60.));
164
165 dist /= 60.; // [min]
166 int rm = (int)dist;
167
168 char txt[100];
169 rm ? sprintf(txt, "%d'%02d\"", rm, rs) : sprintf(txt, "%d\"", rs);
170
171 fTxt->SetText(fTxt->GetX(), fTxt->GetY(), txt);
172
173 fBar->SetY2(dist*60); // [sec]
174 if (dist*16384<1*360*60)
175 fBar->SetLineColor(kGreen);
176 else
177 if (dist*16384<2*360*60)
178 fBar->SetLineColor(kYellow);
179 else
180 fBar->SetLineColor(kRed);
181
182 SetModified();
183}
184
185// dist [deg]
186void MGAccuracy::UpdateGraph(Float_t dist)
187{
188 MTime t(-1);
189 const Double_t dtime = t.GetAxisTime()-fTime; // range [-0.5h, 0h]
190
191 dist *= 60; // min
192
193 static int odist = -1;
194 if (odist==(int)(dist*10*60) && dtime<10)
195 return;
196
197 odist = (int)(dist*10*60);
198
199 fGraph->SetPoint(fGraph->GetN(), dtime, dist*60);
200
201 const Double_t ntime = dtime;
202 for (int i=0; i<fGraph->GetN(); i++)
203 {
204 Double_t x, y;
205 fGraph->GetPoint(i, x, y);
206 fGraph->SetPoint(i, x-ntime, y);
207 //cout << i << ": " << x-ntime << " / " << y << endl;
208 }
209 while (fGraph->GetN()>0)
210 {
211 Double_t x, y;
212 fGraph->GetPoint(0, x, y);
213
214 if (x==-ntime && y==0)
215 {
216 fGraph->RemovePoint(0);
217 continue;
218 }
219
220 if (x>-4.75*60)
221 break;
222
223 fGraph->RemovePoint(0);
224 }
225
226 fTime = t.GetAxisTime();
227
228 SetModified();
229
230 //cout << "N1 == " << fGraph->GetN() << endl;
231
232 //fGraph->GetHistogram()->SetXTitle("Time");
233 //fGraph->GetHistogram()->SetYTitle("\\Delta [arcmin]");
234 //fGraph->GetHistogram()->GetXaxis()->SetTimeFormat("%M %F1995-01-01 00:00:00");
235 //fGraph->GetHistogram()->GetXaxis()->SetTimeDisplay(1);
236 //fGraph->GetHistogram()->GetXaxis()->SetLabelSize(0.033);
237}
238
239void MGAccuracy::Update(Float_t pzd, Float_t azd, Float_t aaz)
240{
241 const double dist = MAstro::GetDevAbs(pzd, azd, aaz);
242
243 UpdateText(dist);
244 UpdateGraph(dist);
245}
246
247void MGAccuracy::UpdateCross(Float_t x, Float_t y)
248{
249 //
250 // calculate actual time for planet positions
251 // acc [deg]
252 //
253 // x["], y["]
254 //
255 static int X = ~0;
256 static int Y = ~0;
257
258 int pixx = (int)(x/fPix); // [pix]
259 int pixy = (int)(y/fPix); // [pix]
260
261 if (X==pixx && Y==pixy)
262 return;
263
264 X = pixx;
265 Y = pixy;
266
267 fLin1->SetX1(x-5.);
268 fLin1->SetX2(x+5.);
269
270 fLin2->SetX1(x-5.);
271 fLin2->SetX2(x+5.);
272
273 fLin1->SetY1(y-5.);
274 fLin1->SetY2(y+5.);
275
276 fLin2->SetY1(y+5.);
277 fLin2->SetY2(y-5.);
278
279 SetModified();
280}
281
282void MGAccuracy::Update(ZdAz &pos, ZdAz &dev)
283{
284 // Estimate the distance in az direction on the camera plane
285 const double daz = MAstro::GetDevAbs(pos.Zd(), 0, dev.Az())*3600.;
286
287 //cout << "--> T: " << dev.Az()*60 << " " << dev.Zd()*60. << endl;
288
289 UpdateCross(TMath::Sign(daz, dev.Az()), dev.Zd()*3600.);
290 Update(pos.Zd(), dev.Zd(), dev.Az());
291
292 UpdateCanvas();
293}
Note: See TracBrowser for help on using the repository browser.