Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 2917)
+++ trunk/MagicSoft/Mars/Changelog	(revision 2918)
@@ -4,4 +4,25 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2004/01/26: Nicola Galante
+
+   * manalisys/MMcTriggerLvl2.[cc,h]:
+     - Defined some static constants to avoid ugly "magic numbers"
+       in arrays: gsNCells, gsNTrigPixels,
+       gsNPixInCell, gsNLutInCell, gsNPixInLut, fNumPixCell.
+     - Added method MMcTriggerLvl2::GetCellCompactPixel(int cell, MGeomCam *fCam)
+       which computes compact pixels into a given L2T macrocell.
+     - Added method MMcTriggerLvl2::CalcBiggerCellPseudoSize() which
+       computes fCellPseudoSize, the maximum Pseudo Size into L2T macrocells
+     - Added method MMcTriggerLvl2::GetCellPseudoSize() const which
+       returns fCellPseudoSize
+     - Added method MMcTriggerLvl2::IsPixelInCell(Int_t pixel, Int_t cell),
+       which controls whether a pixel belongs to a given L2T cell.
+     - Added method MMcTriggerLvl2::GetMaxCell() const which returns fMaxCell, the cell with
+       the maximum fCellPseudoSize.
+     - Re-declared methods MMcTriggerLvl2::CalcCompactPixels(MGeomCam *fCam)
+       and MMcTriggerLvl2::CalcTriggerPattern(MGeomCam *fCam) as private.
+
+
  2004/01/26: Markus Gaug
 
Index: trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2.cc	(revision 2917)
+++ trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2.cc	(revision 2918)
@@ -72,5 +72,7 @@
 // This correspondence is valid only for MAGIC-like geometries!
 //
