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

Last change on this file since 12611 was 11553, checked in by tbretz, 13 years ago
Replaced MZlib with izstream
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 <fstream>
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 "izstream.h" // izstream <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 izstream 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 izstream 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 izstream 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 izstream 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 izstream 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 tip->SetMarkerColor(col);
868
869 TAttMarker::Copy(*tip);
870
871 fMapG.Add(tip, new TString(str));
872
873 if (resize)
874 tip->SetMarkerSize((10 - (mag>1 ? mag : 1))/15);
875}
876
877// --------------------------------------------------------------------------
878//
879// Set pad as modified.
880//
881void MAstroCatalog::Update(Bool_t upd)
882{
883 SetBit(kHasChanged);
884 if (gPad && TestBit(kMustCleanup))
885 {
886 gPad->Modified();
887 if (upd)
888 gPad->Update();
889 }
890}
891
892// --------------------------------------------------------------------------
893//
894// Set the observation time. Necessary to use local coordinate
895// system. The MTime object is cloned.
896//
897void MAstroCatalog::SetTime(const MTime &time)
898{
899 if (fTime)
900 delete fTime;
901 fTime=(MTime*)time.Clone();
902}
903
904// --------------------------------------------------------------------------
905//
906// Set the observatory location. Necessary to use local coordinate
907// system. The MObservatory object is cloned.
908//
909void MAstroCatalog::SetObservatory(const MObservatory &obs)
910{
911 if (fObservatory)
912 delete fObservatory;
913 fObservatory=new MObservatory;
914 obs.Copy(*fObservatory);
915}
916
917// --------------------------------------------------------------------------
918//
919// Convert the vector to pad coordinates. After conversion
920// the x- coordinate of the vector must be the x coordinate
921// of the pad - the same for y. If the coordinate is inside
922// the current draw area return kTRUE, otherwise kFALSE.
923// If it is an invalid coordinate return kERROR
924//
925Int_t MAstroCatalog::ConvertToPad(const TVector3 &w0, TVector2 &v) const
926{
927 TVector3 w(w0);
928
929 // Stretch such, that the Z-component is alwas the same. Now
930 // X and Y contains the intersection point between the star-light
931 // and the plain of a virtual plain screen (ccd...)
932 if (TestBit(kPlainScreen))
933 w *= 1./w(2);
934
935 w *= TMath::RadToDeg(); // FIXME: *conversion factor?
936 v.Set(TestBit(kMirrorX) ? -w(0) : w(0),
937 TestBit(kMirrorY) ? -w(1) : w(1));
938
939 v=v.Rotate(fAngle*TMath::DegToRad());
940
941 if (w(2)<0)
942 return kERROR;
943
944 if (TestBit(kDrawingImage) || !gPad)
945 return v.Mod2()<fRadiusFOV*fRadiusFOV;
946
947 return v.X()>gPad->GetX1() && v.Y()>gPad->GetY1() &&
948 v.X()<gPad->GetX2() && v.Y()<gPad->GetY2();
949}
950
951// --------------------------------------------------------------------------
952//
953// Convert theta/phi coordinates of v by TRotation into new coordinate
954// system and convert the coordinated to pad by ConvertToPad.
955// The result is retunred in v.
956//
957Int_t MAstroCatalog::Convert(const TRotation &rot, TVector2 &v) const
958{
959 MVector3 w;
960 w.SetMagThetaPhi(1, v.Y(), v.X());
961 w *= rot;
962
963 return ConvertToPad(w, v);
964}
965
966// --------------------------------------------------------------------------
967//
968// Draw a line from v to v+(dx,dy) using Convert/ConvertToPad to get the
969// corresponding pad coordinates.
970//
971Bool_t MAstroCatalog::DrawLine(const TVector2 &v, Int_t dx, Int_t dy, const TRotation &rot, Int_t type)
972{
973 const TVector2 add(dx*TMath::DegToRad(), dy*TMath::DegToRad());
974
975 // Define all lines in the same direction
976 const TVector2 va(dy==1?v:v+add);
977 const TVector2 vb(dy==1?v+add:v);
978
979 TVector2 v0(va);
980 TVector2 v1(vb);
981
982 const Int_t rc0 = Convert(rot, v0);
983 const Int_t rc1 = Convert(rot, v1);
984
985 // Both are kFALSE or both are kERROR
986 if ((rc0|rc1)==kFALSE || (rc0&rc1)==kERROR)
987 return kFALSE;
988
989 TLine *line = new TLine(v0.X(), v0.Y(), v1.X(), v1.Y());
990 if (type==1)
991 dynamic_cast<TAttLine&>(fAttLineSky).Copy(dynamic_cast<TAttLine&>(*line));
992 else
993 dynamic_cast<TAttLine&>(fAttLineLocal).Copy(dynamic_cast<TAttLine&>(*line));
994 fMapG.Add(line);
995
996 if (dx!=0)
997 return kTRUE;
998
999 const TVector2 deg = va*TMath::RadToDeg();
1000
1001 const TString txt = type==1 ?
1002 MString::Format("Ra=%.2fh Dec=%.1fd", fmod(deg.X()/15+48, 24), fmod(90-deg.Y()+270,180)-90) :
1003 MString::Format("Zd=%.1fd Az=%.1fd", fmod(deg.Y()+270,180)-90, fmod(deg.X()+720, 360));
1004
1005 TMarker *tip=new TMarker(v0.X(), v0.Y(), kDot);
1006 tip->SetMarkerColor(kWhite+type*2);
1007 fMapG.Add(tip, new TString(txt));
1008
1009 return kTRUE;
1010}
1011
1012// --------------------------------------------------------------------------
1013//
1014// Use "local" draw option to align the display to the local
1015// coordinate system instead of the sky coordinate system.
1016// dx, dy are arrays storing recuresively all touched points
1017// stepx, stepy are the step-size of the current grid.
1018//
1019void MAstroCatalog::Draw(const TVector2 &v0, const TRotation &rot, TArrayI &dx, TArrayI &dy, Int_t stepx, Int_t stepy, Int_t type)
1020{
1021 // Calculate the end point
1022 const TVector2 v1 = v0 + TVector2(dx[0]*TMath::DegToRad(), dy[0]*TMath::DegToRad());
1023
1024 // Check whether the point has already been touched.
1025 Int_t idx[] = {1, 1, 1, 1};
1026
1027 Int_t dirs[4][2] = { {0, stepy}, {stepx, 0}, {0, -stepy}, {-stepx, 0} };
1028
1029 // Check for ambiguities.
1030 for (int i=0; i<dx.GetSize(); i++)
1031 {
1032 for (int j=0; j<4; j++)
1033 {
1034 const Bool_t rcx0 = (dx[i]+720)%360==(dx[0]+dirs[j][0]+720)%360;
1035 const Bool_t rcy0 = (dy[i]+360)%180==(dy[0]+dirs[j][1]+360)%180;
1036 if (rcx0&&rcy0)
1037 idx[j] = 0;
1038 }
1039 }
1040
1041 // Enhance size of array by 1, copy current
1042 // position as last entry
1043 dx.Set(dx.GetSize()+1);
1044 dy.Set(dy.GetSize()+1);
1045
1046 dx[dx.GetSize()-1] = dx[0];
1047 dy[dy.GetSize()-1] = dy[0];
1048
1049 // Store current positon
1050 const Int_t d[2] = { dx[0], dy[0] };
1051
1052 for (int i=0; i<4; i++)
1053 if (idx[i])
1054 {
1055 // Calculate new position
1056 dx[0] = d[0]+dirs[i][0];
1057 dy[0] = d[1]+dirs[i][1];
1058
1059 // Draw corresponding line and iterate through grid
1060 if (DrawLine(v1, dirs[i][0], dirs[i][1], rot, type))
1061 Draw(v0, rot, dx, dy, stepx, stepy, type);
1062
1063 dx[0]=d[0];
1064 dy[0]=d[1];
1065 }
1066}
1067
1068// --------------------------------------------------------------------------
1069//
1070// Draw a grid recursively around the point v0 (either Ra/Dec or Zd/Az)
1071// The points in the grid are converted by a TRotation and CovertToPad
1072// to pad coordinates. The type arguemnts is neccessary to create the
1073// correct tooltip (Ra/Dec, Zd/Az) at the grid-points.
1074// From the pointing position the step-size of teh gris is caluclated.
1075//
1076void MAstroCatalog::DrawGrid(const TVector3 &v0, const TRotation &rot, Int_t type)
1077{
1078 TArrayI dx(1);
1079 TArrayI dy(1);
1080
1081 // align to 1deg boundary
1082 TVector2 v(v0.Phi()*TMath::RadToDeg(), v0.Theta()*TMath::RadToDeg());
1083 v.Set((Float_t)TMath::Nint(v.X()), (Float_t)TMath::Nint(v.Y()));
1084
1085 // calculate stepsizes based on visible FOV
1086 Int_t stepx = 1;
1087
1088 if (v.Y()<fRadiusFOV || v.Y()>180-fRadiusFOV)
1089 stepx=36;
1090 else
1091 {
1092 // This is a rough estimate how many degrees are visible
1093 const Float_t m = log(fRadiusFOV/180.)/log(90./(fRadiusFOV+1)+1);
1094 const Float_t t = log(180.)-m*log(fRadiusFOV);
1095 const Float_t f = m*log(90-fabs(90-v.Y()))+t;
1096 const Int_t nx = (Int_t)(exp(f)+0.5);
1097 stepx = nx<4 ? 1 : nx/4;
1098 if (stepx>36)
1099 stepx=36;
1100 }
1101
1102 const Int_t ny = (Int_t)(fRadiusFOV+1);
1103 Int_t stepy = ny<4 ? 1 : ny/4;
1104
1105 // align stepsizes to be devisor or 180 and 90
1106 while (180%stepx)
1107 stepx++;
1108 while (90%stepy)
1109 stepy++;
1110
1111 // align to step-size boundary (search for the nearest one)
1112 Int_t dv = 1;
1113 while ((int)(v.X())%stepx)
1114 {
1115 v.Set(v.X()+dv, v.Y());
1116 dv = -TMath::Sign(TMath::Abs(dv)+1, dv);
1117 }
1118
1119 dv = 1;
1120 while ((int)(v.Y())%stepy)
1121 {
1122 v.Set(v.X(), v.Y()+dv);
1123 dv = -TMath::Sign(TMath::Abs(dv)+1, dv);
1124 }
1125
1126 // draw...
1127 v *= TMath::DegToRad();
1128
1129 Draw(v, rot, dx, dy, stepx, stepy, type);
1130}
1131
1132// --------------------------------------------------------------------------
1133//
1134// Get a rotation matrix which aligns the pointing position
1135// to the center of the x,y plain
1136//
1137TRotation MAstroCatalog::AlignCoordinates(const TVector3 &v) const
1138{
1139 TRotation trans;
1140 trans.RotateZ(-v.Phi());
1141 trans.RotateY(-v.Theta());
1142 trans.RotateZ(-TMath::Pi()/2);
1143 return trans;
1144}
1145
1146// --------------------------------------------------------------------------
1147//
1148// Return the rotation matrix which converts either sky or
1149// local coordinates to coordinates which pole is the current
1150// pointing direction.
1151//
1152TRotation MAstroCatalog::GetGrid(Bool_t local)
1153{
1154 const Bool_t enable = fTime && fObservatory;
1155
1156 // If sky coordinate view is requested get rotation matrix and
1157 // draw corresponding sky-grid and if possible local grid
1158 if (!local)
1159 {
1160 const TRotation trans(AlignCoordinates(fRaDec));
1161
1162 DrawGrid(fRaDec, trans, 1);
1163
1164 if (enable)
1165 {
1166 const MAstroSky2Local rot(*fTime, *fObservatory);
1167 DrawGrid(rot*fRaDec, trans*rot.Inverse(), 2);
1168 }
1169
1170 // Return the correct rotation matrix
1171 return trans;
1172 }
1173
1174 // If local coordinate view is requested get rotation matrix and
1175 // draw corresponding sky-grid and if possible local grid
1176 if (local && enable)
1177 {
1178 const MAstroSky2Local rot(*fTime, *fObservatory);
1179
1180 const TRotation trans(AlignCoordinates(rot*fRaDec));
1181
1182 DrawGrid(fRaDec, trans*rot, 1);
1183 DrawGrid(rot*fRaDec, trans, 2);
1184
1185 // Return the correct rotation matrix
1186 return trans*rot;
1187 }
1188
1189 return TRotation();
1190}
1191
1192// --------------------------------------------------------------------------
1193//
1194// Create the title for the pad.
1195//
1196TString MAstroCatalog::GetPadTitle() const
1197{
1198 const Double_t ra = fRaDec.Phi()*TMath::RadToDeg();
1199 const Double_t dec = (TMath::Pi()/2-fRaDec.Theta())*TMath::RadToDeg();
1200
1201 TString txt;
1202 txt += MString::Format("\\alpha=%.2fh ", fmod(ra/15+48, 24));
1203 txt += MString::Format("\\delta=%.1f\\circ ", fmod(dec+270,180)-90);
1204 txt += MString::Format("/ FOV=%.1f\\circ", fRadiusFOV);
1205
1206 if (!fTime || !fObservatory)
1207 return txt;
1208
1209 const MAstroSky2Local rot(*fTime, *fObservatory);
1210 const TVector3 loc = rot*fRaDec;
1211
1212 const Double_t rho = rot.RotationAngle(fRaDec.Phi(), TMath::Pi()/2-fRaDec.Theta());
1213
1214 const Double_t zd = TMath::RadToDeg()*loc.Theta();
1215 const Double_t az = TMath::RadToDeg()*loc.Phi();
1216
1217 txt.Prepend("#splitline{");
1218 txt += MString::Format(" \\theta=%.1f\\circ ", fmod(zd+270,180)-90);
1219 txt += MString::Format("\\phi=%.1f\\circ ", fmod(az+720, 360));
1220 txt += MString::Format(" / \\rho=%.1f\\circ", rho*TMath::RadToDeg());
1221 txt += "}{<";
1222 txt += fTime->GetSqlDateTime();
1223 txt += ">}";
1224 return txt;
1225}
1226
1227// --------------------------------------------------------------------------
1228//
1229// To overlay the catalog make sure, that in any case you are using
1230// the 'same' option.
1231//
1232// If you want to overlay this on top of any picture which is created
1233// by derotation of the camera plain you have to use the 'mirror' option
1234// the compensate the mirroring of the image in the camera plain.
1235//
1236// If you have already compensated this by x=-x and y=-y when creating
1237// the histogram you can simply overlay the catalog.
1238//
1239// To overlay the catalog on a 2D histogram the histogram must have
1240// units of degrees (which are plain, like you directly convert the
1241// camera units by multiplication to degrees)
1242//
1243// To be 100% exact you must use the option 'plain' which assumes a plain
1244// screen. This is not necessary for the MAGIC-camera because the
1245// difference between both is less than 1e-3.
1246//
1247// You should always be aware of the fact, that the shown stars and the
1248// displayed grid is the ideal case, like a reflection on a virtual
1249// perfectly aligned central mirror. In reality the star-positions are
1250// smeared to the edge of the camera the more the distance to the center
1251// is, such that the center of gravity of the light distribution might
1252// be more far away from the center than the display shows.
1253//
1254// If you want the stars to be displayed as circles with a size
1255// showing their magnitude use "*" as an option.
1256//
1257// Use 'white' to display white instead of black stars
1258// Use 'yellow' to display white instead of black stars
1259//
1260//
1261void MAstroCatalog::AddPrimitives(TString o)
1262{
1263 const Bool_t same = o.Contains("same", TString::kIgnoreCase);
1264 const Bool_t local = o.Contains("local", TString::kIgnoreCase);
1265 const Bool_t mirx = o.Contains("mirrorx", TString::kIgnoreCase);
1266 const Bool_t miry = o.Contains("mirrory", TString::kIgnoreCase);
1267 const Bool_t mirror = o.Contains("mirror", TString::kIgnoreCase) && !mirx && !miry;
1268 const Bool_t size = o.Contains("*", TString::kIgnoreCase);
1269 const Bool_t white = o.Contains("white", TString::kIgnoreCase);
1270 const Bool_t yellow = o.Contains("yellow", TString::kIgnoreCase) && !white;
1271 const Bool_t rot180 = o.Contains("180", TString::kIgnoreCase);
1272 const Bool_t rot270 = o.Contains("270", TString::kIgnoreCase);
1273 const Bool_t rot90 = o.Contains("90", TString::kIgnoreCase);
1274
1275 if (white)
1276 SetMarkerColor(kWhite);
1277
1278 fAngle = 0;
1279 if (rot90)
1280 fAngle=90;
1281 if (rot180)
1282 fAngle=180;
1283 if (rot270)
1284 fAngle=270;
1285
1286 // X is vice versa, because ra is defined anti-clockwise
1287 mirx || mirror ? ResetBit(kMirrorX) : SetBit(kMirrorX);
1288 miry || mirror ? SetBit(kMirrorY) : ResetBit(kMirrorY);
1289
1290 const TRotation rot(GetGrid(local));
1291
1292 TIter Next(&fList);
1293 MVector3 *v=0;
1294 while ((v=(MVector3*)Next()))
1295 {
1296 if (v->Magnitude()>fLimMag)
1297 continue;
1298
1299 TVector2 s(v->Phi(), v->Theta());
1300 if (Convert(rot, s)==kTRUE)
1301 DrawStar(s.X(), s.Y(), *v, yellow?kYellow:(white?kWhite:kBlack), 0, size);
1302 }
1303
1304 if (!same && !TestBit(kDrawingImage) && gPad)
1305 {
1306 TPaveText *pv = new TPaveText(0.01, 0.90, 0.63, 0.99, "brNDC");
1307 pv->AddText(GetPadTitle());
1308 fMapG.Add(pv);
1309 }
1310
1311 TMarker *mk=new TMarker(0, 0, kMultiply);
1312 mk->SetMarkerColor(white||yellow?kWhite:kBlack);
1313 mk->SetMarkerSize(1.5);
1314 fMapG.Add(mk);
1315}
1316
1317// --------------------------------------------------------------------------
1318//
1319// Do nothing if 'same' option given.
1320// Otherwise set pad-range such that x- and y- coordinates have the same
1321// step-size
1322//
1323void MAstroCatalog::SetRangePad(Option_t *o)
1324{
1325 if (TString(o).Contains("same", TString::kIgnoreCase))
1326 return;
1327
1328 const Double_t edge = fRadiusFOV/TMath::Sqrt(2.);
1329 //gPad->Range(-edge, -edge, edge, edge);
1330
1331 const Float_t w = gPad->GetWw();
1332 const Float_t h = gPad->GetWh();
1333
1334 if (w<h)
1335 gPad->Range(-edge, -edge*h/w, edge, edge*h/w);
1336 else
1337 gPad->Range(-edge*w/h, -edge, edge*w/h, edge);
1338}
1339
1340// --------------------------------------------------------------------------
1341//
1342// Bends some pointers into the right direction...
1343// Calls TAttLine::SetLineAttributes and connects some signals
1344// to the gui to recreate the gui elements if something has changed.
1345//
1346void MAstroCatalog::SetLineAttributes(MAttLine &att)
1347{
1348 if (!gPad)
1349 return;
1350
1351 gPad->SetSelected(&att);
1352 gROOT->SetSelectedPrimitive(&att);
1353
1354 att.SetLineAttributes();
1355
1356 TQObject::Connect("TGColorSelect", "ColorSelected(Pixel_t)", "MAstroCatalog", this, "ForceUpdate()");
1357 TQObject::Connect("TGListBox", "Selected(Int_t)", "MAstroCatalog", this, "ForceUpdate()");
1358}
1359
1360// --------------------------------------------------------------------------
1361//
1362// Calls TAttMarker::SetMarkerAttributes and connects some signals
1363// to the gui to recreate the gui elements if something has changed.
1364//
1365void MAstroCatalog::SetMarkerAttributes()
1366{
1367 if (!gPad)
1368 return;
1369
1370 TAttMarker::SetMarkerAttributes();
1371
1372 // Make sure that if something is changed the gui elements
1373 // are recreated
1374 TQObject::Connect("TGedMarkerSelect", "MarkerSelected(Style_t)", "MAstroCatalog", this, "ForceUpdate()");
1375 TQObject::Connect("TGColorSelect", "ColorSelected(Pixel_t)", "MAstroCatalog", this, "ForceUpdate()");
1376 TQObject::Connect("TGListBox", "Selected(Int_t)", "MAstroCatalog", this, "ForceUpdate()");
1377}
1378
1379void MAstroCatalog::DrawPrimitives(Option_t *o)
1380{
1381 fMapG.Delete();
1382
1383 if (!TestBit(kDrawingImage) && gPad)
1384 SetRangePad(o);
1385
1386#ifdef DEBUG
1387 TStopwatch clk;
1388 clk.Start();
1389#endif
1390 AddPrimitives(o);
1391#ifdef DEBUG
1392 clk.Stop();
1393 clk.Print();
1394#endif
1395
1396 // Append to a possible second pad
1397 if (!TestBit(kDrawingImage) && gPad && !gPad->GetListOfPrimitives()->FindObject(this))
1398 AppendPad(o);
1399
1400 ResetBit(kHasChanged);
1401}
1402
1403// --------------------------------------------------------------------------
1404//
1405// Append "this" to current pad
1406// set bit kHasChanged to recreate all gui elements
1407// Connect signal
1408//
1409void MAstroCatalog::Draw(Option_t *o)
1410{
1411 // Append to first pad
1412 AppendPad(o);
1413
1414 // If contents have not previously changed make sure that
1415 // all primitives are recreated.
1416 SetBit(kHasChanged);
1417
1418 // Connect all TCanvas::ProcessedEvent to this->EventInfo
1419 // This means, that after TCanvas has processed an event
1420 // EventInfo of this class is called, see TCanvas::HandleInput
1421 gPad->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
1422 "MAstroCatalog", this,
1423 "EventInfo(Int_t,Int_t,Int_t,TObject*)");
1424}
1425
1426// --------------------------------------------------------------------------
1427//
1428// This function was connected to all created canvases. It is used
1429// to redirect GetObjectInfo into our own status bar.
1430//
1431// The 'connection' is done in Draw. It seems that 'connected'
1432// functions must be public.
1433//
1434void MAstroCatalog::EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
1435{
1436 TCanvas *c = (TCanvas*)gTQSender;
1437
1438 gPad = c ? c->GetSelectedPad() : NULL;
1439 if (!gPad)
1440 return;
1441
1442
1443 // Try to find a corresponding object with kCannotPick set and
1444 // an available TString (for a tool tip)
1445 TString str;
1446 if (!selected || selected==this)
1447 selected = fMapG.PickObject(px, py, str);
1448
1449 if (!selected)
1450 return;
1451
1452 // Handle some gui events
1453 switch (event)
1454 {
1455 case kMouseMotion:
1456 if (fToolTip && !fToolTip->IsMapped() && !str.IsNull())
1457 ShowToolTip(px, py, str);
1458 break;
1459
1460 case kMouseLeave:
1461 if (fToolTip && fToolTip->IsMapped())
1462 fToolTip->Hide();
1463 break;
1464
1465 case kKeyPress:
1466 ExecuteEvent(kKeyPress, px, py);
1467 break;
1468 }
1469}
1470
1471// --------------------------------------------------------------------------
1472//
1473// Handle keyboard events.
1474//
1475void MAstroCatalog::ExecuteEventKbd(Int_t /*keycode*/, Int_t keysym)
1476{
1477 Double_t dra =0;
1478 Double_t ddec=0;
1479
1480 switch (keysym)
1481 {
1482 case kKey_Left:
1483 dra = -TMath::DegToRad();
1484 break;
1485 case kKey_Right:
1486 dra = +TMath::DegToRad();
1487 break;
1488 case kKey_Up:
1489 ddec = +TMath::DegToRad();
1490 break;
1491 case kKey_Down:
1492 ddec = -TMath::DegToRad();
1493 break;
1494 case kKey_Plus:
1495 SetRadiusFOV(fRadiusFOV+1);
1496 break;
1497 case kKey_Minus:
1498 SetRadiusFOV(fRadiusFOV-1);
1499 break;
1500
1501 default:
1502 return;
1503 }
1504
1505 const Double_t r = fRaDec.Phi();
1506 const Double_t d = TMath::Pi()/2-fRaDec.Theta();
1507
1508 SetRaDec(r+dra, d+ddec);
1509
1510 gPad->Update();
1511}
1512
1513// ------------------------------------------------------------------------
1514//
1515// Execute a gui event on the camera
1516//
1517void MAstroCatalog::ExecuteEvent(Int_t event, Int_t mp1, Int_t mp2)
1518{
1519 if (!TestBit(kGuiActive))
1520 return;
1521
1522 if (event==kKeyPress)
1523 ExecuteEventKbd(mp1, mp2);
1524}
1525
1526// --------------------------------------------------------------------------
1527//
1528// Displays a tooltip
1529//
1530void MAstroCatalog::ShowToolTip(Int_t px, Int_t py, const char *txt)
1531{
1532 if (TestBit(kNoToolTips))
1533 return;
1534
1535 Int_t x=0;
1536 Int_t y=0;
1537
1538 const Window_t id1 = gVirtualX->GetWindowID(gPad->GetCanvasID());
1539 const Window_t id2 = fToolTip->GetParent()->GetId();
1540
1541 Window_t id3;
1542 gVirtualX->TranslateCoordinates(id1, id2, px, py, x, y, id3);
1543
1544 // Show tool tip
1545 fToolTip->SetText(txt);
1546 fToolTip->Show(x+4, y+4);
1547}
1548
1549// --------------------------------------------------------------------------
1550//
1551// Calculate distance to primitive by checking all gui elements
1552//
1553Int_t MAstroCatalog::DistancetoPrimitive(Int_t px, Int_t py)
1554{
1555 return fMapG.DistancetoPrimitive(px, py);
1556}
1557
1558// ------------------------------------------------------------------------
1559//
1560// Returns string containing info about the object at position (px,py).
1561// Returned string will be re-used (lock in MT environment).
1562//
1563char *MAstroCatalog::GetObjectInfo(Int_t px, Int_t py) const
1564{
1565 return fMapG.GetObjectInfo(px, py);
1566}
Note: See TracBrowser for help on using the repository browser.