Index: trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2.cc	(revision 2360)
+++ trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2.cc	(revision 2365)
@@ -18,4 +18,5 @@
 !   Author(s): Antonio Stamerra  1/2003 <mailto:antono.stamerra@pi.infn.it>
 !   Author(s): Marcos Lopez 1/2003 <mailto:marcos@gae.ucm.es>
+!   Author(s): Nicola Galante 7/2003 <mailto:nicola.galante@pi.infn.it>
 !
 !   Copyright: MAGIC Software Development, 2000-2003
@@ -48,7 +49,8 @@
 #include "MGeomPix.h"
 #include "MGeomCamMagic.h"
-#include "MHCamera.h"
 
 #include "MMcTrig.hxx"
+
+#include "MMcEvt.hxx"
 
 #include "MLog.h"
@@ -144,5 +146,4 @@
 MMcTriggerLvl2::~MMcTriggerLvl2()
 {
-  delete fCam;
   delete fGeomCam;
 }
@@ -218,6 +219,4 @@
   fMcTrig = trig;
 
-  //fMcTrig->PrintPixelsFirstLevel();
-  
   for(int i=0; i<36; i++)
     {
@@ -227,6 +226,9 @@
 	  fPixels[i][j] = (fMcTrig->IsPixelFired(pixel,0)) ? 1 : 0;
 	  fFiredPixel[pixel]=(fMcTrig->IsPixelFired(pixel,0)) ? 1 : 0;
-	}
-    }
+	  //if (fFiredPixel[pixel]==1)
+	  //*fLog << pixel<<",";
+	}
+    }
+  //*fLog<<endl<<"Fine evento"<<endl;
 }
 
@@ -269,94 +271,8 @@
   fSizeBiggerCell = GetCellNumberFired(CalcBiggerFiredCell());
 
-}
-
-
-// --------------------------------------------------------------------------
-//
-//  Display the MAGIC Camera a draw the pixels corresponding to a given cell
-//  (preliminary)   <to be fixed>
-//
-void MMcTriggerLvl2::DrawCell(Int_t cell)
-{
-
-  if(cell>18) return;
-
-  //
-  // Use MHCamera class variable for avoiding to create a MHCamera each 
-  // time this function is called. Also, now all the hexagons are drawn in 
-  // the same camera pad
-  //
-  if (!fGeomCam)
-    fGeomCam = new MGeomCamMagic;  
-  if (!fCam)
-    {
-      fCam = new MHCamera(*fGeomCam);
-      fCam->Draw();
-      fCam->DrawPixelIndices();
-    }
-
-  //fCam->Draw();
-  fCam->Reset();
-
-  int color=0;
-
-  for(int i=0; i<36; i++)
-    {
-      color = (fPixels[i][cell]) ? 5 : 3;
-      fCam->SetPix( gsPixelsInCell[i][cell]-1, color, 1, 5 );
-    }
-  
-  //
-  // Update the display (paint the camera with the new colors)
-  //
-  gPad->Modified();
-  gPad->Update(); 
-}
-
-
-
-// --------------------------------------------------------------------------
-//
-//  Display the MAGIC camera and draw all the pixel fired after Lvl1
-//  (preliminary)   <to be fixed>
-// 
-//
-void MMcTriggerLvl2::DrawLv1()
-{
-  //
-  // Use MHCamera class variable for avoiding to create a MHCamera each 
-  // time this function is called. Also, now all the hexagons are drawn in 
-  // the same camera pad
-  //
-  //  !FixMe! Delete this method when the trigger display is available!
-  //
-  if (!fGeomCam)
-    fGeomCam = new MGeomCamMagic;  
-  if (!fCam)
-    {
-      fCam = new MHCamera(*fGeomCam);
-      fCam->Draw();  
-      fCam->DrawPixelIndices();
-    }
-
-  //
-  // Set the array of colors for each pixel (that will be painted after 
-  // updating the dispaly)
-  //
-  int color=0;
-
-  for(int i=0; i<577; i++)
-    {
-      color = (fMcTrig->IsPixelFired(i,0)) ? 1 : 2;
-      fCam->SetPix( i, color, 1, 5 );
-    }
-
-  //
-  // Update the display (paint the camera with the new colors)
-  //
-  gPad->Modified();
-  gPad->Update(); 
-
-}
+  //*fLog << "fLPS="<<fLutPseudoSize<<endl;
+}
+
+
 
 // --------------------------------------------------------------------------
@@ -432,5 +348,5 @@
     }
   
-  //  *fLog <<"Max cell: " << cell+1 << "  Max Lut: " << lut+1 << "  PseudoSize: " << size <<endl;
+  //*fLog <<"Max cell: " << cell+1 << "  Max Lut: " << lut+1 << "  PseudoSize: " << size <<endl;
     
   return cell*10+lut;
@@ -708,4 +624,6 @@
   int maxlut = cellut - maxcell*10;
   int startpix;
+  //if (GetLutCompactPixel(maxcell,maxlut)==0)
+    //*fLog << "Max lut size:" << GetLutCompactPixel(maxcell,maxlut) <<endl;
 
   // 
