Index: /trunk/MagicSoft/Mars/macros/triglvl2.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/triglvl2.C	(revision 1776)
+++ /trunk/MagicSoft/Mars/macros/triglvl2.C	(revision 1777)
@@ -1,26 +1,8 @@
-
-Bool_t HandleInput()
-{
-    TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
-    while (1)
-    {
-        //
-        // While reading the input process gui events asynchronously
-        //
-        timer.TurnOn();
-        TString input = Getline("Type 'q' to exit, <return> to go on: ");
-        timer.TurnOff();
-
-        if (input=="q\n")
-            return kFALSE;
-
-        if (input=="\n")
-            return kTRUE;
-    };
-
-    return kFALSE;
-}
-
-void triglvl2(char *filename = "../../Mars-0.8/gamma_new.root")
+//   triglvl2.C
+//  Macro to use the class MMcTriggerLvl2, which calculates the 
+//   2nd level trigger (L2T) selection parameters.
+//  Filters to select events using these parameter are also created.
+//
+void triglvl2(char *filename = "Gamma.root")
 { 
     //
@@ -30,26 +12,68 @@
     MTaskList tasklist;
 
-    MTrigLvl2 cell;
-      
-    parlist.AddToList(&cell);
     parlist.AddToList(&tasklist);
 
+    // An instance of the class MMcTriggerLvl2 is created and added to the 
+    //  parameter list
+    MMcTriggerLvl2 cell;      
+    parlist.AddToList(&cell);
+
     //
-    // Setup out tasks:
+    //  A filter to select events using the L2T parameters is created
+    //
+    //    MF lvl2filter("MMcTriggerLvl2.fLutPseudoSize > 6");
+    MF lvl2filter("MMcTriggerLvl2.fSizeBiggerCell > 16");
+    // A second filter is created using the class MFTriggerLvl2
+    MFTriggerLvl2 fTrig1("MMcTriggerLvl2", '>', 6);
+    //       this is the value to be compared --^
+
+    //
+    // A selection on the number and energy of the events 
+    //
+    MF energyfilter("MMcEvt.fEnergy > 10");
+    MFEventSelector selector;
+    selector.SetNumSelectEvts(4000);
+
+    // 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(&fTrig1);
+
+    // 
+    // Setup our tasks:
     //  - First we have to read the events
     //  - Then we can fill the efficiency histograms
     //
     MReadMarsFile reader("Events", filename);
-    reader.EnableBranch("fEnergy");
-    reader.EnableBranch("fImpact"); reader.EnableBranch("fTimeFirst[4]");
-    reader.EnableBranch("fPixelsFirst[73][4]");
+    reader.DisableAutoScheme();
+     //  reader.EnableBranch("fEnergy");
+     //  reader.EnableBranch("fImpact"); reader.EnableBranch("fTimeFirst[4]");
+     //  reader.EnableBranch("fPixelsFirst[73][4]");
    
-   
-   
-    MTrigLvl2FillTask fill("MTrigLvl2FillTask","MTrigLvl2FillTask");  
-  
     tasklist.AddToList(&reader);
-      tasklist.AddToList(&fill);
 
+    //
+    // The task to calculate the L2T parameter is added to the task list
+    //
+    MMcTriggerLvl2Calc fill("MMcTriggerLvl2","MMcTriggerLvl2");  
+    tasklist.AddToList(&fill);
+
+    //
+    //  Task to calculate and plot the effective area
+    //
+    MMcCollectionAreaCalc effi;
+    tasklist.AddToList(&effi);
+    //
+    // The filter list selects events for the effective area calculation
+    //
+    effi.SetFilter(&flist);
+
+    //
+    // The filter list is added to the task list
+    //
+    tasklist.AddToList(&flist);
 
     //
@@ -65,34 +89,18 @@
     magic.SetProgressBar(&bar);
 
-
-   //  if (!magic.Eventloop())
-   //         return;
-
-
     if (!magic.PreProcess())
       return;
 
-
-
-    while (tasklist.Process())
-      {
-        cout << "Event #" << reader.GetEventNum() ":" << endl;
-
-	cell.DrawLv1();
-      
-	//if (!HandleInput())
-	 // break;
-    } 
-
-
-
-    magic.PostProcess();
+    if (!magic.Eventloop())
+      return;
 
     tasklist.PrintStatistics();
-
     //
     // Now the histogram we wanted to get out of the data is
     // filled and can be displayd
     //
-  // parlist.FindObject("MHMcCollectionArea")->DrawClone();
+    parlist.FindObject("MHMcCollectionArea")->DrawClone();
+
+    magic.PostProcess();
+
 }
Index: /trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 1776)
+++ /trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 1777)
@@ -52,6 +52,6 @@
 #pragma link C++ class MSelFinal+;
 
-#pragma link C++ class MTrigLvl2+;
-#pragma link C++ class MTrigLvl2FillTask+;
+#pragma link C++ class MMcTriggerLvl2+;
+#pragma link C++ class MMcTriggerLvl2Calc+;
 
 #endif
