Index: trunk/MagicSoft/Cosy/caos/Led.cc
===================================================================
--- trunk/MagicSoft/Cosy/caos/Led.cc	(revision 1799)
+++ trunk/MagicSoft/Cosy/caos/Led.cc	(revision 1802)
@@ -1,4 +1,5 @@
 #include "Led.h"
 
+#include <iostream.h>
 #include <TMath.h>
 
@@ -11,2 +12,11 @@
     fPhi = TMath::ATan2(fY-ring.GetY(), fX-ring.GetX())*180/TMath::Pi();
 }
+
+void Led::Print(Option_t *o=NULL) const
+{
+    cout << "Led: ";
+    cout << "x="   << fX   << "+-" << fDx   << ", ";
+    cout << "y="   << fY   << "+-" << fDy   << ", ";
+    cout << "phi=" << fPhi << "+-" << fDphi << ", ";
+    cout << "mag=" << fMag << endl;
+}
Index: trunk/MagicSoft/Cosy/caos/Led.h
===================================================================
--- trunk/MagicSoft/Cosy/caos/Led.h	(revision 1799)
+++ trunk/MagicSoft/Cosy/caos/Led.h	(revision 1802)
@@ -27,11 +27,30 @@
     }
 
-    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; }
+    Int_t Compare(const TObject *obj) const
+    {
+        const Led *const l = (Led*)obj;
+
+        if (fPhi<l->fPhi)
+            return -1;
+
+        if (fPhi>l->fPhi)
+            return 1;
+
+        return 0;
+    }
+
+    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 GetPhi() const  { return fPhi; }
+    Double_t GetDphi() const { return fDphi; }
+    Double_t GetMag() const  { return fMag; }
+
+        Bool_t IsSortable() const { return kTRUE; }
 
     void CalcPhi(const Ring &ring);
+
+    void Print(Option_t *o=NULL) const;
 
     ClassDef(Led, 1)
Index: trunk/MagicSoft/Cosy/caos/Leds.cc
===================================================================
--- trunk/MagicSoft/Cosy/caos/Leds.cc	(revision 1799)
+++ trunk/MagicSoft/Cosy/caos/Leds.cc	(revision 1802)
@@ -1,3 +1,5 @@
 #include "Leds.h"
+
+#include <iostream.h>
 
 #include "Led.h"
@@ -9,2 +11,8 @@
     new ((*this)[i]) Led(x, y, dx, dy, mag);
 }
+
+void Leds::Print(Option_t *o=NULL) const
+{
+    cout << "Number of Leds: " << GetEntries() << endl;
+    TClonesArray::Print();
+}
Index: trunk/MagicSoft/Cosy/caos/Leds.h
===================================================================
--- trunk/MagicSoft/Cosy/caos/Leds.h	(revision 1799)
+++ trunk/MagicSoft/Cosy/caos/Leds.h	(revision 1802)
@@ -10,5 +10,4 @@
 class Leds : public TClonesArray
 {
-private:
 public:
     Leds() : TClonesArray("Led", 1) {}
@@ -27,4 +26,6 @@
     Led &operator()(int i) { return *(Led*)((*(Leds*)this)[i]); }
 
+    void Print(Option_t *o=NULL) const;
+
     ClassDef(Leds, 1)
 };
Index: trunk/MagicSoft/Cosy/caos/Ring.cc
===================================================================
--- trunk/MagicSoft/Cosy/caos/Ring.cc	(revision 1799)
+++ trunk/MagicSoft/Cosy/caos/Ring.cc	(revision 1802)
@@ -20,6 +20,6 @@
         if (h1==0)
         {
-                cout << "h1==0" <<endl;
-                return kFALSE;
+            cout << "h1==0" <<endl;
+            return kFALSE;
         }
     }
@@ -38,13 +38,13 @@
     }
 
-    Float_t w1 = leds(i).GetX() - leds(j).GetX();
-    Float_t w2 = leds(j).GetX() - leds(k).GetX();
+    const Float_t w1 = leds(i).GetX() - leds(j).GetX();
+    const Float_t w2 = leds(j).GetX() - leds(k).GetX();
 
-    Float_t m1 = -w1/h1;
-    Float_t m2 = -w2/h2;
+    const Float_t m1 = -w1/h1;
+    const Float_t m2 = -w2/h2;
 
     if (m2-m1==0)
     {
-        cout << "m2-m1==0" << endl;
+        cout << "All three points in a row! (m2-m1==0)" << endl;
         return kFALSE;
     }
@@ -66,7 +66,14 @@
     fR = 0;
 