@@ -715,7 +633,7 @@
   for (int pixlut=0;pixlut<12;pixlut++)
     {
-      int pixcell =gsPixelsInLut[maxlut][pixlut];
+      int pixcell =gsPixelsInLut[maxlut][pixlut]-1;
       startpix = gsPixelsInCell[pixcell][maxcell]-1;
-      *fLog << "pix, compact:" << startpix << "@"<<fCompactPixel[startpix];
+      //*fLog << "pix, compact:" << startpix << "@"<<fCompactPixel[startpix];
       if (fCompactPixel[startpix]) // a starting pixel was found
 	break;
@@ -723,9 +641,26 @@
     }
 
+  //*fLog << "check = " << check << endl;
   // A LUT contains 12 pixels
-  if (check >= 12)
-    {
-    *fLog <<"Error: a starting pixels was not found!"<<endl;
-    return;
+  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 <<"Error: a starting pixels was not found! - PseudoSize = "<< fPseudoSize << endl;
+	  fPseudoSize=0;
+	  return;
+	}
     }
   //
@@ -755,5 +690,6 @@
 	  int pix_neigh = pix.GetNeighbor(i);
 	  // check if pixel is fired and doesn't belong to cluster
-	  if (fFiredPixel[pix_neigh] && !cluster[pix_neigh])
+	  if (fCompactPixel[pix_neigh] && !cluster[pix_neigh])
+	  //if (fCompactPixel[pix_neigh])
 	    {
 	      cluster[pix_neigh] = 1;
@@ -765,8 +701,10 @@
 
   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:" << maxcell << " lut:" <<maxlut <<endl;
 
   return;
@@ -786,5 +724,5 @@
 {
   memset (fCompactPixel,0,397*sizeof(Int_t));
-  
+  //  *fLog << endl << "NEW Event!";
   for(UInt_t pixid=0;pixid<397;pixid++)
     {
@@ -798,8 +736,9 @@
       // A compact pixel must have at least fCompactNN adjacent neighbors
       // It checks the 6 different configurations of neighbors pixels
+      int j=0;
       for (int i=0;i<pix.GetNumNeighbors();i++)
 	{ 
-	  int j=0;
-	  while (fFiredPixel[pix.GetNeighbor(i+j)]==1 && j < fCompactNN)
+	  //*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  
@@ -807,5 +746,5 @@
 	  fCompactPixel[pixid]=1; // pixel is compact
 
-	  *fLog << ","<<pixid;
+	  //	  *fLog << ","<<pixid;
 
 	  break;
@@ -816,2 +755,10 @@
 
 
+void MMcTriggerLvl2::CalcEnergy(MMcEvt *fMcEvt)
+{
+  const MMcEvt &h = *(MMcEvt *)fMcEvt;
+  fEnergy = h.GetEnergy();
+}
+
+
+
Index: trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2.h	(revision 2360)
+++ trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2.h	(revision 2365)
@@ -8,5 +8,6 @@
 class MMcTrig;
 
-class MHCamera;
+class MMcEvt;
+
 class MGeomCamMagic;
 
@@ -36,8 +37,9 @@
   Int_t fCluster_pix[397]; //Array with pixel in cluster
 
+  Double_t fEnergy;  // Energy of the shower
+
+
   MMcTrig *fMcTrig;
   MGeomCam *fGeomCam;  
-  MHCamera *fCam;
-  //  MCluster *fClust;
 
   Int_t CalcBiggerFiredCell();
@@ -52,6 +54,4 @@
   ~MMcTriggerLvl2();  
   
-  void DrawCell(Int_t cell);  
-  void DrawLv1();
 
   virtual void Calc();
@@ -74,4 +74,8 @@
   void CalcCompactPixels(MGeomCam *fCam);
 
+  void CalcEnergy(MMcEvt *fMcEvt = NULL);
+
+  Double_t GetEnergy() const    {return fEnergy;}
+
 
   ClassDef(MMcTriggerLvl2,0) // Container for 2nd Level Trigger selection parameters
Index: trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2Calc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2Calc.cc	(revision 2360)
+++ trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2Calc.cc	(revision 2365)
@@ -132,5 +132,5 @@
 Int_t MMcTriggerLvl2Calc::Process()
 {
-  //const Float_t energy = fMcEvt->GetEnergy();
+  fMMcTriggerLvl2->CalcEnergy(fMcEvt);
 
   fMMcTriggerLvl2->SetLv1(fMcTrig);
@@ -139,8 +139,4 @@
 
   fMMcTriggerLvl2->Calc();
-
-  //fMMcTriggerLvl2->DrawLv1();
-  //fMMcTriggerLvl2->DrawCell(fMMcTriggerLvl2->GetBiggerFiredCell() );
-  //fMMcTriggerLvl2->Print();
 
   return kTRUE;
Index: trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2Calc.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2Calc.h	(revision 2360)
+++ trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2Calc.h	(revision 2365)
@@ -20,5 +20,5 @@
  private:
 
-  const MMcEvt  *fMcEvt;
+  MMcEvt  *fMcEvt;
   MMcTrig *fMcTrig;
 
