Index: /trunk/MagicSoft/Cosy/Changelog
===================================================================
--- /trunk/MagicSoft/Cosy/Changelog	(revision 1818)
+++ /trunk/MagicSoft/Cosy/Changelog	(revision 1819)
@@ -1,4 +1,14 @@
                                                                   -*-*- END -*-*-
  2003/03/12 - Daniela Dorner, Thomas Bretz:
+
+   * MStarguider.[h,cc], Starguider.[h,cc]:
+     - removed
+
+   * gui/MGPngReader.[h,cc]:
+     - moved code to MGStarguider.[h,cc]
+     - removed
+
+   * gui/Makefile, gui/GuiLinkDef.h:
+     - updated
 
    * gui/MGPngReader.cc, gui/MGStarguider.cc, videodev/Writer.[h,cc]:
Index: /trunk/MagicSoft/Cosy/gui/GuiLinkDef.h
===================================================================
--- /trunk/MagicSoft/Cosy/gui/GuiLinkDef.h	(revision 1818)
+++ /trunk/MagicSoft/Cosy/gui/GuiLinkDef.h	(revision 1819)
@@ -19,5 +19,4 @@
 #pragma link C++ class MGCosy+;
 #pragma link C++ class MGStarguider+;
-#pragma link C++ class MGPngReader+;
 
 #endif
Index: /trunk/MagicSoft/Cosy/gui/MGAccuracy.cc
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGAccuracy.cc	(revision 1818)
+++ /trunk/MagicSoft/Cosy/gui/MGAccuracy.cc	(revision 1819)
@@ -200,5 +200,16 @@
     const double cos2  = cos(dphi2)*cos(dphi2);
     const double sin2  = sin(dphi2)*sin(dphi2);
-    const double d     = cos(azd)*cos2 - cos(2*el+azd)*sin2;
+    const double d     = cos(azd)*cos2 - cos(2*el)*sin2;
+
+    //
+    // Original:
+    //   cos(Zd1)*cos(Zd2)+sin(Zd1)*sin(Zd2)*cos(dAz)
+    //
+    // Correct:
+    //   const double d = cos(azd)*cos2 - cos(el1+el2)*sin2;
+    //
+    // Estimated:
+    //   const double d = cos(azd)*cos2 - cos(2*el)*sin2;
+    //
 
     double dist = acos(d);
Index: /trunk/MagicSoft/Cosy/gui/MGStarguider.cc
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGStarguider.cc	(revision 1818)
+++ /trunk/MagicSoft/Cosy/gui/MGStarguider.cc	(revision 1819)
@@ -3,8 +3,10 @@
 #include <fstream.h>    // ifstream
 #include <iostream.h>   // cout
+#include <iomanip.h>   // cout
 
 #include <TTimer.h>
 
 #include <TGMenu.h>
+#include <TGLabel.h>
 #include <TSystem.h>
 #include <TGSplitter.h>    // TGHorizontal3DLine
@@ -20,4 +22,5 @@
 #include "Filter.h"
 #include "Filter2.h"
+#include "CaosFilter.h"
 #include "Writer.h"
 #include "base/timer.h"
@@ -25,8 +28,24 @@
 #include "MStarList.h"
 
+#include <TH1.h>
+#include <TH2.h>
+#include <TGraph.h>
+#include <TCanvas.h>
+
+#include <TFile.h>
+#include <TTree.h>
+#include <TBranch.h>
+
+#include "Led.h"
+#include "Leds.h"
+#include "Rings.h"
+
+#include "MGMenu.h"
+
 ClassImp(MGStarguider);
 
 enum {
     IDM_kFilter,
+    IDM_kCaosFilter,
     IDM_kCatalog,
     IDM_kStarguider,
@@ -60,5 +79,11 @@
     IDM_kInterpol5,
     IDM_kInterpol2,
-    IDM_kInterpol1
+    IDM_kInterpol1,
+    IDM_kPositions,
+    IDM_kRings,
+    IDM_kLeds,
+    IDM_kStartAnalyse,
+    IDM_kStopAnalyse,
+    IDM_kResetHistograms
 };
 
@@ -72,16 +97,100 @@
 #define kZOOM 96
 