+    fDx=0;
+    fDy=0;
+    fDr=0;
+
+    if (n<1)
+        return;
+
     for (int i=0; i<n; i++)
     {
-        const Ring &ring = *(Ring*)((Rings&)rings)[i];
+        const Ring &ring = rings(i);
 
         fX += ring.GetX();
@@ -79,24 +86,31 @@
     fR /= n;
 
+    if (n<2)
+        return;
+
     //
     // 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];
+        const Ring &ring = rings(i);
 
-        sumx += sqr(ring.GetX()-fX);
-        sumy += sqr(ring.GetY()-fY);
-        sumr += sqr(ring.GetR()-fR);
+        fDx += sqr(ring.GetX()-fX);
+        fDy += sqr(ring.GetY()-fY);
+        fDr += sqr(ring.GetR()-fR);
     }
 
-        fDx=sqrt(sumx)/(n-1);
-        fDy=sqrt(sumy)/(n-1);
-        fDr=sqrt(sumr)/(n-1);
-
+    fDx=sqrt(fDx)/(n-1);
+    fDy=sqrt(fDy)/(n-1);
+    fDr=sqrt(fDr)/(n-1);
 }
 
+void Ring::Print(Option_t *o=NULL) const
+{
+    cout << "Ring: ";
+    cout << "x="   << fX   << "+-" << fDx   << ", ";
+    cout << "y="   << fY   << "+-" << fDy   << ", ";
+    cout << "r="   << fR   << "+-" << fDr   << ", ";
+    cout << "phi=" << fPhi << "+-" << fDphi << endl;
+}
+
Index: trunk/MagicSoft/Cosy/caos/Ring.h
===================================================================
--- trunk/MagicSoft/Cosy/caos/Ring.h	(revision 1799)
+++ trunk/MagicSoft/Cosy/caos/Ring.h	(revision 1802)
@@ -41,4 +41,6 @@
     void InterpolCenters(const Rings &rings);
 
+    void Print(Option_t *o=NULL) const;
+
     ClassDef(Ring, 1)
 };
Index: trunk/MagicSoft/Cosy/caos/Rings.cc
===================================================================
--- trunk/MagicSoft/Cosy/caos/Rings.cc	(revision 1799)
+++ trunk/MagicSoft/Cosy/caos/Rings.cc	(revision 1802)
@@ -1,3 +1,5 @@
 #include "Rings.h"
+
+#include <iostream.h>
 
 #include "Led.h"
@@ -6,5 +8,5 @@
 ClassImp(Rings);
 
-Int_t Rings::CalcCenters(const Leds &leds)
+void Rings::CalcCenters(const Leds &leds)
 {
     int nPoints = leds.GetEntries();
@@ -15,11 +17,16 @@
             for (int k=j+1; k<nPoints; k++)
             {
-                Ring &ring = *(Ring*)(*this)[n];
+                Ring &ring = *new ((*this)[n]) Ring;
 
-                ring.CalcCenter(leds, i, j, k);
+                if (!ring.CalcCenter(leds, i, j, k))
+                {
+                    RemoveAt(n);
+                    continue;
+                }
 
                 n++;
             }
-    return n;
+
+    Expand(n);
 }
 
@@ -31,7 +38,17 @@
 
     //
-    // angles v and relative angle w
+    // angles v
     //
-    for (int j=0; j<leds.GetEntries(); j++)
+    const int n=leds.GetEntries();
+
+    for (int j=0; j<n; j++)
         leds(j).CalcPhi(fCenter);
 }
+
+void Rings::Print(Option_t *o=NULL) const
+{
+    cout << "Number of Rings: " << GetEntries() << endl;
+    TClonesArray::Print();
+    cout << "Center: " << endl;
+    fCenter.Print();
+}
Index: trunk/MagicSoft/Cosy/caos/Rings.h
===================================================================
--- trunk/MagicSoft/Cosy/caos/Rings.h	(revision 1799)
+++ trunk/MagicSoft/Cosy/caos/Rings.h	(revision 1802)
@@ -17,13 +17,17 @@
     Ring fCenter;
 
-    Int_t CalcCenters(const Leds &leds);
+    void CalcCenters(const Leds &leds);
 
 public:
     Rings() : TClonesArray("Ring", 1) {}
 
-    //
-    //  rings.CalcRings(leds);
-    //
     void CalcRings(Leds &leds);
+
+    void Print(Option_t *o=NULL) const;
+
+    const Ring &operator()(int i) const { return *(Ring*)((*(Rings*)this)[i]); }
+    Ring &operator()(int i) { return *(Ring*)((*(Rings*)this)[i]); }
+
+    const Ring &GetCenter() const { return fCenter; }
 
     ClassDef(Rings, 1)
