Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 2703)
+++ trunk/MagicSoft/Mars/Changelog	(revision 2704)
@@ -4,4 +4,14 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2003/12/18: Thomas Bretz
+
+   * mfilter/MFSoftwareTrigger.[h,cc]:
+     - added - code taken from M[CT1]SelBasic
+
+   * mfilter/Makefile, mfilter/FilterLinkDef.h:
+     - added MFSoftwareTrigger
+
+
+
  2003/12/18: Abelardo Moralejo
 
@@ -13,4 +23,6 @@
        bigger to fit the data).
 
+
+
  2003/12/17: Abelardo Moralejo
 
@@ -22,4 +34,5 @@
    * mhist/MHCalibration*
      - many small changes, mostly cosmetic
+
 
 
@@ -64,4 +77,5 @@
    * mhist/MHCamera.[h,cc]:
      - implemented kVariance
+
 
 
Index: trunk/MagicSoft/Mars/Makefile
===================================================================
--- trunk/MagicSoft/Mars/Makefile	(revision 2703)
+++ trunk/MagicSoft/Mars/Makefile	(revision 2704)
@@ -50,4 +50,5 @@
           mraw \
           mcamera \
+          mpointing \
           mreport \
           mgui \
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 2703)
+++ trunk/MagicSoft/Mars/NEWS	(revision 2704)
@@ -18,4 +18,6 @@
 
    - added class to fill trainings and test matrices (MTFillMatrix)
+
+   - added a filter performing a software trigger (MFSoftwareTrigger)
 
 
Index: trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h	(revision 2703)
+++ trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h	(revision 2704)
@@ -25,4 +25,5 @@
 #pragma link C++ class MFSelStandard+;
 #pragma link C++ class MFSelFinal+;
+#pragma link C++ class MFSoftwareTrigger+;
 
 #pragma link C++ class MFEnergySlope+;
