Index: trunk/MagicSoft/Cosy/caos/CaosLinkDef.h
===================================================================
--- trunk/MagicSoft/Cosy/caos/CaosLinkDef.h	(revision 1798)
+++ trunk/MagicSoft/Cosy/caos/CaosLinkDef.h	(revision 1798)
@@ -0,0 +1,28 @@
+#ifdef __CINT__
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class MGAccuracy+;
+
+#pragma link C++ class MGCoordinate+;
+#pragma link C++ class MGCoordinates+;
+
+#pragma link C++ class MGEmbeddedCanvas+;
+
+#pragma link C++ class MGImage+;
+
+#pragma link C++ class MGSkyPosition+;
+#pragma link C++ class MGVelocity+;
+
+#pragma link C++ class MGCosy+;
+#pragma link C++ class MGStarguider+;
+#pragma link C++ class MGPngReader+;
+
+#pragma link C++ class Led+;
+#pragma link C++ class Leds+;
+#pragma link C++ class Ring+;
+#pragma link C++ class Rings+;
+
+#endif
Index: trunk/MagicSoft/Cosy/caos/Led.cc
===================================================================
--- trunk/MagicSoft/Cosy/caos/Led.cc	(revision 1798)
+++ trunk/MagicSoft/Cosy/caos/Led.cc	(revision 1798)
@@ -0,0 +1,12 @@
+#include "Led.h"
+
+#include <TMath.h>
+
+#include "Ring.h"
+
+ClassImp(Led);
+
+void Led::CalcPhi(const Ring &ring)
+{
+    fPhi = TMath::ATan2(fY-ring.GetY(), fX-ring.GetX())*180/TMath::Pi();
+}
Index: trunk/MagicSoft/Cosy/caos/Led.h
===================================================================
--- trunk/MagicSoft/Cosy/caos/Led.h	(revision 1798)
+++ trunk/MagicSoft/Cosy/caos/Led.h	(revision 1798)
@@ -0,0 +1,40 @@
+#ifndef COSY_Led
+#define COSY_Led
+
+#ifndef ROOT_TObject
+#include <TObject.h>
+#endif
+
+class Ring;
+
+class Led : public TObject
+{
+private:
+    Double_t fX;
+    Double_t fY;
+    Double_t fPhi;
+
+    Double_t fDx;
+    Double_t fDy;
+    Double_t fDphi;
+
+    Double_t fMag;
+
+public:
+    Led(Double_t x=0, Double_t y=0, Double_t dx=0, Double_t dy=0, Double_t mag=0) :
+        fX(x), fY(y), fDx(dx), fDy(dy), fMag(mag)
+    {
+    }
+
+    Double_t GetX() const   { return fX; }
+    Double_t GetY() const   { return fY; }
+    Double_t GetDx() const  { return fDx; }
+    Double_t GetDy() const  { return fDy; }
+    Double_t GetMag() const { return fMag; }
+
+    void CalcPhi(const Ring &ring);
+
+    ClassDef(Led, 1)
+};
+
+#endif
Index: trunk/MagicSoft/Cosy/caos/Leds.cc
===================================================================
--- trunk/MagicSoft/Cosy/caos/Leds.cc	(revision 1798)
+++ trunk/MagicSoft/Cosy/caos/Leds.cc	(revision 1798)
@@ -0,0 +1,10 @@
+#include "Leds.h"
+
+#include "Led.h"
+
+ClassImp(Leds);
+
+void Leds::Set(Int_t i, Double_t x, Double_t y, Double_t dx, Double_t dy, Double_t mag)
+{
+    new ((*this)[i]) Led(x, y, dx, dy, mag);
+}
Index: trunk/MagicSoft/Cosy/caos/Leds.h
===================================================================
--- trunk/MagicSoft/Cosy/caos/Leds.h	(revision 1798)
+++ trunk/MagicSoft/Cosy/caos/Leds.h	(revision 1798)
@@ -0,0 +1,32 @@
+#ifndef COSY_Leds
+#define COSY_Leds
+
+#ifndef ROOT_TClonesArray
+#include <TClonesArray.h>
+#endif
+
+class Led;
+
+class Leds : public TClonesArray
+{
+private:
+public:
+    Leds() : TClonesArray("Led", 1) {}
+
+    //
+    // leds.ExpandCreate(5);
+    // for (int i=1; i<5; i++)
+    //    leds.Set(i, x, y, dx, dy, mag);
+    //
+
+    void Set(Int_t i, Double_t x, Double_t y, Double_t dx, Double_t dy, Double_t mag);
+
+    //nst Led &GetLed(int i) const { return *(Led*)( (*this)[i] ); }
+
+    const Led &operator()(int i) const { return *(Led*)((*(Leds*)this)[i]); }
+    Led &operator()(int i) { return *(Led*)((*(Leds*)this)[i]); }
+
+    ClassDef(Leds, 1)
+};
+
+#endif
Index: trunk/MagicSoft/Cosy/caos/Makefile
===================================================================
--- trunk/MagicSoft/Cosy/caos/Makefile	(revision 1798)
+++ trunk/MagicSoft/Cosy/caos/Makefile	(revision 1798)
@@ -0,0 +1,66 @@
+##################################################################
+#
+#   makefile
+# 
+#   for the MARS software
+#
+##################################################################
+# @maintitle
+
+# @code
+
+#
+#  please change all system depend values in the 
+#  config.mk.${OSTYPE} file 
+#
+#
+include ../Makefile.conf.$(OSTYPE)
+include ../Makefile.conf.general
+
+# @endcode 
+
+INCLUDES = -I. -I.. -I../base -I../slalib -I../candrv -I../incl \
+	   -I../catalog -I../videodev -I../main
+
+# @code 
+
+CINT     = Gui
+LIB      = gui.a
+
+#------------------------------------------------------------------------------
+
+.SUFFIXES: .c .cc .cxx .h .hxx .o 
+
+SRCFILES = MGCoordinate.cc \
+	   MGCoordinates.cc \
+	   MGCosy.cc \
+	   MGImage.cc \
+	   MGEmbeddedCanvas.cc \
+	   MGAccuracy.cc \
+	   MGVelocity.cc \
+           MGStarguider.cc \
+           MGPngReader.cc \
+	   MGSkyPosition.cc \
+           MGMenu.cc \
+           Led.cc \
+           Leds.cc \
+           Ring.cc \
+           Rings.cc
+
+SRCS        = $(SRCFILES)
+HEADERS     = $(SRCFILES:.cc=.h)
+OBJS        = $(SRCFILES:.cc=.o) 
+CINTHEADERS = $(HEADERS)
+
+############################################################
+
+all: $(LIB)
+
+include ../Makefile.rules
+
+clean:	rmlib rmcint rmobjs rmcore
+
+mrproper:	clean rmbak
+
+# @endcode
+
Index: trunk/MagicSoft/Cosy/caos/Ring.cc
===================================================================
--- trunk/MagicSoft/Cosy/caos/Ring.cc	(revision 1798)
+++ trunk/MagicSoft/Cosy/caos/Ring.cc	(revision 1798)
@@ -0,0 +1,102 @@
+#include "Ring.h"
+
+#include <iostream.h>
+
+#include "Led.h"
+#include "Leds.h"
+
+#include "Rings.h"
+
+ClassImp(Ring);
+
+bool Ring::CalcCenter(const Leds &leds, Int_t i, Int_t j, Int_t k)
+{
+    Float_t h1 = leds(i).GetY()- leds(j).GetY();
+
+    if (h1==0)
+    {
+        Swap(&j, &k);
+        h1 = leds(i).GetY()- leds(j).GetY();
+        if (h1==0)
+        {
+                cout << "h1==0" <<endl;
+                return kFALSE;
+        }
+    }
+
+    Float_t h2 = leds(j).GetY() - leds(k).GetY();
+
+    if (h2==0)
+    {
+        Swap(&i, &j);
+        h2 = leds(j).GetY() - leds(k).GetY();
+        if (h2==0)
+        {
+            cout << "h2==0" << endl;
+            return kFALSE;
+        }
+    }
+
+    Float_t w1 = leds(i).GetX() - leds(j).GetX();
+    Float_t w2 = leds(j).GetX() - leds(k).GetX();
+
+    Float_t m1 = -w1/h1;
+    Float_t m2 = -w2/h2;
+
+    if (m2-m1==0)
+    {
+        cout << "m2-m1==0" << endl;
+        return kFALSE;
+    }
+
+    fX = ((m2*(leds(j).GetX() + leds(k).GetX()) + leds(i).GetY() - leds(k).GetY()       -m1*(leds(i).GetX() + leds(j).GetX()))/(m2-m1)/2);
+    fY = ((m2*(leds(i).GetY() + leds(j).GetY()) +m1*m2*(leds(k).GetX() - leds(i).GetX())-m1*(leds(j).GetY() + leds(k).GetY()))/(m2-m1)/2);
+
+    fR = sqrt(sqr(fX-leds(i).GetX())+sqr(fY-leds(i).GetY()));
+
+    return kTRUE;
+}
+
+void Ring::InterpolCenters(const Rings &rings)
+{
+    const int n=rings.GetEntries();
+
+    fX = 0;
+    fX = 0;
+    fR = 0;
+
+    for (int i=0; i<n; i++)
+    {
+        const Ring &ring = *(Ring*)((Rings&)rings)[i];
+
+        fX += ring.GetX();
+        fY += ring.GetY();
+        fR += ring.GetR();
+    }
+
+    fX /= n;
+    fY /= n;
+    fR /= n;
+
+    //
+    // deviation of x- and y coordinate and radius
+    //
+    Float_t sumx=0;
+    Float_t sumy=0;
+    Float_t sumr=0;
+
+    for (int i=0; i<n; i++)
+    {
+        const Ring &ring = *(Ring*)((Rings&)rings)[i];
+
+        sumx += sqr(ring.GetX()-fX);
+        sumy += sqr(ring.GetY()-fY);
+        sumr += sqr(ring.GetR()-fR);
+    }
+
+        fDx=sqrt(sumx)/(n-1);
+        fDy=sqrt(sumy)/(n-1);
+        fDr=sqrt(sumr)/(n-1);
+
+}
+
Index: trunk/MagicSoft/Cosy/caos/Ring.h
===================================================================
--- trunk/MagicSoft/Cosy/caos/Ring.h	(revision 1798)
+++ trunk/MagicSoft/Cosy/caos/Ring.h	(revision 1798)
@@ -0,0 +1,46 @@
+#ifndef COSY_Ring
+#define COSY_Ring
+
+#ifndef ROOT_TObject
+#include <TObject.h>
+#endif
+
+class Leds;
+class Rings;
+
+class Ring : public TObject
+{
+private:
+    Double_t fX;
+    Double_t fY;
+    Double_t fR;
+    Double_t fPhi;
+
+    Double_t fDx;
+    Double_t fDy;
+    Double_t fDr;
+    Double_t fDphi;
+
+    Double_t sqr(Double_t x) { return x*x; }
+
+    void Swap(int *m, int *n)
+    {
+        int dummy = *m;
+        *m = *n;
+        *n = dummy;
+    }
+
+public:
+
+    Double_t GetX() const   { return fX; }
+    Double_t GetY() const   { return fY; }
+    Double_t GetR() const   { return fR; }
+    Double_t GetPhi() const { return fPhi; }
+
+    bool CalcCenter(const Leds &leds, Int_t i, Int_t j, Int_t k);
+    void InterpolCenters(const Rings &rings);
+
+    ClassDef(Ring, 1)
+};
+
+#endif
Index: trunk/MagicSoft/Cosy/caos/Rings.cc
===================================================================
--- trunk/MagicSoft/Cosy/caos/Rings.cc	(revision 1798)
+++ trunk/MagicSoft/Cosy/caos/Rings.cc	(revision 1798)
@@ -0,0 +1,37 @@
+#include "Rings.h"
+
+#include "Led.h"
+#include "Leds.h"
+
+ClassImp(Rings);
+
+Int_t Rings::CalcCenters(const Leds &leds)
+{
+    int nPoints = leds.GetEntries();
+
+    int n=0;
+    for (int i=0; i<nPoints-2; i++)
+        for (int j=i+1; j<nPoints-1; j++)
+            for (int k=j+1; k<nPoints; k++)
+            {
+                Ring &ring = *(Ring*)(*this)[n];
+
+                ring.CalcCenter(leds, i, j, k);
+
+                n++;
+            }
+    return n;
+}
+
+void Rings::CalcRings(Leds &leds)
+{
+    CalcCenters(leds);
+
+    fCenter.InterpolCenters(*this);
+
+    //
+    // angles v and relative angle w
+    //
+    for (int j=0; j<leds.GetEntries(); j++)
+        leds(j).CalcPhi(fCenter);
+}
Index: trunk/MagicSoft/Cosy/caos/Rings.h
===================================================================
--- trunk/MagicSoft/Cosy/caos/Rings.h	(revision 1798)
+++ trunk/MagicSoft/Cosy/caos/Rings.h	(revision 1798)
@@ -0,0 +1,32 @@
+#ifndef COSY_Rings
+#define COSY_Rings
+
+#ifndef ROOT_TClonesArray
+#include <TClonesArray.h>
+#endif
+
+#ifndef COSY_Ring
+#include "Ring.h"
+#endif
+
+class Leds;
+
+class Rings : public TClonesArray
+{
+private:
+    Ring fCenter;
+
+    Int_t CalcCenters(const Leds &leds);
+
+public:
+    Rings() : TClonesArray("Ring", 1) {}
+
+    //
+    //  rings.CalcRings(leds);
+    //
+    void CalcRings(Leds &leds);
+
+    ClassDef(Rings, 1)
+};
+
+#endif
