Index: /trunk/MagicSoft/Mars/manalysis/MMultiDimDistCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MMultiDimDistCalc.cc	(revision 1587)
+++ /trunk/MagicSoft/Mars/manalysis/MMultiDimDistCalc.cc	(revision 1588)
@@ -34,6 +34,8 @@
 //  constructor.
 //
-//  * If you want to use the kernel function to calculate the distance use:
-//      MMultiDimDistCalc::SetUseKernelMethod();
+//  * If you want to use the nearest neighbor function for calculation use:
+//      MMultiDimDistCalc::SetUseKernelMethod(kFALSE);
+//  * If you want to use the kernel function for calculation use:
+//      MMultiDimDistCalc::SetUseKernelMethod(kTRUE); <default>
 //  * To use only the n next neighbors for your calculation use:
 //      MMultiDimDistCalc::SetUseNumRows(n);
@@ -66,5 +68,5 @@
 //
 MMultiDimDistCalc::MMultiDimDistCalc(const char *name, const char *title)
-    : fNum(0), fUseKernel(kFALSE), fData(NULL)
+    : fNum(0), fUseKernel(kTRUE), fData(NULL)
 {
     //
Index: /trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h	(revision 1587)
+++ /trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h	(revision 1588)
@@ -9,4 +9,5 @@
 #pragma link C++ class MF+;
 #pragma link C++ class MFAlpha+;
+#pragma link C++ class MFEventSelector+;
 #pragma link C++ class MFTriggerLvl1+;
 #pragma link C++ class MFParticleId+;
Index: /trunk/MagicSoft/Mars/mfilter/MF.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/MF.cc	(revision 1587)
+++ /trunk/MagicSoft/Mars/mfilter/MF.cc	(revision 1588)
@@ -87,6 +87,6 @@
 ClassImp(MF);
 
-static const TString gsDefName  = "MF";
-static const TString gsDefTitle = "Filter setup by a text-rule";
+const TString MF::gsDefName  = "MF";
+const TString MF::gsDefTitle = "Filter setup by a text-rule";
 
 // --------------------------------------------------------------------------
Index: /trunk/MagicSoft/Mars/mfilter/MF.h
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/MF.h	(revision 1587)
+++ /trunk/MagicSoft/Mars/mfilter/MF.h	(revision 1588)
@@ -18,4 +18,7 @@
 {
 private:
+    static const TString gsDefName;  //!
+    static const TString gsDefTitle; //!
+
     MFilter *fFilter; // Filter
 
Index: /trunk/MagicSoft/Mars/mfilter/MFEventSelector.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/MFEventSelector.cc	(revision 1588)
+++ /trunk/MagicSoft/Mars/mfilter/MFEventSelector.cc	(revision 1588)
@@ -0,0 +1,191 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Thomas Bretz  01/2002 <mailto:tbretz@uni-sw.gwdg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MFEventSelector
+//
+// This is a filter to make a selection of events from a file. At the
+// present implementation you can only use a random selection.
+//
+// If you want to fill only 50% of your events into a histogram please use:
+//   MFEventSelector sel;
+//   sel.SetSelectionRatio(0.5);
+//   MFillH filler(...);
+//   filler.SetFilter(&sel);
+//   tlist.AddToList(&sel);
+//   tlist.AddToList(&filler);
+//
+// To get around 2000 events from all events use (Remark: This will only
+// work if the parlist has an entry called MTaskList which has a task
+// MRTeadTree inheriting from MReadTree):
+//   MFEventSelector sel;
+//   sel.SetNumSelectEvents(2000);
+//   MFillH filler(...);
+//   filler.SetFilter(&sel);
+//   tlist.AddToList(&sel);
+//   tlist.AddToList(&filler);
+//
+// If you don't have MReadTree available you have to set the number of
+// total events manually, using sel.SetNumTotalEvts(10732);
+//
+// The random number is generated using gRandom->Uniform(). You may
+// control this procedure using the global object gRandom.
+//
+// Because of the random numbers this works best for huge samples...
+//
+// Don't try to use this filter for the reading task: This won't work!
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MFEventSelector.h"
+
+#include <TRandom.h>
+
+#include "MParList.h"
+#include "MTaskList.h"
+#include "MReadTree.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MFEventSelector);
+
+static const TString gsDefName  = "MFEventSelector";
+static const TString gsDefTitle = "Filter to select events";
+
+// --------------------------------------------------------------------------
+//
+// Default Constructor. Don't use.
+//
+/*
+MFEventSelector::MFEventSelector()
+    : fNumTotalEvts(-1), fNumSelectEvts(-1), fSelRatio(-1), fNumSelectedEvts(0)
+{
+    fName  = gsDefName.Data();
+    fTitle = gsDefTitle.Data();
+}
+*/
+// --------------------------------------------------------------------------
+//
+// Constructor. For the text describing the filter rule please see
+// the class description above.
+//
+MFEventSelector::MFEventSelector(const char *name, const char *title)
+: fNumTotalEvts(-1), fNumSelectEvts(-1), fSelRatio(-1), fNumSelectedEvts(0)
+{
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+}
+
+// --------------------------------------------------------------------------
+//
+// Destructor. Delete filters.
+//
+MFEventSelector::~MFEventSelector()
+{
+}
+
+// --------------------------------------------------------------------------
+//
+// PreProcess all filters.
+//
+Bool_t MFEventSelector::PreProcess(MParList *plist)
+{
+    fNumSelectedEvts = 0;
+    if (fSelRatio>0)
+        return kTRUE;
+
+    if (fNumTotalEvts<0)
+    {
+        MTaskList *tlist = (MTaskList*)plist->FindObject("MTaskList");
+        if (!tlist)
+        {
+            *fLog << err << dbginf << "Sorry can't determin total number of events... no MTaskList." << endl;
+            return kFALSE;
+        }
+        MReadTree *read = (MReadTree*)tlist->FindObject("MReadTree");
+        if (!read)
+            read = (MReadTree*)tlist->FindObject("MReadMarsFile");
+        if (!read)
+        {
+            *fLog << err << dbginf << "Sorry can't determin total number of events from 'MReadTree/MReadMarsFile'." << endl;
+            return kFALSE;
+        }
+        fNumTotalEvts = read->GetEntries();
+    }
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Process all filters.
+//
+Bool_t MFEventSelector::Process()
+{
+    Float_t evt = gRandom->Uniform();
+
+    if (fNumSelectEvts>0)
+        fResult = evt*fNumTotalEvts < fNumSelectEvts;
+    else
+        fResult = evt < fSelRatio;
+
+    if (fResult)
+        fNumSelectedEvts++;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+//  Postprocess all filters.
+//
+Bool_t MFEventSelector::PostProcess()
+{
+    return kTRUE;
+}
+
+void MFEventSelector::StreamPrimitive(ofstream &out) const
+{
+    /*
+    out << "   MF " << GetUniqueName();
+
+    if (!fFilter)
+    {
+        out << ";" << endl;
+        return;
+    }
+
+    out << "(\"" << fFilter->GetRule() << "\"";
+        if (fName!=gsDefName || fTitle!=gsDefTitle)
+    {
+        out << "(\"" << fName << "\"";
+        if (fTitle!=gsDefTitle)
+            out << ", \"" << fTitle << "\"";
+    }
+    out << ");" << endl;
+    */
+
+}
+
Index: /trunk/MagicSoft/Mars/mfilter/MFEventSelector.h
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/MFEventSelector.h	(revision 1588)
+++ /trunk/MagicSoft/Mars/mfilter/MFEventSelector.h	(revision 1588)
@@ -0,0 +1,55 @@
+#ifndef MARS_MFEventSelector
+#define MARS_MFEventSelector
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MFEventSelector                                                         //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef MARS_MFilter
+#include "MFilter.h"
+#endif
+
+class MParList;
+
+class MFEventSelector : public MFilter
+{
+private:
+    Int_t   fNumTotalEvts;
+    Int_t   fNumSelectEvts;
+    Float_t fSelRatio;
+
+    Int_t   fNumSelectedEvts; //!
+
+    Bool_t  fResult;
+
+    void StreamPrimitive(ofstream &out) const;
+
+    /*
+     enum { kUseFixedRatio=BIT(14) }
+     */
+
+public:
+    // MFEventSelector();
+    MFEventSelector(const char *name=NULL, const char *title=NULL);
+    ~MFEventSelector();
+
+    Bool_t IsExpressionTrue() const { return fResult; }
+
+    void SetNumTotalEvts(Int_t n) { fNumTotalEvts = n; }
+    void SetNumSelectEvts(Int_t n) { fNumSelectEvts = n; }
+    void SetSelectionRatio(Float_t f) { fSelRatio = f; }
+
+    /*
+     void SetUseFixedRatio(Bool_t b=kTRUE) { b ? SetBit(kUseFixedRatio) : ResetBit(kUseFixedRatio); }
+     */
+
+    Bool_t PreProcess(MParList *pList);
+    Bool_t Process();
+    Bool_t PostProcess();
+
+    ClassDef(MFEventSelector, 0) // A Filter to select events from files
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/mfilter/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/Makefile	(revision 1587)
+++ /trunk/MagicSoft/Mars/mfilter/Makefile	(revision 1588)
@@ -20,5 +20,5 @@
 # @endcode 
 
-INCLUDES = -I. -I../mbase -I../mmc -I../manalysis -I../mdata
+INCLUDES = -I. -I../mbase -I../mmc -I../manalysis -I../mdata -I../mfileio
 
 # @code 
@@ -34,4 +34,5 @@
 	   MF.cc \
            MFilterList.cc \
+           MFEventSelector.cc \
 	   MFDataMember.cc \
 	   MFParticleId.cc \