Index: unk/MagicSoft/Mars/manalysis/MTrigLvl2.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MTrigLvl2.cc	(revision 1776)
+++ 	(revision )
@@ -1,582 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Antonio Stamerra  1/2003 <mailto:antono.stamerra@pi.infn.it>
-!   Author(s): Marcos Lopez 1/2003 <mailto:marcos@gae.ucm.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2003
-!
-!
-\* ======================================================================== */
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MTrigLvl2                                                               //
-//   Storage container for the 2nd level trigger selection parameters      //
-//    as part of the 2nd level trigger simulation                          //
-//                                                                         //
-//   (preliminary version)                                                 //
-//                                                                         //
-// Basic L2T Selection Parameters:                                         //
-//                                                                         //
-//    LutPseudoSize       number of compact pixels in one LUT              //
-//                                                                         //
-/////////////////////////////////////////////////////////////////////////////
-
-#include "MTrigLvl2.h"
-
-#include "MGeomCamMagic.h"
-#include "MCamDisplay.h"
-
-#include "MMcTrig.hxx"
-
-#include <fstream.h>
-#include "MLog.h"
-
-#include <TCanvas.h>
-
-
-ClassImp(MTrigLvl2)
-
-
-//
-// Correspondence TABLE between pixel numbering in the trigger cells and
-// the standard spiral counting 
-// (Note: Pixels start to count from 1 instead of 0)
-//
-static const Int_t pixels_in_cell[36][19] = {
-{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},
-{24,  37,  22,  25,  28,  31,  34,  167,  132,  139,  146,  153,  160,  265,  220,  229,  238,  247,  256},
-{23,  19,   9,  11,  13,  15,  17,  125,   95,  101,  107,  113,  119,  211,  171,  179,  187,  195,  203},
-{27,  62,  67,  72,  77,  82,  87,  270,  225,  234,  243,  252,  261,  392,  337,  348,  359,  370,  381},
-{12,  38,  42,  46,  50,  54,  58,  216,  176,  184,  192,  200,  208,  326,  276,  286,  296,  306,  316},
-{11,  20,  23,  26,  29,  32,  35,  168,  133,  140,  147,  154,  161,  266,  221,  230,  239,  248,  257},
-{10,   8,  10,  12,  14,  16,  18,  126,   96,  102,  108,  114,  120,  212,  172,  180,  188,  196,  204},
-{22,   2,   3,   4,   5,   6,   7,   90,   65,   70,   75,   80,   85,  164,  129,  136,  143,  150,  157},
-{28,  93,  99, 105, 111, 117, 123,  271,  226,  235,  244,  253,  262,  393,  338,  349,  360,  371,  382},
-{13,  63,  68,  73,  78,  83,  88,  217,  177,  185,  193,  201,  209,  327,  277,  287,  297,  307,  317},
-{ 4,  39,  43,  47,  51,  55,  59,  169,  134,  141,  148,  155,  162,  267,  222,  231,  240,  249,  258},
-{ 3,  21,  24,  27,  30,  33,  36,  127,   97,  103,  109,  115,  121,  213,  173,  181,  189,  197,  205},
-{ 9,   9,  11,  13,  15,  17,  19,   91,   66,   71,   76,   81,   86,  165,  130,  137,  144,  151,  158},
-{21,   3,   4,   5,   6,   7,   2,   61,   41,   45,   49,   53,   57,  123,   93,   99,  105,  111,  117},
-{29, 130, 137, 144, 151, 158, 165,  218,  227,  236,  245,  254,  263,  394,  339,  350,  361,  372,  383},
-{14,  94, 100, 106, 112, 118, 124,  170,  178,  186,  194,  202,  210,  328,  278,  288,  298,  308,  318},
-{ 5,  64,  69,  74,  79,  84,  89,  128,  135,  142,  149,  156,  163,  268,  223,  232,  241,  250,  259},
-{ 1,  40,  44,  48,  52,  56,  60,   92,   98,  104,  110,  116,  122,  214,  174,  182,  190,  198,  206},
-{ 2,  22,  25,  28,  31,  34,  37,   62,   67,   72,   77,   82,   87,  166,  131,  138,  145,  152,  159},
-{ 8,  10,  12,  14,  16,  18,   8,   38,   42,   46,   50,   54,   58,  124,   94,  100,  106,  112,  118},
-{20,  11,  13,  15,  17,  19,   9,   20,   23,   26,   29,   32,   35,   88,   63,   68,   73,   78,   83},
-{30, 131, 138, 145, 152, 159, 166,  219,  228,  237,  246,  255,  264,  329,  279,  289,  299,  309,  319},
-{15,  95, 101, 107, 113, 119, 125,  171,  179,  187,  195,  203,  211,  269,  224,  233,  242,  251,  260},
-{ 6,  65,  70,  75,  80,  85,  90,  129,  136,  143,  150,  157,  164,  215,  175,  183,  191,  199,  207},
-{ 7,  41,  45,  49,  53,  57,  61,   93,   99,  105,  111,  117,  123,  167,  132,  139,  146,  153,  160},
-{19,  23,  26,  29,  32,  35,  20,   63,   68,   73,   78,   83,   88,  125,   95,  101,  107,  113,  119},
-{37,  24,  27,  30,  33,  36,  21,   39,   43,   47,   51,   55,   59,   89,   64,   69,   74,   79,   84},
-{31, 132, 139, 146, 153, 160, 167,  220,  229,  238,  247,  256,  265,  270,  225,  234,  243,  252,  261},
-{16,  96, 102, 108, 114, 120, 126,  172,  180,  188,  196,  204,  212,  216,  176,  184,  192,  200,  208},
-{17,  66,  71,  76,  81,  86,  91,  130,  137,  144,  151,  158,  165,  168,  133,  140,  147,  154,  161},
-{18,  42,  46,  50,  54,  58,  38,   94,  100,  106,  112,  118,  124,  126,   96,  102,  108,  114,  120},
-{36,  43,  47,  51,  55,  59,  39,   64,   69,   74,   79,   84,   89,   90,   65,   70,   75,   80,   85},
-{32, 133, 140, 147, 154, 161, 168,  221,  230,  239,  248,  257,  266,  217,  177,  185,  193,  201,  209},
-{33,  97, 103, 109, 115, 121, 127,  173,  181,  189,  197,  205,  213,  169,  134,  141,  148,  155,  162},
-{35,  68,  73,  78,  83,  88,  63,   95,  101,  107,  113,  119,  125,   91,   66,   71,   76,   81,   86}
- };
-
-//
-// corrispondence between pixels in cell and lut (pix numbering starts from 1)
-//
-static const Int_t pixels_in_lut[3][12] = {
-{ 1,  2,  3,  4,  6,  7,  8,  9, 12, 13, 14, 15},
-{34, 29, 23, 16, 30, 24, 17, 10, 25, 18, 11,  5},
-{35, 31, 26, 20, 19, 32, 27, 21, 36, 33, 28, 22},
-  };
-
-// --------------------------------------------------------------------------
-//
-//  Default constructor
-//
-MTrigLvl2::MTrigLvl2(const char *name, const char *title)
-{
-  fName = name ? name : ClassName();
-  fTitle = title;
-
-  *fLog << "created MTrigLvl2" << endl;
-
-  //
-  // Initialization of the fPixels array to zero
-  //
-  memset (fPixels,0,36*19);
-
-}
-
-// --------------------------------------------------------------------------
-//  
-//  Print functions for debugging and testing
-//
-//    
-// Print out the pixel number of a given trigger cell
-//
-// Print a table with the status (pixel is fired or not after Lvl1) for all
-// the pixels in all the trigger cells
-//
-void MTrigLvl2::Print(Int_t cell) const
-{
-  if (cell >-1) {
-    for (int i=0;i<36;i++)
-      {
-	*fLog << pixels_in_cell[i][cell]-1 << endl;
-      }
-  }
-  else {
-    for(int i=0; i<36; i++){
-      for(int j=0; j<9; j++){
-	//      *fLog.width(3);
-	*fLog << pixels_in_cell[i][j]-1 << ":" << fPixels[i][j]  << "\t ";
-      } 
-      *fLog << endl;
-    }
-  }
-}
-
-// --------------------------------------------------------------------------
-//
-// Take the information supplied by the Lvl1 (it reads from the object MMcTrig
-// i the status of all pixels after Lvl1) and pass it to the Lvl2 (fill the 
-// array fPixels)
-//
-//
-void MTrigLvl2::SetLv1(MMcTrig *trig)
-{
-  if (!trig)
-    return;
-
-  fMcTrig = trig;
-
-  //fMcTrig->PrintPixelsFirstLevel();
-
-  for(int i=0; i<36; i++){
-    for(int j=0; j<19; j++){
-      int pixel = pixels_in_cell[i][j]-1;
-      fPixels[i][j] = (fMcTrig->IsPixelFired(pixel,0)) ? 1 : 0;
-    }
-  }
-}
-
-
-// --------------------------------------------------------------------------
-//
-// Set the trigger status ( pixel fired(=1) or not(=0) ) manually for a given
-// pixel of a given cell
-//
-//
-void MTrigLvl2::SetPixelFired(Int_t pixel, Int_t fired)
-{
-  for(int i=0; i<36; i++){
-    for(int j=0; j<19; j++){
-	if(pixels_in_cell[i][j]-1==pixel) fPixels[i][j]=fired;
-    }
-  }
-}
-
-
-// --------------------------------------------------------------------------
-//
-//  Display the MAGIC Camera a draw the pixels corresponding to a given cell
-//  (preliminary)   <to be fixed>
-//
-void MTrigLvl2::DrawCell(Int_t cell)
-{
-
-  if(cell>18) return;
-
-  //
-  // Use MCamDisplay class variable for avoiding to create a MCamDisplay 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 MCamDisplay(fGeomcam);
-      fCam->Draw();
-      fCam->DrawPixelNumbers();
-    }
-
-  //fCam->Draw();
-  fCam->Reset();
-
-  int color=0;
-
-  for(int i=0; i<36; i++){
-    color = (fPixels[i][cell]) ? 5 : 3;
-    fCam->SetPix( pixels_in_cell[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 MTrigLvl2::DrawLv1()
-{
-  //
-  // Use MCamDisplay class variable for avoiding to create a MCamDisplay 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 MCamDisplay(fGeomcam);
-      fCam->Draw();  
-      fCam->DrawPixelNumbers();
-    }
-
-  //fCam->Draw(); 
-  //fCam->Reset();
-
-  //
-  // 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)) ? 5 : 3;
-      fCam->SetPix( i, color, 1, 5 );
-    }
-
-  //
-  // Update the display (paint the camera with the new colors)
-  //
-  gPad->Modified();
-  gPad->Update(); 
-
-}
-
-// --------------------------------------------------------------------------
-//  
-// For a given cell, just count how many pixels have been fired after Lvl1
-//
-Int_t MTrigLvl2::GetCellNumberFired(int cell)
-{
-  int size=0;
- 
-  for(int i=0; i<36; i++){
-    size += fPixels[i][cell];
-  }
-
-  return size;
-  
-}
-
-
-// --------------------------------------------------------------------------
-//  
-//  Find the cell which the bigger number of fired pixels
-// 
-//
-Int_t MTrigLvl2::GetBiggerFiredCell()
-{
-  int size=-1;
-  int cell=-1;
-
-  for(int j=0; j<19; j++){
-    if (GetCellNumberFired(j) > size) {
-      size = GetCellNumberFired(j);
-      cell = j;
-    }
-  }
-
-  *fLog << "size " <<size <<" in cell " << cell << endl;
-
-  return cell;
-  
-}
-
-// --------------------------------------------------------------------------
-//  
-// Calculate the LutPseudoSize of one event, defined as the higher number
-//   of compact pixel in the Luts of the trigger cells.
-//  neighpix is the number of Next-Neighbors which defines the compact pixel
-//    topology (it can be 2-NN or 3-NN)
-//
-//
-Int_t MTrigLvl2::GetLutPseudoSize(int neighpix)
-{
-  int size=0;
-  int cell=-1;
-  int lut=-1;
- 
-  if (neighpix >3 || neighpix < 2) return(0);
-
-  for(int j=0; j<19; j++){
-    for(int i=0; i<3; i++){
-      if (GetLutCompactPixel(j,i,neighpix) > size) {
-	size = GetLutCompactPixel(j,i,neighpix);
-	cell = j;
-	lut = i;
-      }      
-    }
-  }
-
-  *fLog <<"Max cell: " << cell+1 << "  Max Lut: " << lut+1 << "  PseudoSize: " << size <<endl;
-
-  fLutPseudoSize = size;
-
-  return fLutPseudoSize;
-}
-
-
-// --------------------------------------------------------------------------
-//  
-// Identify compact pixels in one LUT and calculate the LutPseudoSize 
-//   (=number of compact pixels in one LUT)
-//  neighpix is the number of Next-Neighbors which defines the compact pixel
-//    topology (it can be 2NN or 3NN)
-//
-Int_t MTrigLvl2::GetLutCompactPixel(int cell, int lut, int neighpix)
-{
-  int size=0;
-  int lutpix, a[12]; 
-
-  if (neighpix >3 || neighpix < 2) return(0);
-
-  // LUT 1 and 2 are similar; LUT 3 differs
-  
-  for(int j=0; j<12; j++){
-    lutpix = pixels_in_lut[lut][j]-1;
-    //    *fLog << "j=" <<j<<"  lutpix="<<lutpix<<"  Cell="<<cell<<endl;
-    a[j] = fPixels[lutpix][cell]; 
-  }
-
-  //
-  // Look for compact pixels 2NN
-  //
-  if (neighpix==2){
-    
-    //  case Lut 1 and 2
-    if (lut == 0 || lut == 1){
-      if (a[0] && a[1] && a[4])
-	size ++;
-      if (a[1] && ((a[0] && a[4]) || 
-		   (a[4] && a[5]) || 
-		   (a[5] && a[2]) )) 
-	size ++;
-      if (a[2] && ((a[1] && a[5]) || 
-		   (a[5] && a[6]) || 
-		   (a[6] && a[3]) )) 
-	size ++;
-      if (a[3] && ((a[2] && a[6]) || 
-		   (a[6] && a[7]) )) 
-	size ++;
-      if (a[4] && ((a[0] && a[1]) || 
-		   (a[1] && a[5]) || 
-		   (a[5] && a[8]) )) 
-	size ++;
-      if (a[5] && ((a[1] && a[2]) || 
-		   (a[2] && a[6]) || 
-		   (a[6] && a[9]) || 
-		   (a[9] && a[8]) || 
-		   (a[8] && a[4]) || 
-		   (a[4] && a[1]) )) 
-	size ++;
-      if (a[6] && ((a[2] && a[3]) || 
-		   (a[3] && a[7]) || 
-		   (a[7] && a[10]) || 
-		   (a[10] && a[9]) || 
-		   (a[9] && a[5]) || 
-		   (a[5] && a[2]) )) 
-	size ++;
-      if (a[7] && ((a[3] && a[6]) || 
-		   (a[6] && a[10]) || 
-		   (a[10] && a[11]) )) 
-	size ++;
-      if (a[8] && ((a[4] && a[5]) || 
-		   (a[5] && a[9]) )) 
-	size ++;
-      if (a[9] && ((a[8] && a[5]) || 
-		   (a[5] && a[6]) || 
-		   (a[6] && a[10]) )) 
-	size ++;
-      if (a[10] && ((a[9] && a[6]) || 
-		    (a[6] && a[7]) || 
-		    (a[7] && a[11]) )) 
-	size ++;
-      if (a[11] && a[7] && a[10]) 
-	size ++;
-    }
-
-  //  case Lut 3
-    if (lut==2) {
-      if (a[0] && a[1] && a[5])
-	size ++;
-      if (a[1] && ((a[0] && a[5]) || 
-		   (a[5] && a[2]) )) 
-	size ++;
-      if (a[2] && ((a[1] && a[5]) || 
-		   (a[5] && a[6]) || 
-		   (a[3] && a[4]) || 
-		   (a[6] && a[3]) )) 
-	size ++;
-      if (a[3] && ((a[2] && a[6]) || 
-		   (a[6] && a[7]) || 
-		   (a[2] && a[4]) )) 
-	size ++;
-      if (a[4] && ((a[2] && a[3]) )) 
-	size ++;
-      if (a[5] && ((a[1] && a[2]) || 
-		   (a[2] && a[6]) || 
-		   (a[6] && a[9]) || 
-		   (a[9] && a[8]) )) 
-	size ++;
-      if (a[6] && ((a[2] && a[3]) || 
-		   (a[3] && a[7]) || 
-		   (a[7] && a[10]) || 
-		   (a[10] && a[9]) || 
-		   (a[9] && a[5]) || 
-		   (a[5] && a[2]) )) 
-	size ++;
-      if (a[7] && ((a[3] && a[6]) || 
-		   (a[6] && a[10]) || 
-		   (a[10] && a[11]) )) 
-	size ++;
-      if (a[8] && a[5] && a[9]) 
-	size ++;
-      if (a[9] && ((a[8] && a[5]) || 
-		   (a[5] && a[6]) || 
-		   (a[6] && a[10]) )) 
-	size ++;
-      if (a[10] && ((a[9] && a[6]) || 
-		    (a[6] && a[7]) || 
-		    (a[7] && a[11]) )) 
-	size ++;
-      if (a[11] && a[7] && a[10]) 
-	size ++;    
-    }
-  }
-
-  //
-  // Look for compact pixels 3NN 
-  //
-  if (neighpix==3){
-
-    //  case Lut 1 and 2
-    if (lut == 0 || lut == 1){
-      if (a[0] && a[1] && a[4] && a[5]) // pix 0 is compact if there is a 4NN
-	size ++;
-      if (a[1] && ((a[0] && a[4] && a[5]) || 
-		   (a[2] && a[4] && a[5]) )) 
-	size ++;
-      if (a[2] && ((a[1] && a[5] && a[6]) || 
-		   (a[5] && a[6] && a[3]) )) 
-	size ++;
-      if (a[3] && (a[2] && a[6] && a[7] ))  
-	size ++;
-      if (a[4] && ((a[0] && a[1] && a[5]) || 
-		   (a[1] && a[5] && a[8]) )) 
-	size ++;
-      if (a[5] && ((a[1] && a[2] && a[6]) || 
-		   (a[2] && a[6] && a[9]) || 
-		   (a[6] && a[9] && a[8]) || 
-		   (a[9] && a[8] && a[4]) || 
-		   (a[8] && a[4] && a[1]) || 
-		   (a[4] && a[1] && a[2]) )) 
-	size ++;
-      if (a[6] && ((a[2] && a[3] && a[7]) || 
-		   (a[3] && a[7] && a[10]) || 
-		   (a[7] && a[10] && a[9]) || 
-		   (a[10] && a[9] && a[5]) || 
-		   (a[9] && a[5] && a[2]) || 
-		   (a[5] && a[2] && a[3]) )) 
-	size ++;
-      if (a[7] && ((a[3] && a[6] && a[10]) || 
-		   (a[6] && a[10] && a[11]) )) 
-	size ++;
-      if (a[8] && (a[4] && a[5] && a[9] )) 
-	size ++;
-      if (a[9] && ((a[8] && a[5] && a[6]) || 
-		   (a[5] && a[6] && a[10]) )) 
-	size ++;
-      if (a[10] && ((a[9] && a[6] && a[7]) || 
-		    (a[6] && a[7] && a[11]) )) 
-	size ++;
-      if (a[11] && a[7] && a[10] && a[6]) //pix 0 is compact if there is a 4NN
-	size ++;
-    }
-
-    //  case Lut 3
-    if (lut==2) {
-      if (a[0] && a[1] && a[5] && a[8]) // pix 0 is compact if there is a 4NN
-	size ++;
-      if (a[1] && (a[0] && a[5] && a[2])) //pix 0 is compact if there is a 4NN 
-	size ++;
-      if (a[2] && ((a[1] && a[5] && a[6]) || 
-		   (a[3] && a[5] && a[6]) || 
-		   (a[6] && a[3] && a[4]) )) 
-	size ++;
-      if (a[3] && ((a[2] && a[4] && a[6]) || 
-		   (a[2] && a[6] && a[7]) )) 
-	size ++;
-      if (a[4] && (a[2] && a[3] && a[6] )) 
-	size ++;
-      if (a[5] && ((a[1] && a[2] && a[6]) || 
-		   (a[2] && a[6] && a[9]) || 
-		   (a[6] && a[9] && a[8]) )) 
-	size ++;
-      if (a[6] && ((a[2] && a[3] && a[7]) || 
-		   (a[3] && a[7] && a[10]) || 
-		   (a[7] && a[10] && a[9]) || 
-		   (a[10] && a[9] && a[5]) || 
-		   (a[9] && a[5] && a[2]) || 
-		   (a[5] && a[2] && a[3]) )) 
-	size ++;
-      if (a[7] && ((a[3] && a[6] && a[10]) || 
-		   (a[6] && a[10] && a[11]) )) 
-	size ++;
-      if (a[8] && a[5] && a[9] && a[6])  //pix 0 is compact if there is a 4NN
-	size ++;
-      if (a[9] && ((a[8] && a[5] && a[6]) || 
-		   (a[5] && a[6] && a[10]) )) 
-	size ++;
-      if (a[10] && ((a[9] && a[6] && a[7]) || 
-		    (a[6] && a[7] && a[11]) )) 
-	size ++;
-      if (a[11] && a[7] && a[10] && a[6]) //pix 0 is compact if there is a 4NN
-	size ++;
-    }
-  }
-
-  
-  return size;
-}
-
-
Index: unk/MagicSoft/Mars/manalysis/MTrigLvl2.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MTrigLvl2.h	(revision 1776)
+++ 	(revision )
@@ -1,51 +1,0 @@
-#ifndef MARS_MTrigLvl2
-#define MARS_MTrigLvl2
-
-#ifndef MARS_MParContainer
-#include "MParContainer.h"
-#endif
-
-class MMcTrig;
-class MGeomCamMagic;
-class MCamDisplay;
-
-
-class MTrigLvl2 : public MParContainer
-{
-
- private:
-  Int_t fPixels[36][19];  // Array with the triggered pixels after Lvl1
-                          // First index:  pixels index in trigger cell       
-                          // Second index: trigger cell number  
-
-  Int_t fLutPseudoSize;  // number of compact pixels in one lut
-
-  MMcTrig *fMcTrig;
-  MGeomCamMagic *fGeomcam;  
-  MCamDisplay *fCam;
-
-   
- public: 
-  MTrigLvl2(const char* name = NULL, const char* title = NULL);
-  
-  
-  void DrawCell(Int_t cell);  
-  void DrawLv1();
-
-  void Print(Int_t cell=-1) const;
-
-  void SetLv1(MMcTrig *trig = NULL); 
-  void SetPixelFired(Int_t pixel, Int_t fired=1);
- 
-  Int_t GetCellNumberFired(int cell);
-  Int_t GetBiggerFiredCell();
-
-  Int_t GetLutCompactPixel(int cell, int lut, int neighpix=2);
-  Int_t GetLutPseudoSize(int neighpix=2);
-  
-  ClassDef(MTrigLvl2,0) // Container for 2nd Level Trigger selection parameters
-};
-
-#endif
-
-
Index: unk/MagicSoft/Mars/manalysis/MTrigLvl2FillTask.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MTrigLvl2FillTask.cc	(revision 1776)
+++ 	(revision )
@@ -1,144 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Antonio Stamerra  1/2003 <mailto:antono.stamerra@pi.infn.it>
-!   Author(s): Marcos Lopez 1/2003 <mailto:marcos@gae.ucm.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2003
-!
-!
-\* ======================================================================== */
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MTrigLvl2FillTask                                                       //
-//   This is a task to calculate the 2nd level trigger selection           //
-//   parameters                                                            //
-//                                                                         //
-//  Input containers:                                                      //
-//    MTrigLvl2                                                            //
-//                                                                         //
-/////////////////////////////////////////////////////////////////////////////
-
-#include "MTrigLvl2FillTask.h"
-#include "MTrigLvl2.h"
-
-
-#include "MParList.h"
-#include "MLog.h"
-#include "MLogManip.h"
-
-#include "MMcEvt.hxx"
-#include "MMcTrig.hxx"
-#include "MMcRunHeader.hxx"
-
-#include <TH1.h>
-
-ClassImp(MTrigLvl2FillTask);
-
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-//  Default constructor
-// 
-//
-MTrigLvl2FillTask::MTrigLvl2FillTask(const char *name, const char *title)
-{
-  fName  = name  ? name  : "MTrigLvl2FillTask";
-  fTitle = title ? title : "Task to Fill the MTrigLvl2 object";
-  
-  AddToBranchList("MMcEvt.fEnergy");
-  AddToBranchList("MMcEvt.fImpact"); 
-  AddToBranchList(Form("%s.fNumFirstLevel", "MMcTrig"));
-  AddToBranchList(Form("%s.fPixelsFirst[73][4]", "MMcTrig"));
-
-
-  h1 = new TH1F("h1","h1",30,0,30);
-} 
-
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         
-//  PreProcess
-//
-//
-Bool_t MTrigLvl2FillTask::PreProcess (MParList *pList)
-{
-    // connect the raw data with this task
-
-    fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
-    if (!fMcEvt)
-    {
-        *fLog << err << dbginf << "MMcEvt not found... exit." << endl;
-        return kFALSE;
-    }
-
-    fMcTrig = (MMcTrig*)pList->FindObject("MMcTrig");
-    if (!fMcTrig)
-    {
-        *fLog << err << dbginf << "MMcTrig not found... exit." << endl;
-        return kFALSE;
-    }
-
-    fMTrigLvl2 = (MTrigLvl2*)pList->FindObject("MTrigLvl2");
-    if (!fMTrigLvl2)
-    {
-        *fLog << err << dbginf << "MTrigLvl2 not found... exit." << endl;
-        return kFALSE;
-    }
-
-    return kTRUE;
-}
-
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         
-//  Process 
-// 
-//
-Bool_t MTrigLvl2FillTask::Process()
-{
-  //const Float_t energy = fMcEvt->GetEnergy();
-
-  fMTrigLvl2->SetLv1(fMcTrig);
-
-  //fMTrigLvl2->DrawLv1();
-  //fMTrigLvl2->DrawCell(fMTrigLvl2->GetBiggerFiredCell() );
-  //fMTrigLvl2->PrintStatus();
-
-  h1->Fill( fMTrigLvl2->GetCellNumberFired(fMTrigLvl2->GetBiggerFiredCell()) );
-
-
-  return kTRUE;
-}
-
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         
-//  PostProcess : Display the histogram 
-//           !to be fixed: create an histogram class!
-//
-Bool_t MTrigLvl2FillTask::PostProcess()
-{ 
-  
-    *fLog << inf << "Filling..." << endl;
- 
-    h1->Draw();
-      
-    return kTRUE;
-}
-
Index: unk/MagicSoft/Mars/manalysis/MTrigLvl2FillTask.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MTrigLvl2FillTask.h	(revision 1776)
+++ 	(revision )
@@ -1,41 +1,0 @@
-#ifndef MARS_MTrigLvl2FillTask
-#define MARS_MTrigLvl2FillTask
-
-#ifndef MARS_MTask
-#include "MTask.h"
-#endif
-
-class MParList;
-
-class MMcEvt;
-class MMcTrig;
-
-class MTrigLvl2;
-
-class TH1F;
-
-class MTrigLvl2FillTask : public MTask
-{
- private:
-  const MMcEvt  *fMcEvt;
-  MMcTrig *fMcTrig;
-
-  MTrigLvl2 *fMTrigLvl2;
-    
-  TH1F *h1;
-
- public:
-    MTrigLvl2FillTask(const char *name=NULL, const char *title=NULL);   
-
-    Bool_t PreProcess(MParList *pList);
-    Bool_t Process();
-    Bool_t PostProcess();
-
-    ClassDef(MTrigLvl2FillTask, 0) // Task to calculate the collection area histogram
-};
-
-#endif 
-
-
-
-
Index: /trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h	(revision 1776)
+++ /trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h	(revision 1777)
@@ -11,4 +11,5 @@
 #pragma link C++ class MFEventSelector+;
 #pragma link C++ class MFTriggerLvl1+;
+#pragma link C++ class MFTriggerLvl2+;
 #pragma link C++ class MFParticleId+;
 #pragma link C++ class MFDataChain+;
Index: /trunk/MagicSoft/Mars/mfilter/MFTriggerLvl2.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/MFTriggerLvl2.cc	(revision 1777)
+++ /trunk/MagicSoft/Mars/mfilter/MFTriggerLvl2.cc	(revision 1777)
@@ -0,0 +1,144 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Antonio Stamerra  02/2003 <mailto:antonio.stamerra@pi.infn.it>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!   Filter for L2Trigger. 02/2003
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+//   MFTriggerLvl2                                                         //
+//                                                                         //
+//  A Filter for the 2nd Level trigger, using the MMcTriggerLvl2 Class     //
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MFTriggerLvl2.h"
+
+#include <fstream.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+
+#include "MMcTriggerLvl2.h"
+
+ClassImp(MFTriggerLvl2);
+
+
+// --------------------------------------------------------------------------
+//
+// Default constructor
+//
+MFTriggerLvl2::MFTriggerLvl2(const char *cname, const char type, const Int_t val,
+                             const char *name, const char *title) : fcell(NULL)
+{
+    fContName = cname;
+    Init(type, val, name, title);
+}
+
+// --------------------------------------------------------------------------
+ //
+MFTriggerLvl2::MFTriggerLvl2(MMcTriggerLvl2 *triglvl2, const char type, const Int_t val,
+                             const char *name, const char *title) : fcell(triglvl2)
+{
+    Init(type, val, name, title);
+}
+
+// --------------------------------------------------------------------------
+//
+void MFTriggerLvl2::Init(const char type, const Int_t val,
+                         const char *name, const char *title)
+{
+    fName  = name  ? name  : "MFTriggerLvl2";
+    fTitle = title ? title : "Filter using 2nd level trigger selection";
+
+    fFilterType = (type=='<' ? kELowerThan : kEGreaterThan);
+
+    if (type!='<' && type!='>')
+        *fLog << warn << dbginf << "Warning: Neither '<' nor '>' specified... using '>'." << endl;
+
+    fValue = val;
+
+} 
+// --------------------------------------------------------------------------
+//
+Bool_t MFTriggerLvl2::IsExpressionTrue() const
+{
+    return fResult;
+}
+
+// --------------------------------------------------------------------------
+//
+Bool_t MFTriggerLvl2::PreProcess(MParList *pList)
+{
+    if (fcell)
+        return kTRUE;
+
+    fcell = (MMcTriggerLvl2*)pList->FindObject(fContName);
+    if (fcell)
+        return kTRUE;
+
+    *fLog << err << dbginf << fContName << " [MMcTriggerLvl2] not found... aborting." << endl;
+
+        return kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
+Bool_t MFTriggerLvl2::Process()
+{
+
+  //
+  //  The variable fLutPseudoSize of the class MMcTriggerLvl2 is used 
+  //   for the selection
+  //
+
+  const Int_t lvl2 = fcell->GetLutPseudoSize();
+
+    switch (fFilterType)
+    {
+    case kELowerThan:
+        fResult = (lvl2 < fValue);
+        break;
+    case kEGreaterThan:
+        fResult = (lvl2 > fValue);
+        break;
+    }
+
+    return kTRUE;
+}
+
+void MFTriggerLvl2::StreamPrimitive(ofstream &out) const
+{
+   if (fcell)
+        fcell->SavePrimitive(out);
+
+    out << "   MFTriggerLvl2 " << GetUniqueName() << "(";
+
+    if (fcell)
+        out << "&" << fcell->GetUniqueName();
+    else
+        out << "\"" << fContName << "\"";
+
+    out << ", '" << (fFilterType==kELowerThan?"<":">") << "', " << fValue << ");" << endl;
+
+}
Index: /trunk/MagicSoft/Mars/mfilter/MFTriggerLvl2.h
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/MFTriggerLvl2.h	(revision 1777)
+++ /trunk/MagicSoft/Mars/mfilter/MFTriggerLvl2.h	(revision 1777)
@@ -0,0 +1,54 @@
+#ifndef MARS_MFTriggerLvl2
+#define MARS_MFTriggerLvl2
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MFTriggerLvl2
+//
+// auth. A.stamerra 
+// created 30.01.03                                                       //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef MARS_MFilter
+#include "MFilter.h"
+#endif
+
+class MMcTrig;
+class MParList;
+class MMcTriggerLvl2;
+
+class MFTriggerLvl2 : public MFilter
+{
+private:
+
+    TString fContName;
+
+    MMcTriggerLvl2 *fcell;
+
+    typedef enum { kELowerThan, kEGreaterThan } FilterType_t;
+    FilterType_t fFilterType; 
+
+    Bool_t fResult;             //!
+    Int_t  fValue;
+
+    void Init(const char type, const Int_t val,
+              const char *name, const char *title);
+
+    void StreamPrimitive(ofstream &out) const;
+
+public:
+
+    MFTriggerLvl2(const char *cname="MMcTriggerLvl2", const char type='>', const Int_t val=0,
+                  const char *name=NULL, const char *title=NULL);
+    MFTriggerLvl2(MMcTriggerLvl2 *triglvl2, const char type='>', const Int_t val=0,
+                  const char *name=NULL, const char *title=NULL);
+
+    Bool_t IsExpressionTrue() const;
+    Bool_t PreProcess(MParList *pList);
+    Bool_t Process();
+
+    ClassDef(MFTriggerLvl2, 1) // A Filter for the Level 2 Trigger
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/mfilter/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/Makefile	(revision 1776)
+++ /trunk/MagicSoft/Mars/mfilter/Makefile	(revision 1777)
@@ -32,4 +32,5 @@
 
 SRCFILES = MFTriggerLvl1.cc \
+	   MFTriggerLvl2.cc \
 	   MF.cc \
            MFilterList.cc \