Index: trunk/MagicSoft/Mars/mfilter/MFSoftwareTrigger.cc
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFSoftwareTrigger.cc	(revision 2704)
+++ trunk/MagicSoft/Mars/mfilter/MFSoftwareTrigger.cc	(revision 2704)
@@ -0,0 +1,171 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Wolfgang Wittek, 04/2003 <mailto:wittek@mppmu.mpg.de>
+!   Author(s): Thomas Bretz, 04/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//  MFSoftwareTrigger
+//
+//  This is a class to evaluate a software trigger
+//
+//  to be called after the calibration (when the number of photons is
+//               available for all pixels)
+//
+// require 2 neighboring pixels (which are not in the outermost ring),
+//                       each having at least 'fNumMinPhotons' photons
+//
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MFSoftwareTrigger.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+
+#include "MGeomPix.h"
+#include "MGeomCam.h"
+
+#include "MCerPhotEvt.h"
+
+ClassImp(MFSoftwareTrigger);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MFSoftwareTrigger::MFSoftwareTrigger(const char *name, const char *title)
+    : fNumMinPhotons(0)
+{
+    fName  = name  ? name  : "MFSoftwareTrigger";
+    fTitle = title ? title : "Filter for software trigger";
+}
+
+// --------------------------------------------------------------------------
+//
+// Software trigger
+// 
+// require 2 neighboring pixels (which are not in the outermost ring), 
+//                       each having at least 'fNumMinPhotons' photons
+// 
+Bool_t MFSoftwareTrigger::SwTrigger() const
+{
+    const Int_t entries = fEvt->GetNumPixels();
+ 
+    for (Int_t i=0; i<entries; i++)
+    {
+        const MCerPhotPix &pix = (*fEvt)[i];
+        if (!pix.IsPixelUsed())
+            continue;
+
+        if (pix.GetNumPhotons()<fNumMinPhotons)
+            continue;
+
+        // this pixel is used and has the required no.of photons
+        // check whether this is also true for a neigboring pixel
+        MGeomPix &gpix = (*fCam)[pix.GetPixId()];
+        if (gpix.IsInOutermostRing())
+            continue;
+
+        const Int_t nneighbors = gpix.GetNumNeighbors();
+        for (Int_t n=0; n<nneighbors; n++)
+        {
+            const Int_t id = gpix.GetNeighbor(n);
+            if (!fEvt->IsPixelUsed(id))
+                continue;
+
+            if ((*fCam)[id].IsInOutermostRing())
+                continue;
+
+            const Double_t photons = fEvt->GetPixById(id)->GetNumPhotons();
+            if (photons >= fNumMinPhotons)
+                return kTRUE;
+        }
+    }
+    return kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Request pointer to MCerPhotEvt and MGeomCam from paremeter list
+//
+Int_t MFSoftwareTrigger::PreProcess(MParList *pList)
+{
+    fEvt = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
+    if (!fEvt)
+    {
+        *fLog << err << "MCerPhotEvt not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fCam = (MGeomCam*)pList->FindObject("MGeomCam");
+    if (!fCam)
+    {
+        *fLog << err << "MGeomCam not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    memset(fCut, 0, sizeof(fCut));
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Evaluate software trigger
+//
+Int_t MFSoftwareTrigger::Process()
+{
+    fResult = SwTrigger();
+
+    fCut[fResult ? 0 : 1]++;
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+//  Prints some statistics about the Basic selections.
+//
+Int_t MFSoftwareTrigger::PostProcess()
+{
+    if (GetNumExecutions()==0)
+        return kTRUE;
+
+    *fLog << inf << endl;
+    *fLog << GetDescriptor() << " execution statistics:" << endl;
+    *fLog << dec << setfill(' ');
+
+    *fLog << " " << setw(7) << fCut[1] << " (" << setw(3) ;
+    *fLog << (int)(fCut[1]*100/GetNumExecutions()) ;
+    *fLog << "%) Evts skipped due to: Software trigger not fullfilled" ;
+    *fLog << " (with fNumMinPhotons = " << fNumMinPhotons << ")" << endl;
+
+    *fLog << " " << fCut[0] << " (" << (int)(fCut[0]*100/GetNumExecutions()) ;
+    *fLog << "%) Evts survived software trigger!" << endl;
+    *fLog << endl;
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mfilter/MFSoftwareTrigger.h
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFSoftwareTrigger.h	(revision 2704)
+++ trunk/MagicSoft/Mars/mfilter/MFSoftwareTrigger.h	(revision 2704)
@@ -0,0 +1,40 @@
+#ifndef MARS_MFSoftwareTrigger
+#define MARS_MFSoftwareTrigger
+
+#ifndef MARS_MFilter
+#include "MFilter.h"
+#endif
+
+class MMcEvt;
+class MGeomCam;
+class MCerPhotEvt;
+
+class MFSoftwareTrigger : public MFilter
+{
+private:
+    const MGeomCam    *fCam; // Camera Geometry
+    const MCerPhotEvt *fEvt; // Cerenkov Photon Event
+
+    Float_t     fNumMinPhotons; // nuber of minimum required photons
+
+    Int_t       fCut[2];
+
+    Bool_t      fResult;
+
+    Int_t PreProcess(MParList *pList);
+    Int_t Process();
+    Int_t PostProcess();
+
+    Bool_t SwTrigger() const;
+
+    Bool_t IsExpressionTrue() const { return fResult; }
+
+public:
+    MFSoftwareTrigger(const char *name=NULL, const char *title=NULL);
+
+    void SetNumMinPhotons(Float_t minphotons) { fNumMinPhotons = minphotons; }
+
+    ClassDef(MFSoftwareTrigger, 0) // Filter for software trigger
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mfilter/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mfilter/Makefile	(revision 2703)
+++ trunk/MagicSoft/Mars/mfilter/Makefile	(revision 2704)
@@ -51,4 +51,5 @@
 	   MFSelStandard.cc \
 	   MFSelFinal.cc \
+           MFSoftwareTrigger.cc \
 	   MFEnergySlope.cc \
 	   MFRandomSplit.cc