-MGStarguider::MGStarguider(MObservatory::LocationName_t key)
-: TGMainFrame(gClient->GetRoot(), 768, 700), fObservatory(key), fDx((768-kZOOM)/2), fDy((512-kZOOM)/2)
-{
-    gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kTRUE);
-
+void MGStarguider::InitHists()
+{
+    Double_t xmin = 480.1-1.0;
+    Double_t xmax = 480.1+1.0;
+
+    Double_t ymin = 217.5-1.0;
+    Double_t ymax = 217.5+1.0;
+
+    Double_t rmin = 117.4-1.0;
+    Double_t rmax = 117.4+1.0;
+
+    Int_t xbin = 60;
+    Int_t ybin = 60;
+    Int_t rbin = 60;
+
+    fHistpr = new TH1F;
+    fHistpr->SetNameTitle("pr","Radius of the ring");
+    fHistpr->SetBins(rbin, rmin, rmax);
+    fHistpr->SetXTitle("r [mm]");
+    fHistpr->SetYTitle("counts");
+
+    fHistprx = new TH1F;
+    fHistprx->SetNameTitle("prx","x-coordinate of the ring-center");
+    fHistprx->SetBins(xbin, xmin, xmax);
+    fHistprx->SetXTitle("x [mm]");
+    fHistprx->SetYTitle("counts");
+
+    fHistpry = new TH1F;
+    fHistpry->SetNameTitle("pry","y-coordniate of the ring-center");
+    fHistpry->SetBins(ybin, ymin, ymax);
+    fHistpry->SetXTitle("y [mm]");
+    fHistpry->SetYTitle("counts");
+
+    for (int i=0; i<6; i++)
+    {
+        TString name  = "Angle";
+        TString title = "Angle of Led ";
+
+        name += i;
+        title += i;
+
+        fHistw[i] = new TH1F;
+        fHistw[i]->SetNameTitle(name, title);
+        fHistw[i]->SetBins(26, -25, 25);
+        fHistw[i]->SetXTitle("\\Phi [arcmin]");
+        fHistw[i]->SetYTitle("counts");
+
+        name = "Angles";
+        title = "Angles of the Leds ";
+
+        name += i;
+        title += i;
+
+        fHistv[i] = new TH1F;
+        fHistv[i]->SetNameTitle(name, title);
+        fHistv[i]->SetBins(721, -180.5, 180.5);
+        fHistv[i]->SetXTitle("\\Phi [deg]");
+        fHistv[i]->SetYTitle("counts");
+    }
+
+    fHistallw = new TH1F;
+    fHistallw->SetNameTitle("allw","Rotation angel");
+    fHistallw->SetBins(26, -25, 25);
+    fHistallw->SetXTitle("\\Phi [arcmin]");
+    fHistallw->SetYTitle("counts");
+
+    fHistprxpry = new TH2F;
+    fHistprxpry->SetNameTitle("prx und pry","x- and y-coordniate of the ring-center");
+    fHistprxpry->SetBins(xbin, xmin, xmax, ybin, ymin, ymax);
+    fHistprxpry->SetXTitle("x [mm]");
+    fHistprxpry->SetYTitle("y [mm]");
+    fHistprxpry->SetZTitle("counts");
+}
+
+void MGStarguider::InitGraphs()
+{
+    fGraphprx = new TGraph;
+    fGraphprx->SetTitle("time-developement of the x-coordinate of the ring-center");
+
+    fGraphpry = new TGraph;
+    fGraphpry->SetTitle("time-developement of the y-coordinate of the ring-center");
+
+    for (int i=0; i<6; i++)
+    {
+        TString title = "Time-developement of the angle ";
+        title += i;
+
+        fGraphw[i] = new TGraph;
+        fGraphw[i]->SetTitle(title);
+    }
+}
+
+void MGStarguider::InitGui()
+{
     fList = new MGList;
 
-    fSao = new StarCatalog(fObservatory);
-    fRaDec = new RaDec(180, 40);
-
-    // p = pointer to MainFrame (not owner)
-
     const TGWindow *p=gClient->GetRoot();
 
@@ -89,12 +198,14 @@
     // Create Menu for MGStarguider Display
     //
-    fDisplay = new TGPopupMenu(p);
+    fDisplay = new MGPopupMenu(p);
     fDisplay->AddEntry("&Filter",      IDM_kFilter);
+    fDisplay->AddEntry("C&aosFilter",  IDM_kCaosFilter);
     fDisplay->AddEntry("Sao &Catalog", IDM_kCatalog);
     fDisplay->AddEntry("Starguider",   IDM_kStarguider);
+    fDisplay->DisableEntry(IDM_kStarguider);
     fDisplay->Associate(this);
     fList->Add(fDisplay);
 
-    fFileType = new TGPopupMenu(p);
+    fFileType = new MGPopupMenu(p);
     fFileType->AddEntry("PP&M", IDM_kPPM);
     fFileType->AddEntry("&PNG", IDM_kPNG);
@@ -103,12 +214,11 @@
     fList->Add(fFileType);
 
-    fWriteType = new TGPopupMenu(p);
-    fWriteType->AddEntry("Once",      IDM_kOnce);
-    fWriteType->AddEntry("Continous", IDM_kContinous);
-    fWriteType->CheckEntry(IDM_kOnce);
+    fWriteType = new MGPopupMenu(p);
+    fWriteType->AddEntry("&Once",      IDM_kOnce);
+    fWriteType->AddEntry("&Continous", IDM_kContinous);
     fWriteType->Associate(this);
     fList->Add(fWriteType);
 
-    fWriteRate = new TGPopupMenu(p);
+    fWriteRate = new MGPopupMenu(p);
     fWriteRate->AddEntry("25/s", IDM_kRate25ps);
     fWriteRate->AddEntry("5/s",  IDM_kRate5ps);
@@ -124,16 +234,16 @@
     fWrtRate = 25*60;
 
-    fWrite = new TGPopupMenu(p);
-    fWrite->AddEntry("&Start",      IDM_kStart);
-    fWrite->AddEntry("Sto&p",       IDM_kStop);
-    fWrite->AddSeparator();
-    fWrite->AddPopup("File &Type",  fFileType);
-    fWrite->AddPopup("&Write Type", fWriteType);
-    fWrite->AddPopup("Write &Rate", fWriteRate);
-    fWrite->DisableEntry(IDM_kStop);
-    fWrite->Associate(this);
-    fList->Add(fWrite);
-
-    fLimMag = new TGPopupMenu(p);
+    fWritePictures = new MGPopupMenu(p);
+    fWritePictures->AddEntry("&Start",      IDM_kStart);
+    fWritePictures->AddEntry("Sto&p",       IDM_kStop);
+    fWritePictures->AddSeparator();
+    fWritePictures->AddPopup("File &Type",  fFileType);
+    fWritePictures->AddPopup("&Write Type", fWriteType);
+    fWritePictures->AddPopup("Write &Rate", fWriteRate);
+    fWritePictures->DisableEntry(IDM_kStop);
+    fWritePictures->Associate(this);
+    fList->Add(fWritePictures);
+
+    fLimMag = new MGPopupMenu(p);
     fLimMag->AddEntry("3", IDM_kLimMag3);
     fLimMag->AddEntry("4", IDM_kLimMag4);
@@ -147,7 +257,7 @@
     fList->Add(fLimMag);
 
-    fSao->SetLimitMag(8.0);
-
-    fInterpol = new TGPopupMenu(p);
+    fSao->SetLimitMag(7.0);
+
+    fInterpol = new MGPopupMenu(p);
     fInterpol->AddEntry("125", IDM_kInterpol125);
     fInterpol->AddEntry("25",  IDM_kInterpol25);
@@ -156,11 +266,11 @@
     fInterpol->AddEntry("2",   IDM_kInterpol2);
     fInterpol->AddEntry("Off", IDM_kInterpol1);
-    fInterpol->CheckEntry(IDM_kInterpol25);
+    fInterpol->CheckEntry(IDM_kInterpol1);
     fInterpol->Associate(this);
     fList->Add(fInterpol);
 
-    fIntRate = 25;
-
-    fSetup = new TGPopupMenu(p);
+    fIntRate = 1;
+
+    fSetup = new MGPopupMenu(p);
     fSetup->AddPopup("Lim. &Magnitude",      fLimMag);
     fSetup->AddPopup("Disp. &Interpolation", fInterpol);
@@ -169,11 +279,35 @@
     fList->Add(fSetup);
 
-    fMenu = new TGMenuBar(this, 0, 0, kHorizontalFrame);
+    fWrite = new MGPopupMenu(p);
+    fWrite->AddEntry("&Positions",  IDM_kPositions);
+    fWrite->AddEntry("&Leds", IDM_kLeds);
+    fWrite->AddEntry("&Rings", IDM_kRings);
+    fWrite->Associate(this);
+    fList->Add(fWrite);
+
+    fAnalyse = new MGPopupMenu(p);
+    fAnalyse->AddEntry("S&tart Analyse", IDM_kStartAnalyse);
+    fAnalyse->AddEntry("St&opp Analyse", IDM_kStopAnalyse);
+    fAnalyse->DisableEntry(IDM_kStopAnalyse);
+    fAnalyse->AddEntry("&Reset Histograms", IDM_kResetHistograms);
+//    fAnalyse->AddEntry("Reset &Graph", IDM_kResetGraph);
+    fAnalyse->Associate(this);
+    fList->Add(fAnalyse);
+
+    fMenu = new MGMenuBar(this, 0, 0, kHorizontalFrame);
     fMenu->AddPopup("&Display", fDisplay, NULL);
-    fMenu->AddPopup("&Write",   fWrite,   NULL);
+    fMenu->AddPopup("&WritePics",   fWritePictures,   NULL);
     fMenu->AddPopup("&Setup",   fSetup,   NULL);
     fMenu->Resize(fMenu->GetDefaultSize());
+    fMenu->BindKeys(this);
     AddFrame(fMenu); //, new TGLayoutHints (kLHintsNormal, 0, 4, 0, 0));
     fList->Add(fMenu);
+
+    fCaOs = new MGPopupMenu(p);
+    fCaOs->AddPopup("&Write", fWrite);
+    fCaOs->AddPopup("&Analyse", fAnalyse);
+    fCaOs->Associate(this);
+    fCaOs->BindKeys(fMenu, this);
+    fList->Add(fCaOs);
 
     fCRaDec = new MGCoordinates(this, kETypeRaDec);
@@ -182,10 +316,33 @@
     fList->Add(fCRaDec);
 
-    fCZdAz = new MGCoordinates(this, kETypeZdAz);
+    fCZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
     fCZdAz->Move(240+12+10, fMenu->GetDefaultHeight()+584);
     AddFrame(fCZdAz);
     fList->Add(fCZdAz);
 
-    const Double_t pixsize = 23.5;
+    fPZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
+    fPZdAz->Move(240+12+10, fMenu->GetDefaultHeight()+630);
+    AddFrame(fPZdAz);
+    fList->Add(fPZdAz);
+
+    TGLabel *l = new TGLabel(this, "Arb.-Sky Pos");
+    l->SetTextJustify(kTextLeft);
+    l->Move(480+32, fMenu->GetDefaultHeight()+590);
+    AddFrame(l);
+    fList->Add(l);
+
+    l = new TGLabel(this, "arcsec/pix");
+    l->SetTextJustify(kTextLeft);
+    l->Move(605, fMenu->GetDefaultHeight()+619);
+    AddFrame(l);
+    fList->Add(l);
+
+    l = new TGLabel(this, "Pointing Pos");
+    l->SetTextJustify(kTextLeft);
+    l->Move(480+32, fMenu->GetDefaultHeight()+655);
+    AddFrame(l);
+    fList->Add(l);
+
+    const Double_t pixsize = 23.4;
 
     fSao->SetPixSize(pixsize/3600);
@@ -196,5 +353,5 @@
     fPixSize = new TGTextEntry(this, txt, IDM_kPixSize);
     fPixSize->SetAlignment(kTextCenterX);
-    fPixSize->Move(600, fMenu->GetDefaultHeight()+584);
+    fPixSize->Move(547, fMenu->GetDefaultHeight()+617);
     AddFrame(fPixSize);
     fList->Add(fPixSize);
@@ -226,4 +383,24 @@
     MapWindow();
 
+    //------------------------------------------------------------
+    //    XY xy(3.819444, 24.05333);
+    //    fCRaDec->SetCoordinates(xy);
+    //    fRaDec->Set(xy.X()*360/24, xy.Y());
+    //------------------------------------------------------------
+}
+
+MGStarguider::MGStarguider(MObservatory::LocationName_t obs)
+: TGMainFrame(gClient->GetRoot(), 768, 740), fFile(NULL), fDx((768-kZOOM)/2), fDy((512-kZOOM)/2)
+{
+    fSao = new StarCatalog(obs);
+    fRaDec = new RaDec(180, 40);
+
+    InitHists();
+    InitGraphs();
+
+    InitGui();
+
+    gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kTRUE);
+
     fTimer=new TTimer(this, 100); // 100ms
     fTimer->TurnOn();
