source: trunk/MagicSoft/Cosy/gui/MGStarg.cc@ 7764

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