Index: trunk/MagicSoft/Mars/mtemp/mifae/Changelog
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/Changelog	(revision 4413)
+++ trunk/MagicSoft/Mars/mtemp/mifae/Changelog	(revision 4418)
@@ -18,4 +18,10 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+
+  2004/07/22 Ester Aliu 
+    * library/MIslands.[h,cc],MIslandCalc.cc
+     - Add meanX, meanY and dist of each of the islands
+     - Now the island with id 0 is the larger one
 
   2004/07/21  Javier Rico
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MIslandCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MIslandCalc.cc	(revision 4413)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MIslandCalc.cc	(revision 4418)
@@ -17,9 +17,11 @@
 //   - fIslNum             //  number of islands
 //   - fIslId[577]         //  island Id
-//   - fPixNum[20];        //  number of pixels in the island
-//   - fSigToNoise[20];    //  signal to noise of the island
+//   - fPixNum[20]         //  number of pixels in the island
+//   - fSigToNoise[20]     //  signal to noise of the island
 //   - fTime[20][577]      //  mean of the arrival time  
-//   - fTimeSpread[20];    //  mean arrival time spread of the island
-//
+//   - fTimeSpread[20]     //  mean arrival time spread of the island
+//   - fMeanX[20]          //  mean X position of the island
+//   - fMeanY[20]          //  mean Y position of the island
+//   - fDist[20]           //  dist between an island and the continent
 //
 // Input Containers:
@@ -141,5 +143,5 @@
   //
   //        ALGORITHM # 1
-  // counts the number of algorithms as you can see in 
+  // counts the number of islands as you can see in 
   // the event display after doing the std image cleaning
   //
@@ -215,4 +217,5 @@
   
   // Repeated Chain Corrections
+
   
   for(Int_t i = 1; i <= nvect; i++)
@@ -223,5 +226,4 @@
 	  for(Int_t k = 0; k < npix; k++)
 	    {
-	      
 	      if (vect[i][k] == 1 && vect[j][k] == 1)
 		{
@@ -246,8 +248,14 @@
   
   
+
   Int_t l = 1;
-  
+  Int_t numpixels;
+  Int_t pixMAX = 0;
+  Int_t idMAX = 1;
+
   for(Int_t i = 1;  i<= nvect ; i++)
     {
+      numpixels = 0;
+
       if (zeros[i] == 0)
 	{
@@ -255,4 +263,11 @@
 	    {
 	      vect[l][k] = vect[i][k];
+	      if (vect[l][k] == 1)
+		numpixels++;
+	    }
+	  if (numpixels>pixMAX)
+	    {
+	      pixMAX = numpixels;
+	      idMAX = l;
 	    }
 	  l++;
@@ -260,5 +275,14 @@
     }
   
-  
+  //the larger island will correspond to the 1st component of the vector
+
+  for(Int_t k = 0; k<npix; k++) 
+    {
+      vect[nvect+1][k] = vect[1][k];
+      vect[1][k] = vect[idMAX][k];
+      vect[idMAX][k] = vect[nvect+1][k];
+    }
+
+
   //set the number of islands in one event
   fIsl->SetIslNum(fIslNum);
@@ -269,5 +293,6 @@
   Float_t time[577];
   Float_t timeVariance[fIslNum];
-  
+  Float_t size, meanX, meanY, dist;
+
   //reset the "sets" functions
   if (fIslNum <1)
@@ -287,4 +312,7 @@
     }
  
+
+  Float_t X = 0;
+  Float_t Y = 0;
    
    for(Int_t i = 1; i<=fIslNum ; i++)
@@ -298,4 +326,10 @@
       signal = 0;
       noise = 0;
+
+      size = 0;
+      meanX = 0;
+      meanY = 0;
+      dist = 0;
+
       fPixNum[i-1] = 0;
       timeVariance[i-1] = 0;
@@ -305,6 +339,8 @@
 	  
 	  MCerPhotPix *pix = fEvt->GetPixById(idx);
+	  const MGeomPix &gpix2 = (*fCam)[pix->GetPixId()];
 	  const MPedestalPix &ped  = (*fPed)[idx];
 	  const MArrivalTimePix &timepix = (*fTime)[idx];
+	  const Float_t nphot = pix->GetNumPhotons();
 
 	  if (pix == NULL) break;
@@ -313,6 +349,10 @@
 	    
 	    fPixNum[i-1]++;
-	    signal += pix->GetNumPhotons() * (fCam->GetPixRatio(idx));
+	    signal += nphot * (fCam->GetPixRatio(idx));
 	    noise += pow(ped.GetPedestalRms(),2);
+	    
+	    size += nphot;
+	    meanX += nphot * gpix2.GetX();
+	    meanY += nphot * gpix2.GetY();
 	    
 	    time[n] = timepix.IsLoGainUsed() ? timepix.GetArrivalTimeLoGain() : timepix.GetArrivalTimeHiGain();
@@ -337,10 +377,16 @@
 	}
 
-      // Float_t mean = timeVariance[i-1]/ncore;
-           
-      timeVariance[i-1] = 0;
-     
-      timeVariance[i-1] = (MAX - MIN)/ncore; 
-      timeVariance[i-1] = (MAX - MIN)/ncore; 
+      meanX /= size;
+      meanY /= size;
+  
+      if (i ==1){
+	X = meanX;
+	Y = meanY;
+      }
+    
+      dist = TMath::Power(meanX-X,2) + TMath::Power(meanY-Y,2);
+      dist = TMath::Sqrt(dist);
+
+      timeVariance[i-1] = (MAX - MIN); 
 
       fSigToNoise[i-1]= (Float_t)signal/(Float_t)sqrt(noise);
@@ -349,6 +395,9 @@
       fIsl->SetSigToNoise(i-1,fSigToNoise[i-1]);
       fIsl->SetTimeSpread(i-1, timeVariance[i-1]);
-      
-    } 
+      fIsl->SetMeanX(i-1, meanX);
+      fIsl->SetMeanY(i-1, meanY);
+      fIsl->SetDist(i-1, dist);
+      
+    }
   
   fIsl->SetReadyToSave();