@@ -232,13 +409,29 @@
 MGStarguider::~MGStarguider()
 {
-    gVirtualX->GrabButton(0, kButton2, 0, 0, 0, 0, kFALSE);
+    gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kFALSE);
 
     fTimer->TurnOff();
     delete fTimer;
 
+    delete fList;
+
     delete fSao;
     delete fRaDec;
 
-    delete fList;
+    delete fHistpr;
+    delete fHistprx;
+    delete fHistpry;
+    delete fHistprxpry;
+    delete fHistallw;
+    delete fGraphprx;
+    delete fGraphpry;
+
+    for (int i=0; i<6; i++)
+    {
+        delete fHistw[i];
+        delete fHistv[i];
+        delete fGraphw[i];
+    }
+
     cout << "Camera Display destroyed." << endl;
 }
@@ -253,11 +446,10 @@
     cout << "EventDisplay::CloseWindow: Exit Application Loop." << endl;
 
-    /*ExitLoop();*/
-    //cout << "FIXME: ExitLoop not called!!!!!!" << endl;
-
+    //fClient.ExitLoop();
+    //    cout << "FIXME: ExitLoop not called!!!!!!" << endl;
     gSystem->ExitLoop();
 }
 
-void MGStarguider::Toggle(TGPopupMenu *p, UInt_t id)
+void MGStarguider::Toggle(MGPopupMenu *p, UInt_t id)
 {
     if (p->IsEntryChecked(id))
@@ -265,5 +457,121 @@
     else
         p->CheckEntry(id);
-
+}
+
+void MGStarguider::ResetHists()
+{
+    fHistprx->Reset();
+    fHistpry->Reset();
+    fHistpr->Reset();
+    fHistprxpry->Reset();
+    fHistallw->Reset();
+    for (int i=0; i<6; i++)
+    {
+        fHistw[i]->Reset();
+        fHistv[i]->Reset();
+    }
+}
+
+void MGStarguider::DisplayAnalysis()
+{
+    TCanvas *c = new TCanvas("cring", "Center of the ring", 800, 800);
+    c->Divide(2,2);
+    c->cd(1);
+    fHistprx->Fit("gaus");
+    fHistprx->DrawCopy();
+    c->cd(2);
+    fHistpry->Fit("gaus");
+    fHistpry->DrawCopy();
+    c->cd(3);
+    fHistpr->Fit("gaus");
+    fHistpr->DrawCopy();
+    c->cd(4);
+    fHistprxpry->DrawCopy(/*"surf2"*/);
+    c->Update();
+
+    c = new TCanvas("c3", "Absolute angles of the leds", 800, 800);
+    c->Divide(2,3);
+    for (int i=0; i<6; i++)
+    {
+        c->cd(i+1);
+        TH1 *h = fHistv[i]->DrawCopy();
+        h->SetLineColor(i+1);
+        cout << "Led #" << i << ": MeanPhi=" << h->GetMean() << endl;
+    }
+    c->Update();
+
+    c = new TCanvas("c5", "timedevelopement of prx", 800, 800);
+    fGraphprx->Draw("ALP*");
+    fGraphprx->GetHistogram()->SetXTitle("time [1/25 s]");
+    fGraphprx->GetHistogram()->SetYTitle("x-coordinate");
+    c->Modified();
+    c->Update();
+
+    c = new TCanvas("c6", "timedevelopement of pry", 800, 800);
+    fGraphpry->Draw("ALP*");
+    fGraphpry->GetHistogram()->SetXTitle("time [1/25 s]");
+    fGraphpry->GetHistogram()->SetYTitle("y-coordinate");
+    c->Modified();
+    c->Update();
+
+    c = new TCanvas("c2", "Relative angles of the Leds", 800, 800);
+    c->Divide(2,3);
+    for (int i=0; i<6; i++)
+    {
+        c->cd(i+1);
+        fHistw[i]->DrawCopy();
+    }
+    c->Update();
+
+    c = new TCanvas("c7", "timedevelopement of the relative angles of the Leds", 800, 800);
+    c->Divide(2,3);
+    for (int i=0; i<6; i++)
+    {
+        c->cd(i+1);
+        fGraphw[i]->Draw("ALP*");
+        fGraphw[i]->GetHistogram()->SetXTitle("t [1/25s]");
+        fGraphw[i]->GetHistogram()->SetYTitle("[deg]");
+    }
+    c->Modified();
+    c->Update();
+
+    c = new TCanvas("c4", "rotation angle ", 800, 800);
+    fHistallw->Fit("gaus");
+    fHistallw->DrawCopy();
+}
+
+void MGStarguider::OpenFile()
+{
+    int i=0;
+    char name[100];
+    while (1)
+    {
+        sprintf(name, "data/data%03d.root", i++);
+        if (gSystem->AccessPathName(name, kFileExists))
+            break;
+    }
+
+    fFile = new TFile(name, "RECREATE");
+
+    if (!fFile->IsOpen())
+    {
+        delete fFile;
+        fFile = NULL;
+
+        cout << "Error: Cannot open file '" << name << "'" << endl;
+
+    }
+
+    fTree = new TTree("Data", "Real CaOs Data");
+
+    fLeds = NULL;
+    fRings = NULL;
+    fTime = 0;
+
+    fBranchL = fTree->Branch("Leds.",  "Leds",  &fLeds);
+    fBranchR = fTree->Branch("Rings.", "Rings", &fRings);
+    fBranchT = fTree->Branch("Time.", &fTime, "fTime/D");//, &fTime);
+
+    cout << "Root file '" << name << "' open." << endl;
 }
 
