Ignore:
Timestamp:
03/12/03 14:41:29 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/gui/MGStarguider.cc

    r1816 r1819  
    33#include <fstream.h>    // ifstream
    44#include <iostream.h>   // cout
     5#include <iomanip.h>   // cout
    56
    67#include <TTimer.h>
    78
    89#include <TGMenu.h>
     10#include <TGLabel.h>
    911#include <TSystem.h>
    1012#include <TGSplitter.h>    // TGHorizontal3DLine
     
    2022#include "Filter.h"
    2123#include "Filter2.h"
     24#include "CaosFilter.h"
    2225#include "Writer.h"
    2326#include "base/timer.h"
     
    2528#include "MStarList.h"
    2629
     30#include <TH1.h>
     31#include <TH2.h>
     32#include <TGraph.h>
     33#include <TCanvas.h>
     34
     35#include <TFile.h>
     36#include <TTree.h>
     37#include <TBranch.h>
     38
     39#include "Led.h"
     40#include "Leds.h"
     41#include "Rings.h"
     42
     43#include "MGMenu.h"
     44
    2745ClassImp(MGStarguider);
    2846
    2947enum {
    3048    IDM_kFilter,
     49    IDM_kCaosFilter,
    3150    IDM_kCatalog,
    3251    IDM_kStarguider,
     
    6079    IDM_kInterpol5,
    6180    IDM_kInterpol2,
    62     IDM_kInterpol1
     81    IDM_kInterpol1,
     82    IDM_kPositions,
     83    IDM_kRings,
     84    IDM_kLeds,
     85    IDM_kStartAnalyse,
     86    IDM_kStopAnalyse,
     87    IDM_kResetHistograms
    6388};
    6489
     
    7297#define kZOOM 96
    7398
    74 MGStarguider::MGStarguider(MObservatory::LocationName_t key)
    75 : TGMainFrame(gClient->GetRoot(), 768, 700), fObservatory(key), fDx((768-kZOOM)/2), fDy((512-kZOOM)/2)
    76 {
    77     gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kTRUE);
    78 
     99void MGStarguider::InitHists()
     100{
     101    Double_t xmin = 480.1-1.0;
     102    Double_t xmax = 480.1+1.0;
     103
     104    Double_t ymin = 217.5-1.0;
     105    Double_t ymax = 217.5+1.0;
     106
     107    Double_t rmin = 117.4-1.0;
     108    Double_t rmax = 117.4+1.0;
     109
     110    Int_t xbin = 60;
     111    Int_t ybin = 60;
     112    Int_t rbin = 60;
     113
     114    fHistpr = new TH1F;
     115    fHistpr->SetNameTitle("pr","Radius of the ring");
     116    fHistpr->SetBins(rbin, rmin, rmax);
     117    fHistpr->SetXTitle("r [mm]");
     118    fHistpr->SetYTitle("counts");
     119
     120    fHistprx = new TH1F;
     121    fHistprx->SetNameTitle("prx","x-coordinate of the ring-center");
     122    fHistprx->SetBins(xbin, xmin, xmax);
     123    fHistprx->SetXTitle("x [mm]");
     124    fHistprx->SetYTitle("counts");
     125
     126    fHistpry = new TH1F;
     127    fHistpry->SetNameTitle("pry","y-coordniate of the ring-center");
     128    fHistpry->SetBins(ybin, ymin, ymax);
     129    fHistpry->SetXTitle("y [mm]");
     130    fHistpry->SetYTitle("counts");
     131
     132    for (int i=0; i<6; i++)
     133    {
     134        TString name  = "Angle";
     135        TString title = "Angle of Led ";
     136
     137        name += i;
     138        title += i;
     139
     140        fHistw[i] = new TH1F;
     141        fHistw[i]->SetNameTitle(name, title);
     142        fHistw[i]->SetBins(26, -25, 25);
     143        fHistw[i]->SetXTitle("\\Phi [arcmin]");
     144        fHistw[i]->SetYTitle("counts");
     145
     146        name = "Angles";
     147        title = "Angles of the Leds ";
     148
     149        name += i;
     150        title += i;
     151
     152        fHistv[i] = new TH1F;
     153        fHistv[i]->SetNameTitle(name, title);
     154        fHistv[i]->SetBins(721, -180.5, 180.5);
     155        fHistv[i]->SetXTitle("\\Phi [deg]");
     156        fHistv[i]->SetYTitle("counts");
     157    }
     158
     159    fHistallw = new TH1F;
     160    fHistallw->SetNameTitle("allw","Rotation angel");
     161    fHistallw->SetBins(26, -25, 25);
     162    fHistallw->SetXTitle("\\Phi [arcmin]");
     163    fHistallw->SetYTitle("counts");
     164
     165    fHistprxpry = new TH2F;
     166    fHistprxpry->SetNameTitle("prx und pry","x- and y-coordniate of the ring-center");
     167    fHistprxpry->SetBins(xbin, xmin, xmax, ybin, ymin, ymax);
     168    fHistprxpry->SetXTitle("x [mm]");
     169    fHistprxpry->SetYTitle("y [mm]");
     170    fHistprxpry->SetZTitle("counts");
     171}
     172
     173void MGStarguider::InitGraphs()
     174{
     175    fGraphprx = new TGraph;
     176    fGraphprx->SetTitle("time-developement of the x-coordinate of the ring-center");
     177
     178    fGraphpry = new TGraph;
     179    fGraphpry->SetTitle("time-developement of the y-coordinate of the ring-center");
     180
     181    for (int i=0; i<6; i++)
     182    {
     183        TString title = "Time-developement of the angle ";
     184        title += i;
     185
     186        fGraphw[i] = new TGraph;
     187        fGraphw[i]->SetTitle(title);
     188    }
     189}
     190
     191void MGStarguider::InitGui()
     192{
    79193    fList = new MGList;
    80194
    81     fSao = new StarCatalog(fObservatory);
    82     fRaDec = new RaDec(180, 40);
    83 
    84     // p = pointer to MainFrame (not owner)
    85 
    86195    const TGWindow *p=gClient->GetRoot();
    87196
     
    89198    // Create Menu for MGStarguider Display
    90199    //
    91     fDisplay = new TGPopupMenu(p);
     200    fDisplay = new MGPopupMenu(p);
    92201    fDisplay->AddEntry("&Filter",      IDM_kFilter);
     202    fDisplay->AddEntry("C&aosFilter",  IDM_kCaosFilter);
    93203    fDisplay->AddEntry("Sao &Catalog", IDM_kCatalog);
    94204    fDisplay->AddEntry("Starguider",   IDM_kStarguider);
     205    fDisplay->DisableEntry(IDM_kStarguider);
    95206    fDisplay->Associate(this);
    96207    fList->Add(fDisplay);
    97208
    98     fFileType = new TGPopupMenu(p);
     209    fFileType = new MGPopupMenu(p);
    99210    fFileType->AddEntry("PP&M", IDM_kPPM);
    100211    fFileType->AddEntry("&PNG", IDM_kPNG);
     
    103214    fList->Add(fFileType);
    104215
    105     fWriteType = new TGPopupMenu(p);
    106     fWriteType->AddEntry("Once",      IDM_kOnce);
    107     fWriteType->AddEntry("Continous", IDM_kContinous);
    108     fWriteType->CheckEntry(IDM_kOnce);
     216    fWriteType = new MGPopupMenu(p);
     217    fWriteType->AddEntry("&Once",      IDM_kOnce);
     218    fWriteType->AddEntry("&Continous", IDM_kContinous);
    109219    fWriteType->Associate(this);
    110220    fList->Add(fWriteType);
    111221
    112     fWriteRate = new TGPopupMenu(p);
     222    fWriteRate = new MGPopupMenu(p);
    113223    fWriteRate->AddEntry("25/s", IDM_kRate25ps);
    114224    fWriteRate->AddEntry("5/s",  IDM_kRate5ps);
     
    124234    fWrtRate = 25*60;
    125235
    126     fWrite = new TGPopupMenu(p);
    127     fWrite->AddEntry("&Start",      IDM_kStart);
    128     fWrite->AddEntry("Sto&p",       IDM_kStop);
    129     fWrite->AddSeparator();
    130     fWrite->AddPopup("File &Type",  fFileType);
    131     fWrite->AddPopup("&Write Type", fWriteType);
    132     fWrite->AddPopup("Write &Rate", fWriteRate);
    133     fWrite->DisableEntry(IDM_kStop);
    134     fWrite->Associate(this);
    135     fList->Add(fWrite);
    136 
    137     fLimMag = new TGPopupMenu(p);
     236    fWritePictures = new MGPopupMenu(p);
     237    fWritePictures->AddEntry("&Start",      IDM_kStart);
     238    fWritePictures->AddEntry("Sto&p",       IDM_kStop);
     239    fWritePictures->AddSeparator();
     240    fWritePictures->AddPopup("File &Type",  fFileType);
     241    fWritePictures->AddPopup("&Write Type", fWriteType);
     242    fWritePictures->AddPopup("Write &Rate", fWriteRate);
     243    fWritePictures->DisableEntry(IDM_kStop);
     244    fWritePictures->Associate(this);
     245    fList->Add(fWritePictures);
     246
     247    fLimMag = new MGPopupMenu(p);
    138248    fLimMag->AddEntry("3", IDM_kLimMag3);
    139249    fLimMag->AddEntry("4", IDM_kLimMag4);
     
    147257    fList->Add(fLimMag);
    148258
    149     fSao->SetLimitMag(8.0);
    150 
    151     fInterpol = new TGPopupMenu(p);
     259    fSao->SetLimitMag(7.0);
     260
     261    fInterpol = new MGPopupMenu(p);
    152262    fInterpol->AddEntry("125", IDM_kInterpol125);
    153263    fInterpol->AddEntry("25",  IDM_kInterpol25);
     
    156266    fInterpol->AddEntry("2",   IDM_kInterpol2);
    157267    fInterpol->AddEntry("Off", IDM_kInterpol1);
    158     fInterpol->CheckEntry(IDM_kInterpol25);
     268    fInterpol->CheckEntry(IDM_kInterpol1);
    159269    fInterpol->Associate(this);
    160270    fList->Add(fInterpol);
    161271
    162     fIntRate = 25;
    163 
    164     fSetup = new TGPopupMenu(p);
     272    fIntRate = 1;
     273
     274    fSetup = new MGPopupMenu(p);
    165275    fSetup->AddPopup("Lim. &Magnitude",      fLimMag);
    166276    fSetup->AddPopup("Disp. &Interpolation", fInterpol);
     
    169279    fList->Add(fSetup);
    170280
    171     fMenu = new TGMenuBar(this, 0, 0, kHorizontalFrame);
     281    fWrite = new MGPopupMenu(p);
     282    fWrite->AddEntry("&Positions",  IDM_kPositions);
     283    fWrite->AddEntry("&Leds", IDM_kLeds);
     284    fWrite->AddEntry("&Rings", IDM_kRings);
     285    fWrite->Associate(this);
     286    fList->Add(fWrite);
     287
     288    fAnalyse = new MGPopupMenu(p);
     289    fAnalyse->AddEntry("S&tart Analyse", IDM_kStartAnalyse);
     290    fAnalyse->AddEntry("St&opp Analyse", IDM_kStopAnalyse);
     291    fAnalyse->DisableEntry(IDM_kStopAnalyse);
     292    fAnalyse->AddEntry("&Reset Histograms", IDM_kResetHistograms);
     293//    fAnalyse->AddEntry("Reset &Graph", IDM_kResetGraph);
     294    fAnalyse->Associate(this);
     295    fList->Add(fAnalyse);
     296
     297    fMenu = new MGMenuBar(this, 0, 0, kHorizontalFrame);
    172298    fMenu->AddPopup("&Display", fDisplay, NULL);
    173     fMenu->AddPopup("&Write",   fWrite,   NULL);
     299    fMenu->AddPopup("&WritePics",   fWritePictures,   NULL);
    174300    fMenu->AddPopup("&Setup",   fSetup,   NULL);
    175301    fMenu->Resize(fMenu->GetDefaultSize());
     302    fMenu->BindKeys(this);
    176303    AddFrame(fMenu); //, new TGLayoutHints (kLHintsNormal, 0, 4, 0, 0));
    177304    fList->Add(fMenu);
     305
     306    fCaOs = new MGPopupMenu(p);
     307    fCaOs->AddPopup("&Write", fWrite);
     308    fCaOs->AddPopup("&Analyse", fAnalyse);
     309    fCaOs->Associate(this);
     310    fCaOs->BindKeys(fMenu, this);
     311    fList->Add(fCaOs);
    178312
    179313    fCRaDec = new MGCoordinates(this, kETypeRaDec);
     
    182316    fList->Add(fCRaDec);
    183317
    184     fCZdAz = new MGCoordinates(this, kETypeZdAz);
     318    fCZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
    185319    fCZdAz->Move(240+12+10, fMenu->GetDefaultHeight()+584);
    186320    AddFrame(fCZdAz);
    187321    fList->Add(fCZdAz);
    188322
    189     const Double_t pixsize = 23.5;
     323    fPZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
     324    fPZdAz->Move(240+12+10, fMenu->GetDefaultHeight()+630);
     325    AddFrame(fPZdAz);
     326    fList->Add(fPZdAz);
     327
     328    TGLabel *l = new TGLabel(this, "Arb.-Sky Pos");
     329    l->SetTextJustify(kTextLeft);
     330    l->Move(480+32, fMenu->GetDefaultHeight()+590);
     331    AddFrame(l);
     332    fList->Add(l);
     333
     334    l = new TGLabel(this, "arcsec/pix");
     335    l->SetTextJustify(kTextLeft);
     336    l->Move(605, fMenu->GetDefaultHeight()+619);
     337    AddFrame(l);
     338    fList->Add(l);
     339
     340    l = new TGLabel(this, "Pointing Pos");
     341    l->SetTextJustify(kTextLeft);
     342    l->Move(480+32, fMenu->GetDefaultHeight()+655);
     343    AddFrame(l);
     344    fList->Add(l);
     345
     346    const Double_t pixsize = 23.4;
    190347
    191348    fSao->SetPixSize(pixsize/3600);
     
    196353    fPixSize = new TGTextEntry(this, txt, IDM_kPixSize);
    197354    fPixSize->SetAlignment(kTextCenterX);
    198     fPixSize->Move(600, fMenu->GetDefaultHeight()+584);
     355    fPixSize->Move(547, fMenu->GetDefaultHeight()+617);
    199356    AddFrame(fPixSize);
    200357    fList->Add(fPixSize);
     
    226383    MapWindow();
    227384
     385    //------------------------------------------------------------
     386    //    XY xy(3.819444, 24.05333);
     387    //    fCRaDec->SetCoordinates(xy);
     388    //    fRaDec->Set(xy.X()*360/24, xy.Y());
     389    //------------------------------------------------------------
     390}
     391
     392MGStarguider::MGStarguider(MObservatory::LocationName_t obs)
     393: TGMainFrame(gClient->GetRoot(), 768, 740), fFile(NULL), fDx((768-kZOOM)/2), fDy((512-kZOOM)/2)
     394{
     395    fSao = new StarCatalog(obs);
     396    fRaDec = new RaDec(180, 40);
     397
     398    InitHists();
     399    InitGraphs();
     400
     401    InitGui();
     402
     403    gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kTRUE);
     404
    228405    fTimer=new TTimer(this, 100); // 100ms
    229406    fTimer->TurnOn();
     
    232409MGStarguider::~MGStarguider()
    233410{
    234     gVirtualX->GrabButton(0, kButton2, 0, 0, 0, 0, kFALSE);
     411    gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kFALSE);
    235412
    236413    fTimer->TurnOff();
    237414    delete fTimer;
    238415
     416    delete fList;
     417
    239418    delete fSao;
    240419    delete fRaDec;
    241420
    242     delete fList;
     421    delete fHistpr;
     422    delete fHistprx;
     423    delete fHistpry;
     424    delete fHistprxpry;
     425    delete fHistallw;
     426    delete fGraphprx;
     427    delete fGraphpry;
     428
     429    for (int i=0; i<6; i++)
     430    {
     431        delete fHistw[i];
     432        delete fHistv[i];
     433        delete fGraphw[i];
     434    }
     435
    243436    cout << "Camera Display destroyed." << endl;
    244437}
     
    253446    cout << "EventDisplay::CloseWindow: Exit Application Loop." << endl;
    254447
    255     /*ExitLoop();*/
    256     //cout << "FIXME: ExitLoop not called!!!!!!" << endl;
    257 
     448    //fClient.ExitLoop();
     449    //    cout << "FIXME: ExitLoop not called!!!!!!" << endl;
    258450    gSystem->ExitLoop();
    259451}
    260452
    261 void MGStarguider::Toggle(TGPopupMenu *p, UInt_t id)
     453void MGStarguider::Toggle(MGPopupMenu *p, UInt_t id)
    262454{
    263455    if (p->IsEntryChecked(id))
     
    265457    else
    266458        p->CheckEntry(id);
    267 
     459}
     460
     461void MGStarguider::ResetHists()
     462{
     463    fHistprx->Reset();
     464    fHistpry->Reset();
     465    fHistpr->Reset();
     466    fHistprxpry->Reset();
     467    fHistallw->Reset();
     468    for (int i=0; i<6; i++)
     469    {
     470        fHistw[i]->Reset();
     471        fHistv[i]->Reset();
     472    }
     473}
     474
     475void MGStarguider::DisplayAnalysis()
     476{
     477    TCanvas *c = new TCanvas("cring", "Center of the ring", 800, 800);
     478    c->Divide(2,2);
     479    c->cd(1);
     480    fHistprx->Fit("gaus");
     481    fHistprx->DrawCopy();
     482    c->cd(2);
     483    fHistpry->Fit("gaus");
     484    fHistpry->DrawCopy();
     485    c->cd(3);
     486    fHistpr->Fit("gaus");
     487    fHistpr->DrawCopy();
     488    c->cd(4);
     489    fHistprxpry->DrawCopy(/*"surf2"*/);
     490    c->Update();
     491
     492    c = new TCanvas("c3", "Absolute angles of the leds", 800, 800);
     493    c->Divide(2,3);
     494    for (int i=0; i<6; i++)
     495    {
     496        c->cd(i+1);
     497        TH1 *h = fHistv[i]->DrawCopy();
     498        h->SetLineColor(i+1);
     499        cout << "Led #" << i << ": MeanPhi=" << h->GetMean() << endl;
     500    }
     501    c->Update();
     502
     503    c = new TCanvas("c5", "timedevelopement of prx", 800, 800);
     504    fGraphprx->Draw("ALP*");
     505    fGraphprx->GetHistogram()->SetXTitle("time [1/25 s]");
     506    fGraphprx->GetHistogram()->SetYTitle("x-coordinate");
     507    c->Modified();
     508    c->Update();
     509
     510    c = new TCanvas("c6", "timedevelopement of pry", 800, 800);
     511    fGraphpry->Draw("ALP*");
     512    fGraphpry->GetHistogram()->SetXTitle("time [1/25 s]");
     513    fGraphpry->GetHistogram()->SetYTitle("y-coordinate");
     514    c->Modified();
     515    c->Update();
     516
     517    c = new TCanvas("c2", "Relative angles of the Leds", 800, 800);
     518    c->Divide(2,3);
     519    for (int i=0; i<6; i++)
     520    {
     521        c->cd(i+1);
     522        fHistw[i]->DrawCopy();
     523    }
     524    c->Update();
     525
     526    c = new TCanvas("c7", "timedevelopement of the relative angles of the Leds", 800, 800);
     527    c->Divide(2,3);
     528    for (int i=0; i<6; i++)
     529    {
     530        c->cd(i+1);
     531        fGraphw[i]->Draw("ALP*");
     532        fGraphw[i]->GetHistogram()->SetXTitle("t [1/25s]");
     533        fGraphw[i]->GetHistogram()->SetYTitle("[deg]");
     534    }
     535    c->Modified();
     536    c->Update();
     537
     538    c = new TCanvas("c4", "rotation angle ", 800, 800);
     539    fHistallw->Fit("gaus");
     540    fHistallw->DrawCopy();
     541}
     542
     543void MGStarguider::OpenFile()
     544{
     545    int i=0;
     546    char name[100];
     547    while (1)
     548    {
     549        sprintf(name, "data/data%03d.root", i++);
     550        if (gSystem->AccessPathName(name, kFileExists))
     551            break;
     552    }
     553
     554    fFile = new TFile(name, "RECREATE");
     555
     556    if (!fFile->IsOpen())
     557    {
     558        delete fFile;
     559        fFile = NULL;
     560
     561        cout << "Error: Cannot open file '" << name << "'" << endl;
     562
     563    }
     564
     565    fTree = new TTree("Data", "Real CaOs Data");
     566
     567    fLeds = NULL;
     568    fRings = NULL;
     569    fTime = 0;
     570
     571    fBranchL = fTree->Branch("Leds.",  "Leds",  &fLeds);
     572    fBranchR = fTree->Branch("Rings.", "Rings", &fRings);
     573    fBranchT = fTree->Branch("Time.", &fTime, "fTime/D");//, &fTime);
     574
     575    cout << "Root file '" << name << "' open." << endl;
    268576}
    269577
     
    282590
    283591    case kC_COMMAND:
     592        //cout << "kC_COMMAND" << endl;
    284593        switch (GET_SUBMSG(msg))
    285594        {
    286595        case kCM_MENU:
     596            //cout << "kCM_MENU #" << mp1 << endl;
    287597            switch (mp1)
    288598            {
     
    313623                return kTRUE;
    314624
     625            case IDM_kCaosFilter:
     626                if (!fDisplay->IsEntryChecked(IDM_kCaosFilter))
     627                    OpenFile();
     628                Toggle(fDisplay, IDM_kCaosFilter);
     629                if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
     630                    fMenu->AddPopup("&CaOs", fCaOs, NULL);
     631                else
     632                {
     633                    fFile->Write();
     634                    delete fFile;
     635                    fFile = NULL;
     636
     637                    cout << "Root file closed." << endl;
     638
     639                    if(fWrite->IsEntryChecked(IDM_kPositions))
     640                       fWrite->UnCheckEntry(IDM_kPositions);
     641                    if(fWrite->IsEntryChecked(IDM_kLeds))
     642                       fWrite->UnCheckEntry(IDM_kLeds);
     643                    if(fWrite->IsEntryChecked(IDM_kRings))
     644                        fWrite->UnCheckEntry(IDM_kRings);
     645                    if(fAnalyse->IsEntryEnabled(IDM_kStopAnalyse))
     646                    {
     647                        fAnalyse->DisableEntry(IDM_kStopAnalyse);
     648                        fAnalyse->EnableEntry(IDM_kStartAnalyse);
     649                        ResetHists();
     650                        // Graphs are not reset !!!
     651                    }
     652                    fMenu->RemovePopup("CaOs");
     653                }
     654                fMenu->Resize(fMenu->GetDefaultSize());
     655                MapSubwindows();
     656                MapWindow();
     657                return kTRUE;
     658
     659            case IDM_kPositions:
     660                Toggle(fWrite, IDM_kPositions);
     661                return kTRUE;
     662
     663            case IDM_kLeds:
     664                Toggle(fWrite, IDM_kLeds);
     665                return kTRUE;
     666
     667            case IDM_kRings:
     668                Toggle(fWrite, IDM_kRings);
     669                return kTRUE;
     670
     671            case IDM_kStartAnalyse:
     672                fAnalyse->DisableEntry(IDM_kStartAnalyse);
     673                fAnalyse->EnableEntry(IDM_kStopAnalyse);
     674                return kTRUE;
     675
     676            case IDM_kStopAnalyse:
     677                {
     678                    fAnalyse->DisableEntry(IDM_kStopAnalyse);
     679                    fAnalyse->EnableEntry(IDM_kStartAnalyse);
     680
     681                    DisplayAnalysis();
     682
     683                    return kTRUE;
     684                }
     685
     686            case IDM_kResetHistograms:
     687                ResetHists();
     688                return kTRUE;
     689
     690/*            case IDM_kResetGraph:
     691                {
     692                    fGraphx->GetHistogram()->Reset();
     693
     694                }
     695*/
     696
    315697            case IDM_kUseFileRaDec:
    316698                Toggle(fSetup, IDM_kUseFileRaDec);
     
    318700
    319701            case IDM_kStart:
    320                 fWrite->DisableEntry(IDM_kStart);
    321                 fWrite->EnableEntry(IDM_kStop);
     702                fWritePictures->DisableEntry(IDM_kStart);
     703                fWritePictures->EnableEntry(IDM_kStop);
    322704                return kTRUE;
    323705
    324706            case IDM_kStop:
    325                 fWrite->DisableEntry(IDM_kStop);
    326                 fWrite->EnableEntry(IDM_kStart);
     707                fWritePictures->DisableEntry(IDM_kStop);
     708                fWritePictures->EnableEntry(IDM_kStart);
    327709                return kTRUE;
    328710
     
    460842}
    461843
    462 void MGStarguider::CalcTrackingError(MStarList &spots, MStarList &stars)
    463 {
     844ZdAz MGStarguider::TrackingError(TArrayF &x, TArrayF &y, TArrayF &mag) const
     845{
     846    //
     847    // Viewable area (FIXME: AZ)
     848    //
     849    TH2F h("Hist", "dX/dY",  77, -768/2-.5,  768/2+.5, 58, -576/2-.5,  576/2+.5); // 3
     850
     851    /*
     852    TH1F hmag("HistMag", "Mag", 19, 0, 100);
     853    for (int i=0; i<mag.GetSize(); i++)
     854        hmag.Fill(mag[i]);
     855        */
     856
     857    //
     858    // Search for matching Magnitudes
     859    //
     860    for (int i=0; i<mag.GetSize(); i++)
     861    {
     862        if (mag[i]>48-15 && mag[i]<48+15)
     863            h.Fill(x[i], y[i]);
     864    }
     865
     866    //
     867    // Serach for an excess in the histogram
     868    //
     869    Int_t mx, my, dummy;
     870    h.GetMaximumBin(mx, my, dummy);
     871
     872    const double xmax = h.GetXaxis()->GetBinCenter(mx);
     873    const double dx   = h.GetXaxis()->GetBinWidth(mx);
     874
     875    const double ymax = h.GetYaxis()->GetBinCenter(my);
     876    const double dy   = h.GetYaxis()->GetBinWidth(my);
     877
     878    cout << setprecision(3);
     879    cout << "Cut-XY:       " << xmax << " +- " << dx << " / " << ymax << " +- " << dy << endl;
     880
     881    TGraph g;
     882    for (int i=0; i<mag.GetSize(); i++)
     883    {
     884        if (!(x[i]>xmax-dx && x[i]<xmax+dx &&
     885              y[i]>ymax-dy && y[i]<ymax+dy &&
     886              mag[i]>48-15 && mag[i]<48+15))
     887            continue;
     888
     889        g.SetPoint(g.GetN(), x[i], y[i]);
     890    }
     891
     892    cout << "Offset-XY:    " << g.GetMean(1) << " +- " << g.GetRMS(1) << " / ";
     893    cout << g.GetMean(2) << " +- " << g.GetRMS(2) << endl;
     894
     895    AltAz pos0 = fSao->CalcAltAzFromPix(768/2,              576/2)*kRad2Deg;
     896    AltAz pos1 = fSao->CalcAltAzFromPix(768/2+g.GetMean(1), 576/2+g.GetMean(2))*kRad2Deg;
     897
     898    pos1 -= pos0;
     899
     900    ofstream fout("tracking_error.txt");
     901    fout << setprecision(10) << fSao->GetMjd()-52000 << " " << -pos1.Alt() << " " << pos1.Az() << endl;
     902    fout.close();
     903
     904    return ZdAz(-pos1.Alt(), pos1.Az());
     905}
     906
     907void MGStarguider::CalcTrackingError(Leds &leds, MStarList &stars)
     908{
     909    const Int_t max = leds.GetEntries();
     910
    464911    if (stars.GetRealEntries() < 3)
    465912    {
     
    468915    }
    469916
    470     if (spots.GetRealEntries() < 1)
     917    if (max < 1)
    471918    {
    472919        cout << "Sorry, less than 1 detected spot in FOV!" << endl;
     
    474921    }
    475922
    476     Int_t idx = 0;
    477 
    478     MStarList sortedspots;
     923    stars.Sort(); // Sort by magnitude
     924
     925    TString str = "data/tracking_";
     926    str += fSao->GetMjd()-52000;
     927    str += ".txt";
     928
     929    ofstream fout(str);
     930
     931    TArrayF x, y, mag;
     932
     933    Int_t num = 0;
     934
     935    // FIXME: Is predifined value 3 a good idea?
    479936
    480937    MStar *star;
    481     MStar *spot;
    482938    MStarListIter NextStar(&stars);
    483     MStarListIter NextSpot(&spots);
    484 
    485     while ((spot=NextSpot()))
    486     {
    487         AltAz aa = fSao->CalcAltAzFromPix(spot->GetX(), spot->GetY());
    488         spot->Set(aa.Az(), aa.Alt());
    489     }
    490 
    491     while ((star=NextStar()))
    492     {
    493         AltAz aa = fSao->CalcAltAzFromPix(star->GetX(), star->GetY());
    494         star->Set(aa.Az(), aa.Alt());
    495 
    496         const double aaz   = star->GetX();
    497         const double dphi2 = aaz/2.;
    498         const double cos2  = cos(dphi2)*cos(dphi2);
    499         const double sin2  = sin(dphi2)*sin(dphi2);
    500 
    501         Double_t min = 800;
    502 
    503         NextSpot.Reset();
    504         while ((spot=NextSpot()))
     939    while ((star=NextStar()) && num++<max+3)
     940    {
     941        TIter NextSp(&leds);
     942        Led *spot=NULL;
     943        while ((spot=(Led*)NextSp()))
    505944        {
    506             const double pzd = TMath::Pi()/2-spot->GetY();
    507             const double azd = TMath::Pi()/2-star->GetY();
    508 
    509             const double d = cos(azd)*cos2 - cos(2*pzd+azd)*sin2;
    510 
    511             const Double_t dist = acos(d);
    512 
    513             if (dist>=min)
    514                 continue;
    515 
    516             min = dist;
    517             sortedspots.AddAt(idx, spot->GetX(), spot->GetY(), spot->GetMag());
     945            const XY dpos(spot->GetX()-star->GetX(), spot->GetY()-star->GetY());
     946
     947            const Int_t idx = x.GetSize();
     948
     949            x.Set(idx+1);
     950            y.Set(idx+1);
     951            mag.Set(idx+1);
     952
     953            x.AddAt(dpos.X(), idx);
     954            y.AddAt(dpos.Y(), idx);
     955            mag.AddAt(spot->GetMag()/star->GetMag(), idx);
     956
     957            if (fout)
     958                fout << x[idx] << " " << y[idx] << " " << mag[idx] << endl;
    518959        }
    519         if (min>768)
    520         {
    521             cout << "ERROR!!!!!!!!" << endl;
    522             return;
    523         }
    524         idx++;
    525     }
    526 
    527     //
    528     // Now we have in sortedspots the entries with the shortest distances
    529     // to the corresponding ones in stars.
    530     // Now calculate the tracking error.
    531     //
    532     NextStar.Reset();
    533     MStarListIter NextSpot2(&sortedspots);
    534 
    535     Double_t meanx=0;
    536     Double_t meany=0;
    537 
    538     while ((star=NextStar()))
    539     {
    540         spot = NextSpot2();
    541 
    542         meanx += star->GetX() - spot->GetX();
    543         meany += star->GetY() - spot->GetY();
    544     }
    545 
    546     meanx /= idx;
    547     meany /= idx;
    548 
    549     cout << "Tracking Error:  dAlt=" << meany*180/TMath::Pi();
    550     cout << "°  dAz=" << meanx*180/TMath::Pi() << "°    (calculated";
    551     cout << " with " << idx << " stars/spots)" << endl;
    552 }
     960    }
     961
     962    ZdAz d = TrackingError(x, y, mag);
     963
     964    //
     965    // Calculated offsets
     966    //
     967
     968    // round= floor(x+.5)
     969    cout << "Offset-ZdAz: " << d.Zd()*60 << "' / " << d.Az()*60 << "'" << endl;
     970    cout << "Offset-ZdAz: " << d.Zd()/360*16384 << " / " << d.Az()/360*16384 << " (SE) " << endl;
     971
     972    //
     973    // Current Pointing position
     974    //
     975    ZdAz cpos = fSao->GetZdAz()-d;
     976    fPZdAz->SetCoordinates(cpos);
     977}
     978
    553979
    554980void MGStarguider::ProcessFrame(const unsigned long n, byte *img, struct timeval *tm)
     
    568994        c[i] = (byte)(myimg[i]/fIntRate+.5);
    569995
    570     if (!fWrite->IsEntryEnabled(IDM_kStart) &&
     996    if (!fWritePictures->IsEntryEnabled(IDM_kStart) &&
    571997        (!(n%fWrtRate) || fWriteType->IsEntryChecked(IDM_kOnce)))
    572998    {
     
    5811007    }
    5821008
    583 
    5841009    MStarList spots;
     1010
     1011    /*
    5851012    if (fDisplay->IsEntryChecked(IDM_kStarguider))
    5861013        Filter2::Execute(spots, c);
    5871014    else
    588         if (fDisplay->IsEntryChecked(IDM_kFilter))
    589             Filter::Execute(c);
     1015     */
     1016    if (fDisplay->IsEntryChecked(IDM_kFilter))
     1017        Filter::Execute(c);
     1018
     1019    if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
     1020    {
     1021        // Double_t kConv = 0.502; // [pix/mm]
     1022
     1023        static Timer t0(tm);
     1024        Timer t(tm);
     1025
     1026        fTime = (t.GetMjd()-t0.GetMjd())*24*60*60;
     1027
     1028        Leds leds;
     1029        CaosFilter::Execute(c, leds, 1);
     1030
     1031        if (fWrite->IsEntryChecked(IDM_kPositions))
     1032            leds.Print();
     1033
     1034        CaosFilter::FilterLeds(leds);
     1035        leds.Compress();
     1036
     1037        if (fWrite->IsEntryChecked(IDM_kLeds))
     1038            leds.Print();
     1039
     1040        Rings rings;
     1041        rings.CalcRings(leds);
     1042
     1043        leds.Sort();
     1044
     1045        fLeds  = &leds;
     1046        fRings = &rings;
     1047
     1048        if (fFile)
     1049            fTree->Fill();
     1050
     1051        if (fWrite->IsEntryChecked(IDM_kRings))
     1052            rings.Print();
     1053
     1054        if (fAnalyse->IsEntryEnabled(IDM_kStopAnalyse))
     1055        {
     1056            const Ring &center = rings.GetCenter();
     1057
     1058            Double_t phi[6] =
     1059            {
     1060                -124.727,
     1061                 -61.0495,
     1062                 -16.7907,
     1063                  49.3119,
     1064                 139.086
     1065            };
     1066
     1067            fHistpr->Fill(center.GetR());
     1068            fHistprx->Fill(center.GetX());
     1069            fHistpry->Fill(center.GetY());
     1070            fHistprxpry->Fill(center.GetX(), center.GetY());
     1071
     1072            Double_t sum = 0;
     1073            for (int i=0; i<6 && leds.At(i); i++)
     1074            {
     1075                const Double_t w = (leds(i).GetPhi()-phi[i])*60;
     1076
     1077                sum += w;
     1078
     1079                fHistw[i]->Fill(w);
     1080                fHistv[i]->Fill(leds(i).GetPhi());
     1081                fGraphw[i]->SetPoint(fGraphw[i]->GetN(), fTime, w);
     1082            }
     1083            fHistallw->Fill(sum/5);
     1084
     1085            fGraphprx->SetPoint(fGraphprx->GetN(), fTime, center.GetX());
     1086            fGraphpry->SetPoint(fGraphpry->GetN(), fTime, center.GetY());
     1087        }
     1088    }
    5901089
    5911090    byte zimg[kZOOM*kZOOM];
     
    5981097    if (fDisplay->IsEntryChecked(IDM_kCatalog))
    5991098    {
    600         byte cimg[768*576];
     1099        Timer time(tm);
    6011100
    6021101        GetCoordinates();
    603 
    604         Timer time(tm);
    6051102
    6061103        MStarList stars;
    6071104        fSao->GetStars(stars, time.GetMjd(), *fRaDec);
     1105
     1106        if (fDisplay->IsEntryChecked(IDM_kStarguider))
     1107        {
     1108            Leds leds;
     1109            CaosFilter::Execute(c, leds, 1);
     1110
     1111            cout << "Found: " << leds.GetEntries() << " leds" << endl;
     1112
     1113            CaosFilter::RemoveTwins(leds, 3);
     1114            leds.Compress();
     1115
     1116            cout << "Rest: " << leds.GetEntries() << " leds" << endl;
     1117
     1118            CalcTrackingError(leds, stars);
     1119        }
     1120
     1121        byte cimg[768*576];
    6081122        fSao->GetImg(c, cimg, stars);
    609         //fSao->GetImg(c, cimg, time.CalcMjd(), *fRaDec);
     1123
     1124        DrawCircle(c, 0.5);
     1125        DrawCircle(c, 1.0);
     1126        DrawCircle(c, 1.5);
     1127
     1128        fCZdAz->SetCoordinates(fSao->GetZdAz());
    6101129
    6111130        fImage->DrawColImg(c, cimg);
    612 
    613         fCZdAz->SetCoordinates(fSao->GetZdAz());
    614 
    615         if (fDisplay->IsEntryChecked(IDM_kStarguider))
    616             CalcTrackingError(spots, stars);
    6171131    }
    6181132    else
     
    6201134
    6211135    memset(myimg, 0, 768*576*sizeof(float));
     1136}
     1137
     1138void MGStarguider::DrawCircle(byte *img, double r)
     1139{
     1140    const double rpix = r*60*60/fSao->GetPixSize()+1;
     1141    const int cx = 768/2;
     1142    const int cy = 576/2;
     1143    for (int dx=-(int)(rpix*0.7); dx<(int)(rpix*0.7); dx++)
     1144    {
     1145        const int dy = (int)sqrt(rpix*rpix-dx*dx);
     1146        img[cx+dx + (cy-dy)*768] = 0x40;
     1147        img[cx+dx + (cy+dy)*768] = 0x40;
     1148        img[cx-dy + (cy+dx)*768] = 0x40;
     1149        img[cx+dy + (cy+dx)*768] = 0x40;
     1150    }
    6221151}
    6231152
Note: See TracChangeset for help on using the changeset viewer.