Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 2364)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 2365)
@@ -1,4 +1,32 @@
                                                  -*-*- END OF LINE -*-*-
- 
+  2003/09/29: Nicola Galante & Antonio Stamerra
+
+   * mmc/MMcTrig.cxx:
+     - Fixed a bug in function IsPixelFired():  the binary shift, introduced 
+       by T.B. to replace "pow" for power of two, was wrong. 
+       The correct operator to be used is "<<" and not ">>"! 
+
+   * manalysis/MMcTriggerLvl2.[h,cc]:
+     - Added method "CalcEnergy(MMcEvt *)" used to get correlation between
+       energy and size.
+     - Removed graphical functions "Drawcell" and "DrawLvl1"
+     - Fixed bug in the pixcell setting (pixel numbering in the cell starts 
+       from 0 but gsPixelInLut starts from 1).   
+     - Fixed bug in the "check" variable.	
+
+   * manalysis/MMcTriggerCalc.[h,cc]:
+     - Added call to MMcTriggerLvl2::CalcEnergy() in Process() 
+     - Removed 'const' from fMcEvt declaration	
+
+   * mhistmc/MHMcTriggerLvl2.[h,cc]:
+     - Added method "Draw2DHist" (draw correlation between
+       energy and size)
+     - Fixed bug in "DrawClone" function (histogram normalization)
+
+   * macros/triglvl2.C:
+     - Fixed a bug in the task list order to apply correctly the filters
+     - Now it writes on disk a root file with some histograms
+
+
  2003/09/26: Robert Wagner
    * mfileio/MCT1ReadPreProc.cc
Index: /trunk/MagicSoft/Mars/macros/triglvl2.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/triglvl2.C	(revision 2364)
+++ /trunk/MagicSoft/Mars/macros/triglvl2.C	(revision 2365)
@@ -24,56 +24,4 @@
     parlist.AddToList(&tasklist);
 
-    MGeomCamMagic geocam;
-    parlist.AddToList(&geocam);
-
-    //    MHillas hillas;
-    // parlist.AddToList(&hillas);
-
-    // An instance of the class MMcTriggerLvl2 is created and added to the 
-    //  parameter list
-    MMcTriggerLvl2 cell;     
-    parlist.AddToList(&cell);
-
-    // Set the number of Next Neighbourhoods that define a compact pixel
-    //
-    cell.SetCompactNN(3);
-    //  USER:       --^
-
-    //
-    //  A filter to select events using the L2T parameters is created
-    //
-    MF lvl2filter("MMcTriggerLvl2.fLutPseudoSize > 8");
-
-    //
-    // A second filter is created using the class MFTriggerLvl2
-    //
-    MFTriggerLvl2 fTrig("MMcTriggerLvl2", '>', 8);
-    //      USER:       fValue to be compared --^
-
-    //
-    // A selection on the number and energy of the events 
-    //
-    MF energyfilter("MMcEvt.fEnergy > 100");
-    MFEventSelector selector;
-    //selector.SetNumSelectEvts(4000);
-
-
-    // Filter to select events according to a give slope
-    MFEnergySlope eslope;
-
-    eslope.SetMcMinEnergy(50.);
-    eslope.SetMcMaxEnergy(400.);
-    eslope.SetNewSlope(-3.91);
-
-    // A filter list is created; the filters created can be added to the list
-    //
-    MFilterList flist;
-    //   flist.AddToList(&energyfilter);
-    //   flist.AddToList(&lvl2filter);
-    //   flist.AddToList(&selector);
-    //   flist.AddToList(&eslope);
-       flist.AddToList(&fTrig);
-
-
     // 
     // Setup our tasks:
@@ -81,4 +29,6 @@
     //  - Then we can fill the efficiency histograms
     //
+    
+
     MReadMarsFile reader("Events", filename);
     reader.DisableAutoScheme();
@@ -89,4 +39,68 @@
     tasklist.AddToList(&reader);
 