@@ -282,7 +590,9 @@
 
     case kC_COMMAND:
+        //cout << "kC_COMMAND" << endl;
         switch (GET_SUBMSG(msg))
         {
         case kCM_MENU:
+            //cout << "kCM_MENU #" << mp1 << endl;
             switch (mp1)
             {
@@ -313,4 +623,76 @@
                 return kTRUE;
 
+            case IDM_kCaosFilter:
+                if (!fDisplay->IsEntryChecked(IDM_kCaosFilter))
+                    OpenFile();
+                Toggle(fDisplay, IDM_kCaosFilter);
+                if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
+                    fMenu->AddPopup("&CaOs", fCaOs, NULL);
+                else
+                {
+                    fFile->Write();
+                    delete fFile;
+                    fFile = NULL;
+
+                    cout << "Root file closed." << endl;
+
+                    if(fWrite->IsEntryChecked(IDM_kPositions))
+                       fWrite->UnCheckEntry(IDM_kPositions);
+                    if(fWrite->IsEntryChecked(IDM_kLeds))
+                       fWrite->UnCheckEntry(IDM_kLeds);
+                    if(fWrite->IsEntryChecked(IDM_kRings))
+                        fWrite->UnCheckEntry(IDM_kRings);
+                    if(fAnalyse->IsEntryEnabled(IDM_kStopAnalyse))
+                    {
+                        fAnalyse->DisableEntry(IDM_kStopAnalyse);
+                        fAnalyse->EnableEntry(IDM_kStartAnalyse);
+                        ResetHists();
+                        // Graphs are not reset !!!
+                    }
+                    fMenu->RemovePopup("CaOs");
+                }
+                fMenu->Resize(fMenu->GetDefaultSize());
+                MapSubwindows();
+                MapWindow();
+                return kTRUE;
+
+            case IDM_kPositions:
+                Toggle(fWrite, IDM_kPositions);
+                return kTRUE;
+
+            case IDM_kLeds:
+                Toggle(fWrite, IDM_kLeds);
+                return kTRUE;
+
+            case IDM_kRings:
+                Toggle(fWrite, IDM_kRings);
+                return kTRUE;
+
+            case IDM_kStartAnalyse:
+                fAnalyse->DisableEntry(IDM_kStartAnalyse);
+                fAnalyse->EnableEntry(IDM_kStopAnalyse);
+                return kTRUE;
+
+            case IDM_kStopAnalyse:
+                {
+                    fAnalyse->DisableEntry(IDM_kStopAnalyse);
+                    fAnalyse->EnableEntry(IDM_kStartAnalyse);
+
+                    DisplayAnalysis();
+
+                    return kTRUE;
+                }
+
+            case IDM_kResetHistograms:
+                ResetHists();
+                return kTRUE;
+
+/*            case IDM_kResetGraph:
+                {
+                    fGraphx->GetHistogram()->Reset();
+
+                }
+*/
+
             case IDM_kUseFileRaDec:
                 Toggle(fSetup, IDM_kUseFileRaDec);
@@ -318,11 +700,11 @@
 
             case IDM_kStart:
-                fWrite->DisableEntry(IDM_kStart);
-                fWrite->EnableEntry(IDM_kStop);
+                fWritePictures->DisableEntry(IDM_kStart);
+                fWritePictures->EnableEntry(IDM_kStop);
                 return kTRUE;
 
             case IDM_kStop:
-                fWrite->DisableEntry(IDM_kStop);
-                fWrite->EnableEntry(IDM_kStart);
+                fWritePictures->DisableEntry(IDM_kStop);
+                fWritePictures->EnableEntry(IDM_kStart);
                 return kTRUE;
 
@@ -460,6 +842,71 @@
 }
 
-void MGStarguider::CalcTrackingError(MStarList &spots, MStarList &stars)
-{
+ZdAz MGStarguider::TrackingError(TArrayF &x, TArrayF &y, TArrayF &mag) const
+{
+    //
+    // Viewable area (FIXME: AZ)
+    //
+    TH2F h("Hist", "dX/dY",  77, -768/2-.5,  768/2+.5, 58, -576/2-.5,  576/2+.5); // 3
+
+    /*
+    TH1F hmag("HistMag", "Mag", 19, 0, 100);
+    for (int i=0; i<mag.GetSize(); i++)
+        hmag.Fill(mag[i]);
+        */
+
+    //
+    // Search for matching Magnitudes
+    //
+    for (int i=0; i<mag.GetSize(); i++)
+    {
+        if (mag[i]>48-15 && mag[i]<48+15)
+            h.Fill(x[i], y[i]);
+    }
+
+    //
+    // Serach for an excess in the histogram
+    //
+    Int_t mx, my, dummy;
+    h.GetMaximumBin(mx, my, dummy);
+
+    const double xmax = h.GetXaxis()->GetBinCenter(mx);
+    const double dx   = h.GetXaxis()->GetBinWidth(mx);
+
+    const double ymax = h.GetYaxis()->GetBinCenter(my);
+    const double dy   = h.GetYaxis()->GetBinWidth(my);
+
+    cout << setprecision(3);
+    cout << "Cut-XY:       " << xmax << " +- " << dx << " / " << ymax << " +- " << dy << endl;
+
+    TGraph g;
+    for (int i=0; i<mag.GetSize(); i++)
+    {
+        if (!(x[i]>xmax-dx && x[i]<xmax+dx &&
+              y[i]>ymax-dy && y[i]<ymax+dy &&
+              mag[i]>48-15 && mag[i]<48+15))
+            continue;
+
+        g.SetPoint(g.GetN(), x[i], y[i]);
+    }
+
+    cout << "Offset-XY:    " << g.GetMean(1) << " +- " << g.GetRMS(1) << " / ";
+    cout << g.GetMean(2) << " +- " << g.GetRMS(2) << endl;
+
+    AltAz pos0 = fSao->CalcAltAzFromPix(768/2,              576/2)*kRad2Deg;
+    AltAz pos1 = fSao->CalcAltAzFromPix(768/2+g.GetMean(1), 576/2+g.GetMean(2))*kRad2Deg;
+
+    pos1 -= pos0;
+
+    ofstream fout("tracking_error.txt");
+    fout << setprecision(10) << fSao->GetMjd()-52000 << " " << -pos1.Alt() << " " << pos1.Az() << endl;
+    fout.close();
+
+    return ZdAz(-pos1.Alt(), pos1.Az());
+}
+
+void MGStarguider::CalcTrackingError(Leds &leds, MStarList &stars)
+{
+    const Int_t max = leds.GetEntries();
+
     if (stars.GetRealEntries() < 3)
     {
@@ -468,5 +915,5 @@
     }
 
-    if (spots.GetRealEntries() < 1)
+    if (max < 1)
     {
         cout << "Sorry, less than 1 detected spot in FOV!" << endl;
@@ -474,81 +921,60 @@
     }
 
-    Int_t idx = 0;
-
-    MStarList sortedspots;
+    stars.Sort(); // Sort by magnitude
+
+    TString str = "data/tracking_";
+    str += fSao->GetMjd()-52000;
+    str += ".txt";
+
+    ofstream fout(str);
+
+    TArrayF x, y, mag;
+
+    Int_t num = 0;
+
+    // FIXME: Is predifined value 3 a good idea?
 
     MStar *star;
-    MStar *spot;
     MStarListIter NextStar(&stars);
-    MStarListIter NextSpot(&spots);
-
-    while ((spot=NextSpot()))
-    {
-        AltAz aa = fSao->CalcAltAzFromPix(spot->GetX(), spot->GetY());
-        spot->Set(aa.Az(), aa.Alt());
-    }
-
-    while ((star=NextStar()))
-    {
-        AltAz aa = fSao->CalcAltAzFromPix(star->GetX(), star->GetY());
-        star->Set(aa.Az(), aa.Alt());
-
-        const double aaz   = star->GetX();
-        const double dphi2 = aaz/2.;
-        const double cos2  = cos(dphi2)*cos(dphi2);
-        const double sin2  = sin(dphi2)*sin(dphi2);
-
-        Double_t min = 800;
-
-        NextSpot.Reset();
-        while ((spot=NextSpot()))
+    while ((star=NextStar()) && num++<max+3)
+    {
+        TIter NextSp(&leds);
+        Led *spot=NULL;
+        while ((spot=(Led*)NextSp()))
         {
-            const double pzd = TMath::Pi()/2-spot->GetY();
-            const double azd = TMath::Pi()/2-star->GetY();
-
-            const double d = cos(azd)*cos2 - cos(2*pzd+azd)*sin2;
-
-            const Double_t dist = acos(d);
-
-            if (dist>=min)
-                continue;
-
-            min = dist;
-            sortedspots.AddAt(idx, spot->GetX(), spot->GetY(), spot->GetMag());
+            const XY dpos(spot->GetX()-star->GetX(), spot->GetY()-star->GetY());
+
+            const Int_t idx = x.GetSize();
+
+            x.Set(idx+1);
+            y.Set(idx+1);
+            mag.Set(idx+1);
+
+            x.AddAt(dpos.X(), idx);
+            y.AddAt(dpos.Y(), idx);
+            mag.AddAt(spot->GetMag()/star->GetMag(), idx);
+
+            if (fout)
+                fout << x[idx] << " " << y[idx] << " " << mag[idx] << endl;
         }
-        if (min>768)
-        {
-            cout << "ERROR!!!!!!!!" << endl;
-            return;
-        }
-        idx++;
-    }
-
-    //
-    // Now we have in sortedspots the entries with the shortest distances
-    // to the corresponding ones in stars.
-    // Now calculate the tracking error.
-    //
-    NextStar.Reset();
-    MStarListIter NextSpot2(&sortedspots);
-
-    Double_t meanx=0;
-    Double_t meany=0;
-
-    while ((star=NextStar()))
-    {
-        spot = NextSpot2();
-
-        meanx += star->GetX() - spot->GetX();
-        meany += star->GetY() - spot->GetY();
-    }
-
-    meanx /= idx;
-    meany /= idx;
-
-    cout << "Tracking Error:  dAlt=" << meany*180/TMath::Pi();
-    cout << "°  dAz=" << meanx*180/TMath::Pi() << "°    (calculated";
-    cout << " with " << idx << " stars/spots)" << endl;
-}
+    }
+
+    ZdAz d = TrackingError(x, y, mag);
+
+    //
+    // Calculated offsets
+    //
+
+    // round= floor(x+.5)
+    cout << "Offset-ZdAz: " << d.Zd()*60 << "' / " << d.Az()*60 << "'" << endl;
+    cout << "Offset-ZdAz: " << d.Zd()/360*16384 << " / " << d.Az()/360*16384 << " (SE) " << endl;
+
+    //
+    // Current Pointing position
+    //
+    ZdAz cpos = fSao->GetZdAz()-d;
+    fPZdAz->SetCoordinates(cpos);
+}
+
 
 void MGStarguider::ProcessFrame(const unsigned long n, byte *img, struct timeval *tm)
@@ -568,5 +994,5 @@
         c[i] = (byte)(myimg[i]/fIntRate+.5);
 
-    if (!fWrite->IsEntryEnabled(IDM_kStart) &&
+    if (!fWritePictures->IsEntryEnabled(IDM_kStart) &&
         (!(n%fWrtRate) || fWriteType->IsEntryChecked(IDM_kOnce)))
     {
@@ -581,11 +1007,84 @@
     }
 
-
     MStarList spots;
+
+    /*
     if (fDisplay->IsEntryChecked(IDM_kStarguider))
         Filter2::Execute(spots, c);
     else
-        if (fDisplay->IsEntryChecked(IDM_kFilter))
-            Filter::Execute(c);
+     */
+    if (fDisplay->IsEntryChecked(IDM_kFilter))
+        Filter::Execute(c);
+
+    if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
+    {
+        // Double_t kConv = 0.502; // [pix/mm]
+
+        static Timer t0(tm);
+        Timer t(tm);
+
+        fTime = (t.GetMjd()-t0.GetMjd())*24*60*60;
+
+        Leds leds;
+        CaosFilter::Execute(c, leds, 1);
+
+        if (fWrite->IsEntryChecked(IDM_kPositions))
+            leds.Print();
+
+        CaosFilter::FilterLeds(leds);
+        leds.Compress();
+
+        if (fWrite->IsEntryChecked(IDM_kLeds))
+            leds.Print();
+
+        Rings rings;
+        rings.CalcRings(leds);
+
+        leds.Sort();
+
+        fLeds  = &leds;
+        fRings = &rings;
+
+        if (fFile)
+            fTree->Fill();
+
+        if (fWrite->IsEntryChecked(IDM_kRings))
+            rings.Print();
+
+        if (fAnalyse->IsEntryEnabled(IDM_kStopAnalyse))
+        {
+            const Ring &center = rings.GetCenter();
+
+            Double_t phi[6] =
+            {
+                -124.727,
+                 -61.0495,
+                 -16.7907,
+                  49.3119,
+                 139.086
+            };
+
+            fHistpr->Fill(center.GetR());
+            fHistprx->Fill(center.GetX());
+            fHistpry->Fill(center.GetY());
+            fHistprxpry->Fill(center.GetX(), center.GetY());
+
+            Double_t sum = 0;
+            for (int i=0; i<6 && leds.At(i); i++)
+            {
+                const Double_t w = (leds(i).GetPhi()-phi[i])*60;
+
+                sum += w;
+
+                fHistw[i]->Fill(w);
+                fHistv[i]->Fill(leds(i).GetPhi());
+                fGraphw[i]->SetPoint(fGraphw[i]->GetN(), fTime, w);
+            }
+            fHistallw->Fill(sum/5);
+
+            fGraphprx->SetPoint(fGraphprx->GetN(), fTime, center.GetX());
+            fGraphpry->SetPoint(fGraphpry->GetN(), fTime, center.GetY());
+        }
+    }
 
     byte zimg[kZOOM*kZOOM];
@@ -598,21 +1097,36 @@
     if (fDisplay->IsEntryChecked(IDM_kCatalog))
     {
-        byte cimg[768*576];
+        Timer time(tm);
 
         GetCoordinates();
-
-        Timer time(tm);
 
         MStarList stars;
         fSao->GetStars(stars, time.GetMjd(), *fRaDec);
+
+        if (fDisplay->IsEntryChecked(IDM_kStarguider))
+        {
+            Leds leds;
+            CaosFilter::Execute(c, leds, 1);
+
+            cout << "Found: " << leds.GetEntries() << " leds" << endl;
+
+            CaosFilter::RemoveTwins(leds, 3);
+            leds.Compress();
+
+            cout << "Rest: " << leds.GetEntries() << " leds" << endl;
+
+            CalcTrackingError(leds, stars);
+        }
+
+        byte cimg[768*576];
         fSao->GetImg(c, cimg, stars);
-        //fSao->GetImg(c, cimg, time.CalcMjd(), *fRaDec);
+
+        DrawCircle(c, 0.5);
+        DrawCircle(c, 1.0);
+        DrawCircle(c, 1.5);
+
+        fCZdAz->SetCoordinates(fSao->GetZdAz());
 
         fImage->DrawColImg(c, cimg);
-
-        fCZdAz->SetCoordinates(fSao->GetZdAz());
-
-        if (fDisplay->IsEntryChecked(IDM_kStarguider))
-            CalcTrackingError(spots, stars);
     }
     else
@@ -620,4 +1134,19 @@
 
     memset(myimg, 0, 768*576*sizeof(float));
+}
+
+void MGStarguider::DrawCircle(byte *img, double r)
+{
+    const double rpix = r*60*60/fSao->GetPixSize()+1;
+    const int cx = 768/2;
+    const int cy = 576/2;
+    for (int dx=-(int)(rpix*0.7); dx<(int)(rpix*0.7); dx++)
+    {
+        const int dy = (int)sqrt(rpix*rpix-dx*dx);
+        img[cx+dx + (cy-dy)*768] = 0x40;
+        img[cx+dx + (cy+dy)*768] = 0x40;
+        img[cx-dy + (cy+dx)*768] = 0x40;
+        img[cx+dy + (cy+dx)*768] = 0x40;
+    }
 }
 
Index: /trunk/MagicSoft/Cosy/gui/MGStarguider.h
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGStarguider.h	(revision 1818)
+++ /trunk/MagicSoft/Cosy/gui/MGStarguider.h	(revision 1819)
@@ -1,4 +1,4 @@
-#ifndef MGSTARGUIDER_H
-#define MGSTARGUIDER_H
+#ifndef COSY_MGStarguider
+#define COSY_MGStarguider
 
 #ifndef ROOT_TGFrame
@@ -6,19 +6,22 @@
 #endif
 #include "PixClient.h"
+#ifndef MARS_MObservatory
+#include "MObservatory.h"
+#endif
 
 #include "MGList.h"
 #include "MGImage.h"
 
-#ifndef MARS_MObservatory
-#include "MObservatory.h"
-#endif
+#include "coord.h"
 
-class AltAz;
-class RaDec;
+class TArrayF;
+class TH1F;
+class TH2F;
+class TGraph;
 
 class TTimer;
 
-class TGMenuBar;
-class TGPopupMenu;
+class MGMenuBar;
+class MGPopupMenu;
 class TGTextEntry;
 
@@ -29,4 +32,11 @@
 class MStarList;
 
+class TFile;
+class TTree;
+class TBranch;
+
+class Leds;
+class Rings;
+
 class MGStarguider : public PixClient, public TGMainFrame
 {
@@ -34,19 +44,47 @@
     MGList        *fList;
 
-    TGMenuBar     *fMenu;
+    MGMenuBar     *fMenu;
     MGImage       *fImage;
     MGImage       *fZoomImage;
 
-    TGPopupMenu   *fDisplay;
-    TGPopupMenu   *fWrite;
-    TGPopupMenu   *fFileType;
-    TGPopupMenu   *fWriteType;
-    TGPopupMenu   *fWriteRate;
-    TGPopupMenu   *fInterpol;
-    TGPopupMenu   *fSetup;
-    TGPopupMenu   *fLimMag;
+    MGPopupMenu   *fDisplay;
+    MGPopupMenu   *fWrite;
+    MGPopupMenu   *fWritePictures;
+    MGPopupMenu   *fFileType;
+    MGPopupMenu   *fWriteType;
+    MGPopupMenu   *fAnalyse;
+    MGPopupMenu   *fCaOs;
+    MGPopupMenu   *fWriteRate;
+    MGPopupMenu   *fInterpol;
+    MGPopupMenu   *fSetup;
+    MGPopupMenu   *fLimMag;
+
+    TFile         *fFile;
+    TTree         *fTree;
+    TBranch       *fBranchL;
+    TBranch       *fBranchT;
+    TBranch       *fBranchR;
+
+    Leds *fLeds;
+    Rings *fRings;
+    Double_t fTime;
+
+    TH1F          *fHistpr;
+    TH1F          *fHistprx;
+    TH1F          *fHistpry;
+    TH1F          *fHistw[6];
+    TH1F          *fHistallw;
+    TH1F          *fHistv[6];
+
+    TH2F          *fHistprxpry;
+
+    TGraph        *fGraphprx;
+    TGraph        *fGraphpry;
+    TGraph        *fGraphw[6];
 
     MGCoordinates *fCRaDec;
     MGCoordinates *fCZdAz;
+
+    MGCoordinates *fPZdAz;
 
     TGTextEntry   *fPixSize;
@@ -58,6 +96,4 @@
     TTimer *fTimer;
 
-    const MObservatory::LocationName_t fObservatory;
-
     Int_t fDx;
     Int_t fDy;
@@ -67,12 +103,25 @@
 
     void SetPixSize(const double pixsize);
-    void Toggle(TGPopupMenu *p, UInt_t id);
+    void Toggle(MGPopupMenu *p, UInt_t id);
     void GetCoordinates();
-    void CalcTrackingError(MStarList &, MStarList &);
+    void CalcTrackingError(Leds &, MStarList &);
+    ZdAz TrackingError(TArrayF &alt, TArrayF &az, TArrayF &mag) const;
+
+    void InitHists();
+    void InitGraphs();
+    void InitGui();
+
+    void OpenFile();
+
+    void ResetHists();
+    void DisplayAnalysis();
 
     Bool_t HandleTimer(TTimer *t);
+    //Bool_t HandleKey(Event_t* event);
+
+    void DrawCircle(byte *img, double r);
 
 public:
-    MGStarguider(MObservatory::LocationName_t key);
+    MGStarguider(MObservatory::LocationName_t obs);
     virtual ~MGStarguider();
 
Index: /trunk/MagicSoft/Cosy/gui/Makefile
===================================================================
--- /trunk/MagicSoft/Cosy/gui/Makefile	(revision 1818)
+++ /trunk/MagicSoft/Cosy/gui/Makefile	(revision 1819)
@@ -40,5 +40,4 @@
 	   MGVelocity.cc \
            MGStarguider.cc \
-           MGPngReader.cc \
 	   MGSkyPosition.cc \
            MGMenu.cc
Index: /trunk/MagicSoft/Cosy/main/MCosy.cc
===================================================================
--- /trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 1818)
+++ /trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 1819)
@@ -467,10 +467,18 @@
     cout << "Shortest Dest Zd: " << dest.Zd() << "se  Az:" << dest.Az() << "se" << endl;
 
