1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Bretz, 03/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2002-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MAstroCatalog
|
---|
28 | //
|
---|
29 | // THIS IMPLEMENTATION IS PRELIMINARY AND WILL BE MERGED WITH
|
---|
30 | // SOME PARTS OF THE DRIVE SOFTWARE SOON!
|
---|
31 | //
|
---|
32 | //////////////////////////////////////////////////////////////////////////////
|
---|
33 | #include "MAstroCatalog.h"
|
---|
34 |
|
---|
35 | #include <fstream>
|
---|
36 | #include <stdlib.h>
|
---|
37 |
|
---|
38 | #include <KeySymbols.h>
|
---|
39 |
|
---|
40 | #include <TPad.h> // TPad::GetMaxPickDistance
|
---|
41 | #include <TLine.h>
|
---|
42 | #include <TMarker.h>
|
---|
43 | #include <TCanvas.h>
|
---|
44 | #include <TArrayI.h>
|
---|
45 | #include <TGToolTip.h>
|
---|
46 | #include <TRotation.h>
|
---|
47 | #include <TStopwatch.h>
|
---|
48 |
|
---|
49 | #include "MLog.h"
|
---|
50 | #include "MLogManip.h"
|
---|
51 |
|
---|
52 | #include "MTime.h"
|
---|
53 | #include "MAstro.h"
|
---|
54 | #include "MObservatory.h"
|
---|
55 |
|
---|
56 | ClassImp(MVector3);
|
---|
57 | ClassImp(MAstroCatalog);
|
---|
58 |
|
---|
59 | using namespace std;
|
---|
60 |
|
---|
61 | MVector3 MVector3::GetZdAz(const MObservatory &obs, Double_t gmst) const
|
---|
62 | {
|
---|
63 | if (!fType==kIsRaDec)
|
---|
64 | return MVector3();
|
---|
65 |
|
---|
66 | const Double_t alpha = gmst + obs.GetElong();
|
---|
67 |
|
---|
68 | MVector3 zdaz;
|
---|
69 | zdaz.SetZdAz(Theta(), alpha-Phi(), Mag());
|
---|
70 | zdaz.RotateY(obs.GetPhi()-TMath::Pi()/2);
|
---|
71 |
|
---|
72 | return zdaz;
|
---|
73 |
|
---|
74 | /*
|
---|
75 | // ------ The same using slalib, tested in the drive system -------
|
---|
76 | const Double_t alpha = slaGmst(mjd) + obs.GetElong();
|
---|
77 | Double_t el;
|
---|
78 | slaDe2h(fAlpha-ra, dec, obs.GetPhi(), &az, &el);
|
---|
79 | zd = TMath::Pi()/2-el;
|
---|
80 | return;
|
---|
81 | */
|
---|
82 | }
|
---|
83 |
|
---|
84 | MVector3 MVector3::GetZdAz(const MTime &time, MObservatory &obs) const
|
---|
85 | {
|
---|
86 | return GetZdAz(obs, time.GetGmst());
|
---|
87 | }
|
---|
88 |
|
---|
89 | MVector3 MVector3::GetRaDec(const MObservatory &obs, Double_t gmst) const
|
---|
90 | {
|
---|
91 | if (!fType==kIsZdAz)
|
---|
92 | return MVector3();
|
---|
93 |
|
---|
94 | const Double_t alpha = gmst + obs.GetElong();
|
---|
95 |
|
---|
96 | MVector3 v(*this);
|
---|
97 | v.RotateY(TMath::Pi()/2-obs.GetPhi());
|
---|
98 |
|
---|
99 | MVector3 rd;
|
---|
100 | rd.SetRaDec(alpha-v.Phi(), TMath::Pi()/2-v.Theta(), Mag());
|
---|
101 | return rd;
|
---|
102 |
|
---|
103 | /*
|
---|
104 | // ------ The same using slalib, tested in the drive system -------
|
---|
105 | const Double_t alpha = slaGmst(mjd) + obs.GetElong();
|
---|
106 | Double_t el;
|
---|
107 | slaDe2h(fAlpha-ra, dec, obs.GetPhi(), &az, &el);
|
---|
108 | zd = TMath::Pi()/2-el;
|
---|
109 | return;
|
---|
110 | */
|
---|
111 | }
|
---|
112 |
|
---|
113 | MVector3 MVector3::GetRaDec(const MTime &time, MObservatory &obs) const
|
---|
114 | {
|
---|
115 | return GetRaDec(obs, time.GetGmst());
|
---|
116 | }
|
---|
117 |
|
---|
118 | MAstroCatalog::MAstroCatalog() : fLimMag(99), fRadiusFOV(99), fToolTip(0), fObservatory(0), fTime(0)
|
---|
119 | {
|
---|
120 | fList.SetOwner();
|
---|
121 | fToolTip = new TGToolTip(0, "", 0);
|
---|
122 | }
|
---|
123 |
|
---|
124 | MAstroCatalog::~MAstroCatalog()
|
---|
125 | {
|
---|
126 | if (fTime)
|
---|
127 | delete fTime;
|
---|
128 | if (fObservatory)
|
---|
129 | delete fObservatory;
|
---|
130 |
|
---|
131 | fToolTip->Hide();
|
---|
132 | delete fToolTip;
|
---|
133 |
|
---|
134 | DeleteMap();
|
---|
135 |
|
---|
136 | // FIXME: There must be an easier way!
|
---|
137 | TIter Next(gROOT->GetListOfCanvases());
|
---|
138 | TCanvas *c;
|
---|
139 | while ((c=(TCanvas*)Next()))
|
---|
140 | c->Disconnect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", this,
|
---|
141 | "EventInfo(Int_t,Int_t,Int_t,TObject*)");
|
---|
142 |
|
---|
143 | }
|
---|
144 |
|
---|
145 | TString MAstroCatalog::FindToken(TString &line, Char_t tok)
|
---|
146 | {
|
---|
147 | Ssiz_t token = line.First(tok);
|
---|
148 | if (token<0)
|
---|
149 | {
|
---|
150 | const TString copy(line);
|
---|
151 | line = "";
|
---|
152 | return copy;
|
---|
153 | }
|
---|
154 |
|
---|
155 | const TString res = line(0, token);
|
---|
156 | line.Remove(0, token+1);
|
---|
157 | return res;
|
---|
158 | }
|
---|
159 |
|
---|
160 | Int_t MAstroCatalog::atoi(const TSubString &sub)
|
---|
161 | {
|
---|
162 | return atoi(TString(sub));
|
---|
163 | }
|
---|
164 |
|
---|
165 | Float_t MAstroCatalog::atof(const TSubString &sub)
|
---|
166 | {
|
---|
167 | return atof(TString(sub));
|
---|
168 | }
|
---|
169 |
|
---|
170 | Int_t MAstroCatalog::atoi(const TString &s)
|
---|
171 | {
|
---|
172 | return std::atoi(s);
|
---|
173 | }
|
---|
174 |
|
---|
175 | Float_t MAstroCatalog::atof(const TString &s)
|
---|
176 | {
|
---|
177 | return std::atof(s);
|
---|
178 | }
|
---|
179 |
|
---|
180 | Int_t MAstroCatalog::ReadXephem(TString catalog)
|
---|
181 | {
|
---|
182 | SetBit(kHasChanged);
|
---|
183 |
|
---|
184 | gLog << inf << "Reading Xephem catalog: " << catalog << endl;
|
---|
185 |
|
---|
186 | ifstream fin(catalog);
|
---|
187 |
|
---|
188 | Int_t add =0;
|
---|
189 | Int_t cnt =0;
|
---|
190 | Int_t line=0;
|
---|
191 |
|
---|
192 | Double_t maxmag=0;
|
---|
193 |
|
---|
194 | while (1)
|
---|
195 | {
|
---|
196 | TString row;
|
---|
197 | row.ReadLine(fin);
|
---|
198 | if (!fin)
|
---|
199 | break;
|
---|
200 |
|
---|
201 | line++;
|
---|
202 |
|
---|
203 | if (row[0]=='#')
|
---|
204 | continue;
|
---|
205 |
|
---|
206 | TString line(row);
|
---|
207 |
|
---|
208 | TString name = FindToken(line);
|
---|
209 | TString dummy = FindToken(line);
|
---|
210 | TString r = FindToken(line);
|
---|
211 | TString d = FindToken(line);
|
---|
212 | TString m = FindToken(line);
|
---|
213 | TString epoch = FindToken(line);
|
---|
214 |
|
---|
215 | if (name.IsNull() || r.IsNull() || d.IsNull() || m.IsNull() || epoch.IsNull())
|
---|
216 | {
|
---|
217 | gLog << warn << "Invalid Entry Line #" << line << ": " << row << endl;
|
---|
218 | continue;
|
---|
219 | }
|
---|
220 |
|
---|
221 | cnt++;
|
---|
222 |
|
---|
223 | const Double_t mag = atof(m);
|
---|
224 |
|
---|
225 | maxmag = TMath::Max(maxmag, mag);
|
---|
226 |
|
---|
227 | if (mag>fLimMag)
|
---|
228 | continue;
|
---|
229 |
|
---|
230 | if (epoch!="2000")
|
---|
231 | {
|
---|
232 | gLog << warn << "Epoch != 2000... skipped." << endl;
|
---|
233 | continue;
|
---|
234 | }
|
---|
235 |
|
---|
236 | Double_t ra0, dec0;
|
---|
237 | MAstro::Coordinate2Angle(r, ra0);
|
---|
238 | MAstro::Coordinate2Angle(d, dec0);
|
---|
239 |
|
---|
240 | ra0 *= TMath::Pi()/12;
|
---|
241 | dec0 *= TMath::Pi()/180;
|
---|
242 |
|
---|
243 | MVector3 *star=new MVector3;
|
---|
244 | star->SetRaDec(ra0, dec0, mag);
|
---|
245 | star->SetName(name);
|
---|
246 | if (star->Angle(fRaDec)*TMath::RadToDeg()>fRadiusFOV)
|
---|
247 | {
|
---|
248 | delete star;
|
---|
249 | continue;
|
---|
250 | }
|
---|
251 |
|
---|
252 | fList.Add(star);
|
---|
253 | add++;
|
---|
254 | }
|
---|
255 | gLog << inf << "Read " << add << " out of " << cnt << " (Total max mag=" << maxmag << ")" << endl;
|
---|
256 |
|
---|
257 | return add;
|
---|
258 | }
|
---|
259 |
|
---|
260 | Int_t MAstroCatalog::ReadNGC2000(TString catalog)
|
---|
261 | {
|
---|
262 | SetBit(kHasChanged);
|
---|
263 |
|
---|
264 | gLog << inf << "Reading NGC2000 catalog: " << catalog << endl;
|
---|
265 |
|
---|
266 | ifstream fin(catalog);
|
---|
267 |
|
---|
268 | Int_t add=0;
|
---|
269 | Int_t cnt=0;
|
---|
270 | Int_t n =0;
|
---|
271 |
|
---|
272 | Double_t maxmag=0;
|
---|
273 |
|
---|
274 | while (1)
|
---|
275 | {
|
---|
276 | TString row;
|
---|
277 | row.ReadLine(fin);
|
---|
278 | if (!fin)
|
---|
279 | break;
|
---|
280 |
|
---|
281 | cnt++;
|
---|
282 |
|
---|
283 | const Int_t rah = atoi(row(13, 2));
|
---|
284 | const Float_t ram = atof(row(16, 4));
|
---|
285 | const Char_t decs = row(22);
|
---|
286 | const Int_t decd = atoi(row(23, 2));
|
---|
287 | const Int_t decm = atoi(row(26, 2));
|
---|
288 | const TString m = row(43, 4);
|
---|
289 |
|
---|
290 | if (m.Strip().IsNull())
|
---|
291 | continue;
|
---|
292 |
|
---|
293 | n++;
|
---|
294 |
|
---|
295 | const Double_t mag = atof(m);
|
---|
296 |
|
---|
297 | maxmag = TMath::Max(maxmag, mag);
|
---|
298 |
|
---|
299 | if (mag>fLimMag)
|
---|
300 | continue;
|
---|
301 |
|
---|
302 | const Double_t ra = MAstro::Hms2Rad(rah, (int)ram, fmod(ram, 1)*60);
|
---|
303 | const Double_t dec = MAstro::Dms2Rad(decd, decm, 0, decs);
|
---|
304 |
|
---|
305 | MVector3 *star=new MVector3;
|
---|
306 | star->SetRaDec(ra, dec, mag);
|
---|
307 | star->SetName(row(0, 8));
|
---|
308 | if (star->Angle(fRaDec)*TMath::RadToDeg()>fRadiusFOV)
|
---|
309 | {
|
---|
310 | delete star;
|
---|
311 | continue;
|
---|
312 | }
|
---|
313 |
|
---|
314 | fList.Add(star);
|
---|
315 | add++;
|
---|
316 | }
|
---|
317 |
|
---|
318 | gLog << inf << "Read " << add << " out of " << n << " (Total max mag=" << maxmag << ")" << endl;
|
---|
319 |
|
---|
320 | return add;
|
---|
321 | }
|
---|
322 |
|
---|
323 | Int_t MAstroCatalog::ReadBSC(TString catalog)
|
---|
324 | {
|
---|
325 | SetBit(kHasChanged);
|
---|
326 |
|
---|
327 | gLog << inf << "Reading Bright Star Catalog (BSC5) catalog: " << catalog << endl;
|
---|
328 |
|
---|
329 | ifstream fin(catalog);
|
---|
330 |
|
---|
331 | Int_t add=0;
|
---|
332 | Int_t cnt=0;
|
---|
333 | Int_t n =0;
|
---|
334 |
|
---|
335 | Double_t maxmag=0;
|
---|
336 |
|
---|
337 | while (1)
|
---|
338 | {
|
---|
339 | TString row;
|
---|
340 | row.ReadLine(fin);
|
---|
341 | if (!fin)
|
---|
342 | break;
|
---|
343 |
|
---|
344 | cnt++;
|
---|
345 |
|
---|
346 | const Int_t rah = atoi(row(75, 2));
|
---|
347 | const Int_t ram = atoi(row(77, 2));
|
---|
348 | const Float_t ras = atof(row(79, 4));
|
---|
349 | const Char_t decsgn = row(83);
|
---|
350 | const Int_t decd = atoi(row(84, 2));
|
---|
351 | const Int_t decm = atoi(row(86, 2));
|
---|
352 | const Int_t decs = atoi(row(88, 2));
|
---|
353 | const TString m = row(102, 5);
|
---|
354 |
|
---|
355 | if (m.Strip().IsNull())
|
---|
356 | continue;
|
---|
357 |
|
---|
358 | n++;
|
---|
359 |
|
---|
360 | const Double_t mag = atof(m.Data());
|
---|
361 |
|
---|
362 | maxmag = TMath::Max(maxmag, mag);
|
---|
363 |
|
---|
364 | if (mag>fLimMag)
|
---|
365 | continue;
|
---|
366 |
|
---|
367 | const Double_t ra = MAstro::Hms2Rad(rah, ram, ras);
|
---|
368 | const Double_t dec = MAstro::Dms2Rad(decd, decm, decs, decsgn);
|
---|
369 |
|
---|
370 | MVector3 *star=new MVector3;
|
---|
371 | star->SetRaDec(ra, dec, mag);
|
---|
372 | star->SetName(row(4,9));
|
---|
373 | if (star->Angle(fRaDec)*TMath::RadToDeg()>fRadiusFOV)
|
---|
374 | {
|
---|
375 | delete star;
|
---|
376 | continue;
|
---|
377 | }
|
---|
378 |
|
---|
379 | fList.Add(star);
|
---|
380 | add++;
|
---|
381 | }
|
---|
382 |
|
---|
383 | gLog << inf << "Read " << add << " out of " << n << " (Total max mag=" << maxmag << ")" << endl;
|
---|
384 |
|
---|
385 | return add;
|
---|
386 | }
|
---|
387 |
|
---|
388 | Int_t MAstroCatalog::Convert(const TRotation &rot, TVector2 &v, Int_t type)
|
---|
389 | {
|
---|
390 | MVector3 w;
|
---|
391 |
|
---|
392 | switch (type)
|
---|
393 | {
|
---|
394 | case 1:
|
---|
395 | w.SetRaDec(v.X()-fRaDec.Phi(), v.Y(), 1);
|
---|
396 | break;
|
---|
397 |
|
---|
398 | case 2:
|
---|
399 | if (!fTime || !fObservatory)
|
---|
400 | return kFALSE;
|
---|
401 | w.SetZdAz(v.Y(), v.X(), 1);
|
---|
402 | w = w.GetRaDec(*fTime, *fObservatory);
|
---|
403 | w.RotateZ(-fRaDec.Phi());
|
---|
404 | break;
|
---|
405 |
|
---|
406 | default:
|
---|
407 | return kFALSE;
|
---|
408 | }
|
---|
409 |
|
---|
410 | w *= rot;
|
---|
411 |
|
---|
412 | // Stretch such, that the X-component is alwas the same. Now
|
---|
413 | // Y and Z contains the crossing point between the star-light
|
---|
414 | // and the plain of a virtual screen (ccd...)
|
---|
415 | if (TestBit(kPlainScreen))
|
---|
416 | w *= TMath::RadToDeg()/w.X();
|
---|
417 | else
|
---|
418 | w.SetMag(TMath::RadToDeg());
|
---|
419 |
|
---|
420 | v.Set(w(1), w(2));
|
---|
421 |
|
---|
422 | if (w(0)<0)
|
---|
423 | return kERROR;
|
---|
424 |
|
---|
425 | return w(1)>gPad->GetX1() && w(2)>gPad->GetY1() &&
|
---|
426 | w(1)<gPad->GetX2() && w(2)<gPad->GetY2();
|
---|
427 | }
|
---|
428 |
|
---|
429 | Bool_t MAstroCatalog::DrawLine(const TVector2 &v, Double_t dx, Double_t dy, const TRotation &rot, Int_t type)
|
---|
430 | {
|
---|
431 | const TVector2 add(dx*TMath::DegToRad(), dy*TMath::DegToRad());
|
---|
432 |
|
---|
433 | TVector2 v0 = v;
|
---|
434 | TVector2 v1 = v+add;
|
---|
435 |
|
---|
436 | const Int_t rc0 = Convert(rot, v0, type);
|
---|
437 | const Int_t rc1 = Convert(rot, v1, type);
|
---|
438 | // Both are kFALSE or both are kERROR
|
---|
439 | if ((rc0|rc1)==kFALSE || (rc0&rc1)==kERROR)
|
---|
440 | return kFALSE;
|
---|
441 |
|
---|
442 | TLine *line = new TLine(v0.X(), v0.Y(), v1.X(), v1.Y());
|
---|
443 | line->SetBit(kCanDelete);
|
---|
444 | line->SetLineStyle(kDashDotted); //kDashed, kDotted, kDashDotted
|
---|
445 | line->SetLineColor(kWhite+type*2);
|
---|
446 | line->SetBit(kCannotPick);
|
---|
447 | fMapG.Add((Long_t)line, 0);
|
---|
448 |
|
---|
449 | const TVector2 deg = v*TMath::RadToDeg();
|
---|
450 | TString txt = type==1 ?
|
---|
451 | Form("Ra=%.1fh Dec=%.1fd", fmod(deg.X()/15+48, 24), fmod(deg.Y()+270,180)-90) :
|
---|
452 | Form("Zd=%.1fd Az=%.1fd", fmod(deg.Y()+270,180)-90, fmod(deg.X()+720, 360));
|
---|
453 |
|
---|
454 | TMarker *tip=new TMarker(v0.X(), v0.Y(), kDot);
|
---|
455 | tip->SetBit(kCanDelete);
|
---|
456 | tip->SetBit(kCannotPick);
|
---|
457 | tip->SetMarkerColor(kWhite+type*2);
|
---|
458 | fMapG.Add((Long_t)tip, (Long_t)new TString(txt));
|
---|
459 |
|
---|
460 | return kTRUE;
|
---|
461 | }
|
---|
462 |
|
---|
463 | void MAstroCatalog::Draw(const TVector2 &v0, const TRotation &rot, TArrayI &dx, TArrayI &dy, Int_t stepx, Int_t stepy, Int_t type)
|
---|
464 | {
|
---|
465 | const TVector2 v1 = v0 + TVector2(dx[0]*TMath::DegToRad(), dy[0]*TMath::DegToRad());
|
---|
466 |
|
---|
467 | // if (TMath::Abs(v1.Y())>TMath::Pi()/2)
|
---|
468 | // return;
|
---|
469 |
|
---|
470 | const Int_t v0x = (int)(v0.X()*TMath::RadToDeg());
|
---|
471 | const Int_t v0y = (int)(v0.Y()*TMath::RadToDeg());
|
---|
472 |
|
---|
473 | Int_t idx[] = {1, 1, 1, 1};
|
---|
474 |
|
---|
475 | Int_t dirs[4][2] = { {0, stepy}, {stepx, 0}, {0, -stepy}, {-stepx, 0} };
|
---|
476 |
|
---|
477 | for (int i=0; i<dx.GetSize(); i++)
|
---|
478 | {
|
---|
479 | for (int j=0; j<4; j++)
|
---|
480 | {
|
---|
481 | const Bool_t rcx0 = (dx[i]+720)%360==(dx[0]+dirs[j][0]+720)%360;
|
---|
482 | const Bool_t rcy0 = (dy[i]+360)%180==(dy[0]+dirs[j][1]+360)%180;
|
---|
483 | if (rcx0&&rcy0)
|
---|
484 | idx[j] = 0;
|
---|
485 | }
|
---|
486 | }
|
---|
487 |
|
---|
488 | // Enhance size of array by 1, copy current
|
---|
489 | // position as last entry
|
---|
490 | dx.Set(dx.GetSize()+1);
|
---|
491 | dy.Set(dy.GetSize()+1);
|
---|
492 |
|
---|
493 | dx[dx.GetSize()-1] = dx[0];
|
---|
494 | dy[dy.GetSize()-1] = dy[0];
|
---|
495 |
|
---|
496 | // Store current positon
|
---|
497 | const Int_t d[2] = { dx[0], dy[0] };
|
---|
498 |
|
---|
499 | for (int i=0; i<4; i++)
|
---|
500 | if (idx[i])
|
---|
501 | {
|
---|
502 | // Calculate new position
|
---|
503 | //dx[0] = (d[0]+dirs[i][0]+540-v0x)%360-180+v0x;
|
---|
504 | //dy[0] = (d[1]+dirs[i][1]+270-v0y)%180- 90+v0y;
|
---|
505 | dx[0] = d[0]+dirs[i][0];
|
---|
506 | dy[0] = d[1]+dirs[i][1];
|
---|
507 |
|
---|
508 | // Draw corresponding line and iterate through grid
|
---|
509 | if (DrawLine(v1, dirs[i][0], dirs[i][1], rot, type))
|
---|
510 | Draw(v0, rot, dx, dy, stepx, stepy, type);
|
---|
511 |
|
---|
512 | dx[0]=d[0]; dy[0]=d[1];
|
---|
513 | }
|
---|
514 | }
|
---|
515 |
|
---|
516 | void MAstroCatalog::DrawNet(const TVector2 &v0, const TRotation &rot, Int_t type)
|
---|
517 | {
|
---|
518 | //const Double_t step = TMath::DegToRad();
|
---|
519 |
|
---|
520 | TArrayI dx(1);
|
---|
521 | TArrayI dy(1);
|
---|
522 |
|
---|
523 | // align to 1deg boundary
|
---|
524 | TVector2 v = v0*TMath::RadToDeg();
|
---|
525 | v.Set((Float_t)TMath::Nint(v.X()), (Float_t)TMath::Nint(v.Y()));
|
---|
526 |
|
---|
527 | // calculate stepsizes based on visible FOV
|
---|
528 | Int_t stepx=1;
|
---|
529 | if (fabs(v.Y())>90-fRadiusFOV || fabs(v.Y())<fRadiusFOV)
|
---|
530 | stepx = 180/10;
|
---|
531 | else
|
---|
532 | {
|
---|
533 | // This is a rough estimate how many degrees are visible
|
---|
534 | const Float_t m = log(fRadiusFOV/180.)/log(90./fRadiusFOV-1);
|
---|
535 | const Float_t t = log(180.)-m*log(fRadiusFOV);
|
---|
536 | const Int_t n = (Int_t)(exp(m*log(90-fabs(v.Y()))+t)+0.5);
|
---|
537 | stepx = n<4 ? 1 : n/4;
|
---|
538 | }
|
---|
539 |
|
---|
540 | const Int_t n = (Int_t)(fRadiusFOV+1);
|
---|
541 | Int_t stepy = n<4 ? 1 : n/4;
|
---|
542 |
|
---|
543 | // align stepsizes to be devisor or 180 and 90
|
---|
544 | while (180%stepx)
|
---|
545 | stepx++;
|
---|
546 | while (90%stepy)
|
---|
547 | stepy++;
|
---|
548 |
|
---|
549 | // align to step-size boundary
|
---|
550 | while ((int)(v.X())%stepx)
|
---|
551 | v.Set(v.X()+1, v.Y());
|
---|
552 |
|
---|
553 | while ((int)(v.Y())%stepy)
|
---|
554 | v.Set(v.X(), v.Y()+1);
|
---|
555 |
|
---|
556 | // draw...
|
---|
557 | v *= TMath::DegToRad();
|
---|
558 | Draw(v, rot, dx, dy, stepx, stepy, type);
|
---|
559 | }
|
---|
560 |
|
---|
561 | void MAstroCatalog::Paint(Option_t *o)
|
---|
562 | {
|
---|
563 | if (!gPad->IsBatch())
|
---|
564 | gVirtualX->ClearWindow();
|
---|
565 |
|
---|
566 | if (TestBit(kHasChanged))
|
---|
567 | DrawPrimitives(o);
|
---|
568 | }
|
---|
569 |
|
---|
570 | void MAstroCatalog::DrawStar(Double_t x, Double_t y, const TVector3 &v, Bool_t transparent)
|
---|
571 | {
|
---|
572 | const Double_t ra = v.Phi()*TMath::RadToDeg()/15;
|
---|
573 | const Double_t dec = (TMath::Pi()/2-v.Theta())*TMath::RadToDeg();
|
---|
574 |
|
---|
575 | TString str = v.GetName();
|
---|
576 | str += Form(": Ra=%.1fh", ra);
|
---|
577 | str += Form(" Dec=%.1fd", dec);
|
---|
578 | str += Form(" Mag=%.1f", -2.5*log10(v.Mag()));
|
---|
579 |
|
---|
580 | // draw star on the camera display
|
---|
581 | TMarker *tip=new TMarker(x, y, transparent ? kDot : kFullDotLarge);;
|
---|
582 | tip->SetMarkerColor(kBlack);
|
---|
583 | tip->SetBit(kCanDelete);
|
---|
584 | tip->SetBit(kCannotPick);
|
---|
585 | fMapG.Add((Long_t)tip, (Long_t)new TString(str));
|
---|
586 | }
|
---|
587 |
|
---|
588 | void MAstroCatalog::Update()
|
---|
589 | {
|
---|
590 | if (gPad && TestBit(kMustCleanup))
|
---|
591 | {
|
---|
592 | SetBit(kHasChanged);
|
---|
593 | gPad->Modified();
|
---|
594 | }
|
---|
595 | }
|
---|
596 |
|
---|
597 | void MAstroCatalog::SetTime(const MTime &time)
|
---|
598 | {
|
---|
599 | if (fTime)
|
---|
600 | delete fTime;
|
---|
601 | fTime=(MTime*)time.Clone();
|
---|
602 | }
|
---|
603 |
|
---|
604 | void MAstroCatalog::SetObservatory(const MObservatory &obs)
|
---|
605 | {
|
---|
606 | if (fObservatory)
|
---|
607 | delete fObservatory;
|
---|
608 | fObservatory=(MObservatory*)obs.Clone();
|
---|
609 | }
|
---|
610 |
|
---|
611 | void MAstroCatalog::AddPrimitives(Option_t *o)
|
---|
612 | {
|
---|
613 | const Double_t ra = fRaDec.Phi();
|
---|
614 | const Double_t dec = TMath::Pi()/2-fRaDec.Theta();
|
---|
615 |
|
---|
616 | // Precalc Sin/Cos...
|
---|
617 | TRotation trans;
|
---|
618 | trans.Rotate(dec, TVector3(0, 1, 0));
|
---|
619 |
|
---|
620 | const TVector3 zdaz0 = fRaDec.GetZdAz(*fTime, *fObservatory);
|
---|
621 | TVector2 zdaz(zdaz0.Phi(), zdaz0.Theta());
|
---|
622 | MAstroCatalog::DrawNet(zdaz, trans, 2);
|
---|
623 |
|
---|
624 | TVector2 radec(ra, dec);
|
---|
625 | MAstroCatalog::DrawNet(radec, trans, 1);
|
---|
626 |
|
---|
627 | TIter Next(&fList);
|
---|
628 | TVector3 *v=0;
|
---|
629 | while ((v=(TVector3*)Next()))
|
---|
630 | {
|
---|
631 | // FIXME: Check Magnitude!
|
---|
632 | TVector2 s(v->Phi(), TMath::Pi()/2-v->Theta());
|
---|
633 | if (Convert(trans, s, 1)==kTRUE)
|
---|
634 | DrawStar(s.X(), s.Y(), *v, kFALSE);
|
---|
635 | }
|
---|
636 | }
|
---|
637 |
|
---|
638 | void MAstroCatalog::SetRangePad()
|
---|
639 | {
|
---|
640 | const Double_t edge = fRadiusFOV/TMath::Sqrt(2.);
|
---|
641 | gPad->Range(-edge, -edge, edge, edge);
|
---|
642 |
|
---|
643 | cout << gPad->GetWw() << " " << gPad->GetWh() << endl;
|
---|
644 |
|
---|
645 | const Float_t w = gPad->GetWw();
|
---|
646 | const Float_t h = gPad->GetWh();
|
---|
647 |
|
---|
648 | if (w<h)
|
---|
649 | gPad->Range(-edge, -edge*h/w, edge, edge*h/w);
|
---|
650 | else
|
---|
651 | gPad->Range(-edge*w/h, -edge, edge*w/h, edge);
|
---|
652 | }
|
---|
653 |
|
---|
654 | void MAstroCatalog::DrawPrimitives(Option_t *o)
|
---|
655 | {
|
---|
656 | DeleteMap();
|
---|
657 |
|
---|
658 | SetRangePad();
|
---|
659 |
|
---|
660 | TStopwatch clk;
|
---|
661 | clk.Start();
|
---|
662 | AddPrimitives(o);
|
---|
663 | clk.Stop();
|
---|
664 | clk.Print();
|
---|
665 |
|
---|
666 | // Append all objects to pad
|
---|
667 | DrawMap();
|
---|
668 |
|
---|
669 | ResetBit(kHasChanged);
|
---|
670 | }
|
---|
671 |
|
---|
672 | void MAstroCatalog::Draw(Option_t *o)
|
---|
673 | {
|
---|
674 | TObject::Draw(o);
|
---|
675 |
|
---|
676 | if (!TestBit(kHasChanged))
|
---|
677 | DrawPrimitives(o);
|
---|
678 |
|
---|
679 | // Connect all TCanvas::ProcessedEvent to this->EventInfo
|
---|
680 | // This means, that after TCanvas has processed an event
|
---|
681 | // EventInfo of this class is called, see TCanvas::HandleInput
|
---|
682 | gPad->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
|
---|
683 | "MAstroCatalog", this,
|
---|
684 | "EventInfo(Int_t,Int_t,Int_t,TObject*)");
|
---|
685 |
|
---|
686 | // Do this instead of fListG.Draw, because
|
---|
687 | // TCollection overwrites Draw
|
---|
688 | // Would be nice, but doesn't work because the single
|
---|
689 | // graphical object are not handled by TPad anymore...
|
---|
690 | // fListG.AppendPad();
|
---|
691 | }
|
---|
692 |
|
---|
693 | // --------------------------------------------------------------------------
|
---|
694 | //
|
---|
695 | // This function was connected to all created canvases. It is used
|
---|
696 | // to redirect GetObjectInfo into our own status bar.
|
---|
697 | //
|
---|
698 | // The 'connection' is done in AddTab
|
---|
699 | //
|
---|
700 | void MAstroCatalog::EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
|
---|
701 | {
|
---|
702 | // Try to find a corresponding object with kCannotPick set and
|
---|
703 | // an available TString (for a tool tip)
|
---|
704 | if (!selected || selected==this)
|
---|
705 | {
|
---|
706 | Long_t key, val;
|
---|
707 | TExMapIter map(&fMapG);
|
---|
708 | while (map.Next(key, val))
|
---|
709 | {
|
---|
710 | if (!val)
|
---|
711 | continue;
|
---|
712 |
|
---|
713 | TObject *o=(TObject*)key;
|
---|
714 | if (o->DistancetoPrimitive(px, py)>TPad::GetMaxPickDistance())
|
---|
715 | continue;
|
---|
716 |
|
---|
717 | selected = o;
|
---|
718 | break;
|
---|
719 | }
|
---|
720 | }
|
---|
721 |
|
---|
722 | if (!selected)
|
---|
723 | return;
|
---|
724 |
|
---|
725 | TCanvas *c = (TCanvas*)gTQSender;
|
---|
726 |
|
---|
727 | TVirtualPad* save=gPad;
|
---|
728 |
|
---|
729 | gPad = c ? c->GetSelectedPad() : NULL;
|
---|
730 | if (!gPad)
|
---|
731 | return;
|
---|
732 |
|
---|
733 | switch (event)
|
---|
734 | {
|
---|
735 | case kMouseMotion:
|
---|
736 | {
|
---|
737 | TString *s = (TString*)fMapG.GetValue((Long_t)selected);
|
---|
738 | if (!fToolTip->IsMapped() && s)
|
---|
739 | ShowToolTip(px, py, *s);
|
---|
740 | }
|
---|
741 | break;
|
---|
742 |
|
---|
743 | case kMouseLeave:
|
---|
744 | if (fToolTip->IsMapped())
|
---|
745 | fToolTip->Hide();
|
---|
746 | break;
|
---|
747 |
|
---|
748 | case kKeyPress: // Unresolved keyboard event
|
---|
749 | /*
|
---|
750 | switch (px)
|
---|
751 | {
|
---|
752 | case kKey_Plus:
|
---|
753 | case kKey_Minus:*/
|
---|
754 | ExecuteEvent(kKeyPress, px, py);/*
|
---|
755 | break;
|
---|
756 | }
|
---|
757 | break;*/
|
---|
758 | }
|
---|
759 |
|
---|
760 | gPad=save;
|
---|
761 | }
|
---|
762 |
|
---|
763 | void MAstroCatalog::ExecuteEventKbd(Int_t keycode, Int_t keysym)
|
---|
764 | {
|
---|
765 | Double_t dra =0;
|
---|
766 | Double_t ddec=0;
|
---|
767 |
|
---|
768 | switch (keysym)
|
---|
769 | {
|
---|
770 | case kKey_Left:
|
---|
771 | dra = -TMath::DegToRad();
|
---|
772 | break;
|
---|
773 | case kKey_Right:
|
---|
774 | dra = +TMath::DegToRad();
|
---|
775 | break;
|
---|
776 | case kKey_Up:
|
---|
777 | ddec = +TMath::DegToRad();
|
---|
778 | break;
|
---|
779 | case kKey_Down:
|
---|
780 | ddec = -TMath::DegToRad();
|
---|
781 | break;
|
---|
782 | case kKey_Plus:
|
---|
783 | SetRadiusFOV(fRadiusFOV+1);
|
---|
784 | break;
|
---|
785 | case kKey_Minus:
|
---|
786 | SetRadiusFOV(fRadiusFOV-1);
|
---|
787 | break;
|
---|
788 |
|
---|
789 | default:
|
---|
790 | return;
|
---|
791 | }
|
---|
792 |
|
---|
793 | const Double_t r = fRaDec.Phi();
|
---|
794 | const Double_t d = TMath::Pi()/2-fRaDec.Theta();
|
---|
795 |
|
---|
796 | SetRaDec(r+dra, d+ddec);
|
---|
797 |
|
---|
798 | gPad->Update();
|
---|
799 | }
|
---|
800 |
|
---|
801 | // ------------------------------------------------------------------------
|
---|
802 | //
|
---|
803 | // Execute a gui event on the camera
|
---|
804 | //
|
---|
805 | void MAstroCatalog::ExecuteEvent(Int_t event, Int_t mp1, Int_t mp2)
|
---|
806 | {
|
---|
807 | if (!TestBit(kGuiActive))
|
---|
808 | return;
|
---|
809 |
|
---|
810 | if (event==kKeyPress)
|
---|
811 | ExecuteEventKbd(mp1, mp2);
|
---|
812 |
|
---|
813 | }
|
---|
814 |
|
---|
815 | Int_t MAstroCatalog::DistancetoPrimitive(Int_t px, Int_t py)
|
---|
816 | {
|
---|
817 | Int_t min = INT_MAX;
|
---|
818 |
|
---|
819 | Long_t key, val;
|
---|
820 | TExMapIter map(&fMapG);
|
---|
821 | while (map.Next(key, val))
|
---|
822 | {
|
---|
823 | TObject *o=(TObject*)key;
|
---|
824 |
|
---|
825 | const Int_t d = o->DistancetoPrimitive(px, py);
|
---|
826 |
|
---|
827 | if (d<TPad::GetMaxPickDistance())
|
---|
828 | return 0;
|
---|
829 |
|
---|
830 | if (d<min)
|
---|
831 | min=d;
|
---|
832 | }
|
---|
833 |
|
---|
834 | return min;
|
---|
835 | }
|
---|
836 |
|
---|
837 | void MAstroCatalog::ShowToolTip(Int_t px, Int_t py, const char *txt)
|
---|
838 | {
|
---|
839 | Int_t x=0;
|
---|
840 | Int_t y=0;
|
---|
841 |
|
---|
842 | const Window_t id1 = gVirtualX->GetWindowID(gPad->GetCanvasID());
|
---|
843 | const Window_t id2 = fToolTip->GetParent()->GetId();
|
---|
844 |
|
---|
845 | Window_t id3;
|
---|
846 | gVirtualX->TranslateCoordinates(id1, id2, px, py, x, y, id3);
|
---|
847 |
|
---|
848 | // Show tool tip
|
---|
849 | fToolTip->SetText(txt);
|
---|
850 | fToolTip->Show(x+4, y+4);
|
---|
851 | }
|
---|
852 |
|
---|