Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 3452)
+++ trunk/MagicSoft/Mars/Changelog	(revision 3453)
@@ -18,4 +18,14 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2004/03/10: Ester Aliu
+
+   * mtemp/MIslands.[h,cc]
+     - New MParContainer to hold information about islands
+       (number of islands, pixels in each Island, Signal/Noise of
+	each Island).
+
+   * mtemp/MIslandCalc.[h,cc]
+     - New MTask to count and characterize Islands.
+
  2004/03/09: Thomas Bretz
 
Index: trunk/MagicSoft/Mars/mtemp/MIslandCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/MIslandCalc.cc	(revision 3453)
+++ trunk/MagicSoft/Mars/mtemp/MIslandCalc.cc	(revision 3453)
@@ -0,0 +1,231 @@
+////////////////////////////////////////////////////////////////////////////
+// Input Containers:
+//   MGeomCam
+//   MCerPhotEvt
+//   MPedestalCam
+//
+//  Output Containers:
+//   MIslands
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MIslandCalc.h"
+
+#include <stdlib.h>       // atof					  
+#include <fstream>        // ofstream, SavePrimitive
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MIslands.h"
+
+#include "MParList.h"
+
+//#include "MImgCleanStd.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MGeomPix.h"
+#include "MGeomCam.h"
+
+#include "MCerPhotPix.h"
+#include "MCerPhotEvt.h"
+
+#include "MPedestalCam.h"
+#include "MPedestalPix.h"
+
+
+ClassImp(MIslandCalc);
+
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MIslandCalc::MIslandCalc(const char *name, const char *title)    
+  : fIsl(NULL)
+{
+    fName  = name  ? name  : "MIslandCalc";
+    fTitle = title ? title : "Calculate island parameters";
+}
+
+
+
+Int_t MIslandCalc::PreProcess (MParList *pList)
+{
+    fCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
+    if (!fCam)
+    {
+        *fLog << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
+        return kFALSE;
+    }
+
+    fEvt = (MCerPhotEvt*)pList->FindObject(AddSerialNumber("MCerPhotEvt"));
+    if (!fEvt)
+    {
+        *fLog << dbginf << "MCerPhotEvt not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fPed = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
+    if (!fPed)
+      {
+        *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
+        return kFALSE;
+      }
+    
+    
+    fIsl = (MIslands*)pList->FindCreateObj(AddSerialNumber("MIslands"));
+    if (!fIsl)
+      return kFALSE;
+
+    return kTRUE;
+}
+
+
+//tries to clean a bit more the image avoiding noisy islands
+ 
+Int_t MIslandCalc::Process()
+{
+
+  Float_t  noise;
+  Float_t  signal;
+
+  Int_t    npix = 577;
+  Int_t    sflag;
+  Int_t    control;
+  
+  Int_t    nvect = 0;
+  Int_t    fIslNum = 0;
+  Float_t  fSigToNoise[30];
+
+  Int_t    vect[100][577];
+  Int_t    kk[577];
+  
+  for(Int_t m = 0; m < 50 ; m++)
+    for(Int_t n = 0; n < 577 ; n++)
+      vect[m][n] = 0;
+  
+  for(Int_t n = 0; n < 577 ; n++)
+    kk[n] = 0;
+   
+  // loop over all pixels
+  for(Int_t idx=0 ; idx<npix ; idx++)
+    { 
+      const MGeomPix &gpix  = (*fCam)[idx];
+      const Int_t    nnmax  = gpix.GetNumNeighbors();
+      
+      if(idx<0 || idx==npix)
+	{
+	  cout << "Pixel (software) index out of range [0-576]. Available number of pixels=" << npix << endl;
+	  return 1;
+	}
+      
+   
+      if(fEvt->IsPixelCore(idx) || fEvt->IsPixelUsed(idx)) 
+     	{
+	  sflag = 0;
+	  
+	  for(Int_t j=0; j < nnmax ; j++)
+	    {
+	      const Int_t idx2 = gpix.GetNeighbor(j);
+	      
+	      if (idx2 < idx)
+		{
+		  for(Int_t k = 1; k <= nvect; k++)
+		    {
+		      if (vect[k][idx2] == 1)
+			{
+			  sflag = 1;
+			  vect[k][idx] = 1;
+			}
+		    }
+		}
+	    }
+	  
+	  if (sflag == 0)
+	    {
+	      nvect++;
+	      vect[nvect][idx] = 1;	     
+	    }
+	  
+	}
+    }
+  
+  fIslNum = nvect;
+  
+  // Repeated Chain Corrections
+  for(Int_t i = 1; i <= nvect; i++)
+    {
+      for(Int_t j = i+1; j <= nvect; j++)
+	{
+	  control = 0;
+	  for(Int_t k = 0; k < npix; k++)
+	    {
+	      if (vect[i][k] == 1 && vect[j][k] == 1)
+		{
+		  control = 1; 
+		  //cout << " two vectors coincide... "<< endl;
+		  break;
+		}
+	    }
+	  if (control == 1)
+	    {
+	      for(Int_t k = 0; k < npix; k++)
+		{
+		  if(vect[j][k] == 1)
+		    vect[i][k] = 1;
+		  vect[j][k] = 0;
+		}	
+	      fIslNum = fIslNum-1;	    
+	    }
+	}
+    }
+  
+  cout << " Let me see..." << endl;
+  cout << " Number of vectors: " << nvect << endl;
+  cout << " Number of islands: " << fIslNum << endl;      
+  
+  //examine each island...
+
+  Int_t fPixNum[30];
+
+  for(Int_t i = 1; i<=fIslNum ; i++)
+    {
+      signal = 0;
+      noise = 0;
+      fPixNum[i] = 0;
+      for(Int_t idx=0 ; idx<npix ; idx++)
+	{
+	  const MCerPhotPix &pix = (*fEvt)[idx];
+	  const MPedestalPix &ped  = (*fPed)[idx];
+
+	  if (vect[i][idx]==1){
+
+	    fPixNum[i]++;
+	    signal += pix.GetNumPhotons() * (fCam->GetPixRatio(idx));
+	    noise += pow(ped.GetPedestalRms(),2);
+
+	  }	
+	}
+
+      cout << "Signal: " << signal<<endl;
+      cout << "Noise: " << noise << endl;  
+      fSigToNoise[i] = (Float_t)signal/(Float_t)sqrt(noise);
+
+      fIsl->SetIslNum(fIslNum);
+      fIsl->SetPixNum(i,fPixNum[i]);
+      fIsl->SetSigToNoise(i,fSigToNoise[i]);
+
+      cout << " Island Num " << i << endl;
+      cout << " Pixel Number in the island: " << fPixNum[i] << endl;
+      cout << " Signal to Noise of the island : " << fSigToNoise[i] << endl;
+    	
+    }
+
+  return 1;
+}
+
+  
Index: trunk/MagicSoft/Mars/mtemp/MIslandCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/MIslandCalc.h	(revision 3453)
+++ trunk/MagicSoft/Mars/mtemp/MIslandCalc.h	(revision 3453)
@@ -0,0 +1,38 @@
+#ifndef MARS_MIslandCalc
+#define MARS_MIslandCalc
+
+#ifndef MARS_MGTask
+#include "MGTask.h"
+#endif
+
+#ifndef ROOT_TArrayF
+#include <TArrayF.h>
+#endif
+
+class MGeomCam;
+class MSigmabar;
+class MCerPhotPix;
+class MCerPhotEvt;
+class MPedestalCam;
+class MIslands;
+
+class MIslandCalc : public MGTask
+{
+ private:
+    const MGeomCam    *fCam;        //!
+    MCerPhotEvt       *fEvt;        //!
+    MSigmabar         *fSgb;        //!
+    MPedestalCam      *fPed;        //!
+
+    MIslands          *fIsl;        //!    output container to store result
+   
+    Int_t PreProcess(MParList *plist);
+    Int_t Process();
+           
+ public:
+    MIslandCalc(const char *name=NULL, const char *title=NULL);
+
+    ClassDef(MIslandCalc, 0)        // task doing the image cleaning
+}; 
+
+#endif
Index: trunk/MagicSoft/Mars/mtemp/MIslands.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/MIslands.cc	(revision 3453)
+++ trunk/MagicSoft/Mars/mtemp/MIslands.cc	(revision 3453)
@@ -0,0 +1,25 @@
+#include "MIslands.h"
+
+ClassImp(MIslands);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MIslands::MIslands(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MIslands";
+    fTitle = title ? title : "Storage container for the island information of one event";
+
+}
+
+// --------------------------------------------------------------------------
+//
+// Destructor.
+//
+MIslands::~MIslands()
+{
+}
+
Index: trunk/MagicSoft/Mars/mtemp/MIslands.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/MIslands.h	(revision 3453)
+++ trunk/MagicSoft/Mars/mtemp/MIslands.h	(revision 3453)
@@ -0,0 +1,39 @@
+#ifndef MARS_MIslands
+#define MARS_MIslands
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+#ifndef ROOT_TArrayF
+#include <TArrayF.h>
+#endif
+
+#ifndef ROOT_TArrayI
+#include <TArrayI.h>
+#endif
+
+
+class MIslands : public MParContainer
+{
+private:
+    // for description see MIslands.cc
+    Int_t fIslNum;                    //    number of islands
+    Int_t fPixNum[30];                //    number of pixels in the island
+    Float_t fSigToNoise[30] ;         //    signal to noise of the island
+
+public:
+    MIslands(const char *name=NULL, const char *title=NULL);
+    ~MIslands();
+
+    Int_t    GetIslNum() const                        { return fIslNum; }
+    Int_t    GetPixNum(Int_t i) const                 { return fPixNum[i]; }
+    Float_t  GetSigToNoise(Int_t i) const             { return fSigToNoise[i]; } 
+    void     SetIslNum(Int_t i)                       { fIslNum = i; }
+    void     SetPixNum(Int_t i, Int_t j)              { fPixNum[i] = j; }
+    void     SetSigToNoise(Int_t i, Float_t m)        { fSigToNoise[i] = m; }
+   
+    ClassDef(MIslands, 1) // Storage Container for Island Parameters
+};
+
+#endif