+    /*
+     * re(se) = -28.1*cos(x*360/16384/se - 14.4) + 443.2*re/se
+     *
+     * int(re) = -1278.86*sin(0.021972656   *x/se - 14.4    )re + 443.2re x/se
+     * int(re) = -73273.4*sin(0.000383495197*x/se - .2513274)re + 443.2re x/se
+     *
+     * int (-75deg..95deg) = 3.28343e7 re
+     *
+     */
+
     //
     // Set velocities
     //
     const int vr = fMac1->GetVelRes();
-
-    cout << "Mac1: Velres=" << dec << vr << endl;
 
     int i;
Index: /trunk/MagicSoft/Cosy/starg.cc
===================================================================
--- /trunk/MagicSoft/Cosy/starg.cc	(revision 1818)
+++ /trunk/MagicSoft/Cosy/starg.cc	(revision 1819)
@@ -4,9 +4,7 @@
 #include <iostream.h>
 
-#include "MGStarguider.h"
-#include "MGPngReader.h"
 #include "Camera.h"
 #include "PngReader.h"
-#include "PixClient.h"
+#include "MGStarguider.h"
 
 /* ---------------------------------------------------------------------- */
@@ -29,5 +27,5 @@
     }
 
-    PixClient *client=new MGPngReader(MObservatory::kMagic1);
+    PixClient *client=new MGStarguider(MObservatory::kMagic1);
 
     if (dummy)