+    MGeomCamMagic geocam;
+    parlist.AddToList(&geocam);
+
+    //    MHillas hillas;
+    // parlist.AddToList(&hillas);
+
+    // An instance of the class MMcTriggerLvl2 is created and added to the 
+    //  parameter list
+    MMcTriggerLvl2 cell;     
+    parlist.AddToList(&cell);
+
+    MMcEvt mevt;
+    parlist.AddToList(&mevt);
+
+    // Set the number of Next Neighbourhoods that define a compact pixel
+    //
+    cell.SetCompactNN(2);
+    //  USER:       --^
+
+    //
+    //  A filter to select events using the L2T parameters is created
+    //
+
+    // MF lvl2filter("MMcTriggerLvl2.fPseudoSize > 25 && MMcTriggerLvl2.fPseudoSize < 31");
+    MF lvl2filter("MMcTriggerLvl2.fPseudoSize > 15");
+ 
+    //
+    // A second filter is created using the class MFTriggerLvl2
+    //
+    MFTriggerLvl2 fTrig("MMcTriggerLvl2", '>', 8);
+    //      USER:       fValue to be compared --^
+
+    //
+    // A selection on the number and energy of the events 
+    //
+    MF energyfilter("MMcEvt.fEnergy > 100");
+    MFEventSelector selector;
+    //selector.SetNumSelectEvts(4000);
+
+
+    // Filter to select events according to a give slope
+    MFEnergySlope eslope;
+
+    eslope.SetMcMinEnergy(50.);
+    eslope.SetMcMaxEnergy(400.);
+    eslope.SetNewSlope(-.5);
+
+    // A filter list is created; the filters created can be added to the list
+    //
+    MFilterList flist;
+    //flist.AddToList(&energyfilter);
+    //flist.AddToList(&lvl2filter);
+    //   flist.AddToList(&selector);
+    //   flist.AddToList(&eslope);
+    //   flist.AddToList(&fTrig);
+
+
+    
+    //
+    // The task to calculate the L2T parameter is added to the task list
+    //
+    MMcTriggerLvl2Calc calcps("MMcTriggerLvl2","MMcTriggerLvl2");  
+    tasklist.AddToList(&calcps);
+
     //
     // The filter list is added to the task list
@@ -98,6 +112,5 @@
     //
     MMcCollectionAreaCalc effi;
-    tasklist.AddToList(&effi);
-
+    tasklist.AddToList(&effi);    
     //
     // The filter list selects events for the effective area calculation
@@ -105,9 +118,4 @@
     effi.SetFilter(&flist);
  
-    //
-    // The task to calculate the L2T parameter is added to the task list
-    //
-    MMcTriggerLvl2Calc fill("MMcTriggerLvl2","MMcTriggerLvl2");  
-    tasklist.AddToList(&fill);
 
     //
@@ -116,5 +124,11 @@
     MFillH hfill1("MHMcTriggerLvl2","MMcTriggerLvl2");
     tasklist.AddToList(&hfill1);
-
+    //hfill1.SetFilter(&flist);
+    //MFillH hfill2("MHMcTriggerLvl2", &mevt, &cell);
+    //tasklist.AddToList(&hfill2);
+    //hfill2.SetFilter(&flist);
+
+    
+    
     //
     // set up the loop for the processing
@@ -123,4 +137,5 @@
     magic.SetParList(&parlist);
 
+    
     //
     // Start to loop over all events
@@ -129,6 +144,29 @@
     magic.SetProgressBar(&bar);
 
+
     if (!magic.Eventloop())
       return;
+    /*
+    if (!magic.PreProcess())
+    return;
+    
+    while (tasklist.Process())
+      {
+	cout<< mevt.GetEnergy()<<endl;
+	
+	cell.Print();
+      }
+    */
+    //fMcEvt = (MMcEvt*)parlist->FindObject("MMcEvt");
+    //if (!fMcEvt)
+    //{
+    //cout << "MMcEvt not found... exit." << endl;
+    //*fLog << err << dbginf << "MMcEvt not found... exit." << endl;
+    //  return kFALSE;
+    //}
+    //   cout << "fMcEvt = " << fMcEvt << endl;
+
+    //parlist.FindObject("MHMcTriggerLvl2")->Fill((Double_t) fMcEvt->GetEnergy(), cell);
+
 
     tasklist.PrintStatistics();
@@ -140,10 +178,22 @@
     parlist.FindObject("MHMcCollectionArea")->DrawClone();
 
+    parlist.FindObject("MHMcTriggerLvl2")->DrawClone("sbc");
     parlist.FindObject("MHMcTriggerLvl2")->DrawClone("lps");