-const  Int_t  MMcTriggerLvl2::gsPixelsInCell[36][19] = {
+//  FIXME!  These definitions should be included in a GeomTrig class
+//
+const  Int_t  MMcTriggerLvl2::gsPixelsInCell[gsNPixInCell][gsNCells] = {
     {26,  91,  66,  71,  76,  81,  86,  269,  224,  233,  242,  251,  260,  391,  336,  347,  358,	369,  380},
     {25,  61,  41,  45,  49,  53,  57,  215,  175,  183,  191,  199,  207,  325,  275,  285,  295,  305,  315},
@@ -114,5 +116,5 @@
 // corrispondence between pixels in cell and lut (pix numbering starts from 1)
 //
-const Int_t MMcTriggerLvl2::gsPixelsInLut[3][12] = {
+const Int_t MMcTriggerLvl2::gsPixelsInLut[gsNLutInCell][gsNPixInLut] = {
     { 1,  2,  3,  4,  6,  7,  8,  9, 12, 13, 14, 15},
     {34, 29, 23, 16, 30, 24, 17, 10, 25, 18, 11,  5},
@@ -135,6 +137,6 @@
   // Initialization of the fPixels array to zero
   //
-  memset (fPixels,0,36*19*sizeof(Int_t));
-  memset (fFiredPixel,0,397*sizeof(Int_t));
+  memset (fPixels,0,gsNPixInCell*gsNCells*sizeof(Int_t));
+  memset (fFiredPixel,0,gsNTrigPixels*sizeof(Int_t));
 
   // create a new camera
@@ -180,5 +182,5 @@
     {
       *fLog << "    Status of cells 1-9" <<endl;
-      for(int i=0; i<36; i++)
+      for(int i=0; i<gsNPixInCell; i++)
 	{
 	  for(int j=0; j<9; j++)
@@ -193,5 +195,5 @@
     {
       *fLog << "   Pixel numbering in cells 1-9" <<endl;
-      for (int i=0;i<36;i++)
+      for (int i=0;i<gsNPixInCell;i++)
 	{
 	  for(int j=0; j<9; j++)
@@ -210,7 +212,8 @@
   else 
     {
-      *fLog << "  L2T selection parameters:" << endl;
+      *fLog << "  L2T selection parameters: " << endl;
       *fLog << "   - LutPseudoSize  = " << fLutPseudoSize <<  endl;
-      *fLog << "   - PseudoSize     = " << fPseudoSize << endl;
+      *fLog << "   - CellPseudoSize  = " << fCellPseudoSize <<  endl;
+      *fLog << "   - PseudoSize  = " << fPseudoSize <<  endl;
       *fLog << "   - BiggerCellSize = " << fSizeBiggerCell << endl;
       *fLog << "   - TriggerPattern = " << fTriggerPattern << endl;
@@ -233,7 +236,7 @@
   fMcTrig = trig;
 
-  for(int i=0; i<36; i++)
-    {
-      for(int j=0; j<19; j++)
+  for(int i=0; i<gsNPixInCell; i++)
+    {
+      for(int j=0; j<gsNCells; j++)
 	{
 	  int pixel = gsPixelsInCell[i][j]-1;
@@ -256,7 +259,7 @@
 void MMcTriggerLvl2::SetPixelFired(Int_t pixel, Int_t fired)
 {
-  for(int i=0; i<36; i++)
-    {
-      for(int j=0; j<19; j++)
+  for(int i=0; i<gsNPixInCell; i++)
+    {
+      for(int j=0; j<gsNCells; j++)
 	{
 	  if(gsPixelsInCell[i][j]-1==pixel) fPixels[i][j]=fired;
@@ -277,8 +280,10 @@
   // Find the Lut and cell with the higher LutPseudoSize. 
   int lutcell = CalcBiggerLutPseudoSize(); 
-  int maxcell = lutcell/10;
-  int maxlut = lutcell-maxcell*10;
-  fLutPseudoSize = GetLutCompactPixel(maxcell,maxlut);
-
+  fMaxCell = lutcell/10;
+  int maxlut = lutcell-fMaxCell*10;
+  fLutPseudoSize = GetLutCompactPixel(fMaxCell,maxlut);
+
+  fMaxCell = CalcBiggerCellPseudoSize();  // fCellPseudoSize
+  // fMaxCell is used by the PseudoSize to find the starting pixel
   CalcPseudoSize();
 
@@ -298,5 +303,5 @@
   int size=0;
  
-  for(int i=0; i<36; i++)
+  for(int i=0; i<gsNPixInCell; i++)
     {
       size += fPixels[i][cell];
@@ -318,5 +323,5 @@
   int cell=-1;
 
-  for(int j=0; j<19; j++)
+  for(int j=0; j<gsNCells; j++)
     {
       if (GetCellNumberFired(j) > size) 
@@ -349,7 +354,7 @@
   int lut=-1;
  
-  for(int j=0; j<19; j++)
-    {
-      for(int i=0; i<3; i++)
+  for(int j=0; j<gsNCells; j++)
+    {
+      for(int i=0; i<gsNLutInCell; i++)
 	{
 	  if (GetLutCompactPixel(j,i) >= size) 
@@ -387,5 +392,5 @@
 {
   int size=0;
-  int lutpix, a[12]; 
+  int lutpix, a[gsNPixInLut]; 
   int neighpix= (*this).fCompactNN;
 
@@ -395,14 +400,19 @@
     return(-1);
 
-  if (cell<0 || cell>18)
+  if (cell<0 || cell> gsNCells-1)
     return(-2);
 
-  if (lut<0 || lut>2)
+  if (lut<0 || lut> gsNLutInCell-1)
     return(-3);
 
 
+  //
+  // Warning!!! Following configurations are valid only for the standard MAGIC 
+  // trigger geometry; FIXME! these should be coded somewhere else....
+  //
+
   // LUT 1 and 2 are similar; LUT 3 differs
   
-  for(int j=0; j<12; j++)
+  for(int j=0; j< gsNPixInLut; j++)
     {
       lutpix = gsPixelsInLut[lut][j]-1;
@@ -613,5 +623,5 @@
   
 
-  if(size<0 ||size>12)
+  if(size<0 ||size>gsNPixInLut)
     *fLog << "*" << size <<"-";
   
@@ -634,22 +644,27 @@
   // seek the LUT with higher number of compact pixels
   //
-  int cellut = CalcBiggerLutPseudoSize();
-  int maxcell = cellut/10;
-  int maxlut = cellut - maxcell*10;
+  //int fMaxCell = CalcBiggerCellPseudoSize();
+  int sizetemp=0;
+  int maxlut=0;
+
+  for (int i=0;i<gsNLutInCell;i++)
+    if (GetLutCompactPixel(fMaxCell,i) > sizetemp)
+      {
+        maxlut=i;
+        sizetemp = GetLutCompactPixel(fMaxCell,i);
+      }
+
   int startpix;
-  //if (GetLutCompactPixel(maxcell,maxlut)==0)
-    //*fLog << "Max lut size:" << GetLutCompactPixel(maxcell,maxlut) <<endl;
-
   // 
-  // seek a starting pixel in the lut for the iteration
+  // seek a starting pixel for the iteration inside the lut
   //
   int check=1;
-  for (int pixlut=0;pixlut<12;pixlut++)
+  for (int pixlut=0;pixlut<gsNPixInLut;pixlut++)
     {
       int pixcell =gsPixelsInLut[maxlut][pixlut]-1;
-      startpix = gsPixelsInCell[pixcell][maxcell]-1;
+      startpix = gsPixelsInCell[pixcell][fMaxCell]-1;
       //*fLog << "pix, compact:" << startpix << "@"<<fCompactPixel[startpix];
       if (fCompactPixel[startpix]) // a starting pixel was found
-	break;
+		break;
       check++;
     }
@@ -657,34 +672,20 @@
   //*fLog << "check = " << check << endl;
   // A LUT contains 12 pixels
-  if (check > 12)
-    {
-      check=1;
-      // A starting pixel was not found using the LutPseudoSize. 
-      // We look for it in the BiggerCell
-      maxcell=CalcBiggerFiredCell();
-      for (int pixcell=0;pixcell<36;pixcell++)
-	{
-	  startpix = gsPixelsInCell[pixcell][maxcell]-1;
-	  //*fLog << "pix, compact:" << startpix << "@"<<fCompactPixel[startpix];
-	  if (fCompactPixel[startpix]) // a starting pixel was found
-	    break;
-	  check++;
-	}
-      if (check > 36)
-	{   
-	  //	   *fLog <<"Warning: a starting pixel was not found! - PseudoSize = "<< fPseudoSize << endl;
-	  fPseudoSize=-1;
-	  return;
-	}
-    }
+  if (check > gsNPixInLut)
+	  {   
+		   *fLog <<"Warning: a starting pixel was not found! - PseudoSize = "<< fPseudoSize << endl;
+	    fPseudoSize=-1;
+	    return;
+	  }
+
   //
   // Bulding cluster
   //
-  Int_t cluster[397];
+  Int_t cluster[gsNTrigPixels];
   int pnt=0;
   int pnt2=0; //pointer in the array fCluster_pix, needed for filling
 
-  memset (cluster,0,397*sizeof(Int_t));
-  memset (fCluster_pix,-1,397*sizeof(Int_t));
+  memset (cluster,0,gsNTrigPixels*sizeof(Int_t));
+  memset (fCluster_pix,-1,gsNTrigPixels*sizeof(Int_t));
 
   cluster[startpix]=1;  
@@ -701,25 +702,28 @@
 
       for (int i=0;i<pix.GetNumNeighbors();i++)
-	{
-	  int pix_neigh = pix.GetNeighbor(i);
-	  // check if pixel is fired and doesn't belong to cluster
-	  if (fCompactPixel[pix_neigh] && !cluster[pix_neigh])
-	  //if (fCompactPixel[pix_neigh])
 	    {
-	      cluster[pix_neigh] = 1;
-	      fCluster_pix[++pnt2] = pix_neigh;
+	       int pix_neigh = pix.GetNeighbor(i);
+	       // check if pixel is fired and doesn't belong to cluster
+	       if (fCompactPixel[pix_neigh] && !cluster[pix_neigh])
+	         {
+	            cluster[pix_neigh] = 1;
+	            fCluster_pix[++pnt2] = pix_neigh;
+	         }
 	    }
-	}
       pnt++;
     }
 
   fPseudoSize = pnt;
+
   //if (fPseudoSize < 4)
     //    *fLog << "fPseudoSize = " << fPseudoSize << endl;
 
   //  *fLog << "ClusterID:" <<(*clust).GetClusterId() << " Mult:" << (*clust).GetMultiplicity()<<endl;  
-
-  //  *fLog <<"PSize: "<< fPseudoSize << " in cell:" << maxcell << " lut:" <<maxlut <<endl;
-
+  /*
+  *fLog <<"PSize: "<< fPseudoSize << " in cell:" << fMaxCell << " lut:" <<maxlut << endl << "   Pixels: ";
+  for (int i =0;i<fPseudoSize; i++)
+    *fLog << fCluster_pix[i]+1 <<"; ";
+  *fLog << endl;
+  */
   return;
 }
@@ -737,35 +741,67 @@
 void MMcTriggerLvl2::CalcCompactPixels(MGeomCam *geom)
 {
-  memset (fCompactPixel,0,397*sizeof(Int_t));
+  memset (fCompactPixel,0,gsNTrigPixels*sizeof(Int_t));
   //  *fLog << endl << "NEW Event!";
-  for(UInt_t pixid=0;pixid<397;pixid++)
+  for(Int_t pixid=0; pixid<gsNTrigPixels; pixid++)
     {
       // Look if the pixel is fired, otherwise continue
       if (!fFiredPixel[pixid])
-	continue;
+	     continue;
       
       const MGeomPix &pix=(*geom)[pixid];
       
+      // Reshuffle pixneighbour order, to arrange them (anti)clockwise
+      //   around the current pixel (Bubble sorting)
+      // The NeighPixOrdered array has a doubledd size so that
+      // the content in the first index is repeated in the last one
+      // to have a closed loop
+
+      Int_t NeighPixOrdered[2*pix.GetNumNeighbors()];
+
+      for (Int_t j=0; j<pix.GetNumNeighbors(); j++)
+        NeighPixOrdered[j] = pix.GetNeighbor(j);
+      
+      for (Int_t j=0; j<pix.GetNumNeighbors()-1; j++)
+        {
+          for (Int_t jk=pix.GetNumNeighbors()-1;jk>j;--jk)
+            {
+               UInt_t tmp = NeighPixOrdered[j+1];
+               const MGeomPix &pixneigh = (*geom)[NeighPixOrdered[j]];
+               for (int k=0; k<pix.GetNumNeighbors(); k++)
+                 if (NeighPixOrdered[jk] == pixneigh.GetNeighbor(k))
+     		       {
+                      NeighPixOrdered[j+1] = NeighPixOrdered[jk];
+                      NeighPixOrdered[jk] = tmp;
+              	   }
+	        }
+        }
+      
+      // Duplicate second half to take into account configurations
+ 	  //  containing tha last and first pixel
+      for (Int_t j=pix.GetNumNeighbors(); j<2*pix.GetNumNeighbors(); j++)
+        NeighPixOrdered[j] = NeighPixOrdered[j-pix.GetNumNeighbors()];
+
       // Look for compact pixels. 
-      // A compact pixel must have at least fCompactNN adjacent neighbors
-      // It checks the 6 different configurations of neighbors pixels
-      int j=0;
+      // A compact pixel must have at least fCompactNN adjacent fired neighbors
+      // It checks the 6 different configurations of neighbors pixels; if
+	  // one has fCompacNN adjacent fired pixels than the pixel pixid is
+	  // promoted to compact pixel and saved into the fCompactPixel array.
+	  //
       for (int i=0;i<pix.GetNumNeighbors();i++)
-	{ 
-	  //*fLog << pixid <<"->"<< pix.GetNeighbor(i+j) << endl;
-	  while ((fFiredPixel[pix.GetNeighbor(i+j)]==1) && (j < fCompactNN))
-	    j++;  
-	  if (j!=fCompactNN)  continue;	 // configuration doesn't satisfy compact condition  
-	  
-	  fCompactPixel[pixid]=1; // pixel is compact
-
-	  //	  *fLog << ","<<pixid;
-
-	  break;
-	}      
-    }
-}
-
-
+	    { 
+	      int j=0; // j counts the adjacent fired pixels
+	      //*fLog << pixid <<"->"<< pix.GetNeighbor(i+j) << endl;
+	      while ((i+j < 2*pix.GetNumNeighbors()) && (fFiredPixel[NeighPixOrdered[i+j]]==1) && (j < fCompactNN))
+	        j++;  
+	      if (j>=fCompactNN)	 // configuration satisfies the compact condition  
+		{
+	      	  fCompactPixel[pixid]=1; // pixel is compact
+	      	  //	  *fLog << ","<<pixid;
+		  break;
+		}
+	    }      
+    }
+
+}
 
 // --------------------------------------------------------------------------
@@ -778,4 +814,5 @@
   const MMcEvt &h = *(MMcEvt *)fMcEvt; 
   fEnergy = h.GetEnergy();
+  return;
 }
 
@@ -808,9 +845,9 @@
   fTriggerPattern=0; //initialize
 
-  for(UInt_t pixid=0;pixid<397;pixid++)
+  for(Int_t pixid=0;pixid<gsNTrigPixels;pixid++)
     {
       // Look if the pixel is fired, otherwise continue
       if (!fFiredPixel[pixid])
-	continue;
+		continue;
       
       const MGeomPix &pix=(*geom)[pixid];
@@ -824,13 +861,148 @@
       int j=1;
       for (int i=0;i<pix.GetNumNeighbors();i++)
-	if (fFiredPixel[pix.GetNeighbor(i)]==1) j++;
+		if (fFiredPixel[pix.GetNeighbor(i)]==1) j++;
 	     
       if (j > fTriggerPattern) 
-	fTriggerPattern=j;	 
+		fTriggerPattern=j;	 
 
       if (fTriggerPattern==7) 
-	  break;	 // the 7-NN (max) pattern was found: exit  
+	  	break;	 // the 7-NN (max) pattern was found: exit  
 
     } // next pixel
 }
 
+
+// --------------------------------------------------------------------------
+//  Look for the cell with higher number of Compact pixels
+//  Return the cell number (starting from 0)
+//
+Int_t MMcTriggerLvl2::CalcBiggerCellPseudoSize()
+{
+  Int_t fMaxCell=-1;
+
+  fCellPseudoSize=0;
+
+  for (Int_t i=0;i<gsNCells;i++)
+    {
+      int size = GetCellCompactPixel(i,fGeomCam);
+      if (size > fCellPseudoSize)
+        {
+          fCellPseudoSize = size;
+          fMaxCell = i;
+        }
+    }
+  
+  //*fLog << "fCellPseudoSize = " << fCellPseudoSize << " in cell N. " << fMaxCell+1 << endl;
+
+  return fMaxCell;
+}
+
+// --------------------------------------------------------------------------
+//  Compute the number of compact pixels in one cell
+//
+Int_t MMcTriggerLvl2::GetCellCompactPixel(int cell, MGeomCam *geom)
+{
+  int size=0;
+
+  // check on input variables
+
+  if (cell<0 || cell>gsNCells-1)
+    return(-2);
+
+  //*fLog << " CNN:" << fCompactNN;
+  //*fLog << "Cell: " << cell+1 << " Compat Pixels:"; 
+
+  for(Int_t id=0; id<gsNPixInCell; id++)
+    {
+      UInt_t pixid = gsPixelsInCell[id][cell]-1;
+ 
+      // Look if the pixel is fired, otherwise continue
+      if (!fFiredPixel[pixid])
+        continue;
+
+      //*fLog << "Fired pix:"<<pixid+1 << " ";
+
+      const MGeomPix &pix=(*geom)[pixid];
+      
+      // Reshuffle pixneighbour order, to arrange them (anti)clockwise 
+      //   around the current pixel (Bubble sorting)
+      // The NeighPixOrdered has one index more so that 
+      // the content in the first index is repeated in the last one
+      // to have a closed loop
+      Int_t NeighPixOrdered[2*pix.GetNumNeighbors()];
+      for (Int_t j=0; j<pix.GetNumNeighbors(); j++)
+        NeighPixOrdered[j] = pix.GetNeighbor(j);
+      
+      for (Int_t j=0; j<pix.GetNumNeighbors()-1; j++)
+        {
+          for (Int_t jk=pix.GetNumNeighbors()-1;jk>j;--jk)
+            {
+              UInt_t tmp = NeighPixOrdered[j+1];                  
+              const MGeomPix &pixneigh = (*geom)[NeighPixOrdered[j]];
+              for (int k=0; k<pix.GetNumNeighbors(); k++)
+                if (NeighPixOrdered[jk] == pixneigh.GetNeighbor(k))
+                  {
+                    NeighPixOrdered[j+1] = NeighPixOrdered[jk];
+                    NeighPixOrdered[jk] = tmp;
+                  }
+            }
+        }
+
+      // Duplicate second half of the array to take into account configurations
+      // containing tha last and first pixel
+      for (Int_t j=pix.GetNumNeighbors(); j<2*pix.GetNumNeighbors(); j++)
+        NeighPixOrdered[j] = NeighPixOrdered[j-pix.GetNumNeighbors()];
+
+      // Look for compact pixels. 
+
+      // A compact pixel must have at least fCompactNN adjacent neighbors
+      // It checks the 6 different configurations of neighbors pixels.
+      // The neighbour pixels must belong to the cell
+
+      //      *fLog << "cell:"<< cell << "   ordered pixels:";
+      /*
+      for (int i=0;i<2*pix.GetNumNeighbors();i++)
+	{
+	  if (fFiredPixel[NeighPixOrdered[i]])
+	    *fLog << NeighPixOrdered[i]+1 << "*;";
+	  else
+	    *fLog << NeighPixOrdered[i]+1 << ";";
+	}
+      */
+      //*fLog <<endl;
+      //*fLog << pixid <<"->"<< pix.GetNumNeighbors() << " CNN="<< fCompactNN <<endl;
+
+
+      for (int i=0;i<pix.GetNumNeighbors();i++)
+        { 
+          int j=0;
+          while ((i+j < 2*pix.GetNumNeighbors()) && (fFiredPixel[NeighPixOrdered[i+j]]==1) && (j < fCompactNN) && IsPixelInCell(NeighPixOrdered[i+j],cell) )
+            j++;  
+
+          if (j>=fCompactNN) //configuration satisfies the compact condition  
+	    {          
+	      size++; // pixel is compact
+	      //*fLog << "->" << pixid+1;
+	      break; // (new pixel)
+	    }
+	}
+    }
+  
+  //*fLog <<" - size:" << size << endl<<endl;
+  
+  return size;
+  
+}
+
+//---------------------------------------------------------------------
+//  Check if a given pixel belongs to a given cell
+//
+Bool_t MMcTriggerLvl2::IsPixelInCell(Int_t pixel, Int_t cell)
+{
+  for (int i=0; i<gsNPixInCell; i++)
+    if ((gsPixelsInCell[i][cell]-1) == pixel)
+      return kTRUE;
+  
+  return kFALSE;
+}
+
Index: trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2.h	(revision 2917)
+++ trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2.h	(revision 2918)
@@ -7,9 +7,6 @@
 
 class MMcTrig;
-
 class MMcEvt;
-
 class MGeomCamMagic;
-
 class MGeomCam;
 class MGeomPix;
@@ -17,77 +14,83 @@
 class MMcTriggerLvl2 : public MParContainer
 {
+ private:
+  
+  // Global trigger variables related to the geometry and trigger structures are here defined.  
+  // FIXME!  this is a temporary solution: these variables should be defined in a GeomTrg class    
 
- private:
+  static const Int_t fNumPixCell = 36; // Number of pixels in one cell
 
-  Int_t fPixels[36][19];  // Array with flag for triggered pixels. 1st idx:pixels in trigger cell; 2nd idx:trigger cell number  
+  static const Int_t gsNCells = 19;   
+  static const Int_t gsNTrigPixels = 397;   
+  static const Int_t gsNPixInCell = 36;  
+  static const Int_t gsNLutInCell = 3;  
+  static const Int_t gsNPixInLut = 12; 
+  Int_t fPixels[gsNPixInCell][gsNCells];  
+  
+  // Array with flag for triggered pixels. 1st idx:pixels in trigger cell; 2nd idx:trigger cell number      
 
-  Int_t fFiredPixel[397]; // Array with flag for triggered pixel. idx: pixel id
+  Int_t fFiredPixel[gsNTrigPixels]; // Array with flag for triggered pixel. idx: pixel id    
+  static const Int_t gsPixelsInCell[gsNPixInCell][gsNCells];   
+  static const Int_t gsPixelsInLut[gsNLutInCell][gsNPixInLut];     
 
-  static const Int_t gsPixelsInCell[36][19];
-  static const Int_t gsPixelsInLut[3][12];
+  Int_t fMaxCell;  // Cell with maximum number of fired pixels
 
-  Int_t fLutPseudoSize;  // number of compact pixels in one lut
-  Int_t fPseudoSize;  // Multiplicity of the cluster identified by the L2T 
-  Int_t fSizeBiggerCell; // Number of fired pixel in bigger cell
+  Int_t fLutPseudoSize;   // number of compact pixels in one lut   
+  Int_t fPseudoSize;   // Multiplicity of the cluster identified by the L2T    
+  Int_t fSizeBiggerCell; // Number of fired pixel in bigger cell    
+  Int_t fCompactNN;    //Number of NN pixels that define a compact pixel    
+  Int_t fCompactPixel[gsNTrigPixels]; //Array with flag for compact pixels    
+  Int_t fCluster_pix[gsNTrigPixels]; //Array with pixel in cluster   
+  Double_t fEnergy;  // Energy of the shower    
+  Int_t fTriggerPattern; // x-NN compact trigger pattern;    
+  Int_t fCellPseudoSize; // number of compact pixels in one cell    
+  //  Int_t fCellCompactPixels[fNumPixCell]; // Array with compact pixels in cell
 
-  Int_t fCompactNN;  //Number of NN pixels that define a compact pixel
-
-  Int_t fCompactPixel[397]; //Array with flag for compact pixels
-
-  Int_t fCluster_pix[397]; //Array with pixel in cluster
-
-  Double_t fEnergy;  // Energy of the shower
-
-  Int_t fTriggerPattern; // x-NN compact trigger pattern;
-
-  MMcTrig *fMcTrig;
-  MGeomCam *fGeomCam;  
-
-  Int_t CalcBiggerFiredCell();
-  Int_t CalcBiggerLutPseudoSize();
-  void CalcPseudoSize();
-   
-  void SetNewCamera(MGeomCam *geom) {fGeomCam = geom;}
-
- public: 
-
-  MMcTriggerLvl2(const char* name = NULL, const char* title = NULL);
-  ~MMcTriggerLvl2();  
-  
-
-  virtual void Calc();
-
-  virtual void Print(Option_t *opt="") const;
-
-  void SetLv1(MMcTrig *trig = NULL); 
-  void SetPixelFired(Int_t pixel, Int_t fired=1);
- 
-  void SetCompactNN(Int_t neighpix)     {fCompactNN=neighpix;}
-
-  Int_t GetPseudoSize() const     {return fPseudoSize;}
-  Int_t GetLutPseudoSize() const  {return fLutPseudoSize;}
-  Int_t GetSizeBiggerCell() const {return fSizeBiggerCell;}
-  Int_t GetCompactNN() const      {return fCompactNN;}
-
-  Int_t GetCellNumberFired(int cell);
-  Int_t GetLutCompactPixel(int cell, int lut);
+  MMcTrig *fMcTrig;   
+  MGeomCam *fGeomCam;      
 
   void CalcCompactPixels(MGeomCam *fCam);
+  void CalcTriggerPattern(MGeomCam *fCam);   
+  Int_t CalcBiggerFiredCell();   
+  Int_t CalcBiggerLutPseudoSize();   
+  void CalcPseudoSize();   
+  Int_t CalcCellPseudoSize();   
+  Int_t CalcBiggerCellPseudoSize();    
+  Int_t GetCellCompactPixel(int cell, MGeomCam *fCam);
 
-  void GetEnergy(MMcEvt *fMcEvt = NULL);
+  void SetNewCamera(MGeomCam *geom) {fGeomCam = geom;}   
 
-  Double_t GetEnergy() const    {return fEnergy;}
- 
-  void CalcTriggerPattern(MGeomCam *fCam);
-  Int_t GetTriggerPattern() const {return fTriggerPattern;}
+ public:     
 
+  MMcTriggerLvl2(const char* name = NULL, const char* title = NULL);   
+  ~MMcTriggerLvl2();      
 
-  ClassDef(MMcTriggerLvl2,0) // Container for 2nd Level Trigger selection parameters
-};
+  virtual void Calc();    
+  virtual void Print(Option_t *opt="") const;    
 
-#endif
+  void SetLv1(MMcTrig *trig = NULL);    
+  void SetPixelFired(Int_t pixel, Int_t fired=1);     
+  void SetCompactNN(Int_t neighpix)     {fCompactNN=neighpix;}    
 
+  Int_t GetPseudoSize() const     {return fPseudoSize;}   
+  Int_t GetLutPseudoSize() const  {return fLutPseudoSize;}   
+  Int_t GetSizeBiggerCell() const {return fSizeBiggerCell;}   
+  Int_t GetCompactNN() const      {return fCompactNN;}   
+  Int_t GetCellPseudoSize() const {return fCellPseudoSize;}
+  Int_t GetMaxCell() const        {return (fMaxCell+1);} // Returns
+                     // cell with maximum number of compact pixels
+  Int_t GetCellNumberFired(int cell);   
+  Int_t GetLutCompactPixel(int cell, int lut);   
+    
+  Int_t GetTriggerPattern() const {return fTriggerPattern;}    
 
+  void GetEnergy(MMcEvt *fMcEvt = NULL);    
+  Double_t GetEnergy() const    {return fEnergy;}     
 
+  Bool_t IsPixelInCell(Int_t pixel, Int_t cell);    
 
-
+  ClassDef(MMcTriggerLvl2,0) // Container for 2nd Level Trigger selection parameters 
+    };  
+    
+#endif      
+    
