source: branches/removing_cpp11_features/mastro/MAstroCatalog.cc@ 18167

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