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

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