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

Last change on this file since 10083 was 9518, checked in by tbretz, 15 years ago
*** empty log message ***
File size: 44.2 KB
Line 
1/* ======================================================================== *\
2! $Name: not supported by cvs2svn $:$Id: MAstroCatalog.cc,v 1.34 2009-10-26 14:31:17 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// Datacenter default path for catalogs
172const TString MAstroCatalog::kDefaultPath="/magic/datacenter/setup/";
173
174// --------------------------------------------------------------------------
175//
176// Default Constructor. Set Default values:
177// fLimMag = 99
178// fRadiusFOV = 90
179//
180MAstroCatalog::MAstroCatalog() : fLimMag(99), fRadiusFOV(90), fToolTip(0), fObservatory(0), fTime(0)
181{
182 fList.SetOwner();
183 fMapG.SetOwner();
184
185 fToolTip = gROOT->IsBatch() || !gClient ? 0 : new TGToolTip(0, "", 0);
186
187 fAttLineSky.SetLineStyle(kDashDotted);
188 fAttLineLocal.SetLineStyle(kDashDotted);
189
190 fAttLineSky.SetLineColor(kRed);
191 fAttLineLocal.SetLineColor(kBlue);
192
193 SetMarkerColor(kBlack);
194 SetMarkerStyle(kCircle);
195}
196
197// --------------------------------------------------------------------------
198//
199// Destructor. Delete fTime, fObservatory. Disconnect signal. delete tooltip.
200// Delete Map with gui primitives
201//
202MAstroCatalog::~MAstroCatalog()
203{
204 // First disconnect the EventInfo...
205 // FIXME: There must be an easier way!
206 TIter Next(gROOT->GetListOfCanvases());
207 TCanvas *c;
208 while ((c=(TCanvas*)Next()))
209 c->Disconnect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", this,
210 "EventInfo(Int_t,Int_t,Int_t,TObject*)");
211
212 // Now delete the data members
213 if (fTime)
214 delete fTime;
215 if (fObservatory)
216 delete fObservatory;
217
218 if (fToolTip)
219 {
220 fToolTip->Hide();
221 delete fToolTip;
222 }
223}
224
225// --------------------------------------------------------------------------
226//
227// Set Radius of FOV using the pixsize [arcsec/pix], width
228// and height [pixel] of image
229//
230void MAstroCatalog::SetRadiusFOV(Double_t pixsize, Double_t w, Double_t h)
231{
232 // pixsize [arcsec/pixel]
233 // w [pixel]
234 // h [pixel]
235 const Double_t scale = TMath::Hypot(w, h)/2;
236 SetRadiusFOV(scale*pixsize/3600);
237}
238
239// --------------------------------------------------------------------------
240//
241// Snippet to for reading catalog files.
242//
243TString MAstroCatalog::FindToken(TString &line, Char_t tok)
244{
245 Ssiz_t token = line.First(tok);
246 if (token<0)
247 {
248 const TString copy(line);
249 line = "";
250 return copy;
251 }
252
253 const TString res = line(0, token);
254 line.Remove(0, token+1);
255 return res;
256}
257
258// --------------------------------------------------------------------------
259//
260// return int correspoding to TString
261//
262Int_t MAstroCatalog::atoi(const TString &s)
263{
264 return const_cast<TString&>(s).Atoi();
265}
266
267// --------------------------------------------------------------------------
268//
269// return float correspoding to TString
270//
271Float_t MAstroCatalog::atof(const TString &s)
272{
273 return const_cast<TString&>(s).Atof();
274}
275
276// --------------------------------------------------------------------------
277//
278// Read from a xephem catalog, set bit kHasChahanged.
279// Already read data is not deleted. To delete the stored data call
280// Delete().
281//
282Int_t MAstroCatalog::ReadXephem(TString catalog)
283{
284 gLog << inf << "Reading Xephem catalog: " << catalog << endl;
285
286 gSystem->ExpandPathName(catalog);
287 if (gSystem->AccessPathName(catalog, kReadPermission))
288 {
289 gLog << inf2 << "Searching Xephem catalog " << catalog << " in " << kDefaultPath << endl;
290 catalog.Prepend(kDefaultPath);
291 }
292
293 MZlib fin(catalog);
294 if (!fin)
295 {
296 gLog << err << "Cannot open catalog file " << catalog << ": ";
297 gLog << strerror(errno) << endl;
298 return 0;
299 }
300
301 Int_t add=0;
302 Int_t cnt=0;
303 Int_t pos=0;
304
305 Double_t maxmag=0;
306
307 while (1)
308 {
309 TString row;
310 row.ReadLine(fin);
311 if (!fin)
312 break;
313
314 pos++;
315
316 if (row[0]=='#')
317 continue;
318
319 TString line(row);
320
321 TString name = FindToken(line);
322 TString dummy = FindToken(line);
323 TString r = FindToken(line);
324 TString d = FindToken(line);
325 TString m = FindToken(line);
326 TString epoch = FindToken(line);
327
328 if (name.IsNull() || r.IsNull() || d.IsNull() || m.IsNull() || epoch.IsNull())
329 {
330 gLog << warn << "Invalid Entry Line #" << pos << ": " << row << endl;
331 continue;
332 }
333
334 cnt++;
335
336 const Double_t mag = atof(m);
337
338 maxmag = TMath::Max(maxmag, mag);
339
340 if (mag>fLimMag)
341 continue;
342
343 if (epoch.Atoi()!=2000)
344 {
345 gLog << warn << "Epoch != 2000... skipped." << endl;
346 continue;
347 }
348
349 Double_t ra0, dec0;
350 MAstro::Coordinate2Angle(r, ra0);
351 MAstro::Coordinate2Angle(d, dec0);
352
353 ra0 *= TMath::Pi()/12;
354 dec0 *= TMath::Pi()/180;
355
356 if (AddObject(ra0, dec0, mag, name))
357 add++;
358 }
359 gLog << inf << "Read " << add << " out of " << cnt << " (Total max mag=" << maxmag << ")" << endl;
360
361 return add;
362}
363
364// --------------------------------------------------------------------------
365//
366// Read from a NGC2000 catalog. set bit kHasChanged
367// Already read data is not deleted. To delete the stored data call
368// Delete().
369//
370Int_t MAstroCatalog::ReadNGC2000(TString catalog)
371{
372 gLog << inf << "Reading NGC2000 catalog: " << catalog << endl;
373
374 gSystem->ExpandPathName(catalog);
375 if (gSystem->AccessPathName(catalog, kReadPermission))
376 {
377 gLog << inf2 << "Searching NGC2000 catalog " << catalog << " in " << kDefaultPath << endl;
378 catalog.Prepend(kDefaultPath);
379 }
380
381 MZlib fin(catalog);
382 if (!fin)
383 {
384 gLog << err << "Cannot open catalog file " << catalog << ": ";
385 gLog << strerror(errno) << endl;
386 return 0;
387 }
388
389 Int_t add=0;
390 Int_t cnt=0;
391 Int_t n =0;
392
393 Double_t maxmag=0;
394
395 while (1)
396 {
397 TString row;
398 row.ReadLine(fin);
399 if (!fin)
400 break;
401
402 cnt++;
403
404 const Int_t rah = atoi(row(13, 2));
405 const Float_t ram = atof(row(16, 4));
406 const Char_t decs = row(22);
407 const Int_t decd = atoi(row(23, 2));
408 const Int_t decm = atoi(row(26, 2));
409 const TString m = row(43, 4);
410
411 if (m.Strip().IsNull())
412 continue;
413
414 n++;
415
416 const Double_t mag = atof(m);
417
418 maxmag = TMath::Max(maxmag, mag);
419
420 if (mag>fLimMag)
421 continue;
422
423 const Double_t ra = MAstro::Hms2Rad(rah, (int)ram, fmod(ram, 1)*60);
424 const Double_t dec = MAstro::Dms2Rad(decd, decm, 0, decs);
425
426 if (AddObject(ra, dec, mag, row(0,8)))
427 add++;
428 }
429
430 gLog << inf << "Read " << add << " out of " << n << " (Total max mag=" << maxmag << ")" << endl;
431
432 return add;
433}
434
435// --------------------------------------------------------------------------
436//
437// Read from a Bright Star Catalog catalog. set bit kHasChanged
438// Already read data is not deleted. To delete the stored data call
439// Delete().
440//
441Int_t MAstroCatalog::ReadBSC(TString catalog)
442{
443 gLog << inf << "Reading Bright Star Catalog (BSC5) catalog: " << catalog << endl;
444
445 gSystem->ExpandPathName(catalog);
446 if (gSystem->AccessPathName(catalog, kReadPermission))
447 {
448 gLog << inf2 << "Searching Bright Star catalog " << catalog << " in " << kDefaultPath << endl;
449 catalog.Prepend(kDefaultPath);
450 }
451
452 MZlib fin(catalog);
453 if (!fin)
454 {
455 gLog << err << "Cannot open catalog file " << catalog << ": ";
456 gLog << strerror(errno) << endl;
457 return 0;
458 }
459
460 Int_t add=0;
461 Int_t cnt=0;
462 Int_t n =0;
463
464 Double_t maxmag=0;
465
466 while (1)
467 {
468 TString row;
469 row.ReadLine(fin);
470 if (!fin)
471 break;
472
473 cnt++;
474
475 const Int_t rah = atoi(row(75, 2));
476 const Int_t ram = atoi(row(77, 2));
477 const Float_t ras = atof(row(79, 4));
478 const Char_t decsgn = row(83);
479 const Int_t decd = atoi(row(84, 2));
480 const Int_t decm = atoi(row(86, 2));
481 const Int_t decs = atoi(row(88, 2));
482 const TString m = row(102, 5);
483
484 if (m.Strip().IsNull())
485 continue;
486
487 n++;
488
489 const Double_t mag = atof(m.Data());
490
491 maxmag = TMath::Max(maxmag, mag);
492
493 if (mag>fLimMag)
494 continue;
495
496 const Double_t ra = MAstro::Hms2Rad(rah, ram, ras);
497 const Double_t dec = MAstro::Dms2Rad(decd, decm, decs, decsgn);
498
499 if (AddObject(ra, dec, mag, row(4,9)))
500 add++;
501 }
502
503 gLog << inf << "Read " << add << " out of " << n << " (Total max mag=" << maxmag << ")" << endl;
504
505 return add;
506}
507
508// --------------------------------------------------------------------------
509//
510// Read from a ascii heasarc ppm catalog. set bit kHasChanged
511// Already read data is not deleted. To delete the stored data call
512// Delete().
513// If the second argument is given all survived stars are written
514// to a file outname. This files will contain an apropriate compressed
515// file format. You can read such files again using ReadCompressed.
516//
517// FIXME: A General loader for heasarc catlogs is missing, see
518// http://heasarc.gsfc.nasa.gov/W3Browse/star-catalog/
519//
520Int_t MAstroCatalog::ReadHeasarcPPM(TString catalog, TString outname)
521{
522 gLog << inf << "Reading Heasarc PPM catalog: " << catalog << endl;
523
524 gSystem->ExpandPathName(catalog);
525 if (gSystem->AccessPathName(catalog, kReadPermission))
526 {
527 gLog << inf2 << "Searching Heasarc PPM catalog " << catalog << " in " << kDefaultPath << endl;
528 catalog.Prepend(kDefaultPath);
529 }
530
531 MZlib fin(catalog);
532 if (!fin)
533 {
534 gLog << err << "Cannot open catalog file " << catalog << ": ";
535 gLog << strerror(errno) << endl;
536 return 0;
537 }
538
539 ofstream *fout = outname.IsNull() ? 0 : new ofstream(outname);
540 if (fout && !*fout)
541 {
542 gLog << warn << "Cannot open output file " << outname << ": ";
543 gLog << strerror(errno) << endl;
544 delete fout;
545 fout = 0;
546 }
547
548 Int_t add=0;
549 Int_t cnt=0;
550 Int_t n =0;
551
552 Double_t maxmag=0;
553
554 while (1)
555 {
556 TString row;
557 row.ReadLine(fin);
558 if (!fin)
559 break;
560
561 cnt++;
562
563 if (!row.BeginsWith("PPM "))
564 continue;
565
566 const TString name = row(0, row.First('|'));
567 row = row(row.First('|')+1, row.Length());
568 row = row(row.First('|')+1, row.Length());
569
570 const TString vmag = row(0, row.First('|'));
571
572 n++;
573 const Double_t mag = atof(vmag.Data());
574 maxmag = TMath::Max(maxmag, mag);
575 if (mag>fLimMag)
576 continue;
577
578 row = row(row.First('|')+1, row.Length());
579 row = row(row.First('|')+1, row.Length());
580
581 row = row(row.First('|')+1, row.Length());
582 row = row(row.First('|')+1, row.Length());
583
584 row = row(row.First('|')+1, row.Length());
585 row = row(row.First('|')+1, row.Length());
586
587 const TString ra = row(0, row.First('|'));
588 row = row(row.First('|')+1, row.Length());
589 const TString de = row(0, row.First('|'));
590 row = row(row.First('|')+1, row.Length());
591
592 Char_t sgn;
593 Int_t d, m;
594 Float_t s;
595 if (sscanf(ra.Data(), "%d %d %f", &d, &m, &s)!=3)
596 {
597 // gLog << "Error loading entry in line " << i << endl;
598 continue;
599 }
600 const Double_t ra0 = MAstro::Hms2Rad(d, m, s);
601
602 if (sscanf(de.Data(), "%c%d %d %f", &sgn, &d, &m, &s)!=4)
603 {
604 // gLog << "Error loading entry in line " << i << endl;
605 continue;
606 }
607 const Double_t de0 = MAstro::Dms2Rad(d, m, s, sgn);
608
609 if (!AddObject(ra0, de0, mag, name))
610 continue;
611
612 add++;
613
614 if (fout)
615 ((MVector3*)fList.Last())->WriteBinary(*fout);
616 }
617
618 gLog << inf << "Read " << add << " out of " << n << " (Total max mag=" << maxmag << ")" << endl;
619
620 return add;
621}
622
623// --------------------------------------------------------------------------
624//
625// Read from a MAstroCatalog compressed catalog. set bit kHasChanged
626// Already read data is not deleted. To delete the stored data call
627// Delete().
628//
629Int_t MAstroCatalog::ReadCompressed(TString catalog)
630{
631 SetBit(kHasChanged);
632
633 gLog << inf << "Reading MAstroCatalog compressed catalog: " << catalog << endl;
634
635 gSystem->ExpandPathName(catalog);
636 if (gSystem->AccessPathName(catalog, kReadPermission))
637 {
638 gLog << inf2 << "Searching MAstroCatalog comressed catalog " << catalog << " in " << kDefaultPath << endl;
639 catalog.Prepend(kDefaultPath);
640 }
641
642 MZlib fin(catalog);
643 if (!fin)
644 {
645 gLog << err << "Cannot open catalog file " << catalog << ": ";
646 gLog << strerror(errno) << endl;
647 return 0;
648 }
649
650 Int_t add=0;
651 Int_t cnt=0;
652 Int_t n =0;
653
654 Double_t maxmag=0;
655
656 MVector3 entry;
657
658 while (1)
659 {
660 cnt++;
661
662 entry.ReadBinary(fin);
663 if (!fin)
664 break;
665
666 n++;
667
668 const Double_t mag = entry.Magnitude();
669 maxmag = TMath::Max(maxmag, mag);
670 if (mag>fLimMag)
671 continue;
672
673 if (entry.Angle(fRaDec)*TMath::RadToDeg()>fRadiusFOV)
674 continue;
675
676 fList.Add(entry.Clone());
677 add++;
678 }
679
680 gLog << inf << "Read " << add << " out of " << n << " (Total max mag=" << maxmag << ")" << endl;
681
682 return add;
683}
684
685// --------------------------------------------------------------------------
686//
687// Add an object to the star catalog manually. Return true if the object
688// was added and false otherwise (criteria is the FOV)
689//
690Bool_t MAstroCatalog::AddObject(Float_t ra, Float_t dec, Float_t mag, TString name)
691{
692 MVector3 *star = new MVector3;
693 star->SetRaDec(ra, dec, mag);
694 star->SetName(name);
695
696 if (star->Angle(fRaDec)*TMath::RadToDeg()>fRadiusFOV)
697 {
698 delete star;
699 return 0;
700 }
701
702 SetBit(kHasChanged);
703 fList.AddLast(star);
704 return 1;
705}
706
707// --------------------------------------------------------------------------
708//
709// Get the visibility curve (altitude vs time) for the current time
710// and observatory for the catalog entry with name name.
711// If name==0 the name of the TGraph is taken instead.
712// The day is divided into as many points as the graph has
713// points. If the graph has no points the default is 96.
714//
715void MAstroCatalog::GetVisibilityCurve(TGraph &g, const char *name) const
716{
717 if (!fTime || !fObservatory)
718 {
719 g.Set(0);
720 return;
721 }
722
723 MVector3 *star = static_cast<MVector3*>(FindObject(name ? name : g.GetName()));
724 if (!star)
725 return;
726
727 const Double_t mjd = TMath::Floor(fTime->GetMjd());
728 const Double_t lng = fObservatory->GetLongitudeDeg()/360;
729
730 if (g.GetN()==0)
731 g.Set(96);
732
733 for (int i=0; i<g.GetN(); i++)
734 {
735 const Double_t offset = (Double_t)i/g.GetN() - 0.5;
736
737 const MTime tm(mjd-lng+offset);
738
739 MVector3 v(*star);
740 v *= MAstroSky2Local(tm.GetGmst(), *fObservatory);
741
742 g.SetPoint(i, tm.GetAxisTime(), 90-v.Theta()*TMath::RadToDeg());
743 }
744
745 TH1 &h = *g.GetHistogram();
746 TAxis &x = *h.GetXaxis();
747 TAxis &y = *h.GetYaxis();
748
749 y.SetTitle("Altitude [\\circ]");
750 y.CenterTitle();
751
752 x.SetTitle("UTC");
753 x.CenterTitle();
754 x.SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
755 x.SetTimeDisplay(1);
756 x.SetLabelSize(0.033);
757
758 const Double_t atm = MTime(mjd).GetAxisTime();
759
760 x.SetRangeUser(atm-(0.5+lng)*24*60*60+15*60, atm+(0.5-lng)*24*60*60-15*60);
761
762 g.SetMinimum(5);
763 g.SetMaximum(90);
764}
765
766// --------------------------------------------------------------------------
767//
768// Set Range of pad. If something has changed create and draw new primitives.
769// Paint all gui primitives.
770//
771void MAstroCatalog::Paint(Option_t *o)
772{
773 if (!fRaDec.IsValid())
774 return;
775
776 SetRangePad(o);
777
778 // In the case MAstroCatalog has been loaded from a file
779 // kHasChanged is not set, but fMapG.GetSize() is ==0
780 if (TestBit(kHasChanged) || fMapG.GetSize()==0)
781 DrawPrimitives(o);
782
783 fMapG.Paint();
784}
785
786// --------------------------------------------------------------------------
787//
788// Set Range of pad if pad available. If something has changed create
789// and draw new primitives. Paint all gui primitives to the Drawable with
790// Id id. This can be used to be able to
791//
792/*
793void MAstroCatalog::PaintImg(Int_t id, Option_t *o)
794{
795 if (gPad)
796 SetRangePad(o);
797
798 if (TestBit(kHasChanged))
799 {
800 if (id>0)
801 gPad=0;
802 DrawPrimitives(o);
803 }
804
805 fMapG.Paint(id, fRadiusFOV);
806}
807*/
808
809// --------------------------------------------------------------------------
810//
811// Set Range of pad. If something has changed create and draw new primitives.
812// Paint all gui primitives.
813//
814// Because in some kind of multi-threaded environments gPad doesn't stay
815// the same in a single thread (because it might be changed in the same
816// thread inside a gui updating timer for example) we have to secure the
817// usage of gPad with a bit. This is also not multi-thread safe against
818// calling this function, but the function should work well in multi-
819// threaded environments. Never call this function from different threads
820// simultaneously.
821//
822void MAstroCatalog::PaintImg(unsigned char *buf, int w, int h, Option_t *o)
823{
824 if (!o)
825 o = "local mirrorx yellow * =";
826
827 if (TestBit(kHasChanged))
828 {
829 SetBit(kDrawingImage);
830 DrawPrimitives(o);
831 ResetBit(kDrawingImage);
832 }
833
834 fMapG.Paint(buf, w, h, fRadiusFOV);
835}
836
837// --------------------------------------------------------------------------
838//
839// Draw a black marker at the position of the star. Create a corresponding
840// tooltip with the coordinates.
841// x, y: Pad Coordinates to draw star
842// v: Sky position (Ra/Dec) of the star
843// col: Color of marker (<0 mean transparent)
844// txt: additional tooltip text
845// resize: means resize the marker according to the magnitude
846//
847void MAstroCatalog::DrawStar(Double_t x, Double_t y, const TVector3 &v, Int_t col, const char *txt, Bool_t resize)
848{
849 const Double_t ra = v.Phi()*TMath::RadToDeg()/15;
850 const Double_t dec = (TMath::Pi()/2-v.Theta())*TMath::RadToDeg();
851
852 const Double_t mag = -2.5*log10(v.Mag());
853
854 TString str(v.GetName());
855 if (!str.IsNull())
856 str += ": ";
857 str += MString::Format("Ra=%.2fh Dec=%.1fd Mag=%.1f", ra, dec, mag);
858 if (txt)
859 {
860 str += " (";
861 str += txt;
862 str += ")";
863 }
864
865 // draw star on the camera display
866 TMarker *tip=new TMarker(x, y, kDot);
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.