Index: /trunk/MagicSoft/Cosy/tpoint/tpointfit.C
===================================================================
--- /trunk/MagicSoft/Cosy/tpoint/tpointfit.C	(revision 1818)
+++ /trunk/MagicSoft/Cosy/tpoint/tpointfit.C	(revision 1819)
@@ -27,7 +27,4 @@
     friend ifstream &operator>>(ifstream &fin, Set &set);
 private:
-    Double_t fOrigStarAz;
-    Double_t fOrigStarEl;
-
     Double_t fStarAz;
     Double_t fStarEl;
@@ -47,15 +44,14 @@
     Double_t GetResidual() const
     {
-        Double_t del = fRawEl-fStarEl;
-        Double_t daz = fRawAz-fStarAz;
-
-        Double_t dphi2 = daz/2.;
-        Double_t cos2  = cos(dphi2)*cos(dphi2);
-        Double_t sin2  = sin(dphi2)*sin(dphi2);
-        Double_t d = cos(del)*cos2 - cos(2*fOrigStarEl+del)*sin2;
-
-        Double_t  dist = acos(d);
-
-        return dist * 180 / TMath::Pi();
+         Double_t del = fRawEl-fStarEl;
+         Double_t daz = fRawAz-fStarAz;
+         Double_t dphi2 = daz/2.;
+         Double_t cos2  = cos(dphi2)*cos(dphi2);
+         Double_t sin2  = sin(dphi2)*sin(dphi2);
+         Double_t d = cos(del)*cos2 - cos(fRawEl+fStarEl)*sin2;
+
+         Double_t dist = acos(d);
+
+         return dist * 180 / TMath::Pi();
     }
 
