source: trunk/Mars/mastro/MAstroCatalog.cc@ 10316

Last change on this file since 10316 was 10281, checked in by tbretz, 14 years ago
File size: 44.1 KB
Line 
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 expressed
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-2008
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MAstroCatalog
28// =============
29//
30// THIS IMPLEMENTATION IS PRELIMINARY AND WILL BE MERGED WITH
31// SOME PARTS OF THE DRIVE SOFTWARE SOON!
32//
33//
34// Catalogs:
35// ---------
36//
37// To be able to use this class you need a catalog file suppored by
38// MAstroCatalog.
39// Catalog files can be found at
40// http://magic.astro.uni-wuerzburg.de/mars/catalogs.html
41// You must copy the file into the directory from which you start your macro
42// or give an abolute path loading the catalog.
43//
44//
45// Usage:
46// ------
47//
48// To display a starfield you must have a supported catalog, then do:
49//
50// MTime time;
51// // Time for which to get the picture
52// time.Set(2004, 2, 28, 20, 14, 7);
53// // Current observatory
54// MObservatory magic1;
55// // Right Ascension [h] and declination [deg] of source
56// // Currently 'perfect' pointing is assumed
57// const Double_t ra = MAstro::Hms2Rad(5, 34, 31.9);
58// const Double_t dec = MAstro::Dms2Rad(22, 0, 52.0);
59// MAstroCatalog stars;
60// // Magnitude up to which the stars are loaded from the catalog
61// stars.SetLimMag(6);
62// // Radius of FOV around the source position to load the stars
63// stars.SetRadiusFOV(3);
64// // Source position
65// stars.SetRaDec(ra, dec);
66// // Catalog to load (here: Bright Star Catalog V5)
67// stars.ReadBSC("bsc5.dat");
68// // Obersavatory and time to also get local coordinate information
69// stars.SetObservatory(magic1);
70// stars.SetTime(time);
71// // Enable interactive GUI
72// stars.SetGuiActive();
73// //Clone the catalog due to the validity range of the instance
74// TObject *o = stars.Clone();
75// o->SetBit(kCanDelete);
76// o->Draw();
77//
78// If no time and/or Obervatory location is given no local coordinate
79// information is displayed.
80//
81//
82// Coordinate Transformation:
83// -------------------------
84// The conversion from sky coordinates to local coordinates is done using
85// MAstroSky2Local which does a simple rotation of the coordinate system.
86// This is inaccurate in the order of 30arcsec due to ignorance of all
87// astrometrical corrections (nutation, precission, abberation, ...)
88//
89//
90// GUI:
91// ----
92// * If the gui is interactive you can use the cursor keys to change
93// the position you are looking at and with plus/minus you
94// can (un)zoom the FOV (Field Of View)
95// * The displayed values mean the following:
96// + alpha: Right Ascension
97// + delta: Declination
98// + theta: zenith distance / zenith angle
99// + phi: azimuth angle
100// + rho: angle of rotation sky-coordinate system vs local-
101// coordinate system
102// + time of display
103// * Move the mouse on top of the grid points or the stars to get
104// more setailed information.
105// * Enable the event-info in a canvas to see the current
106// ObjectInfo=tooltip-text
107// * call SetNoToolTips to supress the tooltips
108// * the blue lines are the local coordinat system
109// * the red lines are sky coordinate system
110//
111//
112// ToDo:
113// -----
114// - replace MVetcor3 by a more convinient class. Maybe use TExMap, too.
115// - change tooltips to multi-line tools tips as soon as root
116// supports them
117// - a derived class is missing which supports all astrometrical
118// correction (base on slalib and useable in Cosy)
119// - Implement a general loader for heasarc catlogs, see
120// http://heasarc.gsfc.nasa.gov/W3Browse/star-catalog/
121//
122// Class Version 2:
123// + MAttLine fAttLineSky; // Line Style and color for sky coordinates
124// + MAttLine fAttLineLocal; // Line Style and color for local coordinates
125// + added new base class TAttMarker
126//
127//////////////////////////////////////////////////////////////////////////////
128#include "MAstroCatalog.h"
129
130#include <errno.h> // strerror
131#include <stdlib.h> // ati, atof
132#include <limits.h> // INT_MAX (Suse 7.3/gcc 2.95)
133
134#include <KeySymbols.h> // kKey_*
135
136#include <TLine.h> // TLine
137#include <TMarker.h> // TMarker
138#include <TCanvas.h> // TCanvas
139#include <TArrayI.h> // TArrayI
140#include <TGToolTip.h> // TGToolTip
141#include <TPaveText.h> // TPaveText
142
143#include <TH1.h> // TH1F
144#include <TGraph.h> // TGraph
145
146#include "MLog.h"
147#include "MLogManip.h"
148
149#include "MZlib.h" // MZlib <ifstream>
150
151#include "MTime.h"
152#include "MString.h"
153#include "MAstro.h"
154#include "MAstroSky2Local.h"
155#include "MObservatory.h"
156
157#undef DEBUG
158//#define DEBUG
159
160#ifdef DEBUG
161#include <TStopwatch.h>
162#endif
163
164ClassImp(MAttLine);
165ClassImp(MAstroCatalog);
166
167using namespace std;
168
169// Datacenter default path for catalogs
170const TString MAstroCatalog::kDefaultPath="/magic/datacenter/setup/";
171
172// --------------------------------------------------------------------------
173//
174// Default Constructor. Set Default values:
175// fLimMag = 99
176// fRadiusFOV = 90
177//
178MAstroCatalog::MAstroCatalog() : fLimMag(99), fRadiusFOV(90), fToolTip(0), fObservatory(0), fTime(0)
179{
180 fList.SetOwner();
181 fMapG.SetOwner();
182
183 fToolTip = gROOT->IsBatch() || !gClient ? 0 : new TGToolTip(0, "", 0);
184
185 fAttLineSky.SetLineStyle(kDashDotted);
186 fAttLineLocal.SetLineStyle(kDashDotted);
187
188 fAttLineSky.SetLineColor(kRed);
189 fAttLineLocal.SetLineColor(kBlue);
190
191 SetMarkerColor(kBlack);
192 SetMarkerStyle(kCircle);
193}
194
195// --------------------------------------------------------------------------
196//
197// Destructor. Delete fTime, fObservatory. Disconnect signal. delete tooltip.
198// Delete Map with gui primitives
199//
200MAstroCatalog::~MAstroCatalog()
201{
202 // First disconnect the EventInfo...
203 // FIXME: There must be an easier way!
204 TIter Next(gROOT->GetListOfCanvases());
205 TCanvas *c;
206 while ((c=(TCanvas*)Next()))
207 c->Disconnect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", this,
208 "EventInfo(Int_t,Int_t,Int_t,TObject*)");
209
210 // Now delete the data members
211 if (fTime)
212 delete fTime;
213 if (fObservatory)
214 delete fObservatory;
215
216 if (fToolTip)
217 {
218 fToolTip->Hide();
219 delete fToolTip;
220 }
221}
222
223// --------------------------------------------------------------------------
224//
225// Set Radius of FOV using the pixsize [arcsec/pix], width
226// and height [pixel] of image
227//
228void MAstroCatalog::SetRadiusFOV(Double_t pixsize, Double_t w, Double_t h)
229{
230 // pixsize [arcsec/pixel]
231 // w [pixel]
232 // h [pixel]
233 const Double_t scale = TMath::Hypot(w, h)/2;
234 SetRadiusFOV(scale*pixsize/3600);
235}
236
237// --------------------------------------------------------------------------
238//
239// Snippet to for reading catalog files.
240//
241TString MAstroCatalog::FindToken(TString &line, Char_t tok)
242{
243 Ssiz_t token = line.First(tok);
244 if (token<0)
245 {
246 const TString copy(line);
247 line = "";
248 return copy;
249 }
250
251 const TString res = line(0, token);
252 line.Remove(0, token+1);
253 return res;
254}
255
256// --------------------------------------------------------------------------
257//
258// return int correspoding to TString
259//
260Int_t MAstroCatalog::atoi(const TString &s)
261{
262 return const_cast<TString&>(s).Atoi();
263}
264
265// --------------------------------------------------------------------------
266//
267// return float correspoding to TString
268//
269Float_t MAstroCatalog::atof(const TString &s)
270{
271 return const_cast<TString&>(s).Atof();
272}
273
274// --------------------------------------------------------------------------
275//
276// Read from a xephem catalog, set bit kHasChahanged.
277// Already read data is not deleted. To delete the stored data call
278// Delete().
279//
280Int_t MAstroCatalog::ReadXephem(TString catalog)
281{
282 gLog << inf << "Reading Xephem catalog: " << catalog << endl;
283
284 gSystem->ExpandPathName(catalog);
285 if (gSystem->AccessPathName(catalog, kReadPermission))
286 {
287 gLog << inf2 << "Searching Xephem catalog " << catalog << " in " << kDefaultPath << endl;
288 catalog.Prepend(kDefaultPath);
289 }
290
291 MZlib fin(catalog);
292 if (!fin)
293 {
294 gLog << err << "Cannot open catalog file " << catalog << ": ";
295 gLog << strerror(errno) << endl;
296 return 0;
297 }
298
299 Int_t add=0;
300 Int_t cnt=0;
301 Int_t pos=0;
302
303 Double_t maxmag=0;
304
305 while (1)
306 {
307 TString row;
308 row.ReadLine(fin);
309 if (!fin)
310 break;
311
312 pos++;
313
314 if (row[0]=='#')
315 continue;
316
317 TString line(row);
318
319 TString name = FindToken(line);
320 TString dummy = FindToken(line);
321 TString r = FindToken(line);
322 TString d = FindToken(line);
323 TString m = FindToken(line);
324 TString epoch = FindToken(line);
325
326 if (name.IsNull() || r.IsNull() || d.IsNull() || m.IsNull() || epoch.IsNull())
327 {
328 gLog << warn << "Invalid Entry Line #" << pos << ": " << row << endl;
329 continue;
330 }
331
332 cnt++;
333
334 const Double_t mag = atof(m);
335
336 maxmag = TMath::Max(maxmag, mag);
337
338 if (mag>fLimMag)
339 continue;
340
341 if (epoch.Atoi()!=2000)
342 {
343 gLog << warn << "Epoch != 2000... skipped." << endl;
344 continue;
345 }
346
347 Double_t ra0, dec0;
348 MAstro::Coordinate2Angle(r, ra0);
349 MAstro::Coordinate2Angle(d, dec0);
350
351 ra0 *= TMath::Pi()/12;
352 dec0 *= TMath::Pi()/180;
353
354 if (AddObject(ra0, dec0, mag, name))
355 add++;
356 }
357 gLog << inf << "Read " << add << " out of " << cnt << " (Total max mag=" << maxmag << ")" << endl;
358
359 return add;
360}
361
362// --------------------------------------------------------------------------
363//
364// Read from a NGC2000 catalog. set bit kHasChanged
365// Already read data is not deleted. To delete the stored data call
366// Delete().
367//
368Int_t MAstroCatalog::ReadNGC2000(TString catalog)
369{
370 gLog << inf << "Reading NGC2000 catalog: " << catalog << endl;
371
372 gSystem->ExpandPathName(catalog);
373 if (gSystem->AccessPathName(catalog, kReadPermission))
374 {
375 gLog << inf2 << "Searching NGC2000 catalog " << catalog << " in " << kDefaultPath << endl;
376 catalog.Prepend(kDefaultPath);
377 }
378
379 MZlib fin(catalog);
380 if (!fin)
381 {
382 gLog << err << "Cannot open catalog file " << catalog << ": ";
383 gLog << strerror(errno) << endl;
384 return 0;
385 }
386
387 Int_t add=0;
388 Int_t cnt=0;
389 Int_t n =0;
390
391 Double_t maxmag=0;
392
393 while (1)
394 {
395 TString row;
396 row.ReadLine(fin);
397 if (!fin)
398 break;
399
400 cnt++;
401
402 const Int_t rah = atoi(row(13, 2));
403 const Float_t ram = atof(row(16, 4));
404 const Char_t decs = row(22);
405 const Int_t decd = atoi(row(23, 2));
406 const Int_t decm = atoi(row(26, 2));
407 const TString m = row(43, 4);
408
409 if (m.Strip().IsNull())
410 continue;
411
412 n++;
413
414 const Double_t mag = atof(m);
415
416 maxmag = TMath::Max(maxmag, mag);
417
418 if (mag>fLimMag)
419 continue;
420
421 const Double_t ra = MAstro::Hms2Rad(rah, (int)ram, fmod(ram, 1)*60);
422 const Double_t dec = MAstro::Dms2Rad(decd, decm, 0, decs);
423
424 if (AddObject(ra, dec, mag, row(0,8)))
425 add++;
426 }
427
428 gLog << inf << "Read " << add << " out of " << n << " (Total max mag=" << maxmag << ")" << endl;
429
430 return add;
431}
432
433// --------------------------------------------------------------------------
434//
435// Read from a Bright Star Catalog catalog. set bit kHasChanged
436// Already read data is not deleted. To delete the stored data call
437// Delete().
438//
439Int_t MAstroCatalog::ReadBSC(TString catalog)
440{
441 gLog << inf << "Reading Bright Star Catalog (BSC5) catalog: " << catalog << endl;
442
443 gSystem->ExpandPathName(catalog);
444 if (gSystem->AccessPathName(catalog, kReadPermission))
445 {
446 gLog << inf2 << "Searching Bright Star catalog " << catalog << " in " << kDefaultPath << endl;
447 catalog.Prepend(kDefaultPath);
448 }
449
450 MZlib fin(catalog);
451 if (!fin)
452 {
453 gLog << err << "Cannot open catalog file " << catalog << ": ";
454 gLog << strerror(errno) << endl;
455 return 0;
456 }
457
458 Int_t add=0;
459 Int_t cnt=0;
460 Int_t n =0;
461
462 Double_t maxmag=0;
463
464 while (1)
465 {
466 TString row;
467 row.ReadLine(fin);
468 if (!fin)
469 break;
470
471 cnt++;
472
473 const Int_t rah = atoi(row(75, 2));
474 const Int_t ram = atoi(row(77, 2));
475 const Float_t ras = atof(row(79, 4));
476 const Char_t decsgn = row(83);
477 const Int_t decd = atoi(row(84, 2));
478 const Int_t decm = atoi(row(86, 2));
479 const Int_t decs = atoi(row(88, 2));
480 const TString m = row(102, 5);
481
482 if (m.Strip().IsNull())
483 continue;
484
485 n++;
486
487 const Double_t mag = atof(m.Data());
488
489 maxmag = TMath::Max(maxmag, mag);
490
491 if (mag>fLimMag)
492 continue;
493
494 const Double_t ra = MAstro::Hms2Rad(rah, ram, ras);
495 const Double_t dec = MAstro::Dms2Rad(decd, decm, decs, decsgn);
496
497 if (AddObject(ra, dec, mag, row(4,9)))
498 add++;
499 }
500
501 gLog << inf << "Read " << add << " out of " << n << " (Total max mag=" << maxmag << ")" << endl;
502
503 return add;
504}
505
506// --------------------------------------------------------------------------
507//
508// Read from a ascii heasarc ppm catalog. set bit kHasChanged
509// Already read data is not deleted. To delete the stored data call
510// Delete().
511// If the second argument is given all survived stars are written
512// to a file outname. This files will contain an apropriate compressed
513// file format. You can read such files again using ReadCompressed.
514//
515// FIXME: A General loader for heasarc catlogs is missing, see
516// http://heasarc.gsfc.nasa.gov/W3Browse/star-catalog/
517//
518Int_t MAstroCatalog::ReadHeasarcPPM(TString catalog, TString outname)
519{
520 gLog << inf << "Reading Heasarc PPM catalog: " << catalog << endl;
521
522 gSystem->ExpandPathName(catalog);
523 if (gSystem->AccessPathName(catalog, kReadPermission))
524 {
525 gLog << inf2 << "Searching Heasarc PPM catalog " << catalog << " in " << kDefaultPath << endl;
526 catalog.Prepend(kDefaultPath);
527 }
528
529 MZlib fin(catalog);
530 if (!fin)
531 {
532 gLog << err << "Cannot open catalog file " << catalog << ": ";
533 gLog << strerror(errno) << endl;
534 return 0;
535 }
536
537 ofstream *fout = outname.IsNull() ? 0 : new ofstream(outname);
538 if (fout && !*fout)
539 {
540 gLog << warn << "Cannot open output file " << outname << ": ";
541 gLog << strerror(errno) << endl;
542 delete fout;
543 fout = 0;
544 }
545
546 Int_t add=0;
547 Int_t cnt=0;
548 Int_t n =0;
549
550 Double_t maxmag=0;
551
552 while (1)
553 {
554 TString row;
555 row.ReadLine(fin);
556 if (!fin)
557 break;
558
559 cnt++;
560
561 if (!row.BeginsWith("PPM "))
562 continue;
563
564 const TString name = row(0, row.First('|'));
565 row = row(row.First('|')+1, row.Length());
566 row = row(row.First('|')+1, row.Length());
567
568 const TString vmag = row(0, row.First('|'));
569
570 n++;
571 const Double_t mag = atof(vmag.Data());
572 maxmag = TMath::Max(maxmag, mag);
573 if (mag>fLimMag)
574 continue;
575
576 row = row(row.First('|')+1, row.Length());
577 row = row(row.First('|')+1, row.Length());
578
579 row = row(row.First('|')+1, row.Length());
580 row = row(row.First('|')+1, row.Length());
581
582 row = row(row.First('|')+1, row.Length());
583 row = row(row.First('|')+1, row.Length());
584
585 const TString ra = row(0, row.First('|'));
586 row = row(row.First('|')+1, row.Length());
587 const TString de = row(0, row.First('|'));
588 row = row(row.First('|')+1, row.Length());
589
590 Char_t sgn;
591 Int_t d, m;
592 Float_t s;
593 if (sscanf(ra.Data(), "%d %d %f", &d, &m, &s)!=3)
594 {
595 // gLog << "Error loading entry in line " << i << endl;
596 continue;
597 }
598 const Double_t ra0 = MAstro::Hms2Rad(d, m, s);
599
600 if (sscanf(de.Data(), "%c%d %d %f", &sgn, &d, &m, &s)!=4)
601 {
602 // gLog << "Error loading entry in line " << i << endl;
603 continue;
604 }
605 const Double_t de0 = MAstro::Dms2Rad(d, m, s, sgn);
606
607 if (!AddObject(ra0, de0, mag, name))
608 continue;
609
610 add++;
611
612 if (fout)
613 ((MVector3*)fList.Last())->WriteBinary(*fout);
614 }
615
616 gLog << inf << "Read " << add << " out of " << n << " (Total max mag=" << maxmag << ")" << endl;
617
618 return add;
619}
620
621// --------------------------------------------------------------------------
622//
623// Read from a MAstroCatalog compressed catalog. set bit kHasChanged
624// Already read data is not deleted. To delete the stored data call
625// Delete().
626//
627Int_t MAstroCatalog::ReadCompressed(TString catalog)
628{
629 SetBit(kHasChanged);
630
631 gLog << inf << "Reading MAstroCatalog compressed catalog: " << catalog << endl;
632
633 gSystem->ExpandPathName(catalog);
634 if (gSystem->AccessPathName(catalog, kReadPermission))
635 {
636 gLog << inf2 << "Searching MAstroCatalog comressed catalog " << catalog << " in " << kDefaultPath << endl;
637 catalog.Prepend(kDefaultPath);
638 }
639
640 MZlib fin(catalog);
641 if (!fin)
642 {
643 gLog << err << "Cannot open catalog file " << catalog << ": ";
644 gLog << strerror(errno) << endl;
645 return 0;
646 }
647
648 Int_t add=0;
649 Int_t cnt=0;
650 Int_t n =0;
651
652 Double_t maxmag=0;
653
654 MVector3 entry;
655
656 while (1)
657 {
658 cnt++;
659
660 entry.ReadBinary(fin);
661 if (!fin)
662 break;
663
664 n++;
665
666 const Double_t mag = entry.Magnitude();
667 maxmag = TMath::Max(maxmag, mag);
668 if (mag>fLimMag)
669 continue;
670
671 if (entry.Angle(fRaDec)*TMath::RadToDeg()>fRadiusFOV)
672 continue;
673
674 fList.Add(entry.Clone());
675 add++;
676 }
677
678 gLog << inf << "Read " << add << " out of " << n << " (Total max mag=" << maxmag << ")" << endl;
679
680 return add;
681}
682
683// --------------------------------------------------------------------------
684//
685// Add an object to the star catalog manually. Return true if the object
686// was added and false otherwise (criteria is the FOV)
687//
688Bool_t MAstroCatalog::AddObject(Float_t ra, Float_t dec, Float_t mag, TString name)
689{
690 MVector3 *star = new MVector3;
691 star->SetRaDec(ra, dec, mag);
692 star->SetName(name);
693
694 if (star->Angle(fRaDec)*TMath::RadToDeg()>fRadiusFOV)
695 {
696 delete star;
697 return 0;
698 }
699
700 SetBit(kHasChanged);
701 fList.AddLast(star);
702 return 1;
703}
704
705// --------------------------------------------------------------------------
706//
707// Get the visibility curve (altitude vs time) for the current time
708// and observatory for the catalog entry with name name.
709// If name==0 the name of the TGraph is taken instead.
710// The day is divided into as many points as the graph has
711// points. If the graph has no points the default is 96.
712//
713void MAstroCatalog::GetVisibilityCurve(TGraph &g, const char *name) const
714{
715 if (!fTime || !fObservatory)
716 {
717 g.Set(0);
718 return;
719 }
720
721 MVector3 *star = static_cast<MVector3*>(FindObject(name ? name : g.GetName()));
722 if (!star)
723 return;
724
725 const Double_t mjd = TMath::Floor(fTime->GetMjd());
726 const Double_t lng = fObservatory->GetLongitudeDeg()/360;
727
728 if (g.GetN()==0)
729 g.Set(96);
730
731 for (int i=0; i<g.GetN(); i++)
732 {
733 const Double_t offset = (Double_t)i/g.GetN() - 0.5;
734
735 const MTime tm(mjd-lng+offset);
736
737 MVector3 v(*star);
738 v *= MAstroSky2Local(tm.GetGmst(), *fObservatory);
739
740 g.SetPoint(i, tm.GetAxisTime(), 90-v.Theta()*TMath::RadToDeg());
741 }
742
743 TH1 &h = *g.GetHistogram();
744 TAxis &x = *h.GetXaxis();
745 TAxis &y = *h.GetYaxis();
746
747 y.SetTitle("Altitude [\\circ]");
748 y.CenterTitle();
749
750 x.SetTitle("UTC");
751 x.CenterTitle();
752 x.SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
753 x.SetTimeDisplay(1);
754 x.SetLabelSize(0.033);
755
756 const Double_t atm = MTime(mjd).GetAxisTime();
757
758 x.SetRangeUser(atm-(0.5+lng)*24*60*60+15*60, atm+(0.5-lng)*24*60*60-15*60);
759
760 g.SetMinimum(5);
761 g.SetMaximum(90);
762}
763
764// --------------------------------------------------------------------------
765//
766// Set Range of pad. If something has changed create and draw new primitives.
767// Paint all gui primitives.
768//
769void MAstroCatalog::Paint(Option_t *o)
770{
771 if (!fRaDec.IsValid())
772 return;
773
774 SetRangePad(o);
775
776 // In the case MAstroCatalog has been loaded from a file
777 // kHasChanged is not set, but fMapG.GetSize() is ==0
778 if (TestBit(kHasChanged) || fMapG.GetSize()==0)
779 DrawPrimitives(o);
780
781 fMapG.Paint();
782}
783
784// --------------------------------------------------------------------------
785//
786// Set Range of pad if pad available. If something has changed create
787// and draw new primitives. Paint all gui primitives to the Drawable with
788// Id id. This can be used to be able to
789//
790/*
791void MAstroCatalog::PaintImg(Int_t id, Option_t *o)
792{
793 if (gPad)
794 SetRangePad(o);
795
796 if (TestBit(kHasChanged))
797 {
798 if (id>0)
799 gPad=0;
800 DrawPrimitives(o);
801 }
802
803 fMapG.Paint(id, fRadiusFOV);
804}
805*/
806
807// --------------------------------------------------------------------------
808//
809// Set Range of pad. If something has changed create and draw new primitives.
810// Paint all gui primitives.
811//
812// Because in some kind of multi-threaded environments gPad doesn't stay
813// the same in a single thread (because it might be changed in the same
814// thread inside a gui updating timer for example) we have to secure the
815// usage of gPad with a bit. This is also not multi-thread safe against
816// calling this function, but the function should work well in multi-
817// threaded environments. Never call this function from different threads
818// simultaneously.
819//
820void MAstroCatalog::PaintImg(unsigned char *buf, int w, int h, Option_t *o)
821{
822 if (!o)
823 o = "local mirrorx yellow * =";
824
825 if (TestBit(kHasChanged))
826 {
827 SetBit(kDrawingImage);
828 DrawPrimitives(o);
829 ResetBit(kDrawingImage);
830 }
831
832 fMapG.Paint(buf, w, h, fRadiusFOV);
833}
834
835// --------------------------------------------------------------------------
836//
837// Draw a black marker at the position of the star. Create a corresponding
838// tooltip with the coordinates.
839// x, y: Pad Coordinates to draw star
840// v: Sky position (Ra/Dec) of the star
841// col: Color of marker (<0 mean transparent)
842// txt: additional tooltip text
843// resize: means resize the marker according to the magnitude
844//
845void MAstroCatalog::DrawStar(Double_t x, Double_t y, const TVector3 &v, Int_t col, const char *txt, Bool_t resize)
846{
847 const Double_t ra = v.Phi()*TMath::RadToDeg()/15;
848 const Double_t dec = (TMath::Pi()/2-v.Theta())*TMath::RadToDeg();
849
850 const Double_t mag = -2.5*log10(v.Mag());
851
852 TString str(v.GetName());
853 if (!str.IsNull())
854 str += ": ";
855 str += MString::Format("Ra=%.2fh Dec=%.1fd Mag=%.1f", ra, dec, mag);
856 if (txt)
857 {
858 str += " (";
859 str += txt;
860 str += ")";
861 }
862
863 // draw star on the camera display
864 TMarker *tip=new TMarker(x, y, kDot);
865 tip->SetMarkerColor(col);
866
867 TAttMarker::Copy(*tip);
868
869 fMapG.Add(tip, new TString(str));
870
871 if (resize)
872 tip->SetMarkerSize((10 - (mag>1 ? mag : 1))/15);
873}
874
875// --------------------------------------------------------------------------
876//
877// Set pad as modified.
878//
879void MAstroCatalog::Update(Bool_t upd)
880{
881 SetBit(kHasChanged);
882 if (gPad && TestBit(kMustCleanup))
883 {
884 gPad->Modified();
885 if (upd)
886 gPad->Update();
887 }
888}
889
890// --------------------------------------------------------------------------
891//
892// Set the observation time. Necessary to use local coordinate
893// system. The MTime object is cloned.
894//
895void MAstroCatalog::SetTime(const MTime &time)
896{
897 if (fTime)
898 delete fTime;
899 fTime=(MTime*)time.Clone();
900}
901
902// --------------------------------------------------------------------------
903//
904// Set the observatory location. Necessary to use local coordinate
905// system. The MObservatory object is cloned.
906//
907void MAstroCatalog::SetObservatory(const MObservatory &obs)
908{
909 if (fObservatory)
910 delete fObservatory;
911 fObservatory=new MObservatory;
912 obs.Copy(*fObservatory);
913}
914
915// --------------------------------------------------------------------------
916//
917// Convert the vector to pad coordinates. After conversion
918// the x- coordinate of the vector must be the x coordinate
919// of the pad - the same for y. If the coordinate is inside
920// the current draw area return kTRUE, otherwise kFALSE.
921// If it is an invalid coordinate return kERROR
922//
923Int_t MAstroCatalog::ConvertToPad(const TVector3 &w0, TVector2 &v) const
924{
925 TVector3 w(w0);
926
927 // Stretch such, that the Z-component is alwas the same. Now
928 // X and Y contains the intersection point between the star-light
929 // and the plain of a virtual plain screen (ccd...)
930 if (TestBit(kPlainScreen))
931 w *= 1./w(2);
932
933 w *= TMath::RadToDeg(); // FIXME: *conversion factor?
934 v.Set(TestBit(kMirrorX) ? -w(0) : w(0),
935 TestBit(kMirrorY) ? -w(1) : w(1));
936
937 v=v.Rotate(fAngle*TMath::DegToRad());
938
939 if (w(2)<0)
940 return kERROR;
941
942 if (TestBit(kDrawingImage) || !gPad)
943 return v.Mod2()<fRadiusFOV*fRadiusFOV;
944
945 return v.X()>gPad->GetX1() && v.Y()>gPad->GetY1() &&
946 v.X()<gPad->GetX2() && v.Y()<gPad->GetY2();
947}
948
949// --------------------------------------------------------------------------
950//
951// Convert theta/phi coordinates of v by TRotation into new coordinate
952// system and convert the coordinated to pad by ConvertToPad.
953// The result is retunred in v.
954//
955Int_t MAstroCatalog::Convert(const TRotation &rot, TVector2 &v) const
956{
957 MVector3 w;
958 w.SetMagThetaPhi(1, v.Y(), v.X());
959 w *= rot;
960
961 return ConvertToPad(w, v);
962}
963
964// --------------------------------------------------------------------------
965//
966// Draw a line from v to v+(dx,dy) using Convert/ConvertToPad to get the
967// corresponding pad coordinates.
968//
969Bool_t MAstroCatalog::DrawLine(const TVector2 &v, Int_t dx, Int_t dy, const TRotation &rot, Int_t type)
970{
971 const TVector2 add(dx*TMath::DegToRad(), dy*TMath::DegToRad());
972
973 // Define all lines in the same direction
974 const TVector2 va(dy==1?v:v+add);
975 const TVector2 vb(dy==1?v+add:v);
976
977 TVector2 v0(va);
978 TVector2 v1(vb);
979
980 const Int_t rc0 = Convert(rot, v0);
981 const Int_t rc1 = Convert(rot, v1);
982
983 // Both are kFALSE or both are kERROR
984 if ((rc0|rc1)==kFALSE || (rc0&rc1)==kERROR)
985 return kFALSE;
986
987 TLine *line = new TLine(v0.X(), v0.Y(), v1.X(), v1.Y());
988 if (type==1)
989 dynamic_cast<TAttLine&>(fAttLineSky).Copy(dynamic_cast<TAttLine&>(*line));
990 else
991 dynamic_cast<TAttLine&>(fAttLineLocal).Copy(dynamic_cast<TAttLine&>(*line));
992 fMapG.Add(line);
993
994 if (dx!=0)
995 return kTRUE;
996
997 const TVector2 deg = va*TMath::RadToDeg();
998
999 const TString txt = type==1 ?
1000 MString::Format("Ra=%.2fh Dec=%.1fd", fmod(deg.X()/15+48, 24), fmod(90-deg.Y()+270,180)-90) :
1001 MString::Format("Zd=%.1fd Az=%.1fd", fmod(deg.Y()+270,180)-90, fmod(deg.X()+720, 360));
1002
1003 TMarker *tip=new TMarker(v0.X(), v0.Y(), kDot);
1004 tip->SetMarkerColor(kWhite+type*2);
1005 fMapG.Add(tip, new TString(txt));
1006
1007 return kTRUE;
1008}
1009
1010// --------------------------------------------------------------------------
1011//
1012// Use "local" draw option to align the display to the local
1013// coordinate system instead of the sky coordinate system.
1014// dx, dy are arrays storing recuresively all touched points
1015// stepx, stepy are the step-size of the current grid.
1016//
1017void MAstroCatalog::Draw(const TVector2 &v0, const TRotation &rot, TArrayI &dx, TArrayI &dy, Int_t stepx, Int_t stepy, Int_t type)
1018{
1019 // Calculate the end point
1020 const TVector2 v1 = v0 + TVector2(dx[0]*TMath::DegToRad(), dy[0]*TMath::DegToRad());
1021
1022 // Check whether the point has already been touched.
1023 Int_t idx[] = {1, 1, 1, 1};
1024
1025 Int_t dirs[4][2] = { {0, stepy}, {stepx, 0}, {0, -stepy}, {-stepx, 0} };
1026
1027 // Check for ambiguities.
1028 for (int i=0; i<dx.GetSize(); i++)
1029 {
1030 for (int j=0; j<4; j++)
1031 {
1032 const Bool_t rcx0 = (dx[i]+720)%360==(dx[0]+dirs[j][0]+720)%360;
1033 const Bool_t rcy0 = (dy[i]+360)%180==(dy[0]+dirs[j][1]+360)%180;
1034 if (rcx0&&rcy0)
1035 idx[j] = 0;
1036 }
1037 }
1038
1039 // Enhance size of array by 1, copy current
1040 // position as last entry
1041 dx.Set(dx.GetSize()+1);
1042 dy.Set(dy.GetSize()+1);
1043
1044 dx[dx.GetSize()-1] = dx[0];
1045 dy[dy.GetSize()-1] = dy[0];
1046
1047 // Store current positon
1048 const Int_t d[2] = { dx[0], dy[0] };
1049
1050 for (int i=0; i<4; i++)
1051 if (idx[i])
1052 {
1053 // Calculate new position
1054 dx[0] = d[0]+dirs[i][0];
1055 dy[0] = d[1]+dirs[i][1];
1056
1057 // Draw corresponding line and iterate through grid
1058 if (DrawLine(v1, dirs[i][0], dirs[i][1], rot, type))
1059 Draw(v0, rot, dx, dy, stepx, stepy, type);
1060
1061 dx[0]=d[0];
1062 dy[0]=d[1];
1063 }
1064}
1065
1066// --------------------------------------------------------------------------
1067//
1068// Draw a grid recursively around the point v0 (either Ra/Dec or Zd/Az)
1069// The points in the grid are converted by a TRotation and CovertToPad
1070// to pad coordinates. The type arguemnts is neccessary to create the
1071// correct tooltip (Ra/Dec, Zd/Az) at the grid-points.
1072// From the pointing position the step-size of teh gris is caluclated.
1073//
1074void MAstroCatalog::DrawGrid(const TVector3 &v0, const TRotation &rot, Int_t type)
1075{
1076 TArrayI dx(1);
1077 TArrayI dy(1);
1078
1079 // align to 1deg boundary
1080 TVector2 v(v0.Phi()*TMath::RadToDeg(), v0.Theta()*TMath::RadToDeg());
1081 v.Set((Float_t)TMath::Nint(v.X()), (Float_t)TMath::Nint(v.Y()));
1082
1083 // calculate stepsizes based on visible FOV
1084 Int_t stepx = 1;
1085
1086 if (v.Y()<fRadiusFOV || v.Y()>180-fRadiusFOV)
1087 stepx=36;
1088 else
1089 {
1090 // This is a rough estimate how many degrees are visible
1091 const Float_t m = log(fRadiusFOV/180.)/log(90./(fRadiusFOV+1)+1);
1092 const Float_t t = log(180.)-m*log(fRadiusFOV);
1093 const Float_t f = m*log(90-fabs(90-v.Y()))+t;
1094 const Int_t nx = (Int_t)(exp(f)+0.5);
1095 stepx = nx<4 ? 1 : nx/4;
1096 if (stepx>36)
1097 stepx=36;
1098 }
1099
1100 const Int_t ny = (Int_t)(fRadiusFOV+1);
1101 Int_t stepy = ny<4 ? 1 : ny/4;
1102
1103 // align stepsizes to be devisor or 180 and 90
1104 while (180%stepx)
1105 stepx++;
1106 while (90%stepy)
1107 stepy++;
1108
1109 // align to step-size boundary (search for the nearest one)
1110 Int_t dv = 1;
1111 while ((int)(v.X())%stepx)
1112 {
1113 v.Set(v.X()+dv, v.Y());
1114 dv = -TMath::Sign(TMath::Abs(dv)+1, dv);
1115 }
1116
1117 dv = 1;
1118 while ((int)(v.Y())%stepy)
1119 {
1120 v.Set(v.X(), v.Y()+dv);
1121 dv = -TMath::Sign(TMath::Abs(dv)+1, dv);
1122 }
1123
1124 // draw...
1125 v *= TMath::DegToRad();
1126
1127 Draw(v, rot, dx, dy, stepx, stepy, type);
1128}
1129
1130// --------------------------------------------------------------------------
1131//
1132// Get a rotation matrix which aligns the pointing position
1133// to the center of the x,y plain
1134//
1135TRotation MAstroCatalog::AlignCoordinates(const TVector3 &v) const
1136{
1137 TRotation trans;
1138 trans.RotateZ(-v.Phi());
1139 trans.RotateY(-v.Theta());
1140 trans.RotateZ(-TMath::Pi()/2);
1141 return trans;
1142}
1143
1144// --------------------------------------------------------------------------
1145//
1146// Return the rotation matrix which converts either sky or
1147// local coordinates to coordinates which pole is the current
1148// pointing direction.
1149//
1150TRotation MAstroCatalog::GetGrid(Bool_t local)
1151{
1152 const Bool_t enable = fTime && fObservatory;
1153
1154 // If sky coordinate view is requested get rotation matrix and
1155 // draw corresponding sky-grid and if possible local grid
1156 if (!local)
1157 {
1158 const TRotation trans(AlignCoordinates(fRaDec));
1159
1160 DrawGrid(fRaDec, trans, 1);
1161
1162 if (enable)
1163 {
1164 const MAstroSky2Local rot(*fTime, *fObservatory);
1165 DrawGrid(rot*fRaDec, trans*rot.Inverse(), 2);
1166 }
1167
1168 // Return the correct rotation matrix
1169 return trans;
1170 }
1171
1172 // If local coordinate view is requested get rotation matrix and
1173 // draw corresponding sky-grid and if possible local grid
1174 if (local && enable)
1175 {
1176 const MAstroSky2Local rot(*fTime, *fObservatory);
1177
1178 const TRotation trans(AlignCoordinates(rot*fRaDec));
1179
1180 DrawGrid(fRaDec, trans*rot, 1);
1181 DrawGrid(rot*fRaDec, trans, 2);
1182
1183 // Return the correct rotation matrix
1184 return trans*rot;
1185 }
1186
1187 return TRotation();
1188}
1189
1190// --------------------------------------------------------------------------
1191//
1192// Create the title for the pad.
1193//
1194TString MAstroCatalog::GetPadTitle() const
1195{
1196 const Double_t ra = fRaDec.Phi()*TMath::RadToDeg();
1197 const Double_t dec = (TMath::Pi()/2-fRaDec.Theta())*TMath::RadToDeg();
1198
1199 TString txt;
1200 txt += MString::Format("\\alpha=%.2fh ", fmod(ra/15+48, 24));
1201 txt += MString::Format("\\delta=%.1f\\circ ", fmod(dec+270,180)-90);
1202 txt += MString::Format("/ FOV=%.1f\\circ", fRadiusFOV);
1203
1204 if (!fTime || !fObservatory)
1205 return txt;
1206
1207 const MAstroSky2Local rot(*fTime, *fObservatory);
1208 const TVector3 loc = rot*fRaDec;
1209
1210 const Double_t rho = rot.RotationAngle(fRaDec.Phi(), TMath::Pi()/2-fRaDec.Theta());
1211
1212 const Double_t zd = TMath::RadToDeg()*loc.Theta();
1213 const Double_t az = TMath::RadToDeg()*loc.Phi();
1214
1215 txt.Prepend("#splitline{");
1216 txt += MString::Format(" \\theta=%.1f\\circ ", fmod(zd+270,180)-90);
1217 txt += MString::Format("\\phi=%.1f\\circ ", fmod(az+720, 360));
1218 txt += MString::Format(" / \\rho=%.1f\\circ", rho*TMath::RadToDeg());
1219 txt += "}{<";
1220 txt += fTime->GetSqlDateTime();
1221 txt += ">}";
1222 return txt;
1223}
1224
1225// --------------------------------------------------------------------------
1226//
1227// To overlay the catalog make sure, that in any case you are using
1228// the 'same' option.
1229//
1230// If you want to overlay this on top of any picture which is created
1231// by derotation of the camera plain you have to use the 'mirror' option
1232// the compensate the mirroring of the image in the camera plain.
1233//
1234// If you have already compensated this by x=-x and y=-y when creating
1235// the histogram you can simply overlay the catalog.
1236//
1237// To overlay the catalog on a 2D histogram the histogram must have
1238// units of degrees (which are plain, like you directly convert the
1239// camera units by multiplication to degrees)
1240//
1241// To be 100% exact you must use the option 'plain' which assumes a plain
1242// screen. This is not necessary for the MAGIC-camera because the
1243// difference between both is less than 1e-3.
1244//
1245// You should always be aware of the fact, that the shown stars and the
1246// displayed grid is the ideal case, like a reflection on a virtual
1247// perfectly aligned central mirror. In reality the star-positions are
1248// smeared to the edge of the camera the more the distance to the center
1249// is, such that the center of gravity of the light distribution might
1250// be more far away from the center than the display shows.
1251//
1252// If you want the stars to be displayed as circles with a size
1253// showing their magnitude use "*" as an option.
1254//
1255// Use 'white' to display white instead of black stars
1256// Use 'yellow' to display white instead of black stars
1257//
1258//
1259void MAstroCatalog::AddPrimitives(TString o)
1260{
1261 const Bool_t same = o.Contains("same", TString::kIgnoreCase);
1262 const Bool_t local = o.Contains("local", TString::kIgnoreCase);
1263 const Bool_t mirx = o.Contains("mirrorx", TString::kIgnoreCase);
1264 const Bool_t miry = o.Contains("mirrory", TString::kIgnoreCase);
1265 const Bool_t mirror = o.Contains("mirror", TString::kIgnoreCase) && !mirx && !miry;
1266 const Bool_t size = o.Contains("*", TString::kIgnoreCase);
1267 const Bool_t white = o.Contains("white", TString::kIgnoreCase);
1268 const Bool_t yellow = o.Contains("yellow", TString::kIgnoreCase) && !white;
1269 const Bool_t rot180 = o.Contains("180", TString::kIgnoreCase);
1270 const Bool_t rot270 = o.Contains("270", TString::kIgnoreCase);
1271 const Bool_t rot90 = o.Contains("90", TString::kIgnoreCase);
1272
1273 if (white)
1274 SetMarkerColor(kWhite);
1275
1276 fAngle = 0;
1277 if (rot90)
1278 fAngle=90;
1279 if (rot180)
1280 fAngle=180;
1281 if (rot270)
1282 fAngle=270;
1283
1284 // X is vice versa, because ra is defined anti-clockwise
1285 mirx || mirror ? ResetBit(kMirrorX) : SetBit(kMirrorX);
1286 miry || mirror ? SetBit(kMirrorY) : ResetBit(kMirrorY);
1287
1288 const TRotation rot(GetGrid(local));
1289
1290 TIter Next(&fList);
1291 MVector3 *v=0;
1292 while ((v=(MVector3*)Next()))
1293 {
1294 if (v->Magnitude()>fLimMag)
1295 continue;
1296
1297 TVector2 s(v->Phi(), v->Theta());
1298 if (Convert(rot, s)==kTRUE)
1299 DrawStar(s.X(), s.Y(), *v, yellow?kYellow:(white?kWhite:kBlack), 0, size);
1300 }
1301
1302 if (!same && !TestBit(kDrawingImage) && gPad)
1303 {
1304 TPaveText *pv = new TPaveText(0.01, 0.90, 0.63, 0.99, "brNDC");
1305 pv->AddText(GetPadTitle());
1306 fMapG.Add(pv);
1307 }
1308
1309 TMarker *mk=new TMarker(0, 0, kMultiply);
1310 mk->SetMarkerColor(white||yellow?kWhite:kBlack);
1311 mk->SetMarkerSize(1.5);
1312 fMapG.Add(mk);
1313}
1314
1315// --------------------------------------------------------------------------
1316//
1317// Do nothing if 'same' option given.
1318// Otherwise set pad-range such that x- and y- coordinates have the same
1319// step-size
1320//
1321void MAstroCatalog::SetRangePad(Option_t *o)
1322{
1323 if (TString(o).Contains("same", TString::kIgnoreCase))
1324 return;
1325
1326 const Double_t edge = fRadiusFOV/TMath::Sqrt(2.);
1327 //gPad->Range(-edge, -edge, edge, edge);
1328
1329 const Float_t w = gPad->GetWw();
1330 const Float_t h = gPad->GetWh();
1331
1332 if (w<h)
1333 gPad->Range(-edge, -edge*h/w, edge, edge*h/w);
1334 else
1335 gPad->Range(-edge*w/h, -edge, edge*w/h, edge);
1336}
1337
1338// --------------------------------------------------------------------------
1339//
1340// Bends some pointers into the right direction...
1341// Calls TAttLine::SetLineAttributes and connects some signals
1342// to the gui to recreate the gui elements if something has changed.
1343//
1344void MAstroCatalog::SetLineAttributes(MAttLine &att)
1345{
1346 if (!gPad)
1347 return;
1348
1349 gPad->SetSelected(&att);
1350 gROOT->SetSelectedPrimitive(&att);
1351
1352 att.SetLineAttributes();
1353
1354 TQObject::Connect("TGColorSelect", "ColorSelected(Pixel_t)", "MAstroCatalog", this, "ForceUpdate()");
1355 TQObject::Connect("TGListBox", "Selected(Int_t)", "MAstroCatalog", this, "ForceUpdate()");
1356}
1357
1358// --------------------------------------------------------------------------
1359//
1360// Calls TAttMarker::SetMarkerAttributes and connects some signals
1361// to the gui to recreate the gui elements if something has changed.
1362//
1363void MAstroCatalog::SetMarkerAttributes()
1364{
1365 if (!gPad)
1366 return;
1367
1368 TAttMarker::SetMarkerAttributes();
1369
1370 // Make sure that if something is changed the gui elements
1371 // are recreated
1372 TQObject::Connect("TGedMarkerSelect", "MarkerSelected(Style_t)", "MAstroCatalog", this, "ForceUpdate()");
1373 TQObject::Connect("TGColorSelect", "ColorSelected(Pixel_t)", "MAstroCatalog", this, "ForceUpdate()");
1374 TQObject::Connect("TGListBox", "Selected(Int_t)", "MAstroCatalog", this, "ForceUpdate()");
1375}
1376
1377void MAstroCatalog::DrawPrimitives(Option_t *o)
1378{
1379 fMapG.Delete();
1380
1381 if (!TestBit(kDrawingImage) && gPad)
1382 SetRangePad(o);
1383
1384#ifdef DEBUG
1385 TStopwatch clk;
1386 clk.Start();
1387#endif
1388 AddPrimitives(o);
1389#ifdef DEBUG
1390 clk.Stop();
1391 clk.Print();
1392#endif
1393
1394 // Append to a possible second pad
1395 if (!TestBit(kDrawingImage) && gPad && !gPad->GetListOfPrimitives()->FindObject(this))
1396 AppendPad(o);
1397
1398 ResetBit(kHasChanged);
1399}
1400
1401// --------------------------------------------------------------------------
1402//
1403// Append "this" to current pad
1404// set bit kHasChanged to recreate all gui elements
1405// Connect signal
1406//
1407void MAstroCatalog::Draw(Option_t *o)
1408{
1409 // Append to first pad
1410 AppendPad(o);
1411
1412 // If contents have not previously changed make sure that
1413 // all primitives are recreated.
1414 SetBit(kHasChanged);
1415
1416 // Connect all TCanvas::ProcessedEvent to this->EventInfo
1417 // This means, that after TCanvas has processed an event
1418 // EventInfo of this class is called, see TCanvas::HandleInput
1419 gPad->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
1420 "MAstroCatalog", this,
1421 "EventInfo(Int_t,Int_t,Int_t,TObject*)");
1422}
1423
1424// --------------------------------------------------------------------------
1425//
1426// This function was connected to all created canvases. It is used
1427// to redirect GetObjectInfo into our own status bar.
1428//
1429// The 'connection' is done in Draw. It seems that 'connected'
1430// functions must be public.
1431//
1432void MAstroCatalog::EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
1433{
1434 TCanvas *c = (TCanvas*)gTQSender;
1435
1436 gPad = c ? c->GetSelectedPad() : NULL;
1437 if (!gPad)
1438 return;
1439
1440
1441 // Try to find a corresponding object with kCannotPick set and
1442 // an available TString (for a tool tip)
1443 TString str;
1444 if (!selected || selected==this)
1445 selected = fMapG.PickObject(px, py, str);
1446
1447 if (!selected)
1448 return;
1449
1450 // Handle some gui events
1451 switch (event)
1452 {
1453 case kMouseMotion:
1454 if (fToolTip && !fToolTip->IsMapped() && !str.IsNull())
1455 ShowToolTip(px, py, str);
1456 break;
1457
1458 case kMouseLeave:
1459 if (fToolTip && fToolTip->IsMapped())
1460 fToolTip->Hide();
1461 break;
1462
1463 case kKeyPress:
1464 ExecuteEvent(kKeyPress, px, py);
1465 break;
1466 }
1467}
1468
1469// --------------------------------------------------------------------------
1470//
1471// Handle keyboard events.
1472//
1473void MAstroCatalog::ExecuteEventKbd(Int_t /*keycode*/, Int_t keysym)
1474{
1475 Double_t dra =0;
1476 Double_t ddec=0;
1477
1478 switch (keysym)
1479 {
1480 case kKey_Left:
1481 dra = -TMath::DegToRad();
1482 break;
1483 case kKey_Right:
1484 dra = +TMath::DegToRad();
1485 break;
1486 case kKey_Up:
1487 ddec = +TMath::DegToRad();
1488 break;
1489 case kKey_Down:
1490 ddec = -TMath::DegToRad();
1491 break;
1492 case kKey_Plus:
1493 SetRadiusFOV(fRadiusFOV+1);
1494 break;
1495 case kKey_Minus:
1496 SetRadiusFOV(fRadiusFOV-1);
1497 break;
1498
1499 default:
1500 return;
1501 }
1502
1503 const Double_t r = fRaDec.Phi();
1504 const Double_t d = TMath::Pi()/2-fRaDec.Theta();
1505
1506 SetRaDec(r+dra, d+ddec);
1507
1508 gPad->Update();
1509}
1510
1511// ------------------------------------------------------------------------
1512//
1513// Execute a gui event on the camera
1514//
1515void MAstroCatalog::ExecuteEvent(Int_t event, Int_t mp1, Int_t mp2)
1516{
1517 if (!TestBit(kGuiActive))
1518 return;
1519
1520 if (event==kKeyPress)
1521 ExecuteEventKbd(mp1, mp2);
1522}
1523
1524// --------------------------------------------------------------------------
1525//
1526// Displays a tooltip
1527//
1528void MAstroCatalog::ShowToolTip(Int_t px, Int_t py, const char *txt)
1529{
1530 if (TestBit(kNoToolTips))
1531 return;
1532
1533 Int_t x=0;
1534 Int_t y=0;
1535
1536 const Window_t id1 = gVirtualX->GetWindowID(gPad->GetCanvasID());
1537 const Window_t id2 = fToolTip->GetParent()->GetId();
1538
1539 Window_t id3;
1540 gVirtualX->TranslateCoordinates(id1, id2, px, py, x, y, id3);
1541
1542 // Show tool tip
1543 fToolTip->SetText(txt);
1544 fToolTip->Show(x+4, y+4);
1545}
1546
1547// --------------------------------------------------------------------------
1548//
1549// Calculate distance to primitive by checking all gui elements
1550//
1551Int_t MAstroCatalog::DistancetoPrimitive(Int_t px, Int_t py)
1552{
1553 return fMapG.DistancetoPrimitive(px, py);
1554}
1555
1556// ------------------------------------------------------------------------
1557//
1558// Returns string containing info about the object at position (px,py).
1559// Returned string will be re-used (lock in MT environment).
1560//
1561char *MAstroCatalog::GetObjectInfo(Int_t px, Int_t py) const
1562{
1563 return fMapG.GetObjectInfo(px, py);
1564}
Note: See TracBrowser for help on using the repository browser.