@@ -493,9 +542,14 @@
     }
   
-  
+    
   Int_t l = 1;
-  
+  Int_t numpixels;
+  Int_t pixMAX = 0;
+  Int_t idMAX = 1;
+
   for(Int_t i = 1;  i<= nvect ; i++)
     {
+      numpixels = 0;
+
       if (zeros[i] == 0)
 	{
@@ -503,4 +557,11 @@
 	    {
 	      vect[l][k] = vect[i][k];
+	      if (vect[l][k] == 1)
+		numpixels++;
+	    }
+	  if (numpixels>pixMAX)
+	    {
+	      pixMAX = numpixels;
+	      idMAX = l;
 	    }
 	  l++;
@@ -509,4 +570,14 @@
   
   
+  //the larger island will correspond to the 1st component of the vector
+
+  for(Int_t k = 0; k<npix; k++) 
+    {
+      vect[nvect+1][k] = vect[1][k];
+      vect[1][k] = vect[idMAX][k];
+      vect[idMAX][k] = vect[nvect+1][k];
+    }
+  
+
   //set the number of islands in one event
   fIsl->SetIslNum(fIslNum);
@@ -517,5 +588,6 @@
   Float_t time[577];
   Float_t timeVariance[fIslNum];
-  
+  Float_t size, meanX, meanY, dist;
+
   //reset the "sets" functions
   if (fIslNum <1)
@@ -535,4 +607,7 @@
     }
  
+
+  Float_t X = 0;
+  Float_t Y = 0;
    
    for(Int_t i = 1; i<=fIslNum ; i++)
@@ -546,4 +621,10 @@
       signal = 0;
       noise = 0;
+
+      size = 0;
+      meanX = 0;
+      meanY = 0;
+      dist = 0;
+
       fPixNum[i-1] = 0;
       timeVariance[i-1] = 0;
@@ -553,14 +634,20 @@
 	  
 	  MCerPhotPix *pix = fEvt->GetPixById(idx);
+	  const MGeomPix &gpix2 = (*fCam)[pix->GetPixId()];
 	  const MPedestalPix &ped  = (*fPed)[idx];
 	  const MArrivalTimePix &timepix = (*fTime)[idx];
+	  const Float_t nphot = pix->GetNumPhotons();
 
 	  if (pix == NULL) break;
 	    
-	  if (vect[i][idx] ==1 && fEvt->IsPixelUsed(idx)){
+	  if (vect[i][idx]==1){
 	    
 	    fPixNum[i-1]++;
-	    signal += pix->GetNumPhotons() * (fCam->GetPixRatio(idx));
+	    signal += nphot * (fCam->GetPixRatio(idx));
 	    noise += pow(ped.GetPedestalRms(),2);
+	    
+	    size += nphot;
+	    meanX += nphot * gpix2.GetX();
+	    meanY += nphot * gpix2.GetY();
 	    
 	    time[n] = timepix.IsLoGainUsed() ? timepix.GetArrivalTimeLoGain() : timepix.GetArrivalTimeHiGain();
@@ -585,10 +672,16 @@
 	}
 
-      // Float_t mean = timeVariance[i-1]/ncore;
-           
-      timeVariance[i-1] = 0;
-     
-      timeVariance[i-1] = (MAX - MIN)/ncore; 
-      timeVariance[i-1] = (MAX - MIN)/ncore; 
+      meanX /= size;
+      meanY /= size;
+  
+      if (i ==1){
+	X = meanX;
+	Y = meanY;
+      }
+    
+      dist = TMath::Power(meanX-X,2) + TMath::Power(meanY-Y,2);
+      dist = TMath::Sqrt(dist);
+
+      timeVariance[i-1] = (MAX - MIN); 
 
       fSigToNoise[i-1]= (Float_t)signal/(Float_t)sqrt(noise);
@@ -597,7 +690,11 @@
       fIsl->SetSigToNoise(i-1,fSigToNoise[i-1]);
       fIsl->SetTimeSpread(i-1, timeVariance[i-1]);
-      
-    } 
-  
+      fIsl->SetMeanX(i-1, meanX);
+      fIsl->SetMeanY(i-1, meanY);
+      fIsl->SetDist(i-1, dist);
+      
+    }
+
+     
   fIsl->SetReadyToSave();
   
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MIslands.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MIslands.cc	(revision 4413)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MIslands.cc	(revision 4418)
@@ -47,4 +47,7 @@
     	*fLog << "    + SigToNoise = " << fSigToNoise[i] << endl;
     	*fLog << "    + TimeSpread = " << fTimeSpread[i] << endl;