@@ -112,7 +108,4 @@
     set.fStarEl = v[1]*TMath::Pi()/180;
 
-    set.fOrigStarAz = v[0]*TMath::Pi()/180;
-    set.fOrigStarEl = v[1]*TMath::Pi()/180;
-
     set.fRawAz  = v[2]*TMath::Pi()/180;
     set.fRawEl  = v[3]*TMath::Pi()/180;
@@ -284,8 +277,10 @@
         phi0 += scale*d;
         phi1 -= scale*d;
-    }
-
-    DrawPolLine(pad, r0, phi0, r1, phi1);
-    DrawMarker(pad,  r0, phi0, r1, phi1);
+
+        DrawPolLine(pad, r0, phi0, r1, phi1);
+        DrawMarker(pad,  r0, phi0, r1, phi1);
+    }
+    else
+        DrawMarker(pad,  r1, phi1, 0 ,0);
 }
 
@@ -296,6 +291,6 @@
     gCoordinates.SetOwner();
 
-    TH1F hres1("Res1", "  Residuals before correction     ", 10, 0, 180);
-    TH1F hres2("Res2", "  Residuals after correction     ",  10, 0,   1);
+    TH1F hres1("Res1", "  Residuals before correction     ", 10, 0,   4);
+    TH1F hres2("Res2", "  Residuals after correction     ",  40, 0,   4);
 
     hres1.SetXTitle("\\Delta [\\circ]");