-    //     parlist.FindObject("MHMcTriggerLvl2")->DrawClone();
+    parlist.FindObject("MHMcTriggerLvl2")->DrawClone();
+    parlist.FindObject("MHMcTriggerLvl2")->DrawClone("energy");
 
     // Returns histogram of the class MHMcTriggerLvl2  
-    //   parlist.FindObject("MHMcTriggerLvl2")->GetHistByName("hfPseudoSize"));
-    
+
+    MHMcTriggerLvl2 *htrig = (MHMcTriggerLvl2 *)parlist.FindObject("MHMcTriggerLvl2");
+    TH1F *h1 = htrig->GetHistByName("fHistPseudoSize");
+    TH2D *h2 = htrig->GetHistPseudoSizeEnergy();
+
+    // h2->DrawClone();
+
+    hfile = new TFile("HistFileLUT.root", "RECREATE");
+    h1->Write();
+    h2->Write();
+    hfile->Close();
+
 }
 
Index: /trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2.cc	(revision 2364)
+++ /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 2364)
+++ /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 2364)
+++ /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 2364)
+++ /trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2Calc.h	(revision 2365)
@@ -20,5 +20,5 @@
  private:
 
-  const MMcEvt  *fMcEvt;
+  MMcEvt  *fMcEvt;
   MMcTrig *fMcTrig;
 
Index: /trunk/MagicSoft/Mars/mhistmc/MHMcTriggerLvl2.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhistmc/MHMcTriggerLvl2.cc	(revision 2364)
+++ /trunk/MagicSoft/Mars/mhistmc/MHMcTriggerLvl2.cc	(revision 2365)
@@ -33,6 +33,7 @@
 #include "MHMcTriggerLvl2.h"
 
-#include <math.h>
-
+#include <TMath.h>
+
+#include <TH2.h>
 #include <TH1.h>
 #include <TF1.h>
@@ -48,27 +49,6 @@
 
 #include "MMcTriggerLvl2.h"
-#include "MGeomCam.h"
-#include "MBinning.h"
 
 using namespace std;
