Index: trunk/MagicSoft/Cosy/base/BaseLinkDef.h
===================================================================
--- trunk/MagicSoft/Cosy/base/BaseLinkDef.h	(revision 1690)
+++ trunk/MagicSoft/Cosy/base/BaseLinkDef.h	(revision 1691)
@@ -8,4 +8,5 @@
 #pragma link C++ class MLog;
 #pragma link C++ class MStar+;
+#pragma link C++ class MGList+;
 
 #endif
Index: trunk/MagicSoft/Cosy/base/MStar.cc
===================================================================
--- trunk/MagicSoft/Cosy/base/MStar.cc	(revision 1691)
+++ trunk/MagicSoft/Cosy/base/MStar.cc	(revision 1691)
@@ -0,0 +1,3 @@
+#include "MStar.h"
+
+ClassImp(MStar);
Index: trunk/MagicSoft/Cosy/base/MStar.h
===================================================================
--- trunk/MagicSoft/Cosy/base/MStar.h	(revision 1691)
+++ trunk/MagicSoft/Cosy/base/MStar.h	(revision 1691)
@@ -0,0 +1,26 @@
+#ifndef COSY_MStar
+#define COSY_MStar
+
+#include <TObject.h>
+
+class MStar : public TObject
+{
+private:
+    Double_t fX;
+    Double_t fY;
+
+    Double_t fMag;
+
+public:
+    MStar(Double_t x=0, Double_t y=0, Int_t m=0) : fX(x), fY(y), fMag(m) {}
+    MStar(const MStar &p) { fX = p.fX; fY=p.fY; fMag=p.fMag; }
+    Double_t GetX() const   { return fX; }
+    Double_t GetY() const   { return fY; }
+    Double_t GetMag() const { return fMag; }
+
+    void Set(Double_t mx, Double_t my) { fX=mx; fY=my; }
+
+    ClassDef(MStar, 1)
+};
+
+#endif
Index: trunk/MagicSoft/Cosy/base/MStarList.cc
===================================================================
--- trunk/MagicSoft/Cosy/base/MStarList.cc	(revision 1691)
+++ trunk/MagicSoft/Cosy/base/MStarList.cc	(revision 1691)
@@ -0,0 +1,40 @@
+#include "MStarList.h"
+
+void MStarList::RemoveTwins(Double_t radius)
+{
+    MStarList stars;
+
+    Int_t numfirst=0;
+
+    while (1)
+    {
+        int idx;
+        MStar *first=NULL;
+        for (idx=numfirst; idx<GetMax(); idx++)
+            if ((first = (*this)[idx]))
+                break;
+
+        if (!first)
+            return;
+
+        MStarListIter Next(this, *first, radius);
+        Delete(idx);
+
+        MStar *pos;
+        Float_t mx=0;
+        Float_t my=0;
+        Int_t cnt=0;
+        while ((pos=Next()))
+        {
+            mx += pos->GetX();
+            my += pos->GetY();
+            Delete(pos);
+            cnt++;
+        }
+        mx /= cnt;
+        my /= cnt;
+
+        AddAt(idx, mx, my, cnt);
+        numfirst = idx+1;
+    }
+}
Index: trunk/MagicSoft/Cosy/base/MStarList.h
===================================================================
--- trunk/MagicSoft/Cosy/base/MStarList.h	(revision 1691)
+++ trunk/MagicSoft/Cosy/base/MStarList.h	(revision 1691)
@@ -0,0 +1,89 @@
+#ifndef COSY_MStarList
+#define COSY_MStarList
+
+#include <TClonesArray.h>
+
+#include "MStar.h"
+
+class MStarListIter;
+
+class MStarList : public TObject
+{
+private:
+    TClonesArray fStars;
+
+public:
+    MStarList() : fStars("MStar", 1000) {}
+
+    void AddAt(Int_t idx, Double_t meanx, Double_t meany, Double_t mag)
+    {
+        new (fStars[idx]) MStar(meanx, meany, mag);
+    }
+    void Add(Double_t meanx, Double_t meany, Double_t mag)
+    {
+        AddAt(fStars.GetLast()+1, meanx, meany, mag);
+    }
+    MStar *operator[](Int_t i) { return (MStar*)fStars[i]; }
+
+    void Reset()
+    {
+        fStars.Delete();
+    }
+
+    void Delete(Int_t i)    { delete fStars.RemoveAt(i); }
+    void Delete(MStar *obj) { delete fStars.Remove(obj); }
+
+    Int_t GetMax() const { return fStars.GetLast()+1; }
+    Int_t GetRealEntries() const { return fStars.GetEntries(); }
+
+    void RemoveTwins(Double_t radius);
+};
+
+class MStarListIter
+{
+private:
+    MStarList *fList;
+
+    Int_t      fNumPos;     // actual position in list
+
+    Bool_t     fAll;        // iterate over all stars
+
+    MStar      fReference;  // iterate only over stars not more than
+    Float_t    fRadius;     // fRadius away from the reference
+
+public:
+    MStarListIter(MStarList *list) : fList(list), fNumPos(0),  fAll(kTRUE) {}
+    MStarListIter(MStarList *list, const MStar &s, Float_t r) : fList(list), fNumPos(0), fAll(kFALSE), fReference(s), fRadius(r) {}
+
+    MStar *Next()
+    {
+        const Double_t r2 = fRadius*fRadius;
+
+        for (int i=fNumPos; i<fList->GetMax(); i++)
+        {
+            MStar *p = (*fList)[i];
+
+            if (!p)
+                continue;
+
+            if (!fAll)
+            {
+                Double_t dx = p->GetX()-fReference.GetX();
+                Double_t dy = p->GetY()-fReference.GetY();
+
+                if (dx*dx + dy*dy > r2)
+                    continue;
+            }
+
+            fNumPos = i+1;
+            return p;
+        }
+        return NULL;
+    }
+
+    MStar *operator()() { return Next(); }
+
+    void Reset() { fNumPos=0; }
+};
+
+#endif
Index: trunk/MagicSoft/Cosy/base/Makefile
===================================================================
--- trunk/MagicSoft/Cosy/base/Makefile	(revision 1690)
+++ trunk/MagicSoft/Cosy/base/Makefile	(revision 1691)
@@ -40,7 +40,9 @@
            MLog.cc \
            MLogManip.cc \
+           MGList.cc \
            timer.cc 
 
 CINTHEADERS = MStar.h \
+	      MGList.h \
 	      MLog.h \
 	      MLogManip.h