@@ -316,5 +311,5 @@
     gzd.SetTitle(" \\Delta Zd vs. Zd ");
 
-    ifstream fin("tpoint/tpoint3.txt");
+    ifstream fin("/home/tbretz/pc4/results/tpoint3.txt");
 
     while (fin && fin.get()!='\n');
@@ -395,4 +390,13 @@
 
     //
+    // Correct for Offsets only
+    //
+    double par[16];
+    bending.GetParameters(par);
+    for (int i=2; i<16; i++) par[i]=0;
+    MBending b2;
+    b2.SetParameters(par);
+
+    //
     // Calculate correction and residuals
     //
@@ -403,5 +407,12 @@
         ZdAz za = set0.GetStarZdAz()*kRad2Deg;
 
-        hres1.Fill(set0.GetResidual());
+        //
+        // Correct for offsets only
+        //
+        Set set1(set0);
+        set1.Adjust(b2);
+
+        hres1.Fill(set1.GetResidual());
+
         set0.Adjust(bending);
         hres2.Fill(set0.GetResidual());
@@ -412,8 +423,8 @@
 
         static int j=0;
-        gdzd.SetPoint(j, za.Az()/*   set0.GetStarAz()*/, set0.GetDZd());
-        gaz.SetPoint( j, za.Az()/*   set0.GetStarAz()*/, dz);
-        gdaz.SetPoint(j, za.Zd()/*90-set0.GetStarEl()*/, dz);
-        gzd.SetPoint( j, za.Zd()/*90-set0.GetStarEl()*/, set0.GetDZd());
+        gdzd.SetPoint(j, za.Az(), set0.GetDZd());
+        gaz.SetPoint( j, za.Az(), dz);
+        gdaz.SetPoint(j, za.Zd(), dz);
+        gzd.SetPoint( j, za.Zd(), set0.GetDZd());
         j++;
     }
@@ -463,5 +474,7 @@
     cout << "Spead after:  " << hres2.GetMean() << "deg  +-  " << hres2.GetRMS() << "deg" << endl;
     cout << "Spead before: " << (int)(hres1.GetMean()*60+.5) << "'  +-  " << (int)(hres1.GetRMS()*60+.5) << "'" << endl;
+    cout << "Spead before: " << (int)(hres1.GetMean()*60*60/23.4+.5) << "pix  +-  " << (int)(hres1.GetRMS()*60*60/23.4+.5) << "pix" << endl;
     cout << "Spead after:  " << (int)(hres2.GetMean()*60+.5) << "'  +-  " << (int)(hres2.GetRMS()*60+.5) << "'" << endl;
+    cout << "Spead after:  " << (int)(hres2.GetMean()*60*60/23.4+.5) << "pix  +-  " << (int)(hres2.GetRMS()*60*60/23.4+.5) << "pix" << endl;
     cout << "Spead after:  " << (int)(hres2.GetMean()*16384/360+.5) << "SE  +-  " << (int)(hres2.GetRMS()*16384/360+.5) << "SE" << endl;
     cout << endl;
@@ -505,5 +518,5 @@
     gPad->Update();
     for (int i=0; i<gCoordinates.GetSize(); i++)
-        DrawSet(gPad, *(Set*)list.At(i), 10./hres1.GetMean());
+        DrawSet(gPad, *(Set*)list.At(i));//, 10./hres1.GetMean());
 
     c1->cd(3);