+    	*fLog << "    + MeanX = " << fMeanX[i] << endl;
+    	*fLog << "    + MeanY = " << fMeanY[i] << endl;
+    	*fLog << "    + Dist = " << fDist[i] << endl;
       }
 }
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MIslands.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MIslands.h	(revision 4413)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MIslands.h	(revision 4418)
@@ -25,4 +25,7 @@
     Float_t fTime[20][577];        //  mean of the arrival time  
     Float_t fTimeSpread[20];       //  mean arrival time spread of the island  
+    Float_t fMeanX[20];            //  mean X position of the island
+    Float_t fMeanY[20];            //  mean Y position of the island
+    Float_t fDist[20];    //  dist between islands and continent(larger island)
 
 public:
@@ -37,5 +40,8 @@
     Float_t  GetSigToNoise(Int_t isl)                 { return fSigToNoise[isl]; }
     Float_t  GetArrivalTime(Int_t isl, Int_t idx) { return fTime[isl][idx]; }           
-    Float_t  GetTimeSpread(Int_t isl) { return fTimeSpread[isl];}          
+    Float_t  GetTimeSpread(Int_t isl)             { return fTimeSpread[isl];}          
+    Float_t  GetMeanX(Int_t isl)                  { return fMeanX[isl];}
+    Float_t  GetMeanY(Int_t isl)                  { return fMeanY[isl];}
+    Float_t  GetDist(Int_t isl)                   { return fDist[isl]; }
 
     void     SetIslNum(Int_t nisl)                    { fIslNum = nisl; }
@@ -46,5 +52,9 @@
 
     void     SetTimeSpread(Int_t isl, Float_t val) { fTimeSpread[isl] = val; }
-    
+    void     SetMeanX(Int_t isl, Float_t val) { fMeanX[isl]=val; }
+    void     SetMeanY(Int_t isl, Float_t val) { fMeanY[isl]=val; }
+    void     SetDist(Int_t isl, Float_t val) { fDist[isl]=val; }
+
+
     ClassDef(MIslands, 1) // Storage Container for Island Parameters
 };