-
-/*
- Please, DON'T USE IFDEFS IN SUCH A CONTEXT, Thomas.
- --------------------------------------------------
-#ifndef COLOR_LINELPS
-#define COLOR_LINELPS Int_t colorlps = 1
-COLOR_LINELPS;
-#endif
-
-#ifndef COLOR_LINESBC
-#define COLOR_LINESBC Int_t colorsbc = 1
-COLOR_LINESBC;
-#endif
-
-#ifndef COLOR_LINEPS
-#define COLOR_LINEPS Int_t colorps = 1
-COLOR_LINEPS;
-#endif
-*/
 
 /* Use this insteadif you want to have some value which is the same for all
@@ -80,4 +60,5 @@
 Int_t MHMcTriggerLvl2::fColorSbc = 1;
 Int_t MHMcTriggerLvl2::fColorPs = 1;
+Int_t MHMcTriggerLvl2::fColorPsE = 1;
 
 ClassImp(MHMcTriggerLvl2);
@@ -95,11 +76,11 @@
     fTitle = title ? title : "Trigger L2 image parameters";
 
-    fHistLutPseudoSize  = new TH1F("fHistLutPseudoSize",  "number of compact pixels in one lut",                13,   0, 12);
-    fHistPseudoSize     = new TH1F("fHistPseudoSize",   "Multiplicity of the cluster identified by the L2T",    41,   0, 40);
-    fHistSizeBiggerCell  = new TH1F("fHistSizeBiggerCell",   "Number of fired pixel in bigger cell",            37,   0, 36);
-
-    fHistLutPseudoSizeNorm  = new TH1F("fHistLutPseudoSizeNorm",  "Normalized Number of compact pixels in one lut",                13,   0, 12);
-    fHistPseudoSizeNorm     = new TH1F("fHistPseudoSizeNorm",   "Normalized Multiplicity of the cluster identified by the L2T",    41,   0, 40);
-    fHistSizeBiggerCellNorm  = new TH1F("fHistSizeBiggerCellNorm",   "Normalized Number of fired pixel in bigger cell",            37,   0, 36);
+    fHistLutPseudoSize  = new TH1F("fHistLutPseudoSize",  "number of compact pixels in one lut",                12,   0, 12);
+    fHistPseudoSize     = new TH1F("fHistPseudoSize",   "Multiplicity of the cluster identified by the L2T",    397,   0, 397);
+    fHistSizeBiggerCell  = new TH1F("fHistSizeBiggerCell",   "Number of fired pixel in bigger cell",            36,   0, 36);
+
+    fHistLutPseudoSizeNorm  = new TH1F("fHistLutPseudoSizeNorm",  "Normalized Number of compact pixels in one lut",                12,   0, 12);
+    fHistPseudoSizeNorm     = new TH1F("fHistPseudoSizeNorm",   "Normalized Multiplicity of the cluster identified by the L2T",    397,   0, 397);
+    fHistSizeBiggerCellNorm  = new TH1F("fHistSizeBiggerCellNorm",   "Normalized Number of fired pixel in bigger cell",            36,   0, 36);
 
     fHistLutPseudoSize->SetDirectory(NULL);
@@ -124,5 +105,12 @@
     fHistSizeBiggerCellNorm->SetYTitle("Counts/Total Counts");
 
-    fFNorm = new TF1("FNorm", "1", -1, 40);
+    fHistPseudoSizeEnergy = new TH2D("fHistPseudoSizeEnergy","Ps Size vs Energy", 40, 1, 5, 397, 0,397);
+ 
+    fHistPseudoSizeEnergy->SetName("fHistPseudoSizeEnergy");
+    fHistPseudoSizeEnergy->SetTitle("PseudoSize vs. Energy");
+    fHistPseudoSizeEnergy->SetXTitle("Log(E[GeV])");
+    fHistPseudoSizeEnergy->SetYTitle("PseudoSize");
+
+    fFNorm = new TF1("FNorm", "1", -1, 397);
 }
 
@@ -139,7 +127,9 @@
     delete fHistPseudoSizeNorm;
     delete fHistSizeBiggerCellNorm;
+    delete fHistPseudoSizeEnergy;
 
     delete fFNorm;
 }
+
 
 // --------------------------------------------------------------------------
@@ -155,7 +145,11 @@
   fHistPseudoSize->Fill(h.GetPseudoSize());
   fHistSizeBiggerCell->Fill(h.GetSizeBiggerCell());
+  //fHistPseudoSizeEnergy->Fill(TMath::Log10(h.GetEnergy()), h.GetPseudoSize());
+  fHistPseudoSizeEnergy->Fill(TMath::Log10(h.GetEnergy()), h.GetLutPseudoSize());
 
   return kTRUE;
 }
+
+
 
 
@@ -186,4 +180,29 @@
     histNorm.SetLineColor(col);
     histNorm.DrawCopy(same?"same":"");
+
+    return c;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// This is the private function member which draw a clone of a 2D-histogram. 
+// This method is called by the DrawClone method.
+//
+TObject *MHMcTriggerLvl2::Draw2DHist(TH1 &hist, const TString &canvasname, Int_t &col) const
+{
+    col++;
+
+    TCanvas *c = (TCanvas*)gROOT->FindObject(canvasname);
+
+    Bool_t same = kTRUE;
+    if (!c)
+    {
+        c = MakeDefCanvas(canvasname,canvasname, 800, 600);
+        same = kFALSE;
+    }
+
+    hist.SetLineColor(col);
+    hist.DrawCopy(same?"same":"");
 
     return c;
@@ -213,5 +232,6 @@
     if (!str.Contains("lps", TString::kIgnoreCase) &&
         !str.Contains("sbc", TString::kIgnoreCase) &&
-        !str.Contains("ps",  TString::kIgnoreCase))
+        !str.Contains("ps",  TString::kIgnoreCase) &&
+        !str.Contains("energy",  TString::kIgnoreCase))
     {
         *fLog << "ARGH!@! Possible options are \"lps\", \"sbc\", \"ps\" or NULL!" <<endl;
@@ -219,17 +239,21 @@
     }
 
-    TH1 *hist=NormalizeHist(fHistLutPseudoSizeNorm, fHistLutPseudoSize);
-
-    if (!hist)
-        return NULL;
-
-    if (str.Contains("lps",TString::kIgnoreCase))
-        return DrawHist(*fHistLutPseudoSize, *hist, "CanvasLPS", fColorLps);
-
-    if (str.Contains("sbc",TString::kIgnoreCase))
-        return DrawHist(*fHistSizeBiggerCell, *hist, "CanvasSBC", fColorSbc);
-
-    if (str.Contains("ps",TString::kIgnoreCase))
-        return DrawHist(*fHistPseudoSize, *hist, "CanvasPS", fColorPs);
+    if (str.Contains("lps",TString::kIgnoreCase)){
+      TH1 *hist=NormalizeHist(fHistLutPseudoSizeNorm, fHistLutPseudoSize);
+      return DrawHist(*fHistLutPseudoSize, *hist, "CanvasLPS", fColorLps);
+    }
+
+    if (str.Contains("sbc",TString::kIgnoreCase)){
+      TH1 *hist=NormalizeHist(fHistSizeBiggerCellNorm, fHistSizeBiggerCell);
+      return DrawHist(*fHistSizeBiggerCell, *hist, "CanvasSBC", fColorSbc);
+    }
+
+    if (str.Contains("ps",TString::kIgnoreCase)){
+      TH1 *hist=NormalizeHist(fHistPseudoSizeNorm, fHistPseudoSize);
+      return DrawHist(*fHistPseudoSize, *hist, "CanvasPS", fColorPs);
+    }
+
+    if (str.Contains("energy",TString::kIgnoreCase))
+      return Draw2DHist(*fHistPseudoSizeEnergy, "CanvasPSE", fColorPsE);
 
     return NULL;
Index: /trunk/MagicSoft/Mars/mhistmc/MHMcTriggerLvl2.h
===================================================================
--- /trunk/MagicSoft/Mars/mhistmc/MHMcTriggerLvl2.h	(revision 2364)
+++ /trunk/MagicSoft/Mars/mhistmc/MHMcTriggerLvl2.h	(revision 2365)
@@ -6,4 +6,5 @@
 #endif
 
+class TH2D;
 class TH1F;
 class TF1;
@@ -20,5 +21,5 @@
     TH1F *fHistSizeBiggerCell;       // Histogram of fSizeBiggerCell
     TH1F *fHistSizeBiggerCellNorm;   // Histogram of fSizeBiggerCell normalized on integral of distribution
-
+    TH2D *fHistPseudoSizeEnergy;           // 2D-Histogram of fPseudoSize vs. Energy
     TF1* fFNorm;                     // Function used to normalize histograms
 
@@ -26,6 +27,8 @@
     static Int_t fColorSbc;
     static Int_t fColorPs;
+    static Int_t fColorPsE;
 
     TObject *DrawHist(TH1 &hist, TH1 &histNorm, const TString &canvasname, Int_t &colore) const;
+    TObject *Draw2DHist(TH1 &hist, const TString &canvasname, Int_t &col) const;
     
 public:
@@ -34,5 +37,5 @@
 
     Bool_t Fill(const MParContainer *par, const Stat_t w=1);
-
+    //    Bool_t Fill(const Double_t energy, const MParContainer *par, const Stat_t w=1);
     TH1 *GetHistByName(const TString name);
 
@@ -43,4 +46,5 @@
     TH1F *GetHistSizeBiggerCell()  const { return fHistSizeBiggerCell; }
     TH1F *GetHistSizeBiggerCellNorm()  const { return fHistSizeBiggerCellNorm; }
+    TH2D *GetHistPseudoSizeEnergy() const { return fHistPseudoSizeEnergy; }
 
     void Draw(Option_t *opt=NULL);
Index: /trunk/MagicSoft/include-Classes/MMcFormat/MMcTrig.cxx
===================================================================
--- /trunk/MagicSoft/include-Classes/MMcFormat/MMcTrig.cxx	(revision 2364)
+++ /trunk/MagicSoft/include-Classes/MMcFormat/MMcTrig.cxx	(revision 2365)
@@ -1,5 +1,5 @@
 #include "MMcTrig.hxx"
 
-#include <iostream>
+#include <iostream.h>
 
 
@@ -123,8 +123,18 @@
   //  first level trigger happened, 0 if not.
   //
-
+  
   const Int_t  body=npix/8;
-  const Byte_t reminder= 1>>(npix%8);
+  const Byte_t reminder= 1<<(npix%8);
 
   return reminder&fPixelsFirst[body][nfirstlevel];
+  /*
+  Byte_t ret=0;
+  Byte_t reminder;
+  Int_t body;
+
+  body=npix/8;
+  reminder=(Byte_t)(pow(2,npix%8));
+  ret=reminder&fPixelsFirst[body][nfirstlevel];
+  return(ret);
+  */
 }
