Ignore:
Timestamp:
03/17/04 17:17:14 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mastro/MAstroCatalog.cc

    r3525 r3537  
    5252#include "MTime.h"
    5353#include "MAstro.h"
     54#include "MAstroSky2Local.h"
    5455#include "MObservatory.h"
    5556
     
    5960using namespace std;
    6061
     62class MRotation : public TRotation
     63{
     64public:
     65    MRotation(Double_t gmst, const MObservatory &obs) : TRotation(1, 0, 0, 0, -1, 0, 0, 0, 1)
     66    {
     67        RotateZ(gmst + obs.GetElong());
     68        RotateY(obs.GetPhi()-TMath::Pi()/2);
     69        RotateZ(TMath::Pi());
     70    }
     71    MRotation(const MTime &t, const MObservatory &obs) : TRotation(1, 0, 0, 0, -1, 0, 0, 0, 1)
     72    {
     73        RotateZ(t.GetGmst() + obs.GetElong());
     74        RotateY(obs.GetPhi()-TMath::Pi()/2);
     75        RotateZ(TMath::Pi());
     76    }
     77};
     78
     79/*
    6180MVector3 MVector3::GetZdAz(const MObservatory &obs, Double_t gmst) const
    6281{
     
    6483        return MVector3();
    6584
    66     const Double_t alpha = gmst + obs.GetElong();
    67 
    68     MVector3 zdaz;
    69     zdaz.SetZdAz(Theta(), alpha-Phi(), Mag());
    70     zdaz.RotateY(obs.GetPhi()-TMath::Pi()/2);
    71 
    72     return zdaz;
    73 
    74     /*
     85    MVector3 v(*this);
     86    v *= MAstroSky2Local(gmst, obs);
     87
     88    return v;
     89
     90     // ------ Using vectors -------
     91     // v(1) = -v(1);                     //  phi -->      -phi
     92     // v.RotateZ(gmst + obs.GetElong()); // -phi --> alpha-phi
     93     // v.RotateY(obs.GetPhi()-TMath::Pi()/2);
     94     // v.RotateZ(TMath::Pi());
     95
    7596     // ------ The same using slalib, tested in the drive system -------
    76      const Double_t alpha = slaGmst(mjd) + obs.GetElong();
    77      Double_t el;
    78      slaDe2h(fAlpha-ra, dec, obs.GetPhi(), &az, &el);
    79      zd = TMath::Pi()/2-el;
    80      return;
    81      */
     97     // const Double_t alpha = slaGmst(mjd) + obs.GetElong();
     98     // Double_t el;
     99     // slaDe2h(fAlpha-ra, dec, obs.GetPhi(), &az, &el);
     100     // zd = TMath::Pi()/2-el;
    82101}
    83102
     
    92111        return MVector3();
    93112
    94     const Double_t alpha = gmst + obs.GetElong();
    95 
    96113    MVector3 v(*this);
    97     v.RotateY(TMath::Pi()/2-obs.GetPhi());
    98 
    99     MVector3 rd;
    100     rd.SetRaDec(alpha-v.Phi(), TMath::Pi()/2-v.Theta(), Mag());
    101     return rd;
    102 
    103     /*
     114    v *= MAstroSky2Local(gmst, obs).Inverse();
     115
     116    return v;
     117
     118     // ------ Using vectors -------
     119     // v.RotateZ(-TMath::Pi());
     120     // v.RotateY(TMath::Pi()/2-obs.GetPhi());
     121     // v.RotateZ(-gmst - obs.GetElong()); // alpha-phi --> -phi
     122     // v(1) = -v(1);                      //      -phi -->  phi
     123
    104124     // ------ The same using slalib, tested in the drive system -------
    105      const Double_t alpha = slaGmst(mjd) + obs.GetElong();
    106      Double_t el;
    107      slaDe2h(fAlpha-ra, dec, obs.GetPhi(), &az, &el);
    108      zd = TMath::Pi()/2-el;
    109      return;
    110      */
     125     // const Double_t alpha = slaGmst(mjd) + obs.GetElong();
     126     // Double_t el;
     127     // slaDe2h(fAlpha-ra, dec, obs.GetPhi(), &az, &el);
     128     // zd = TMath::Pi()/2-el;
    111129}
    112130
     
    115133    return GetRaDec(obs, time.GetGmst());
    116134}
    117 
     135*/
    118136MAstroCatalog::MAstroCatalog() : fLimMag(99), fRadiusFOV(99), fToolTip(0), fObservatory(0), fTime(0)
    119137{
     
    386404}
    387405
    388 Int_t MAstroCatalog::Convert(const TRotation &rot, TVector2 &v, Int_t type)
    389 {
    390     MVector3 w;
    391 
    392     switch (type)
    393     {
    394     case 1:
    395         w.SetRaDec(v.X()-fRaDec.Phi(), v.Y(), 1);
    396         break;
    397 
    398     case 2:
    399         if (!fTime || !fObservatory)
    400             return kFALSE;
    401         w.SetZdAz(v.Y(), v.X(), 1);
    402         w = w.GetRaDec(*fTime, *fObservatory);
    403         w.RotateZ(-fRaDec.Phi());
    404         break;
    405 
    406     default:
    407         return kFALSE;
    408     }
    409 
    410     w *= rot;
     406void MAstroCatalog::Paint(Option_t *o)
     407{
     408//    if (!gPad->IsBatch())
     409//        gVirtualX->ClearWindow();
     410
     411    if (TestBit(kHasChanged))
     412        DrawPrimitives(o);
     413}
     414
     415void MAstroCatalog::DrawStar(Double_t x, Double_t y, const TVector3 &v, Bool_t transparent, const char *txt)
     416{
     417    const Double_t ra  = v.Phi()*TMath::RadToDeg()/15;
     418    const Double_t dec = (TMath::Pi()/2-v.Theta())*TMath::RadToDeg();
     419
     420    TString str = v.GetName();
     421    str += Form(":  Ra=%.2fh", ra);
     422    str += Form("  Dec=%.1fd", dec);
     423    str += Form("  Mag=%.1f", -2.5*log10(v.Mag()));
     424    if (txt)
     425        str += Form("  (%s)", txt);
     426
     427    // draw star on the camera display
     428    TMarker *tip=new TMarker(x, y, transparent ? kDot : kFullDotLarge);;
     429    tip->SetMarkerColor(kBlack);
     430    tip->SetBit(kCanDelete);
     431    tip->SetBit(kCannotPick);
     432    AddMap(tip, new TString(str));
     433}
     434
     435void MAstroCatalog::Update()
     436{
     437    if (gPad && TestBit(kMustCleanup))
     438    {
     439        SetBit(kHasChanged);
     440        gPad->Modified();
     441    }
     442}
     443
     444void MAstroCatalog::SetTime(const MTime &time)
     445{
     446    if (fTime)
     447        delete fTime;
     448    fTime=(MTime*)time.Clone();
     449}
     450
     451void MAstroCatalog::SetObservatory(const MObservatory &obs)
     452{
     453    if (fObservatory)
     454        delete fObservatory;
     455    fObservatory=(MObservatory*)obs.Clone();
     456}
     457
     458Int_t MAstroCatalog::ConvertToPad(const TVector3 &w0, TVector2 &v)
     459{
     460    TVector3 w(w0);
    411461
    412462    // Stretch such, that the X-component is alwas the same. Now
     
    427477}
    428478
     479Int_t MAstroCatalog::Convert(const TRotation &rot, TVector2 &v)
     480{
     481    MVector3 w;
     482    w.SetMagThetaPhi(1, v.Y(), v.X());
     483    w *= rot;
     484
     485    return ConvertToPad(w, v);
     486}
     487
    429488Bool_t MAstroCatalog::DrawLine(const TVector2 &v, Double_t dx, Double_t dy, const TRotation &rot, Int_t type)
    430489{
     
    434493    TVector2 v1 = v+add;
    435494
    436     const Int_t rc0 = Convert(rot, v0, type);
    437     const Int_t rc1 = Convert(rot, v1, type);
     495    const Int_t rc0 = Convert(rot, v0);
     496    const Int_t rc1 = Convert(rot, v1);
     497
    438498    // Both are kFALSE or both are kERROR
    439499    if ((rc0|rc1)==kFALSE || (rc0&rc1)==kERROR)
     
    449509    const TVector2 deg = v*TMath::RadToDeg();
    450510    TString txt = type==1 ?
    451         Form("Ra=%.1fh  Dec=%.1fd", fmod(deg.X()/15+48, 24),  fmod(deg.Y()+270,180)-90) :
     511        Form("Ra=%.1fh  Dec=%.1fd", fmod(deg.X()/15+48, 24),  fmod(90-deg.Y()+270,180)-90) :
    452512        Form("Zd=%.1fd  Az=%.1fd",  fmod(deg.Y()+270,180)-90, fmod(deg.X()+720, 360));
    453513
     
    461521}
    462522
     523
    463524void MAstroCatalog::Draw(const TVector2 &v0, const TRotation &rot, TArrayI &dx, TArrayI &dy, Int_t stepx, Int_t stepy, Int_t type)
    464525{
    465526    const TVector2 v1 = v0 + TVector2(dx[0]*TMath::DegToRad(), dy[0]*TMath::DegToRad());
    466 
    467     //    if (TMath::Abs(v1.Y())>TMath::Pi()/2)
    468     //        return;
    469 
    470     //    const Int_t v0x = (int)(v0.X()*TMath::RadToDeg());
    471     //    const Int_t v0y = (int)(v0.Y()*TMath::RadToDeg());
    472527
    473528    Int_t idx[] = {1, 1, 1, 1};
     
    501556        {
    502557            // Calculate new position
    503             //dx[0] = (d[0]+dirs[i][0]+540-v0x)%360-180+v0x;
    504             //dy[0] = (d[1]+dirs[i][1]+270-v0y)%180- 90+v0y;
    505558            dx[0] = d[0]+dirs[i][0];
    506559            dy[0] = d[1]+dirs[i][1];
     560
     561            //cout << dx[0] << " " << dy[0] << endl;
    507562
    508563            // Draw corresponding line and iterate through grid
     
    510565                Draw(v0, rot, dx, dy, stepx, stepy, type);
    511566
    512             dx[0]=d[0]; dy[0]=d[1];
     567            dx[0]=d[0];
     568            dy[0]=d[1];
    513569        }
    514570}
     
    516572void MAstroCatalog::DrawNet(const TVector2 &v0, const TRotation &rot, Int_t type)
    517573{
    518     //const Double_t step = TMath::DegToRad();
    519 
    520574    TArrayI dx(1);
    521575    TArrayI dy(1);
     
    527581    // calculate stepsizes based on visible FOV
    528582    Int_t stepx=1;
    529     if (fabs(v.Y())>90-fRadiusFOV || fabs(v.Y())<fRadiusFOV)
     583
     584    if (fabs(90-v.Y())>90-fRadiusFOV || fabs(90-v.Y())<fRadiusFOV)
    530585        stepx = 180/10;
    531586    else
     
    534589        const Float_t m = log(fRadiusFOV/180.)/log(90./fRadiusFOV-1);
    535590        const Float_t t = log(180.)-m*log(fRadiusFOV);
    536         const Int_t n = (Int_t)(exp(m*log(90-fabs(v.Y()))+t)+0.5);
    537         stepx = n<4 ? 1 : n/4;
     591        const Int_t n = (Int_t)(exp(m*log(90-fabs(90-v.Y()))+t)+0.5);
     592        stepx = n<6 ? 1 : n/6;
    538593    }
    539594
     
    556611    // draw...
    557612    v *= TMath::DegToRad();
     613
    558614    Draw(v, rot, dx, dy, stepx, stepy, type);
    559615}
    560616
    561 void MAstroCatalog::Paint(Option_t *o)
    562 {
    563 //    if (!gPad->IsBatch())
    564 //        gVirtualX->ClearWindow();
    565 
    566     if (TestBit(kHasChanged))
    567         DrawPrimitives(o);
    568 }
    569 
    570 void MAstroCatalog::DrawStar(Double_t x, Double_t y, const TVector3 &v, Bool_t transparent, const char *txt)
    571 {
    572     const Double_t ra  = v.Phi()*TMath::RadToDeg()/15;
    573     const Double_t dec = (TMath::Pi()/2-v.Theta())*TMath::RadToDeg();
    574 
    575     TString str = v.GetName();
    576     str += Form(":  Ra=%.1fh", ra);
    577     str += Form("  Dec=%.1fd", dec);
    578     str += Form("  Mag=%.1f", -2.5*log10(v.Mag()));
    579     if (txt)
    580         str += Form("  (%s)", txt);
    581 
    582     // draw star on the camera display
    583     TMarker *tip=new TMarker(x, y, transparent ? kDot : kFullDotLarge);;
    584     tip->SetMarkerColor(kBlack);
    585     tip->SetBit(kCanDelete);
    586     tip->SetBit(kCannotPick);
    587     AddMap(tip, new TString(str));
    588 }
    589 
    590 void MAstroCatalog::Update()
    591 {
    592     if (gPad && TestBit(kMustCleanup))
    593     {
    594         SetBit(kHasChanged);
    595         gPad->Modified();
    596     }
    597 }
    598 
    599 void MAstroCatalog::SetTime(const MTime &time)
    600 {
    601     if (fTime)
    602         delete fTime;
    603     fTime=(MTime*)time.Clone();
    604 }
    605 
    606 void MAstroCatalog::SetObservatory(const MObservatory &obs)
    607 {
    608     if (fObservatory)
    609         delete fObservatory;
    610     fObservatory=(MObservatory*)obs.Clone();
    611 }
    612 
    613617void MAstroCatalog::AddPrimitives(Option_t *o)
    614618{
    615     const Double_t ra  = fRaDec.Phi();
    616     const Double_t dec = TMath::Pi()/2-fRaDec.Theta();
    617 
    618619    // Precalc Sin/Cos...
    619620    TRotation trans;
    620     trans.Rotate(dec, TVector3(0, 1, 0));
    621 
    622     const TVector3 zdaz0 = fRaDec.GetZdAz(*fTime, *fObservatory);
    623     TVector2 zdaz(zdaz0.Phi(), zdaz0.Theta());
    624     MAstroCatalog::DrawNet(zdaz, trans, 2);
    625 
    626     TVector2 radec(ra, dec);
    627     MAstroCatalog::DrawNet(radec, trans, 1);
     621    trans.RotateZ(-fRaDec.Phi());
     622    trans.Rotate(TMath::Pi()/2-fRaDec.Theta(), TVector3(0, 1, 0));
     623
     624    if (fTime && fObservatory)
     625    {
     626        const TRotation rot(MAstroSky2Local(*fTime, *fObservatory));
     627        const TVector3 zdaz0 = rot*fRaDec;
     628        const TVector2 zdaz(zdaz0.Phi(), zdaz0.Theta());
     629        DrawNet(zdaz, trans*rot.Inverse(), 2);
     630    }
     631
     632    const TVector2 radec(fRaDec.Phi(), fRaDec.Theta());
     633    DrawNet(radec, trans, 1);
    628634
    629635    TIter Next(&fList);
     
    632638    {
    633639        // FIXME: Check Magnitude!
    634         TVector2 s(v->Phi(), TMath::Pi()/2-v->Theta());
    635         if (Convert(trans, s, 1)==kTRUE)
    636             DrawStar(s.X(), s.Y(), *v, kFALSE);
     640        TVector2 s(v->Phi(), v->Theta());
     641        if (Convert(trans, s)==kTRUE)
     642            DrawStar(s.X(), TMath::Pi()/2-s.Y(), *v, kFALSE);
    637643    }
    638644}
Note: See TracChangeset for help on using the changeset viewer.