Index: trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc	(revision 601)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc	(revision 603)
@@ -18,4 +18,5 @@
   fPixId    = pix ; 
   fIsUsed   = kTRUE ; 
+  fIsCore   = kFALSE ; 
   fPhot     = phot ; 
   fErrPhot  = errphot ; 
@@ -26,4 +27,5 @@
   fPixId    = pix ; 
   fIsUsed   = kTRUE ; 
+  fIsUsed   = kFALSE ; 
   fPhot     = phot ; 
   fErrPhot  = errphot ; 
@@ -41,4 +43,10 @@
       cout << " UnUsed " ;
 
+  if ( fIsCore == kTRUE )
+    cout << "   Core " ; 
+  else 
+    if ( fIsCore == kFALSE )
+      cout << "        " ;
+
   cout << "  Nphot= " << fPhot
        << "  Error(Nphot) = " << fErrPhot
@@ -127,5 +135,5 @@
     {
       entry = ((MCerPhotPix *) fPixels->At(il))->GetPhotons() ; 
-      noise =  3 * ((MCerPhotPix *) fPixels->At(il))->GetErrorPhot() ; 
+      noise = ((MCerPhotPix *) fPixels->At(il))->GetErrorPhot() ; 
       
       if (entry < 3 * noise ) 
@@ -154,8 +162,61 @@
 	    id2 = fNN->GetNN(id, in ) ; 
 	    
-	    if ( PixelIsUsed(id2) == kTRUE ) 
-	      cout << " hulibu " << id << "/" << id2 << endl ;  
-	    
-	    
+	    if (id2 >=0 ) { 
+	      if ( PixelIsUsed(id2) == kTRUE ) 
+		itest++ ; 
+	    }   
+	  } 
+	  
+	  // 
+	  //   check if no neighbor, then set unused 
+	  //
+	  if ( itest == 0 ) 
+	    { 
+	      ((MCerPhotPix *) fPixels->At(il))->SetPixelUnused() ; 
+	    }
+
+	} 
+    } 
+  
+  // now we declare all pixels that survive as CorePixels
+  
+  for (Int_t il=0; il<fPixels->GetEntries(); il++ ) 
+    {
+      if ( ((MCerPhotPix *) fPixels->At(il))->IsPixelUsed() == kTRUE )
+	{ 
+	  ((MCerPhotPix *) fPixels->At(il))->SetCorePixel() ; 
+	}
+    }
+
+} 
+
+void MCerPhotEvt::CleanLevel3()
+{
+  //   Look for the boundary pixels around the core pixels
+  //   if a pixel has more than 2.5 sigma, and a core neigbor
+  //   it is declared as used. 
+  
+  Float_t entry, noise ; 
+  Int_t   id, id2 ; 
+  for (Int_t il=0; il<fPixels->GetEntries(); il++ ) 
+    {
+      if ( ((MCerPhotPix *) fPixels->At(il))->IsCorePixel() == kFALSE )
+	{  
+	  entry = ((MCerPhotPix *) fPixels->At(il))->GetPhotons() ; 
+	  noise = ((MCerPhotPix *) fPixels->At(il))->GetErrorPhot() ; 
+      
+	  if (entry > 2.5 * noise ) { 
+	    id = ((MCerPhotPix *) fPixels->At(il))->GetPixId()  ; 
+	    for (Int_t in=0 ; in < 6 ; in++ )
+	      { 
+		id2 = fNN->GetNN(id, in ) ; 
+		if (id2 >=0 ) 
+		  { 
+		    if ( PixelIsCore(id2) == kTRUE ) { 
+		      ((MCerPhotPix *) fPixels->At(il))->SetPixelUsed() ; 
+		      break ; 
+		    } 
+		  } 
+	      } 
 	  } 
 	} 
@@ -163,4 +224,7 @@
 } 
 
+
+
+
 Bool_t MCerPhotEvt::PixelExist(Int_t id ) 
 { 
@@ -171,5 +235,5 @@
       if ( id == ((MCerPhotPix *) fPixels->At(il))->GetPixId() ) { 
 	
-	cout << " PixelExist " << il ; 
+	// cout << " PixelExist " << il ; 
 	return kTRUE ; 
       } 
@@ -189,5 +253,22 @@
 	   ((MCerPhotPix *) fPixels->At(il))->IsPixelUsed() == kTRUE ) { 
 	
-	cout << " PixelIsUsed  " << il ; 
+	// cout << " PixelIsUsed  " << il ; 
+	return kTRUE ; 
+      } 
+    } 
+
+  return kFALSE ; 
+
+} 
+
+Bool_t MCerPhotEvt::PixelIsCore(Int_t id ) 
+{ 
+  //   Checks if in the pixel list is an entry with pixel id
+  
+  for (Int_t il=0; il<fPixels->GetEntries(); il++ ) 
+    {
+      if ( id == ((MCerPhotPix *) fPixels->At(il))->GetPixId() && 
+	   ((MCerPhotPix *) fPixels->At(il))->IsCorePixel() == kTRUE ) { 
+	
 	return kTRUE ; 
       } 
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h	(revision 601)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h	(revision 603)
@@ -18,4 +18,5 @@
   Int_t    fPixId     ;  //   the pixel Id
   Bool_t   fIsUsed    ;  //   the pixel is used for calculations --> kTRUE
+  Bool_t   fIsCore    ;  //   the pixel is a Core pixel          --> kTRUE
   Float_t  fPhot      ;  //   The number of Cerenkov photons 
   Float_t  fErrPhot   ;  //   the error of fPhot
@@ -59,4 +60,13 @@
     }  
   
+  void SetCorePixel() 
+    { 
+      fIsCore = kTRUE ; 
+    } 
+
+  Bool_t IsCorePixel() 
+    { 
+      return fIsCore ; 
+    }  
   
   
@@ -96,7 +106,9 @@
   void CleanLevel1() ; 
   void CleanLevel2() ; 
+  void CleanLevel3() ; 
   
   Bool_t PixelExist( Int_t id ) ; 
   Bool_t PixelIsUsed( Int_t id ) ; 
+  Bool_t PixelIsCore( Int_t id ) ; 
  
   Int_t GetPixelId(Int_t i ) ; 
