Index: /trunk/MagicSoft/Mars/mtemp/MFindStars.cc
===================================================================
--- /trunk/MagicSoft/Mars/mtemp/MFindStars.cc	(revision 4070)
+++ /trunk/MagicSoft/Mars/mtemp/MFindStars.cc	(revision 4071)
@@ -588,4 +588,18 @@
   Float_t expY = star->GetYExp();
   
+  Float_t max=0;
+  Float_t meanX=0;
+  Float_t meanY=0;
+  Float_t meanSqX=0;
+  Float_t meanSqY=0;
+  Float_t sumCharge=0;
+  UInt_t usedPx=0;	
+
+  const Float_t meanPresition = 3.; //[mm]
+  const UInt_t maxNumIterations = 10;
+  UInt_t numIterations = 0;
+
+  do
+    {
   // First define a area of interest around the expected position of the star
   for (UInt_t pix=1; pix<numPixels; pix++)
@@ -606,11 +620,5 @@
     
 // determine mean x and mean y
-    Float_t max=0;
-    Float_t meanX=0;
-    Float_t meanY=0;
-    Float_t meanSqX=0;
-    Float_t meanSqY=0;
-    Float_t sumCharge=0;
-    UInt_t usedPx=0;	
+    usedPx=0;	
     for(UInt_t pix=0; pix<numPixels; pix++)
     {
@@ -619,5 +627,5 @@
 	    usedPx++;
 
-	    Float_t charge  = fDisplay.GetBinContent(pix+1)-fPedestalDC;
+	    Float_t charge  = fDisplay.GetBinContent(pix+1);
 	    Float_t pixXpos = (*fGeomCam)[pix].GetX();
 	    Float_t pixYpos = (*fGeomCam)[pix].GetY();
@@ -639,6 +647,17 @@
     meanSqY /= sumCharge;
 
-    Float_t rmsX = (meanSqX - meanX*meanX);
-    Float_t rmsY = (meanSqY - meanY*meanY);
+    expX = meanX;
+    expY = meanY;
+
+    if (++numIterations >  maxNumIterations)
+      {
+        *fLog << warn << GetName() << "Mean calculation not converge after " << maxNumIterations << " iterations" << endl;
+        break;
+      }
+        
+    }while(TMath::Abs(meanX-expX) > meanPresition || TMath::Abs(meanY-expY) > meanPresition);
+  
+    Float_t rmsX = (meanSqX - meanX*meanX) - fRingInterest*fRingInterest/12;
+    Float_t rmsY = (meanSqY - meanY*meanY) - fRingInterest*fRingInterest/12;
 
     if ( rmsX > 0)
@@ -647,5 +666,5 @@
       {
         *fLog << warn << " MFindStars::FindStar negative rmsX² " << rmsX << endl;
-        *fLog << warn << " meanSqX " << meanSqX << " meanX " << meanX << " sumCharge " << sumCharge << endl;
+        *fLog << warn << " meanSqX " << meanSqX << " meanX " << meanX << " fRingInterest " << fRingInterest << " sumCharge " << sumCharge << endl;
         rmsX = 0.;
       }
@@ -656,12 +675,18 @@
       {
         *fLog << warn << " MFindStars::FindStar negative rmsY² " << rmsY << endl;
-        *fLog << warn << " meanSqY " << meanSqY << " meanY " << meanY << endl;
+        *fLog << warn << " meanSqY " << meanSqY << " meanY " << meanY << " fRingInterest " << fRingInterest << " sumCharge " << sumCharge<< endl;
         rmsY = 0.;
       }
     
+    // Substrack pedestal DC
+    sumCharge-=fPedestalDC*usedPx;
+    max-=fPedestalDC;
+    
+
     star->SetCalcValues(sumCharge,max,meanX,meanY,rmsX,rmsY);
 
     if (rmsX <= 0. || rmsY <= 0.)
       return kFALSE;
+    
     
 // fit the star spot using TMinuit
