source: trunk/MagicSoft/Mars/mastro/MAstroCatalog.cc@ 9166

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