Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 3329)
+++ trunk/MagicSoft/Mars/Changelog	(revision 3330)
@@ -14,4 +14,6 @@
          MF filter2("{MMcEvt;1.fEvtNumber%2}>0");
 
+
+
  2004/02/26: Thomas Bretz
 
@@ -50,4 +52,27 @@
    * Makefile:
      - added mastro
+     - added msql
+     - added mfbase
+
+   * mtemp/MObservatory.[h,cc], mtemp/MObservatoryLocation.[h,cc]:
+     - removed
+
+   * merpp.cc:
+     - added Sql support
+     
+   * mraw/MRawFileRead.h:
+     - added GetFileName
+
+   * msql/Makefile, msql/SqlLinkDef.h, msql/SqlIncl.h, 
+     MSQLServer.[h,cc], MSqlInsertRun.[h,cc]:
+     - added
+
+   * mfilter/MF.[h,cc], mfilter/MFDataChain.[h,cc], 
+     mfilter/MFDataMember.[h,cc], mfilter/MFEventSelector.[h,cc],
+     mfilter/MFEventSelector2.[h,cc], mfilter/MFRealTimePeriod.[h,cc]:
+       - moved to mfbase
+
+   * mfbase/Makefile, mfbase/FBaseLinkDef.h, mfbase/FBaseIncl.h:
+     - added
 
 
Index: trunk/MagicSoft/Mars/Makefile
===================================================================
--- trunk/MagicSoft/Mars/Makefile	(revision 3329)
+++ trunk/MagicSoft/Mars/Makefile	(revision 3330)
@@ -39,4 +39,5 @@
 	  mastro \
 	  mmain \
+          mfbase \
           mfilter \
           mdata \
Index: trunk/MagicSoft/Mars/mfbase/FBaseIncl.h
===================================================================
--- trunk/MagicSoft/Mars/mfbase/FBaseIncl.h	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/FBaseIncl.h	(revision 3330)
@@ -0,0 +1,3 @@
+#ifndef __CINT__
+
+#endif // __CINT__
Index: trunk/MagicSoft/Mars/mfbase/FBaseLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mfbase/FBaseLinkDef.h	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/FBaseLinkDef.h	(revision 3330)
@@ -0,0 +1,16 @@
+#ifdef __CINT__
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class MFilterList+;
+
+#pragma link C++ class MF+;
+#pragma link C++ class MFEventSelector+;
+#pragma link C++ class MFEventSelector2+;
+#pragma link C++ class MFDataChain+;
+#pragma link C++ class MFDataMember+;
+#pragma link C++ class MFRealTimePeriod+;
+
+#endif
Index: trunk/MagicSoft/Mars/mfbase/MF.cc
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MF.cc	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/MF.cc	(revision 3330)
@@ -0,0 +1,484 @@
+/* ======================================================================== *\
+!
+! *
+! * 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
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MF                                                              
+//
+// With this filter you can filter in all variables from Mars parameter
+// containers.
+//
+// In the constructor you can give the filter rule, like
+//   "MHillas.fLength < 15"
+// Where MHillas is the name of the parameter container in the parameter
+// list and fLength is the name of the data member which should be used
+// for the filter rule. If the name of the container is use specified
+// (MyHillas) the name to give would be:
+//   "MyHillas.fLength < 15"
+//
+// Also more difficult rules are allowed, like:
+//   "MHillas.fWidth<0.5 && MHillas.fLength<0.6"
+//
+// You can also use brackets:
+//   "MHillas.fSize>200 || (MHillas.fWidth<0.5 && MHillas.fLength<0.6)"
+//
+// If you want to use mathematic expressions (as defined in MDataChain)
+// you must encapsulate it in {}-Brackets, eg:
+//   "{log10(MHillas.fSize)}>3"
+//
+// The allowed logigal conditionals are:
+//   &&: logical and
+//   ||: logical or
+//   ^:  exclusive or
+//
+// As conditional signs, for now, only:
+//   <, >
+// are allowed.
+//
+//   -------->  '==' is NOT supported!
+//
+//
+// Warning: There is no priority rule build in. So better use brackets
+//   to get correct results. The rule is parsed/evaluated from the left
+//   to the right, which means:
+//
+//   "MHillas.fSize>200 || MHillas.fWidth<0.5 && MHillas.fLength<0.6"
+//
+//    is parses as
+//
+//   "(MHillas.fSize>200 || MHillas.fWidth<0.5) && MHillas.fLength<0.6"
+//
+//
+//  If you intend to use Data Chains in filters enclose the chains in
+//  this {}-parenthesis, eg.
+//
+//   "{MHillas.fSize*MHillas.fWidth}<0.5"
+//
+// FIXME: The possibility to use also complete filters is missing.
+//        Maybe we can use gInterpreter->Calc("") for this.
+//        gROOT->ProcessLineFast("line");
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MF.h"
+
+#include <ctype.h>        // isalnum, ...
+#include <stdlib.h>       // strtod, ...
+#include <fstream>        // ofstream, ...
+
+#include <TMethodCall.h>
+
+#include "MParList.h"
+
+#include "MFilterList.h"
+#include "MFDataChain.h"
+#include "MFDataMember.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MF);
+
+using namespace std;
+
+const TString MF::gsDefName  = "MF";
+const TString MF::gsDefTitle = "Filter setup by a text-rule";
+
+// --------------------------------------------------------------------------
+//
+// Default Constructor. Don't use.
+//
+MF::MF() : fF(NULL)
+{
+    fName  = gsDefName.Data();
+    fTitle = gsDefTitle.Data();
+}
+
+// --------------------------------------------------------------------------
+//
+// Constructor. For the text describing the filter rule please see
+// the class description above.
+//
+MF::MF(const char *text, const char *name, const char *title)
+{
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+
+    *fLog << inf << "Trying to resolve filter rule..." << endl;
+    if (!(fF=ParseString(text, 1)))
+    {
+        *fLog << err << dbginf << "Parsing '" << text << "' failed." << endl;
+        return;
+    }
+
+    *fLog << inf << endl;
+    *fLog << "Using Filter rule " << fF->GetName();
+    *fLog << " for " << fName << ":" << endl;
+    fF->Print();
+    *fLog << endl << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// Destructor. Delete filters.
+//
+MF::~MF()
+{
+    if (fF)
+        delete fF;
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the number of alphanumeric characters (including '.')
+// in the given string
+//
+Int_t MF::IsAlNum(TString txt) const
+{
+    int l = txt.Length();
+    for (int i = 0; i<l; i++)
+        if (!isalnum(txt[i]) && txt[i]!='.' && txt[i]!=';')
+            return i;
+
+    return l;
+}
+
+MFilter *MF::ParseRule(TString &txt, MFilter *filter0, Int_t level) const
+{
+    TString text;
+
+    Bool_t isrule = kFALSE;
+
+    if (txt[0]=='{')
+    {
+        //
+        // Search for the corresponding bracket
+        //
+        Int_t first=1;
+        for (int cnt=0; first<txt.Length(); first++)
+        {
+            if (txt[first]=='{')
+                cnt++;
+            if (txt[first]=='}')
+                cnt--;
+
+            if (cnt==-1)
+                break;
+        }
+
+        if (first==txt.Length())
+        {
+            *fLog << err << dbginf << "Syntax Error: '}' missing." << endl;
+            return NULL;
+        }
+
+        //
+        // Make a copy of the 'interieur' and delete the substringä
+        // including the brackets
+        //
+        TString sub = txt(1, first-1);
+        txt.Remove(0, first+1);
+
+        text=sub;
+        isrule = kTRUE;
+    }
+    else
+    {
+        int i = IsAlNum(txt);
+
+        if (i==0)
+        {
+            *fLog << err << dbginf << "Syntax Error: Name of data member missing in '" << txt << "'" << endl;
+            return NULL;
+        }
+
+        text = txt(0, i);
+
+        txt.Remove(0, i);
+    }
+
+    txt = txt.Strip(TString::kBoth);
+
+    if (txt.IsNull())
+    {
+        *fLog << err << dbginf << "Syntax Error: No conditional in '" << text << "'" << endl;
+        return NULL;
+    }
+
+    char c;
+    switch (txt[0])
+    {
+    case '>':
+    case '<':
+        c = txt[0];
+        txt.Remove(0, 1);
+        break;
+
+    default:
+        *fLog << err << dbginf << "Syntax Error: Conditional '" << txt[0] << "' unknown." << endl;
+        return NULL;
+    }
+
+    char *end;
+    Double_t num = strtod(txt.Data(), &end);
+    if (!end || txt.Data()==end)
+    {
+        *fLog << err << dbginf << "Error trying to convert '" << txt << "' to value." << endl;
+        return NULL;
+    }
+
+    txt.Remove(0, end-txt.Data());
+
+    MFilter *newfilter;
+    if (isrule)
+    {
+        Int_t lvl = gLog.GetDebugLevel();
+        gLog.SetDebugLevel(1);
+        newfilter = new MFDataChain(text.Data(), c, num);
+        newfilter->SetName(Form("Chain%02d%c%f", level, c, num));
+        gLog.SetDebugLevel(lvl);
+    }
+    else
+    {
+        newfilter = new MFDataMember(text.Data(), c, num);
+        newfilter->SetName(Form("%s%c%f", text.Data(), c, num));
+    }
+
+    return newfilter;
+}
+// --------------------------------------------------------------------------
+//
+// Parse a text string. Returns a corresponding filter of filter list.
+//
+MFilter *MF::ParseString(TString txt, Int_t level)
+{
+    MFilter *filter0=NULL;
+
+    TString type;
+    int nlist = 0;
+
+    while (!txt.IsNull())
+    {
+        MFilter *newfilter = NULL;
+
+        txt = txt.Strip(TString::kBoth);
+
+        //*fLog << all << setw(level) << " " << "Text: " << level << " '" << txt << "'" << endl;
+
+        switch (txt[0])
+        {
+        case '(':
+            {
+                //
+                // Search for the corresponding bracket
+                //
+                Int_t first=1;
+                for (int cnt=0; first<txt.Length(); first++)
+                {
+                    if (txt[first]=='(')
+                        cnt++;
+                    if (txt[first]==')')
+                        cnt--;
+
+                    if (cnt==-1)
+                        break;
+                }
+
+                if (first==txt.Length())
+                {
+                    *fLog << err << dbginf << "Syntax Error: ')' missing." << endl;
+                    if (filter0)
+                        delete filter0;
+                    return NULL;
+                }
+
+                //
+                // Make a copy of the 'interieur' and delete the substringä
+                // including the brackets
+                //
+                TString sub = txt(1, first-1);
+                txt.Remove(0, first+1);
+
+                //
+                // Parse the substring
+                //
+                newfilter = ParseString(sub, level+1);
+                if (!newfilter)
+                {
+                    *fLog << err << dbginf << "Parsing '" << sub << "' failed." << endl;
+                    if (filter0)
+                        delete filter0;
+                    return NULL;
+                }
+            }
+            break;
+
+        case ')':
+            *fLog << err << dbginf << "Syntax Error: Too many ')'" << endl;
+            if (filter0)
+                delete filter0;
+            return NULL;
+
+
+        case '&':
+        case '|':
+        case '^':
+            if (filter0)
+            {
+                //
+                // Check for the type of the conditional
+                //
+                TString is = txt[0];
+                txt.Remove(0, 1);
+
+                if (is==txt[0] && is!='^')
+                {
+                    is += txt[0];
+                    txt.Remove(0, 1);
+                }
+
+                //
+                // If no filter is available or the available filter
+                // is of a different conditional we have to create a new
+                // filter list with the new conditional
+                //
+                if (!filter0->InheritsFrom(MFilterList::Class()) || type!=is)
+                {
+                    MFilterList *list = new MFilterList(is);
+                    list->SetName(Form("List_%s_%d", (const char*)is, 10*level+nlist++));
+
+                    list->SetOwner();
+                    list->AddToList(filter0);
+                    filter0 = list;
+
+                    type = is;
+                }
+                continue;
+            }
+
+            *fLog << err << dbginf << "Syntax Error: First argument of condition missing." << endl;
+            if (filter0)
+                delete filter0;
+            return NULL;
+
+        default:
+            newfilter = ParseRule(txt, filter0, level++);
+            if (!newfilter)
+            {
+                if (filter0)
+                    delete filter0;
+                return NULL;
+            }
+        }
+
+        if (!filter0)
+        {
+            filter0 = newfilter;
+            continue;
+        }
+
+        if (!filter0->InheritsFrom(MFilterList::Class()))
+            continue;
+
+        ((MFilterList*)filter0)->AddToList(newfilter);
+    }
+
+    return filter0;
+}
+
+// --------------------------------------------------------------------------
+//
+// PreProcess all filters.
+//
+Int_t MF::PreProcess(MParList *plist)
+{
+    if (!fF)
+    {
+        *fLog << err << dbginf << "No filter rule available." << endl;
+        return kFALSE;
+    }
+
+    if (!fF->CallPreProcess(plist))
+    {
+        *fLog << err << dbginf << "PreProcessing filters in ";
+        *fLog << fName << " failed." << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Process all filters.
+//
+Int_t MF::Process()
+{
+    return fF->CallProcess();
+}
+
+// --------------------------------------------------------------------------
+//
+//  Postprocess all filters.
+//
+Int_t MF::PostProcess()
+{
+    return fF->CallPostProcess();
+}
+
+// --------------------------------------------------------------------------
+//
+// Return the result of the filter rule.
+//
+Bool_t MF::IsExpressionTrue() const
+{
+    return fF->IsConditionTrue();
+}
+
+void MF::StreamPrimitive(ofstream &out) const
+{
+    out << "   MF " << GetUniqueName();
+
+    if (!fF)
+    {
+        out << ";" << endl;
+        return;
+    }
+
+    out << "(\"" << fF->GetRule() << "\"";
+        if (fName!=gsDefName || fTitle!=gsDefTitle)
+    {
+        out << "(\"" << fName << "\"";
+        if (fTitle!=gsDefTitle)
+            out << ", \"" << fTitle << "\"";
+    }
+    out << ");" << endl;
+
+}
+
+void MF::Print(Option_t *opt) const
+{
+    *fLog << all << underline << GetDescriptor() << endl;
+    fF->Print();
+    *fLog << endl << endl;
+}
Index: trunk/MagicSoft/Mars/mfbase/MF.h
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MF.h	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/MF.h	(revision 3330)
@@ -0,0 +1,48 @@
+#ifndef MARS_MF
+#define MARS_MF
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MF                                                                      //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef MARS_MFilter
+#include "MFilter.h"
+#endif
+
+class MParList;
+class TMethodCall;
+
+class MF : public MFilter
+{
+private:
+    static const TString gsDefName;  //!
+    static const TString gsDefTitle; //!
+
+    MFilter *fF; // Filter
+
+    Int_t IsAlNum(TString txt) const;
+
+    MFilter *ParseRule(TString &txt, MFilter *filter0, Int_t level) const;
+    MFilter *ParseString(TString txt, Int_t level);
+
+    void StreamPrimitive(ofstream &out) const;
+
+public:
+    MF();
+    MF(const char *text, const char *name=NULL, const char *title=NULL);
+    ~MF();
+
+    Bool_t IsExpressionTrue() const;
+
+    Int_t PreProcess(MParList *pList);
+    Int_t Process();
+    Int_t PostProcess();
+
+    void Print(Option_t *opt="") const;
+
+    ClassDef(MF, 0) // A Filter for cuts in any data member
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mfbase/MFDataChain.cc
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MFDataChain.cc	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/MFDataChain.cc	(revision 3330)
@@ -0,0 +1,126 @@
+/* ======================================================================== *\
+!
+! *
+! * 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  11/2002 <mailto:tbretz@astro.uni-wueruburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MFDataChain                                                              
+//
+// With this filter you can filter in all variables from Mars parameter
+// containers using rules (for more details see MDataChain).
+//
+// In the constructor you can give the filter variable, like
+//   "sqrt(MHillas.fLength*MHillas.fLength)"
+// Where MHillas is the name of the parameter container in the parameter
+// list and fLength is the name of the data member which should be used
+// for the filter rule. If the name of the container is use specified
+// (MyHillas) the name to give would be:
+//   "MyHillas.fLength"
+//
+// For example:
+//   MFDataChain filter("sqr(MHillas.fLength)", '<', 150);
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MFDataChain.h"
+
+#include <fstream>
+
+#include <TMethodCall.h>
+
+#include "MParList.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MFDataChain);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+MFDataChain::MFDataChain(const char *member, const char type, const Double_t val,
+                         const char *name, const char *title)
+    : fData(member), fValue(val)
+{
+    fName  = name  ? name  : "MFDataChain";
+    fTitle = title ? title : "Filter using any data member of a class";
+
+    //AddToBranchList(member);
+
+    fFilterType = (type=='<' ? kELowerThan : kEGreaterThan);
+
+    if (type!='<' && type!='>')
+        *fLog << warn << dbginf << "Warning: Neither '<' nor '>' specified... using '>'." << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+Int_t MFDataChain::PreProcess(MParList *plist)
+{
+    return fData.PreProcess(plist);
+}
+
+// --------------------------------------------------------------------------
+//
+Int_t MFDataChain::Process()
+{
+    switch (fFilterType)
+    {
+    case kELowerThan:
+        fResult = (fData.GetValue() < fValue);
+        return kTRUE;
+    case kEGreaterThan:
+        fResult = (fData.GetValue() > fValue);
+        return kTRUE;
+    }
+
+    return kFALSE;
+}
+
+void MFDataChain::Print(Option_t *) const
+{
+    *fLog << GetRule() << flush;
+}
+
+void MFDataChain::StreamPrimitive(ofstream &out) const
+{
+    out << "   MFDataChain " << GetUniqueName() << "(\"";
+    out << fData.GetRule() << "\", '";
+    out << (fFilterType==kELowerThan?"<":">");
+    out << "', " << fValue << ");" << endl;
+}
+
+TString MFDataChain::GetRule() const
+{
+    TString ret = "{";
+    ret += fData.GetRule();
+    ret += "}";
+    ret += fFilterType==kELowerThan?"<":">";
+
+    TString str;
+    str += fValue;
+
+    ret += str.Strip(TString::kBoth);
+    return ret;
+}
+
Index: trunk/MagicSoft/Mars/mfbase/MFDataChain.h
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MFDataChain.h	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/MFDataChain.h	(revision 3330)
@@ -0,0 +1,47 @@
+#ifndef MARS_MFDataChain
+#define MARS_MFDataChain
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MFDataChain                                                                 //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef MARS_MFilter
+#include "MFilter.h"
+#endif
+#ifndef MARS_MDataChain
+#include "MDataChain.h"
+#endif
+
+class MParList;
+
+class MFDataChain : public MFilter
+{
+private:
+    MDataChain fData;
+
+    typedef enum { kELowerThan, kEGreaterThan } FilterType_t;
+    FilterType_t fFilterType;
+
+    Bool_t  fResult;           //!
+    Double_t fValue;
+
+    void StreamPrimitive(ofstream &out) const;
+
+    Int_t PreProcess(MParList *pList);
+    Int_t Process();
+
+public:
+    MFDataChain(const char *member, const char type, const Double_t val,
+                const char *name=NULL, const char *title=NULL);
+
+    Bool_t IsExpressionTrue() const { return fResult; }
+
+    void Print(Option_t *opt = "") const;
+    TString GetRule() const;
+
+    ClassDef(MFDataChain, 1) // A Filter for cuts in any data member
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mfbase/MFDataMember.cc
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MFDataMember.cc	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/MFDataMember.cc	(revision 3330)
@@ -0,0 +1,169 @@
+/* ======================================================================== *\
+!
+! *
+! * 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@astro.uni-wueruburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MFDataMember                                                              
+//
+// With this filter you can filter in all variables from Mars parameter
+// containers.
+//
+// In the constructor you can give the filter variable, like
+//   "MHillas.fLength"
+// Where MHillas is the name of the parameter container in the parameter
+// list and fLength is the name of the data member which should be used
+// for the filter rule. If the name of the container is use specified
+// (MyHillas) the name to give would be:
+//   "MyHillas.fLength"
+//
+// For example:
+//   MFDataMember filter("MHillas.fLength", '<', 150);
+//
+// You can test '<', '>' and '='. Warning: Using '=' may give strange results
+// in case you are comparing floating point values.
+//
+// In case the data member is detected to be an integer value, both
+// the data member and the val given as argument in the constructor
+// are castet to Long_t.
+//
+// To test != use the SetInverted() member function.
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MFDataMember.h"
+
+#include <fstream>
+
+#include <TMethodCall.h>
+
+#include "MParList.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MFDataMember);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+MFDataMember::MFDataMember(const char *member, const char type, const Double_t val,
+                           const char *name, const char *title)
+    : fData(member), fValue(val)
+{
+    fName  = name  ? name  : "MFDataMember";
+    fTitle = title ? title : "Filter using any data member of a class";
+
+    AddToBranchList(member);
+
+    switch (type)
+    {
+    case '>': fFilterType = kEGreaterThan; break;
+    case '<': fFilterType = kELowerThan;   break;
+    case '=': fFilterType = kEEqual;       break;
+    default:  fFilterType = kEGreaterThan; break;
+    }
+
+    if (type!='<' && type!='=' && type!='>')
+        *fLog << warn << dbginf << "Warning: Neither '<' nor '=' nor '>' specified... using '>'." << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+Int_t MFDataMember::PreProcess(MParList *plist)
+{
+    return fData.PreProcess(plist);
+}
+
+// --------------------------------------------------------------------------
+//
+Int_t MFDataMember::Process()
+{
+    if (fData.IsInt())
+    {
+        switch (fFilterType)
+        {
+        case kELowerThan:
+            fResult = ((Long_t)fData.GetValue() < (Long_t)fValue);
+            return kTRUE;
+        case kEGreaterThan:
+            fResult = ((Long_t)fData.GetValue() > (Long_t)fValue);
+            return kTRUE;
+        case kEEqual:
+            fResult = ((Long_t)fData.GetValue() == (Long_t)fValue);
+            return kTRUE;
+        }
+    }
+    else
+    {
+        switch (fFilterType)
+        {
+        case kELowerThan:
+            fResult = (fData.GetValue() < fValue);
+            return kTRUE;
+        case kEGreaterThan:
+            fResult = (fData.GetValue() > fValue);
+            return kTRUE;
+        case kEEqual:
+            fResult = (fData.GetValue() == fValue);
+            return kTRUE;
+        }
+    }
+
+    return kFALSE;
+}
+
+void MFDataMember::Print(Option_t *) const
+{
+    *fLog << GetRule() << flush;
+}
+
+void MFDataMember::StreamPrimitive(ofstream &out) const
+{
+    out << "   MFDataMember " << GetUniqueName() << "(\"";
+    out << fData.GetRule() << "\", '";
+    switch (fFilterType)
+    {
+    case kEGreaterThan: out << '>'; break;
+    case kELowerThan:   out << '<'; break;
+    case kEEqual:       out << '='; break;
+    }
+    out << "', " << fValue << ");" << endl;
+}
+
+TString MFDataMember::GetRule() const
+{
+    TString ret = fData.GetRule();
+    switch (fFilterType)
+    {
+    case kEGreaterThan: ret +='>'; break;
+    case kELowerThan:   ret +='<'; break;
+    case kEEqual:       ret +='='; break;
+    }
+
+    TString str;
+    str += fValue;
+
+    return ret+str.Strip(TString::kBoth);
+}
+
Index: trunk/MagicSoft/Mars/mfbase/MFDataMember.h
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MFDataMember.h	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/MFDataMember.h	(revision 3330)
@@ -0,0 +1,44 @@
+#ifndef MARS_MFDataMember
+#define MARS_MFDataMember
+
+#ifndef MARS_MFilter
+#include "MFilter.h"
+#endif
+#ifndef MARS_MDataMember
+#include "MDataMember.h"
+#endif
+
+class MParList;
+
+class MFDataMember : public MFilter
+{
+private:
+    MDataMember fData;
+
+    typedef enum { kELowerThan, kEGreaterThan, kEEqual } FilterType_t;
+    FilterType_t fFilterType;
+
+    Bool_t  fResult;           //!
+    Double_t fValue;
+
+    void StreamPrimitive(ofstream &out) const;
+
+    Int_t PreProcess(MParList *pList);
+    Int_t Process();
+
+public:
+    enum {
+        kIsInt = BIT(14)
+    };
+    MFDataMember(const char *member, const char type, const Double_t val,
+                 const char *name=NULL, const char *title=NULL);
+
+    Bool_t IsExpressionTrue() const { return fResult; }
+
+    void Print(Option_t *opt = "") const;
+    TString GetRule() const;
+
+    ClassDef(MFDataMember, 1) // A Filter for cuts in any data member
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mfbase/MFEventSelector.cc
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MFEventSelector.cc	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/MFEventSelector.cc	(revision 3330)
@@ -0,0 +1,228 @@
+/* ======================================================================== *\
+!
+! *
+! * 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@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// 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.
+//
+// This filter can be used for a random split...
+//
+// 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
+// MRead inheriting from MRead):
+//   MFEventSelector sel;
+//   sel.SetNumSelectEvts(2000);
+//   MFillH filler(...);
+//   filler.SetFilter(&sel);
+//   tlist.AddToList(&sel);
+//   tlist.AddToList(&filler);
+//
+// If you don't have MRead 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!
+//
+// Remark: You can also use the filter together with MContinue
+//
+//
+// FIXME: Merge MFEventSelector and MFEventSelector2
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MFEventSelector.h"
+
+#include <TRandom.h>
+
+#include "MParList.h"
+#include "MTaskList.h"
+#include "MRead.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MFEventSelector);
+
+using namespace std;
+
+static const TString gsDefName  = "MFEventSelector";
+static const TString gsDefTitle = "Filter to select events";
+
+// --------------------------------------------------------------------------
+//
+// 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();
+}
+
+// --------------------------------------------------------------------------
+//
+// Set a probability with which events are selected. Eg, f=0.5
+// will select roughly half of all events.
+//
+void MFEventSelector::SetSelectionRatio(Float_t f)
+{
+    if (f < 0)
+    {
+        *fLog << warn << "MFEventSelector::SetSelectionRatio: WARNING - Probability less than 0... set to 0." << endl;
+        f = 0;
+    }
+
+    if (f > 1)
+    {
+        *fLog << warn << "MFEventSelector::SetSelectionRatio: WARNING - Probability greater than 1... set to 1." << endl;
+        f = 1;
+    }
+    fSelRatio = f;
+}
+
+// --------------------------------------------------------------------------
+//
+// PreProcess all filters.
+//
+Int_t MFEventSelector::PreProcess(MParList *plist)
+{
+    fNumSelectedEvts = 0;
+
+    // In the case a ratio was set by the user we are done.
+    if (fSelRatio>0)
+        return kTRUE;
+
+    // If the number of total events wasn't set try to get it
+    if (fNumTotalEvts<0)
+    {
+        MTaskList *tlist = (MTaskList*)plist->FindObject("MTaskList");
+        if (!tlist)
+        {
+            *fLog << err << "Can't determin total number of events... no MTaskList." << endl;
+            return kFALSE;
+        }
+
+        MRead *read = (MRead*)tlist->FindObject("MRead");
+        if (!read)
+        {
+            *fLog << err << "Can't determin total number of events from 'MRead'." << endl;
+            return kFALSE;
+        }
+        fNumTotalEvts = read->GetEntries();
+
+        SetBit(kNumTotalFromFile);
+    }
+
+    // Calculate selection probability
+    fSelRatio = (Double_t)fNumSelectEvts/fNumTotalEvts;
+
+    *fLog << inf << "MFEventSelector:  Selection probability = " << fNumSelectEvts;
+    *fLog << "/" << fNumTotalEvts << " = " << Form("%.2f", fSelRatio) << endl;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Process all filters, FIXME: Make it fit the requested number of events
+// exactly like it is done in MFEventSelector2. This can be done by merging
+// both classes!
+//
+Int_t MFEventSelector::Process()
+{
+    fResult = gRandom->Uniform() < fSelRatio;
+
+    if (!fResult)
+        return kTRUE;
+
+    fNumSelectedEvts++;
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+//  Postprocess all filters.
+//
+Int_t MFEventSelector::PostProcess()
+{
+    //---------------------------------
+    if (GetNumExecutions() != 0)
+    {
+        const Double_t sel = (Double_t)fNumSelectedEvts/GetNumExecutions();
+        const UInt_t   non = GetNumExecutions()-fNumSelectedEvts;
+
+        *fLog << inf << dec << setfill(' ') << endl;
+        *fLog << GetDescriptor() << " execution statistics:" << endl;
+
+        *fLog << " " << setw(7) << non << " (" << setw(3);
+        *fLog << (int)(100*(1-sel)) << "%) Events not selected" << endl;
+
+        *fLog << " " << setw(7) << fNumSelectedEvts << " (";
+        *fLog << (int)(100*sel) << "%) Events selected!" << endl;
+        *fLog << endl;
+    }
+
+    //---------------------------------
+    if (TestBit(kNumTotalFromFile))
+        fNumTotalEvts = -1;
+
+    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/mfbase/MFEventSelector.h
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MFEventSelector.h	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/MFEventSelector.h	(revision 3330)
@@ -0,0 +1,41 @@
+#ifndef MARS_MFEventSelector
+#define MARS_MFEventSelector
+
+#ifndef MARS_MFilter
+#include "MFilter.h"
+#endif
+
+class MParList;
+
+class MFEventSelector : public MFilter
+{
+private:
+    Int_t   fNumTotalEvts;    // Number of total events from which are selected
+    Int_t   fNumSelectEvts;   // Number of events to be selected
+    Float_t fSelRatio;        // Selection Probability
+
+    Int_t   fNumSelectedEvts; //! Number of events which have been selected
+
+    Bool_t  fResult;          //! Reseult of a single selection
+
+    void StreamPrimitive(ofstream &out) const;
+
+    Int_t PreProcess(MParList *pList);
+    Int_t Process();
+    Int_t PostProcess();
+
+    enum { kNumTotalFromFile = BIT(14) };
+
+public:
+    MFEventSelector(const char *name=NULL, const char *title=NULL);
+
+    Bool_t IsExpressionTrue() const { return fResult; }
+
+    void SetNumTotalEvts(Int_t n)  { fNumTotalEvts = n; ResetBit(kNumTotalFromFile); }
+    void SetNumSelectEvts(Int_t n) { fNumSelectEvts = n; }
+    void SetSelectionRatio(Float_t f);
+
+    ClassDef(MFEventSelector, 0) // A filter to do a random selection of events
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mfbase/MFEventSelector2.cc
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MFEventSelector2.cc	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/MFEventSelector2.cc	(revision 3330)
@@ -0,0 +1,500 @@
+/* ======================================================================== *\
+!
+! *
+! * 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@astro.uni-wuerzburg.de>
+!   Author(s): Wolfgang Wittek 11/2003 <mailto:wittek@mppmu.mpg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MFEventSelector2
+//
+// This is a filter to make a selection of events from a file.
+//
+// see Construtor for more instructions and the example below:
+//
+// --------------------------------------------------------------------
+//
+// void select()
+// {
+//     MParList plist;
+//     MTaskList tlist;
+// 
+//     MStatusDisplay *d=new MStatusDisplay;
+// 
+//     plist.AddToList(&tlist);
+// 
+//     MReadTree read("Events", "myinputfile.root");
+//     read.DisableAutoScheme();
+//     // Accelerate execution...
+//     // read.EnableBranch("MMcEvt.fTelescopeTheta");
+// 
+//     // create nominal distribution (theta converted into degrees)
+//     MH3 nomdist("r2d(MMcEvt.fTelescopeTheta)");
+//     MBinning binsx;
+//     binsx.SetEdges(5, 0, 45);   // five bins from 0deg to 45deg
+//     MH::SetBinning(&nomdist.GetHist(), &binsx);
+//
+//     // use this to create a nominal distribution in 2D
+//     //  MH3 nomdist("r2d(MMcEvt.fTelescopeTheta)", "MMcEvt.fEnergy");
+//     //  MBinning binsy;
+//     //  binsy.SetEdgesLog(5, 10, 10000);
+//     //  MH::SetBinning((TH2*)&nomdist.GetHist(), &binsx, &binsy);
+//
+//     // Fill the nominal distribution with whatever you want:
+//     for (int i=0; i<nomdist.GetNbins(); i++)
+//         nomdist.GetHist().SetBinContent(i, i*i);
+// 
+//     MFEventSelector2 test(nomdist);
+//     test.SetNumMax(9999);  // total number of events selected
+//     MContinue cont(&test);
+// 
+//     MEvtLoop run;
+//     run.SetDisplay(d);
+//     run.SetParList(&plist);
+//     tlist.AddToList(&read);
+//     tlist.AddToList(&cont);
+// 
+//     if (!run.Eventloop())
+//         return;
+// 
+//     tlist.PrintStatistics();
+// }
+// 
+// --------------------------------------------------------------------
+//
+// The random number is generated using gRandom->Rndm(). 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 or as a selector
+// in the reading task: This won't work!
+//
+// Remark: You can also use the filter together with MContinue
+//
+//
+// FIXME: Merge MFEventSelector and MFEventSelector2
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MFEventSelector2.h"
+
+#include <TRandom.h>        // gRandom
+#include <TCanvas.h>        // TCanvas
+
+#include "MH3.h"            // MH3
+#include "MRead.h"          // MRead
+#include "MEvtLoop.h"       // MEvtLoop
+#include "MTaskList.h"      // MTaskList
+#include "MBinning.h"       // MBinning
+#include "MFillH.h"         // MFillH
+#include "MParList.h"       // MParList
+#include "MStatusDisplay.h" // MStatusDisplay
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MFEventSelector2);
+
+using namespace std;
+
+const TString MFEventSelector2::gsDefName  = "MFEventSelector2";
+const TString MFEventSelector2::gsDefTitle = "Filter to select events with a given distribution";
+
+// --------------------------------------------------------------------------
+//
+// Constructor. Takes a reference to an MH3 which gives you
+//  1) The nominal distribution. The distribution is renormalized, so
+//     that the absolute values doesn't matter. To crop the distribution
+//     to a nominal value of total events use SetNumMax
+//  2) The dimension of the MH3 determins the dimension in which the
+//     event selector will work, eg
+//       MH3 hist("MMcEvt.fTelescopeTheta", "MMcEvt.fEnergy");
+//     Would result in a redistribution of Theta and Energy.
+//  3) The given rules are the variables which are used for the
+//     redistribution, eg:
+//       MH3 hist("MMcEvt.fTelescopeTheta");
+//     would result in redistributing Theta.
+//       MH3 hist("cos(MMcEvt.fTelescopeTheta)");
+//     would result in redistributing cos(Theta).
+//
+//  If the reference distribution doesn't contain entries (GetEntries()==0)
+//     the original distribution will be used as the nominal distribution;
+//     note that also in this case a dummy nominal distribution has to be
+//     provided in the first argument (the dummy distribution defines the
+//     variable(s) of interest and the binnings)
+//
+
+MFEventSelector2::MFEventSelector2(MH3 &hist, const char *name, const char *title)
+: fHistOrig(NULL), fHistNom(&hist), fHistRes(NULL),
+  fDataX(hist.GetRule('x')), fDataY(hist.GetRule('y')),
+  fDataZ(hist.GetRule('z')), fNumMax(-1)
+{
+    fName  = name  ? (TString)name  : gsDefName;
+    fTitle = title ? (TString)title : gsDefTitle;
+}
+
+// --------------------------------------------------------------------------
+//
+// Delete fHistRes if instatiated
+//
+MFEventSelector2::~MFEventSelector2()
+{
+    if (fHistRes)
+        delete fHistRes;
+}
+
+//---------------------------------------------------------------------------
+//
+// Recreate a MH3 from fHistNom used as a template. Copy the Binning
+// from fHistNom to the new histogram, and return a pointer to the TH1
+// base class of the MH3.
+//
+TH1 &MFEventSelector2::InitHistogram(MH3* &hist)
+{
+    // if fHistRes is already allocated delete it first
+    if (hist)
+        delete hist;
+
+    // duplicate the fHistNom histogram
+    hist = (MH3*)fHistNom->New();
+
+    // copy binning from one histogram to the other one
+    MH::SetBinning(&hist->GetHist(), &fHistNom->GetHist());
+
+    return hist->GetHist();
+}
+
+// --------------------------------------------------------------------------
+//
+// Try to read the present distribution from the file. Therefore the
+// Reading task of the present loop is used in a new eventloop.
+//
+Bool_t MFEventSelector2::ReadDistribution(MRead &read)
+{
+    if (read.GetEntries() > kMaxUInt) // FIXME: LONG_MAX ???
+    {
+        *fLog << err << "kIntMax exceeded." << endl;
+        return kFALSE;
+    }
+
+    *fLog << inf << underline << endl;
+    *fLog << "MFEventSelector2::ReadDistribution:" << endl;
+    *fLog << " - Start of eventloop to generate the original distribution..." << endl;
+
+    MEvtLoop run(GetName());
+    MParList plist;
+    MTaskList tlist;
+    plist.AddToList(&tlist);
+    run.SetParList(&plist);
+
+    MBinning binsx("BinningMH3X");
+    MBinning binsy("BinningMH3Y");
+    MBinning binsz("BinningMH3Z");
+    binsx.SetEdges(fHistNom->GetHist(), 'x');
+    binsy.SetEdges(fHistNom->GetHist(), 'y');
+    binsz.SetEdges(fHistNom->GetHist(), 'z');
+    plist.AddToList(&binsx);
+    plist.AddToList(&binsy);
+    plist.AddToList(&binsz);
+
+    MFillH fill(fHistOrig);
+    fill.SetBit(MFillH::kDoNotDisplay);
+    tlist.AddToList(&read);
+    tlist.AddToList(&fill);
+    run.SetDisplay(fDisplay);
+    if (!run.Eventloop())
+    {
+        *fLog << err << dbginf << "Evtloop in MFEventSelector2::ReadDistribution failed." << endl;
+        return kFALSE;
+    }
+
+    tlist.PrintStatistics();
+
+    *fLog << inf;
+    *fLog << "MFEventSelector2::ReadDistribution:" << endl;
+    *fLog << " - Original distribution has " << fHistOrig->GetHist().GetEntries() << " entries." << endl;
+    *fLog << " - End of eventloop to generate the original distribution." << endl;
+
+    return read.Rewind();
+}
+
+// --------------------------------------------------------------------------
+//
+// After reading the histograms the arrays used for the random event
+// selction are created. If a MStatusDisplay is set the histograms are
+// displayed there.
+//
+void MFEventSelector2::PrepareHistograms()
+{
+    TH1 &ho = fHistOrig->GetHist();
+
+    //-------------------
+    // if requested
+    // set the nominal distribution equal to the original distribution
+
+    const Bool_t useorigdist = fHistNom->GetHist().GetEntries()==0;
+    TH1 *hnp =  useorigdist ? (TH1*)(fHistOrig->GetHist()).Clone() : &fHistNom->GetHist();
+
+    TH1 &hn = *hnp;
+    //--------------------
+
+    // normalize to number of counts in primary distribution
+    hn.Scale(1./hn.Integral());
+
+    MH3 *h3 = NULL;
+    TH1 &hist = InitHistogram(h3);
+
+    hist.Divide(&hn, &ho);
+    hist.Scale(1./hist.GetMaximum());
+
+    if (fCanvas)
+    {
+        fCanvas->Clear();
+        fCanvas->Divide(2,2);
+
+        fCanvas->cd(1);
+        gPad->SetBorderMode(0);
+        hn.DrawCopy();
+
+        fCanvas->cd(2);
+        gPad->SetBorderMode(0);
+        ho.DrawCopy();
+    }
+    hn.Multiply(&ho, &hist);
+    hn.SetTitle("Resulting Nominal Distribution");
+
+    if (fNumMax>0)
+    {
+        *fLog << inf;
+        *fLog << "MFEventSelector2::PrepareHistograms:" << endl;
+        *fLog << " - requested number of events = " << fNumMax << endl;
+        *fLog << " - maximum number of events possible = " << hn.Integral() << endl;
+
+        if (fNumMax > hn.Integral())
+	{
+            *fLog << warn << "WARNING - Requested no.of events (" << fNumMax;
+            *fLog << ") is too high... reduced to " << hn.Integral() << endl;
+	}
+        else
+            hn.Scale(fNumMax/hn.Integral());
+    }
+
+    hn.SetEntries(hn.Integral()+0.5);
+    if (fCanvas)
+    {
+        fCanvas->cd(3);
+        gPad->SetBorderMode(0);
+        hn.DrawCopy();
+
+        fCanvas->cd(4);
+        gPad->SetBorderMode(0);
+        fHistRes->Draw();
+    }
+    delete h3;
+
+    const Int_t num = fHistRes->GetNbins();
+    fIs.Set(num);
+    fNom.Set(num);
+    for (int i=0; i<num; i++)
+    {
+        fIs[i]  = (Long_t)(ho.GetBinContent(i+1)+0.5);
+        fNom[i] = (Long_t)(hn.GetBinContent(i+1)+0.5);
+    }
+
+    if (useorigdist)
+      delete hnp;
+}
+
+// --------------------------------------------------------------------------
+//
+// PreProcess the data rules extracted from the MH3 nominal distribution
+//
+Bool_t MFEventSelector2::PreProcessData(MParList *parlist)
+{
+    switch (fHistNom->GetDimension())
+    {
+    case 3:
+        if (!fDataZ.PreProcess(parlist))
+        {
+            *fLog << err << "Preprocessing of rule for z-axis failed... abort." << endl;
+            return kFALSE;
+        }
+        // FALLTHROUGH!
+    case 2:
+        if (!fDataY.PreProcess(parlist))
+        {
+            *fLog << err << "Preprocessing of rule for y-axis failed... abort." << endl;
+            return kFALSE;
+        }
+        // FALLTHROUGH!
+    case 1:
+        if (!fDataX.PreProcess(parlist))
+        {
+            *fLog << err << "Preprocessing of rule for x-axis failed... abort." << endl;
+            return kFALSE;
+        }
+    }
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// PreProcess the filter. Means:
+//  1) Preprocess the rules
+//  2) Read The present distribution from the file.
+//  3) Initialize the histogram for the resulting distribution
+//  4) Prepare the random selection
+//  5) Repreprocess the reading task.
+//
+Int_t MFEventSelector2::PreProcess(MParList *parlist)
+{
+    memset(fCounter, 0, sizeof(fCounter));
+
+    MTaskList *tasklist = (MTaskList*)parlist->FindObject("MTaskList");
+    if (!tasklist)
+    {
+        *fLog << err << "MTaskList not found... abort." << endl;
+        return kFALSE;
+    }
+
+    MRead *read = (MRead*)tasklist->FindObject("MRead");
+    if (!read)
+    {
+        *fLog << err << "MRead not found... abort." << endl;
+        return kFALSE;
+    }
+
+    if (!PreProcessData(parlist))
+        return kFALSE;
+
+    InitHistogram(fHistOrig);
+    InitHistogram(fHistRes);
+
+    fHistNom->SetTitle("Users Nominal Distribution");
+    fHistOrig->SetTitle("Primary Distribution");
+    fHistRes->SetTitle("Resulting Distribution");
+
+    // Initialize online display if requested
+    fCanvas = fDisplay ? &fDisplay->AddTab(GetName()) : NULL;
+    if (fCanvas)
+        fHistOrig->Draw();
+
+    // Generate primary distribution
+    if (!ReadDistribution(*read))
+        return kFALSE;
+
+    // Prepare histograms and arrays for selection
+    PrepareHistograms();
+
+    return read->CallPreProcess(parlist);
+}
+
+// --------------------------------------------------------------------------
+//
+// Part of Process(). Select() at the end checks whether a selection should
+// be done or not. Under-/Overflowbins are rejected.
+//
+Bool_t MFEventSelector2::Select(Int_t bin)
+{
+    // under- and overflow bins are not counted
+    if (bin<0)
+        return kFALSE;
+
+    Bool_t rc = kFALSE;
+
+    if (gRandom->Rndm()*fIs[bin]<=fNom[bin])
+    {
+        // how many events do we still want to read in this bin
+        fNom[bin] -= 1;
+        rc = kTRUE;
+
+        // fill bin (same as Fill(valx, valy, valz))
+        TH1 &h = fHistRes->GetHist();
+        h.AddBinContent(bin+1);
+        h.SetEntries(h.GetEntries()+1);
+    }
+
+    // how many events are still pending to be read
+    fIs[bin] -= 1;
+
+    return rc;
+}
+
+// --------------------------------------------------------------------------
+//
+// fIs[i] contains the distribution of the events still to be read from
+// the file. fNom[i] contains the number of events in each bin which
+// are requested.
+// The events are selected by:
+//     gRandom->Rndm()*fIs[bin]<=fNom[bin]
+//
+Int_t MFEventSelector2::Process()
+{
+    // get x,y and z (0 if fData not valid)
+    const Double_t valx=fDataX.GetValue();
+    const Double_t valy=fDataY.GetValue();
+    const Double_t valz=fDataZ.GetValue();
+
+    // Get corresponding bin number and check
+    // whether a selection should be made
+    fResult = Select(fHistNom->FindFixBin(valx, valy, valz)-1);
+
+    fCounter[fResult ? 1 : 0]++;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Update online display if set.
+//
+Int_t MFEventSelector2::PostProcess()
+{
+    //---------------------------------
+
+    if (GetNumExecutions()>0)
+    {
+      *fLog << inf << endl;
+      *fLog << GetDescriptor() << " execution statistics:" << endl;
+      *fLog << dec << setfill(' ');
+      *fLog << " " << setw(7) << fCounter[1] << " (" << setw(3)
+            << (int)(fCounter[0]*100/GetNumExecutions())
+            << "%) Events not selected" << endl;
+
+      *fLog << " " << fCounter[0] << " ("
+            << (int)(fCounter[1]*100/GetNumExecutions())
+            << "%) Events selected" << endl;
+      *fLog << endl;
+    }
+
+    //---------------------------------
+
+    if (fDisplay && fDisplay->HasCanvas(fCanvas))
+    {
+        fCanvas->cd(4);
+        fHistRes->DrawClone("nonew");
+        fCanvas->Modified();
+        fCanvas->Update();
+    }
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mfbase/MFEventSelector2.h
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MFEventSelector2.h	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/MFEventSelector2.h	(revision 3330)
@@ -0,0 +1,68 @@
+#ifndef MARS_MFEventSelector2
+#define MARS_MFEventSelector2
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MFEventSelector2                                                        //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef MARS_MFilter
+#include "MFilter.h"
+#endif
+#ifndef ROOT_TArrayL
+#include <TArrayL.h>
+#endif
+#ifndef MARS_MDataChain
+#include "MDataChain.h"
+#endif
+
+class TH1;
+class TCanvas;
+
+class MH3;
+class MRead;
+
+class MFEventSelector2 : public MFilter
+{
+private:
+    static const TString gsDefName;
+    static const TString gsDefTitle;
+
+    MH3       *fHistOrig; // original distribution of the events
+    MH3       *fHistNom;  // nominal distribution
+    MH3       *fHistRes;  // resulting distribution
+    MDataChain fDataX;    // data rule for the x-axis
+    MDataChain fDataY;    // data rule for the y-axis
+    MDataChain fDataZ;    // data rule for the z-axis
+    Long_t     fNumMax;   // Maximum number of selected events
+    TArrayL    fIs;       //! array storing the original distribution
+    TArrayL    fNom;      //! array storing the nominal distribution
+    TCanvas   *fCanvas;   //! canvas for online display
+
+    Bool_t fResult;
+    Int_t  fCounter[2];
+
+    TH1   &InitHistogram(MH3* &hist);
+    Bool_t ReadDistribution(MRead &read);
+    void   PrepareHistograms();
+    Bool_t PreProcessData(MParList *parlist);
+    Bool_t Select(Int_t bin);
+
+    Int_t PreProcess(MParList *parlist);
+    Int_t Process();
+    Int_t PostProcess();
+
+public:
+    MFEventSelector2(MH3 &hist, const char *name=NULL, const char *title=NULL);
+    ~MFEventSelector2();
+
+    MH3 *GetHistOrig() { return fHistOrig; }
+
+    void SetNumMax(Long_t max=-1) { fNumMax = max; }
+    Bool_t IsExpressionTrue() const { return fResult; }
+
+    ClassDef(MFEventSelector2, 0) // FIMXE!
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mfbase/MFRealTimePeriod.cc
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MFRealTimePeriod.cc	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/MFRealTimePeriod.cc	(revision 3330)
@@ -0,0 +1,59 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 10/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//  MFRealTimePeriod
+//
+//  This filter allows the execution of tasks in real time intervals. If
+//  a timeout (given in milliseconds in the constructor) was exceeded
+//  the return value for IsExpression is set to kTRUE and the timer is
+//  reset.
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MFRealTimePeriod.h"
+
+#include <TTime.h>
+#include <TSystem.h>
+
+ClassImp(MFRealTimePeriod);
+
+// --------------------------------------------------------------------------
+//
+// Check, whether the current time is greater than the stored time plus
+// the timeout time. If this is the case the return value of
+// IsExpressionTrue is set to kTRUE and the stored time is reset to the
+// current time. To get the current time gSystem->Now() is used.
+//
+Int_t MFRealTimePeriod::Process()
+{
+    const ULong_t t = (ULong_t)gSystem->Now();
+
+    fResult = t>fTime+fMilliSec;
+
+    if (fResult)
+        fTime=t;
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mfbase/MFRealTimePeriod.h
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MFRealTimePeriod.h	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/MFRealTimePeriod.h	(revision 3330)
@@ -0,0 +1,31 @@
+#ifndef MARS_MFRealTimePeriod
+#define MARS_MFRealTimePeriod
+
+#ifndef MARS_MFilter
+#include "MFilter.h"
+#endif
+
+class MFRealTimePeriod : public MFilter
+{
+private:
+    ULong_t fTime;     //!
+    Bool_t  fResult;   //!
+
+    ULong_t fMilliSec;
+
+public:
+    MFRealTimePeriod(UInt_t millis=1000) : fTime(0), fMilliSec(millis)
+    {
+        fName  = "MFRealTimePeriod";
+        fTitle = "Filter allowing execution of a task only after a given real time interval";
+    }
+
+    void SetTime(UInt_t millis) { fMilliSec = millis; }
+
+    Int_t Process();
+    Bool_t IsExpressionTrue() const { return fResult; }
+
+    ClassDef(MFRealTimePeriod, 0) //Filter allowing execution of a task only after a given real time interval
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mfbase/MFilterList.cc
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MFilterList.cc	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/MFilterList.cc	(revision 3330)
@@ -0,0 +1,380 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 07/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//   MFilterList
+//
+// A filter list can be used to concatenate filter (derived from MFilter)
+// by a logical or bitwise operator. For more details see the constructor.
+//
+// The list is setup by adding filters to the list calling AddToList().
+// For example in the case of the default constructor ("&&") all results
+// are logically and'd together and the result of this and is returned.
+//
+// Because the meaning of all filters can be inverted calling SetInverted()
+// which is defined in the base class MFilter you can use this list to
+// invert the meaning of a filter, by eg:
+//
+//   MF anyfilter("MHillas.fAlpha");
+//
+//   MFilterList alist;
+//   alist.AddToList(&anyfilter);
+//
+//   alist.SetInverted();
+//
+// Adding the filterlist to the eventloop will process all contained filters.
+// Doing this as early as possible is a simple way of processing all filters.
+//
+// If you want to make the list delete all contained filters you may make
+// the list owner of the filters by calling SetOwner()
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MFilterList.h"
+
+#include <fstream>
+
+#include <TString.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MIter.h"
+
+ClassImp(MFilterList);
+
+using namespace std;
+
+static const TString gsDefName  = "MFilterList";
+static const TString gsDefTitle = "List combining filters logically.";
+
+// --------------------------------------------------------------------------
+//
+//   Constructor.
+//
+//   Specify the boolean operation which is used to evaluate the
+//   result of this list. If no operation is specified "land" is
+//   used.
+//
+//   Options:
+//      and, &   : is a bitwise and
+//      or, |    : is a bitwise or
+//      xor, ^   : is a bitwise exclusive or
+//      land, && : is a logical and
+//      lor, ||  : is a logical or
+//
+MFilterList::MFilterList(const char *type, const char *name, const char *title)
+{
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+
+    gROOT->GetListOfCleanups()->Add(&fFilters);
+    fFilters.SetBit(kMustCleanup);
+
+    fFilterType = kEAnd;
+
+    TString str(type);
+
+    if (!str.CompareTo("OR", TString::kIgnoreCase)  || !str.CompareTo("|"))
+        fFilterType = kEOr;
+    if (!str.CompareTo("XOR", TString::kIgnoreCase) || !str.CompareTo("^"))
+        fFilterType = kEXor;
+    if (!str.CompareTo("LAND", TString::kIgnoreCase) || !str.CompareTo("&&"))
+        fFilterType = kELAnd;
+    if (!str.CompareTo("LOR", TString::kIgnoreCase) || !str.CompareTo("||"))
+        fFilterType = kELOr;
+}
+
+// --------------------------------------------------------------------------
+//
+//   CopyConstructor
+//
+MFilterList::MFilterList(MFilterList &ts)
+{
+    fFilters.AddAll(&ts.fFilters);
+    fFilterType = ts.fFilterType;
+}
+
+// --------------------------------------------------------------------------
+//
+//  Evaluates and returns the result of the filter list.
+//  The expression is evaluated step by step, eg:
+//  ((filter[0] # filter[1]) # filter[3]) # filter[4])
+//  The '#' stands for the boolean operation which is specified in
+//  the constructor.
+//
+Bool_t MFilterList::IsExpressionTrue() const
+{
+    TIter Next(&fFilters);
+
+    MFilter *filter=(MFilter*)Next();
+
+    if (!filter)
+        return kTRUE;
+
+    Bool_t rc = filter->IsConditionTrue();
+
+    //
+    // loop over all filters
+    //
+    switch (fFilterType)
+    {
+    case kEAnd:
+        while ((filter=(MFilter*)Next()))
+            rc &= filter->IsConditionTrue();
+        break;
+
+    case kEOr:
+        while ((filter=(MFilter*)Next()))
+            rc |= filter->IsConditionTrue();
+        break;
+
+    case kEXor:
+        while ((filter=(MFilter*)Next()))
+            rc ^= filter->IsConditionTrue();
+        break;
+
+    case kELAnd:
+        while ((filter=(MFilter*)Next()))
+            rc = (rc && filter->IsConditionTrue());
+        break;
+
+    case kELOr:
+        while ((filter=(MFilter*)Next()))
+            rc = (rc || filter->IsConditionTrue());
+        break;
+    }
+    return rc;
+}
+
+// --------------------------------------------------------------------------
+//
+// If you want to add a new filter to the list call this function with the
+// pointer to the filter to be added. 
+//
+Bool_t MFilterList::AddToList(MFilter *filter)
+{
+    if (!filter)
+        return kTRUE;
+
+    const char *name = filter->GetName();
+
+    if (fFilters.FindObject(filter))
+    {
+        *fLog << warn << dbginf << "Filter already existing... skipped." << endl;
+        return kTRUE;
+    }
+
+    if (fFilters.FindObject(name))
+        *fLog << warn << "MFilterList::AddToList - '" << name << "' exists in List already..." << endl;
+
+    *fLog << inf << "Adding " << name << " to " << GetName() << "... " << flush;
+
+    filter->SetBit(kMustCleanup);
+    fFilters.Add(filter);
+
+    *fLog << "Done." << endl;
+
+    return kTRUE;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// PreProcesses all filters in the list
+//
+Int_t MFilterList::PreProcess(MParList *pList)
+{
+    TIter Next(&fFilters);
+
+    MFilter *filter=NULL;
+
+    //
+    // loop over all filters
+    //
+    while ((filter=(MFilter*)Next()))
+        if (!filter->CallPreProcess(pList))
+        {
+            *fLog << err << "Error - Preprocessing Filter ";
+            *fLog << filter->GetName() << " in " << fName << endl;
+            return kFALSE;
+        }
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Processes (updates) all filters in the list.
+//
+Int_t MFilterList::Process()
+{
+    TIter Next(&fFilters);
+
+    MFilter *filter=NULL;
+
+    //
+    // loop over all filters
+    //
+    while ((filter=(MFilter*)Next()))
+        if (!filter->CallProcess())
+            return kFALSE;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// PostProcesses all filters in the list.
+//
+Int_t MFilterList::PostProcess()
+{
+    TIter Next(&fFilters);
+
+    MFilter *filter=NULL;
+
+    //
+    // loop over all filters
+    //
+    while ((filter=(MFilter*)Next()))
+        if (!filter->CallPostProcess())
+            return kFALSE;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// If you want to use a verbose output ("and") instead of a symbolic ("&")
+// one the option string must conatin a "v"
+//
+void MFilterList::Print(Option_t *opt) const
+{
+    *fLog << all << GetRule(opt) << flush;
+}
+
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
+void MFilterList::StreamPrimitive(ofstream &out) const
+{
+    out << "   MFilterList " << ToLower(fName) << "(\"";
+
+    switch (fFilterType)
+    {
+    case kEAnd:
+        out << "&";
+        break;
+
+    case kEOr:
+        out  << "|";
+        break;
+
+    case kEXor:
+        out  << "^";
+        break;
+
+    case kELAnd:
+        out << "&&";
+        break;
+
+    case kELOr:
+        out << "||";
+        break;
+    }
+
+    out << "\"";
+
+    if (fName!=gsDefName || fTitle!=gsDefTitle)
+    {
+        out << ", \"" << fName << "\"";
+        if (fTitle!=gsDefTitle)
+            out << ", \"" << fTitle << "\"";
+    }
+    out << ");" << endl << endl;
+
+    MIter Next(&fFilters);
+
+    MParContainer *cont = NULL;
+    while ((cont=Next()))
+    {
+        cont->SavePrimitive(out, "");
+
+        out << "   " << ToLower(fName) << ".AddToList(&";
+        out << cont->GetUniqueName() << ");" << endl << endl;
+    }
+}
+
+TString MFilterList::GetRule(Option_t *opt) const
+{
+    TString str(opt);
+    const Bool_t verbose = str.Contains("V", TString::kIgnoreCase);
+
+    TString ret = "(";
+
+    TIter Next(&fFilters);
+
+    MFilter *filter=(MFilter*)Next();
+
+    //
+    // loop over all filters
+    //
+    if (!filter)
+        return "<empty>";
+
+    ret += filter->GetRule();
+
+    while ((filter=(MFilter*)Next()))
+    {
+        switch (fFilterType)
+        {
+        case kEAnd:
+            ret += (verbose?" and ":" & ");
+            break;
+
+        case kEOr:
+            ret += (verbose?" or ":" | ");
+            break;
+
+        case kEXor:
+            ret += (verbose?" xor ":" ^ ");
+            break;
+
+        case kELAnd:
+            ret += (verbose?" land ":" && ");
+            break;
+
+        case kELOr:
+            ret += (verbose?" lor ":" || ");
+            break;
+        }
+
+        ret += filter->GetRule();
+    }
+
+    return ret+")";
+}
Index: trunk/MagicSoft/Mars/mfbase/MFilterList.h
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MFilterList.h	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/MFilterList.h	(revision 3330)
@@ -0,0 +1,58 @@
+#ifndef MARS_MFilterList
+#define MARS_MFilterList
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+//  MFilterList                                                            //
+//                                                                         //
+//  List of several filters                                                //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef ROOT_TOrdCollection
+#include <TOrdCollection.h>
+#endif
+#ifndef MARS_MFilter
+#include "MFilter.h"
+#endif
+
+class MParList;
+
+class MFilterList : public MFilter
+{
+private:
+    TOrdCollection fFilters;	// Container for the filters
+
+    typedef enum { kEAnd, kEOr, kEXor, kELAnd, kELOr } FilterType_t;
+    FilterType_t fFilterType;
+
+    enum { kIsOwner = BIT(14) };
+
+    void StreamPrimitive(ofstream &out) const;
+
+public:
+    MFilterList(const char *type="&&", const char *name=NULL, const char *title=NULL);
+    MFilterList(MFilterList &ts);
+    ~MFilterList()
+    {
+        if (TestBit(kIsOwner))
+            fFilters.SetOwner();
+    }
+
+    Bool_t AddToList(MFilter *filter);
+    void SetOwner(Bool_t enable=kTRUE) { enable ? SetBit(kIsOwner) : ResetBit(kIsOwner); }
+
+    Bool_t IsExpressionTrue() const;
+
+    void Print(Option_t *opt = "") const;
+    TString GetRule() const { return GetRule(""); }
+    TString GetRule(Option_t *opt) const;
+
+    Int_t PreProcess(MParList *pList);
+    Int_t Process();
+    Int_t PostProcess();
+
+    ClassDef(MFilterList, 1)		// List to combine several filters logically
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mfbase/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mfbase/Makefile	(revision 3330)
+++ trunk/MagicSoft/Mars/mfbase/Makefile	(revision 3330)
@@ -0,0 +1,56 @@
+##################################################################
+#
+#   makefile
+# 
+#   for the MARS software
+#
+##################################################################
+# @maintitle
+
+# @code
+
+#
+#  please change all system depend values in the 
+#  config.mk.${OSTYPE} file 
+#
+#
+include ../Makefile.conf.$(OSTYPE)
+include ../Makefile.conf.general
+
+# @endcode 
+
+INCLUDES = -I. -I../mbase -I../mdata
+
+# @code 
+
+CINT     = FBase
+LIB      = mfbase.a
+
+#------------------------------------------------------------------------------
+
+.SUFFIXES: .c .cc .cxx .h .hxx .o 
+
+SRCFILES = MF.cc \
+           MFilterList.cc \
+           MFEventSelector.cc \
+           MFEventSelector2.cc \
+	   MFDataChain.cc \
+	   MFDataMember.cc \
+           MFRealTimePeriod.cc
+
+SRCS    = $(SRCFILES)
+HEADERS = $(SRCFILES:.cc=.h)
+OBJS    = $(SRCFILES:.cc=.o) 
+
+############################################################
+
+all: $(LIB)
+
+include ../Makefile.rules
+
+#clean:	rmcint rmobjs rmcore rmlib
+
+mrproper:	clean rmbak
+
+# @endcode
+
Index: trunk/MagicSoft/Mars/mfilter/MF.cc
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MF.cc	(revision 3329)
+++ 	(revision )
@@ -1,484 +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): Thomas Bretz  01/2002 <mailto:tbretz@uni-sw.gwdg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2002
-!
-!
-\* ======================================================================== */
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// MF                                                              
-//
-// With this filter you can filter in all variables from Mars parameter
-// containers.
-//
-// In the constructor you can give the filter rule, like
-//   "MHillas.fLength < 15"
-// Where MHillas is the name of the parameter container in the parameter
-// list and fLength is the name of the data member which should be used
-// for the filter rule. If the name of the container is use specified
-// (MyHillas) the name to give would be:
-//   "MyHillas.fLength < 15"
-//
-// Also more difficult rules are allowed, like:
-//   "MHillas.fWidth<0.5 && MHillas.fLength<0.6"
-//
-// You can also use brackets:
-//   "MHillas.fSize>200 || (MHillas.fWidth<0.5 && MHillas.fLength<0.6)"
-//
-// If you want to use mathematic expressions (as defined in MDataChain)
-// you must encapsulate it in {}-Brackets, eg:
-//   "{log10(MHillas.fSize)}>3"
-//
-// The allowed logigal conditionals are:
-//   &&: logical and
-//   ||: logical or
-//   ^:  exclusive or
-//
-// As conditional signs, for now, only:
-//   <, >
-// are allowed.
-//
-//   -------->  '==' is NOT supported!
-//
-//
-// Warning: There is no priority rule build in. So better use brackets
-//   to get correct results. The rule is parsed/evaluated from the left
-//   to the right, which means:
-//
-//   "MHillas.fSize>200 || MHillas.fWidth<0.5 && MHillas.fLength<0.6"
-//
-//    is parses as
-//
-//   "(MHillas.fSize>200 || MHillas.fWidth<0.5) && MHillas.fLength<0.6"
-//
-//
-//  If you intend to use Data Chains in filters enclose the chains in
-//  this {}-parenthesis, eg.
-//
-//   "{MHillas.fSize*MHillas.fWidth}<0.5"
-//
-// FIXME: The possibility to use also complete filters is missing.
-//        Maybe we can use gInterpreter->Calc("") for this.
-//        gROOT->ProcessLineFast("line");
-//
-/////////////////////////////////////////////////////////////////////////////
-#include "MF.h"
-
-#include <ctype.h>        // isalnum, ...
-#include <stdlib.h>       // strtod, ...
-#include <fstream>        // ofstream, ...
-
-#include <TMethodCall.h>
-
-#include "MParList.h"
-
-#include "MFilterList.h"
-#include "MFDataChain.h"
-#include "MFDataMember.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-ClassImp(MF);
-
-using namespace std;
-
-const TString MF::gsDefName  = "MF";
-const TString MF::gsDefTitle = "Filter setup by a text-rule";
-
-// --------------------------------------------------------------------------
-//
-// Default Constructor. Don't use.
-//
-MF::MF() : fF(NULL)
-{
-    fName  = gsDefName.Data();
-    fTitle = gsDefTitle.Data();
-}
-
-// --------------------------------------------------------------------------
-//
-// Constructor. For the text describing the filter rule please see
-// the class description above.
-//
-MF::MF(const char *text, const char *name, const char *title)
-{
-    fName  = name  ? name  : gsDefName.Data();
-    fTitle = title ? title : gsDefTitle.Data();
-
-    *fLog << inf << "Trying to resolve filter rule..." << endl;
-    if (!(fF=ParseString(text, 1)))
-    {
-        *fLog << err << dbginf << "Parsing '" << text << "' failed." << endl;
-        return;
-    }
-
-    *fLog << inf << endl;
-    *fLog << "Using Filter rule " << fF->GetName();
-    *fLog << " for " << fName << ":" << endl;
-    fF->Print();
-    *fLog << endl << endl;
-}
-
-// --------------------------------------------------------------------------
-//
-// Destructor. Delete filters.
-//
-MF::~MF()
-{
-    if (fF)
-        delete fF;
-}
-
-// --------------------------------------------------------------------------
-//
-// Returns the number of alphanumeric characters (including '.')
-// in the given string
-//
-Int_t MF::IsAlNum(TString txt) const
-{
-    int l = txt.Length();
-    for (int i = 0; i<l; i++)
-        if (!isalnum(txt[i]) && txt[i]!='.' && txt[i]!=';')
-            return i;
-
-    return l;
-}
-
-MFilter *MF::ParseRule(TString &txt, MFilter *filter0, Int_t level) const
-{
-    TString text;
-
-    Bool_t isrule = kFALSE;
-
-    if (txt[0]=='{')
-    {
-        //
-        // Search for the corresponding bracket
-        //
-        Int_t first=1;
-        for (int cnt=0; first<txt.Length(); first++)
-        {
-            if (txt[first]=='{')
-                cnt++;
-            if (txt[first]=='}')
-                cnt--;
-
-            if (cnt==-1)
-                break;
-        }
-
-        if (first==txt.Length())
-        {
-            *fLog << err << dbginf << "Syntax Error: '}' missing." << endl;
-            return NULL;
-        }
-
-        //
-        // Make a copy of the 'interieur' and delete the substringä
-        // including the brackets
-        //
-        TString sub = txt(1, first-1);
-        txt.Remove(0, first+1);
-
-        text=sub;
-        isrule = kTRUE;
-    }
-    else
-    {
-        int i = IsAlNum(txt);
-
-        if (i==0)
-        {
-            *fLog << err << dbginf << "Syntax Error: Name of data member missing in '" << txt << "'" << endl;
-            return NULL;
-        }
-
-        text = txt(0, i);
-
-        txt.Remove(0, i);
-    }
-
-    txt = txt.Strip(TString::kBoth);
-
-    if (txt.IsNull())
-    {
-        *fLog << err << dbginf << "Syntax Error: No conditional in '" << text << "'" << endl;
-        return NULL;
-    }
-
-    char c;
-    switch (txt[0])
-    {
-    case '>':
-    case '<':
-        c = txt[0];
-        txt.Remove(0, 1);
-        break;
-
-    default:
-        *fLog << err << dbginf << "Syntax Error: Conditional '" << txt[0] << "' unknown." << endl;
-        return NULL;
-    }
-
-    char *end;
-    Double_t num = strtod(txt.Data(), &end);
-    if (!end || txt.Data()==end)
-    {
-        *fLog << err << dbginf << "Error trying to convert '" << txt << "' to value." << endl;
-        return NULL;
-    }
-
-    txt.Remove(0, end-txt.Data());
-
-    MFilter *newfilter;
-    if (isrule)
-    {
-        Int_t lvl = gLog.GetDebugLevel();
-        gLog.SetDebugLevel(1);
-        newfilter = new MFDataChain(text.Data(), c, num);
-        newfilter->SetName(Form("Chain%02d%c%f", level, c, num));
-        gLog.SetDebugLevel(lvl);
-    }
-    else
-    {
-        newfilter = new MFDataMember(text.Data(), c, num);
-        newfilter->SetName(Form("%s%c%f", text.Data(), c, num));
-    }
-
-    return newfilter;
-}
-// --------------------------------------------------------------------------
-//
-// Parse a text string. Returns a corresponding filter of filter list.
-//
-MFilter *MF::ParseString(TString txt, Int_t level)
-{
-    MFilter *filter0=NULL;
-
-    TString type;
-    int nlist = 0;
-
-    while (!txt.IsNull())
-    {
-        MFilter *newfilter = NULL;
-
-        txt = txt.Strip(TString::kBoth);
-
-        //*fLog << all << setw(level) << " " << "Text: " << level << " '" << txt << "'" << endl;
-
-        switch (txt[0])
-        {
-        case '(':
-            {
-                //
-                // Search for the corresponding bracket
-                //
-                Int_t first=1;
-                for (int cnt=0; first<txt.Length(); first++)
-                {
-                    if (txt[first]=='(')
-                        cnt++;
-                    if (txt[first]==')')
-                        cnt--;
-
-                    if (cnt==-1)
-                        break;
-                }
-
-                if (first==txt.Length())
-                {
-                    *fLog << err << dbginf << "Syntax Error: ')' missing." << endl;
-                    if (filter0)
-                        delete filter0;
-                    return NULL;
-                }
-
-                //
-                // Make a copy of the 'interieur' and delete the substringä
-                // including the brackets
-                //
-                TString sub = txt(1, first-1);
-                txt.Remove(0, first+1);
-
-                //
-                // Parse the substring
-                //
-                newfilter = ParseString(sub, level+1);
-                if (!newfilter)
-                {
-                    *fLog << err << dbginf << "Parsing '" << sub << "' failed." << endl;
-                    if (filter0)
-                        delete filter0;
-                    return NULL;
-                }
-            }
-            break;
-
-        case ')':
-            *fLog << err << dbginf << "Syntax Error: Too many ')'" << endl;
-            if (filter0)
-                delete filter0;
-            return NULL;
-
-
-        case '&':
-        case '|':
-        case '^':
-            if (filter0)
-            {
-                //
-                // Check for the type of the conditional
-                //
-                TString is = txt[0];
-                txt.Remove(0, 1);
-
-                if (is==txt[0] && is!='^')
-                {
-                    is += txt[0];
-                    txt.Remove(0, 1);
-                }
-
-                //
-                // If no filter is available or the available filter
-                // is of a different conditional we have to create a new
-                // filter list with the new conditional
-                //
-                if (!filter0->InheritsFrom(MFilterList::Class()) || type!=is)
-                {
-                    MFilterList *list = new MFilterList(is);
-                    list->SetName(Form("List_%s_%d", (const char*)is, 10*level+nlist++));
-
-                    list->SetOwner();
-                    list->AddToList(filter0);
-                    filter0 = list;
-
-                    type = is;
-                }
-                continue;
-            }
-
-            *fLog << err << dbginf << "Syntax Error: First argument of condition missing." << endl;
-            if (filter0)
-                delete filter0;
-            return NULL;
-
-        default:
-            newfilter = ParseRule(txt, filter0, level++);
-            if (!newfilter)
-            {
-                if (filter0)
-                    delete filter0;
-                return NULL;
-            }
-        }
-
-        if (!filter0)
-        {
-            filter0 = newfilter;
-            continue;
-        }
-
-        if (!filter0->InheritsFrom(MFilterList::Class()))
-            continue;
-
-        ((MFilterList*)filter0)->AddToList(newfilter);
-    }
-
-    return filter0;
-}
-
-// --------------------------------------------------------------------------
-//
-// PreProcess all filters.
-//
-Int_t MF::PreProcess(MParList *plist)
-{
-    if (!fF)
-    {
-        *fLog << err << dbginf << "No filter rule available." << endl;
-        return kFALSE;
-    }
-
-    if (!fF->CallPreProcess(plist))
-    {
-        *fLog << err << dbginf << "PreProcessing filters in ";
-        *fLog << fName << " failed." << endl;
-        return kFALSE;
-    }
-
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Process all filters.
-//
-Int_t MF::Process()
-{
-    return fF->CallProcess();
-}
-
-// --------------------------------------------------------------------------
-//
-//  Postprocess all filters.
-//
-Int_t MF::PostProcess()
-{
-    return fF->CallPostProcess();
-}
-
-// --------------------------------------------------------------------------
-//
-// Return the result of the filter rule.
-//
-Bool_t MF::IsExpressionTrue() const
-{
-    return fF->IsConditionTrue();
-}
-
-void MF::StreamPrimitive(ofstream &out) const
-{
-    out << "   MF " << GetUniqueName();
-
-    if (!fF)
-    {
-        out << ";" << endl;
-        return;
-    }
-
-    out << "(\"" << fF->GetRule() << "\"";
-        if (fName!=gsDefName || fTitle!=gsDefTitle)
-    {
-        out << "(\"" << fName << "\"";
-        if (fTitle!=gsDefTitle)
-            out << ", \"" << fTitle << "\"";
-    }
-    out << ");" << endl;
-
-}
-
-void MF::Print(Option_t *opt) const
-{
-    *fLog << all << underline << GetDescriptor() << endl;
-    fF->Print();
-    *fLog << endl << endl;
-}
Index: trunk/MagicSoft/Mars/mfilter/MF.h
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MF.h	(revision 3329)
+++ 	(revision )
@@ -1,48 +1,0 @@
-#ifndef MARS_MF
-#define MARS_MF
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MF                                                                      //
-//                                                                         //
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef MARS_MFilter
-#include "MFilter.h"
-#endif
-
-class MParList;
-class TMethodCall;
-
-class MF : public MFilter
-{
-private:
-    static const TString gsDefName;  //!
-    static const TString gsDefTitle; //!
-
-    MFilter *fF; // Filter
-
-    Int_t IsAlNum(TString txt) const;
-
-    MFilter *ParseRule(TString &txt, MFilter *filter0, Int_t level) const;
-    MFilter *ParseString(TString txt, Int_t level);
-
-    void StreamPrimitive(ofstream &out) const;
-
-public:
-    MF();
-    MF(const char *text, const char *name=NULL, const char *title=NULL);
-    ~MF();
-
-    Bool_t IsExpressionTrue() const;
-
-    Int_t PreProcess(MParList *pList);
-    Int_t Process();
-    Int_t PostProcess();
-
-    void Print(Option_t *opt="") const;
-
-    ClassDef(MF, 0) // A Filter for cuts in any data member
-};
-
-#endif
Index: trunk/MagicSoft/Mars/mfilter/MFDataChain.cc
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFDataChain.cc	(revision 3329)
+++ 	(revision )
@@ -1,126 +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): Thomas Bretz  11/2002 <mailto:tbretz@astro.uni-wueruburg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2002
-!
-!
-\* ======================================================================== */
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// MFDataChain                                                              
-//
-// With this filter you can filter in all variables from Mars parameter
-// containers using rules (for more details see MDataChain).
-//
-// In the constructor you can give the filter variable, like
-//   "sqrt(MHillas.fLength*MHillas.fLength)"
-// Where MHillas is the name of the parameter container in the parameter
-// list and fLength is the name of the data member which should be used
-// for the filter rule. If the name of the container is use specified
-// (MyHillas) the name to give would be:
-//   "MyHillas.fLength"
-//
-// For example:
-//   MFDataChain filter("sqr(MHillas.fLength)", '<', 150);
-//
-/////////////////////////////////////////////////////////////////////////////
-#include "MFDataChain.h"
-
-#include <fstream>
-
-#include <TMethodCall.h>
-
-#include "MParList.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-ClassImp(MFDataChain);
-
-using namespace std;
-
-// --------------------------------------------------------------------------
-//
-MFDataChain::MFDataChain(const char *member, const char type, const Double_t val,
-                         const char *name, const char *title)
-    : fData(member), fValue(val)
-{
-    fName  = name  ? name  : "MFDataChain";
-    fTitle = title ? title : "Filter using any data member of a class";
-
-    //AddToBranchList(member);
-
-    fFilterType = (type=='<' ? kELowerThan : kEGreaterThan);
-
-    if (type!='<' && type!='>')
-        *fLog << warn << dbginf << "Warning: Neither '<' nor '>' specified... using '>'." << endl;
-}
-
-// --------------------------------------------------------------------------
-//
-Int_t MFDataChain::PreProcess(MParList *plist)
-{
-    return fData.PreProcess(plist);
-}
-
-// --------------------------------------------------------------------------
-//
-Int_t MFDataChain::Process()
-{
-    switch (fFilterType)
-    {
-    case kELowerThan:
-        fResult = (fData.GetValue() < fValue);
-        return kTRUE;
-    case kEGreaterThan:
-        fResult = (fData.GetValue() > fValue);
-        return kTRUE;
-    }
-
-    return kFALSE;
-}
-
-void MFDataChain::Print(Option_t *) const
-{
-    *fLog << GetRule() << flush;
-}
-
-void MFDataChain::StreamPrimitive(ofstream &out) const
-{
-    out << "   MFDataChain " << GetUniqueName() << "(\"";
-    out << fData.GetRule() << "\", '";
-    out << (fFilterType==kELowerThan?"<":">");
-    out << "', " << fValue << ");" << endl;
-}
-
-TString MFDataChain::GetRule() const
-{
-    TString ret = "{";
-    ret += fData.GetRule();
-    ret += "}";
-    ret += fFilterType==kELowerThan?"<":">";
-
-    TString str;
-    str += fValue;
-
-    ret += str.Strip(TString::kBoth);
-    return ret;
-}
-
Index: trunk/MagicSoft/Mars/mfilter/MFDataChain.h
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFDataChain.h	(revision 3329)
+++ 	(revision )
@@ -1,47 +1,0 @@
-#ifndef MARS_MFDataChain
-#define MARS_MFDataChain
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MFDataChain                                                                 //
-//                                                                         //
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef MARS_MFilter
-#include "MFilter.h"
-#endif
-#ifndef MARS_MDataChain
-#include "MDataChain.h"
-#endif
-
-class MParList;
-
-class MFDataChain : public MFilter
-{
-private:
-    MDataChain fData;
-
-    typedef enum { kELowerThan, kEGreaterThan } FilterType_t;
-    FilterType_t fFilterType;
-
-    Bool_t  fResult;           //!
-    Double_t fValue;
-
-    void StreamPrimitive(ofstream &out) const;
-
-    Int_t PreProcess(MParList *pList);
-    Int_t Process();
-
-public:
-    MFDataChain(const char *member, const char type, const Double_t val,
-                const char *name=NULL, const char *title=NULL);
-
-    Bool_t IsExpressionTrue() const { return fResult; }
-
-    void Print(Option_t *opt = "") const;
-    TString GetRule() const;
-
-    ClassDef(MFDataChain, 1) // A Filter for cuts in any data member
-};
-
-#endif
Index: trunk/MagicSoft/Mars/mfilter/MFDataMember.cc
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFDataMember.cc	(revision 3329)
+++ 	(revision )
@@ -1,169 +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): Thomas Bretz  01/2002 <mailto:tbretz@astro.uni-wueruburg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2002
-!
-!
-\* ======================================================================== */
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// MFDataMember                                                              
-//
-// With this filter you can filter in all variables from Mars parameter
-// containers.
-//
-// In the constructor you can give the filter variable, like
-//   "MHillas.fLength"
-// Where MHillas is the name of the parameter container in the parameter
-// list and fLength is the name of the data member which should be used
-// for the filter rule. If the name of the container is use specified
-// (MyHillas) the name to give would be:
-//   "MyHillas.fLength"
-//
-// For example:
-//   MFDataMember filter("MHillas.fLength", '<', 150);
-//
-// You can test '<', '>' and '='. Warning: Using '=' may give strange results
-// in case you are comparing floating point values.
-//
-// In case the data member is detected to be an integer value, both
-// the data member and the val given as argument in the constructor
-// are castet to Long_t.
-//
-// To test != use the SetInverted() member function.
-//
-/////////////////////////////////////////////////////////////////////////////
-#include "MFDataMember.h"
-
-#include <fstream>
-
-#include <TMethodCall.h>
-
-#include "MParList.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-ClassImp(MFDataMember);
-
-using namespace std;
-
-// --------------------------------------------------------------------------
-//
-MFDataMember::MFDataMember(const char *member, const char type, const Double_t val,
-                           const char *name, const char *title)
-    : fData(member), fValue(val)
-{
-    fName  = name  ? name  : "MFDataMember";
-    fTitle = title ? title : "Filter using any data member of a class";
-
-    AddToBranchList(member);
-
-    switch (type)
-    {
-    case '>': fFilterType = kEGreaterThan; break;
-    case '<': fFilterType = kELowerThan;   break;
-    case '=': fFilterType = kEEqual;       break;
-    default:  fFilterType = kEGreaterThan; break;
-    }
-
-    if (type!='<' && type!='=' && type!='>')
-        *fLog << warn << dbginf << "Warning: Neither '<' nor '=' nor '>' specified... using '>'." << endl;
-}
-
-// --------------------------------------------------------------------------
-//
-Int_t MFDataMember::PreProcess(MParList *plist)
-{
-    return fData.PreProcess(plist);
-}
-
-// --------------------------------------------------------------------------
-//
-Int_t MFDataMember::Process()
-{
-    if (fData.IsInt())
-    {
-        switch (fFilterType)
-        {
-        case kELowerThan:
-            fResult = ((Long_t)fData.GetValue() < (Long_t)fValue);
-            return kTRUE;
-        case kEGreaterThan:
-            fResult = ((Long_t)fData.GetValue() > (Long_t)fValue);
-            return kTRUE;
-        case kEEqual:
-            fResult = ((Long_t)fData.GetValue() == (Long_t)fValue);
-            return kTRUE;
-        }
-    }
-    else
-    {
-        switch (fFilterType)
-        {
-        case kELowerThan:
-            fResult = (fData.GetValue() < fValue);
-            return kTRUE;
-        case kEGreaterThan:
-            fResult = (fData.GetValue() > fValue);
-            return kTRUE;
-        case kEEqual:
-            fResult = (fData.GetValue() == fValue);
-            return kTRUE;
-        }
-    }
-
-    return kFALSE;
-}
-
-void MFDataMember::Print(Option_t *) const
-{
-    *fLog << GetRule() << flush;
-}
-
-void MFDataMember::StreamPrimitive(ofstream &out) const
-{
-    out << "   MFDataMember " << GetUniqueName() << "(\"";
-    out << fData.GetRule() << "\", '";
-    switch (fFilterType)
-    {
-    case kEGreaterThan: out << '>'; break;
-    case kELowerThan:   out << '<'; break;
-    case kEEqual:       out << '='; break;
-    }
-    out << "', " << fValue << ");" << endl;
-}
-
-TString MFDataMember::GetRule() const
-{
-    TString ret = fData.GetRule();
-    switch (fFilterType)
-    {
-    case kEGreaterThan: ret +='>'; break;
-    case kELowerThan:   ret +='<'; break;
-    case kEEqual:       ret +='='; break;
-    }
-
-    TString str;
-    str += fValue;
-
-    return ret+str.Strip(TString::kBoth);
-}
-
Index: trunk/MagicSoft/Mars/mfilter/MFDataMember.h
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFDataMember.h	(revision 3329)
+++ 	(revision )
@@ -1,44 +1,0 @@
-#ifndef MARS_MFDataMember
-#define MARS_MFDataMember
-
-#ifndef MARS_MFilter
-#include "MFilter.h"
-#endif
-#ifndef MARS_MDataMember
-#include "MDataMember.h"
-#endif
-
-class MParList;
-
-class MFDataMember : public MFilter
-{
-private:
-    MDataMember fData;
-
-    typedef enum { kELowerThan, kEGreaterThan, kEEqual } FilterType_t;
-    FilterType_t fFilterType;
-
-    Bool_t  fResult;           //!
-    Double_t fValue;
-
-    void StreamPrimitive(ofstream &out) const;
-
-    Int_t PreProcess(MParList *pList);
-    Int_t Process();
-
-public:
-    enum {
-        kIsInt = BIT(14)
-    };
-    MFDataMember(const char *member, const char type, const Double_t val,
-                 const char *name=NULL, const char *title=NULL);
-
-    Bool_t IsExpressionTrue() const { return fResult; }
-
-    void Print(Option_t *opt = "") const;
-    TString GetRule() const;
-
-    ClassDef(MFDataMember, 1) // A Filter for cuts in any data member
-};
-
-#endif
Index: trunk/MagicSoft/Mars/mfilter/MFEventSelector.cc
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFEventSelector.cc	(revision 3329)
+++ 	(revision )
@@ -1,228 +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): Thomas Bretz, 01/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2003
-!
-!
-\* ======================================================================== */
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// 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.
-//
-// This filter can be used for a random split...
-//
-// 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
-// MRead inheriting from MRead):
-//   MFEventSelector sel;
-//   sel.SetNumSelectEvts(2000);
-//   MFillH filler(...);
-//   filler.SetFilter(&sel);
-//   tlist.AddToList(&sel);
-//   tlist.AddToList(&filler);
-//
-// If you don't have MRead 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!
-//
-// Remark: You can also use the filter together with MContinue
-//
-//
-// FIXME: Merge MFEventSelector and MFEventSelector2
-//
-/////////////////////////////////////////////////////////////////////////////
-#include "MFEventSelector.h"
-
-#include <TRandom.h>
-
-#include "MParList.h"
-#include "MTaskList.h"
-#include "MRead.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-ClassImp(MFEventSelector);
-
-using namespace std;
-
-static const TString gsDefName  = "MFEventSelector";
-static const TString gsDefTitle = "Filter to select events";
-
-// --------------------------------------------------------------------------
-//
-// 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();
-}
-
-// --------------------------------------------------------------------------
-//
-// Set a probability with which events are selected. Eg, f=0.5
-// will select roughly half of all events.
-//
-void MFEventSelector::SetSelectionRatio(Float_t f)
-{
-    if (f < 0)
-    {
-        *fLog << warn << "MFEventSelector::SetSelectionRatio: WARNING - Probability less than 0... set to 0." << endl;
-        f = 0;
-    }
-
-    if (f > 1)
-    {
-        *fLog << warn << "MFEventSelector::SetSelectionRatio: WARNING - Probability greater than 1... set to 1." << endl;
-        f = 1;
-    }
-    fSelRatio = f;
-}
-
-// --------------------------------------------------------------------------
-//
-// PreProcess all filters.
-//
-Int_t MFEventSelector::PreProcess(MParList *plist)
-{
-    fNumSelectedEvts = 0;
-
-    // In the case a ratio was set by the user we are done.
-    if (fSelRatio>0)
-        return kTRUE;
-
-    // If the number of total events wasn't set try to get it
-    if (fNumTotalEvts<0)
-    {
-        MTaskList *tlist = (MTaskList*)plist->FindObject("MTaskList");
-        if (!tlist)
-        {
-            *fLog << err << "Can't determin total number of events... no MTaskList." << endl;
-            return kFALSE;
-        }
-
-        MRead *read = (MRead*)tlist->FindObject("MRead");
-        if (!read)
-        {
-            *fLog << err << "Can't determin total number of events from 'MRead'." << endl;
-            return kFALSE;
-        }
-        fNumTotalEvts = read->GetEntries();
-
-        SetBit(kNumTotalFromFile);
-    }
-
-    // Calculate selection probability
-    fSelRatio = (Double_t)fNumSelectEvts/fNumTotalEvts;
-
-    *fLog << inf << "MFEventSelector:  Selection probability = " << fNumSelectEvts;
-    *fLog << "/" << fNumTotalEvts << " = " << Form("%.2f", fSelRatio) << endl;
-
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Process all filters, FIXME: Make it fit the requested number of events
-// exactly like it is done in MFEventSelector2. This can be done by merging
-// both classes!
-//
-Int_t MFEventSelector::Process()
-{
-    fResult = gRandom->Uniform() < fSelRatio;
-
-    if (!fResult)
-        return kTRUE;
-
-    fNumSelectedEvts++;
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-//  Postprocess all filters.
-//
-Int_t MFEventSelector::PostProcess()
-{
-    //---------------------------------
-    if (GetNumExecutions() != 0)
-    {
-        const Double_t sel = (Double_t)fNumSelectedEvts/GetNumExecutions();
-        const UInt_t   non = GetNumExecutions()-fNumSelectedEvts;
-
-        *fLog << inf << dec << setfill(' ') << endl;
-        *fLog << GetDescriptor() << " execution statistics:" << endl;
-
-        *fLog << " " << setw(7) << non << " (" << setw(3);
-        *fLog << (int)(100*(1-sel)) << "%) Events not selected" << endl;
-
-        *fLog << " " << setw(7) << fNumSelectedEvts << " (";
-        *fLog << (int)(100*sel) << "%) Events selected!" << endl;
-        *fLog << endl;
-    }
-
-    //---------------------------------
-    if (TestBit(kNumTotalFromFile))
-        fNumTotalEvts = -1;
-
-    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 3329)
+++ 	(revision )
@@ -1,41 +1,0 @@
-#ifndef MARS_MFEventSelector
-#define MARS_MFEventSelector
-
-#ifndef MARS_MFilter
-#include "MFilter.h"
-#endif
-
-class MParList;
-
-class MFEventSelector : public MFilter
-{
-private:
-    Int_t   fNumTotalEvts;    // Number of total events from which are selected
-    Int_t   fNumSelectEvts;   // Number of events to be selected
-    Float_t fSelRatio;        // Selection Probability
-
-    Int_t   fNumSelectedEvts; //! Number of events which have been selected
-
-    Bool_t  fResult;          //! Reseult of a single selection
-
-    void StreamPrimitive(ofstream &out) const;
-
-    Int_t PreProcess(MParList *pList);
-    Int_t Process();
-    Int_t PostProcess();
-
-    enum { kNumTotalFromFile = BIT(14) };
-
-public:
-    MFEventSelector(const char *name=NULL, const char *title=NULL);
-
-    Bool_t IsExpressionTrue() const { return fResult; }
-
-    void SetNumTotalEvts(Int_t n)  { fNumTotalEvts = n; ResetBit(kNumTotalFromFile); }
-    void SetNumSelectEvts(Int_t n) { fNumSelectEvts = n; }
-    void SetSelectionRatio(Float_t f);
-
-    ClassDef(MFEventSelector, 0) // A filter to do a random selection of events
-};
-
-#endif
Index: trunk/MagicSoft/Mars/mfilter/MFEventSelector2.cc
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFEventSelector2.cc	(revision 3329)
+++ 	(revision )
@@ -1,500 +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): Thomas Bretz,   01/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
-!   Author(s): Wolfgang Wittek 11/2003 <mailto:wittek@mppmu.mpg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2003
-!
-!
-\* ======================================================================== */
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// MFEventSelector2
-//
-// This is a filter to make a selection of events from a file.
-//
-// see Construtor for more instructions and the example below:
-//
-// --------------------------------------------------------------------
-//
-// void select()
-// {
-//     MParList plist;
-//     MTaskList tlist;
-// 
-//     MStatusDisplay *d=new MStatusDisplay;
-// 
-//     plist.AddToList(&tlist);
-// 
-//     MReadTree read("Events", "myinputfile.root");
-//     read.DisableAutoScheme();
-//     // Accelerate execution...
-//     // read.EnableBranch("MMcEvt.fTelescopeTheta");
-// 
-//     // create nominal distribution (theta converted into degrees)
-//     MH3 nomdist("r2d(MMcEvt.fTelescopeTheta)");
-//     MBinning binsx;
-//     binsx.SetEdges(5, 0, 45);   // five bins from 0deg to 45deg
-//     MH::SetBinning(&nomdist.GetHist(), &binsx);
-//
-//     // use this to create a nominal distribution in 2D
-//     //  MH3 nomdist("r2d(MMcEvt.fTelescopeTheta)", "MMcEvt.fEnergy");
-//     //  MBinning binsy;
-//     //  binsy.SetEdgesLog(5, 10, 10000);
-//     //  MH::SetBinning((TH2*)&nomdist.GetHist(), &binsx, &binsy);
-//
-//     // Fill the nominal distribution with whatever you want:
-//     for (int i=0; i<nomdist.GetNbins(); i++)
-//         nomdist.GetHist().SetBinContent(i, i*i);
-// 
-//     MFEventSelector2 test(nomdist);
-//     test.SetNumMax(9999);  // total number of events selected
-//     MContinue cont(&test);
-// 
-//     MEvtLoop run;
-//     run.SetDisplay(d);
-//     run.SetParList(&plist);
-//     tlist.AddToList(&read);
-//     tlist.AddToList(&cont);
-// 
-//     if (!run.Eventloop())
-//         return;
-// 
-//     tlist.PrintStatistics();
-// }
-// 
-// --------------------------------------------------------------------
-//
-// The random number is generated using gRandom->Rndm(). 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 or as a selector
-// in the reading task: This won't work!
-//
-// Remark: You can also use the filter together with MContinue
-//
-//
-// FIXME: Merge MFEventSelector and MFEventSelector2
-//
-/////////////////////////////////////////////////////////////////////////////
-#include "MFEventSelector2.h"
-
-#include <TRandom.h>        // gRandom
-#include <TCanvas.h>        // TCanvas
-
-#include "MH3.h"            // MH3
-#include "MRead.h"          // MRead
-#include "MEvtLoop.h"       // MEvtLoop
-#include "MTaskList.h"      // MTaskList
-#include "MBinning.h"       // MBinning
-#include "MFillH.h"         // MFillH
-#include "MParList.h"       // MParList
-#include "MStatusDisplay.h" // MStatusDisplay
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-ClassImp(MFEventSelector2);
-
-using namespace std;
-
-const TString MFEventSelector2::gsDefName  = "MFEventSelector2";
-const TString MFEventSelector2::gsDefTitle = "Filter to select events with a given distribution";
-
-// --------------------------------------------------------------------------
-//
-// Constructor. Takes a reference to an MH3 which gives you
-//  1) The nominal distribution. The distribution is renormalized, so
-//     that the absolute values doesn't matter. To crop the distribution
-//     to a nominal value of total events use SetNumMax
-//  2) The dimension of the MH3 determins the dimension in which the
-//     event selector will work, eg
-//       MH3 hist("MMcEvt.fTelescopeTheta", "MMcEvt.fEnergy");
-//     Would result in a redistribution of Theta and Energy.
-//  3) The given rules are the variables which are used for the
-//     redistribution, eg:
-//       MH3 hist("MMcEvt.fTelescopeTheta");
-//     would result in redistributing Theta.
-//       MH3 hist("cos(MMcEvt.fTelescopeTheta)");
-//     would result in redistributing cos(Theta).
-//
-//  If the reference distribution doesn't contain entries (GetEntries()==0)
-//     the original distribution will be used as the nominal distribution;
-//     note that also in this case a dummy nominal distribution has to be
-//     provided in the first argument (the dummy distribution defines the
-//     variable(s) of interest and the binnings)
-//
-
-MFEventSelector2::MFEventSelector2(MH3 &hist, const char *name, const char *title)
-: fHistOrig(NULL), fHistNom(&hist), fHistRes(NULL),
-  fDataX(hist.GetRule('x')), fDataY(hist.GetRule('y')),
-  fDataZ(hist.GetRule('z')), fNumMax(-1)
-{
-    fName  = name  ? (TString)name  : gsDefName;
-    fTitle = title ? (TString)title : gsDefTitle;
-}
-
-// --------------------------------------------------------------------------
-//
-// Delete fHistRes if instatiated
-//
-MFEventSelector2::~MFEventSelector2()
-{
-    if (fHistRes)
-        delete fHistRes;
-}
-
-//---------------------------------------------------------------------------
-//
-// Recreate a MH3 from fHistNom used as a template. Copy the Binning
-// from fHistNom to the new histogram, and return a pointer to the TH1
-// base class of the MH3.
-//
-TH1 &MFEventSelector2::InitHistogram(MH3* &hist)
-{
-    // if fHistRes is already allocated delete it first
-    if (hist)
-        delete hist;
-
-    // duplicate the fHistNom histogram
-    hist = (MH3*)fHistNom->New();
-
-    // copy binning from one histogram to the other one
-    MH::SetBinning(&hist->GetHist(), &fHistNom->GetHist());
-
-    return hist->GetHist();
-}
-
-// --------------------------------------------------------------------------
-//
-// Try to read the present distribution from the file. Therefore the
-// Reading task of the present loop is used in a new eventloop.
-//
-Bool_t MFEventSelector2::ReadDistribution(MRead &read)
-{
-    if (read.GetEntries() > kMaxUInt) // FIXME: LONG_MAX ???
-    {
-        *fLog << err << "kIntMax exceeded." << endl;
-        return kFALSE;
-    }
-
-    *fLog << inf << underline << endl;
-    *fLog << "MFEventSelector2::ReadDistribution:" << endl;
-    *fLog << " - Start of eventloop to generate the original distribution..." << endl;
-
-    MEvtLoop run(GetName());
-    MParList plist;
-    MTaskList tlist;
-    plist.AddToList(&tlist);
-    run.SetParList(&plist);
-
-    MBinning binsx("BinningMH3X");
-    MBinning binsy("BinningMH3Y");
-    MBinning binsz("BinningMH3Z");
-    binsx.SetEdges(fHistNom->GetHist(), 'x');
-    binsy.SetEdges(fHistNom->GetHist(), 'y');
-    binsz.SetEdges(fHistNom->GetHist(), 'z');
-    plist.AddToList(&binsx);
-    plist.AddToList(&binsy);
-    plist.AddToList(&binsz);
-
-    MFillH fill(fHistOrig);
-    fill.SetBit(MFillH::kDoNotDisplay);
-    tlist.AddToList(&read);
-    tlist.AddToList(&fill);
-    run.SetDisplay(fDisplay);
-    if (!run.Eventloop())
-    {
-        *fLog << err << dbginf << "Evtloop in MFEventSelector2::ReadDistribution failed." << endl;
-        return kFALSE;
-    }
-
-    tlist.PrintStatistics();
-
-    *fLog << inf;
-    *fLog << "MFEventSelector2::ReadDistribution:" << endl;
-    *fLog << " - Original distribution has " << fHistOrig->GetHist().GetEntries() << " entries." << endl;
-    *fLog << " - End of eventloop to generate the original distribution." << endl;
-
-    return read.Rewind();
-}
-
-// --------------------------------------------------------------------------
-//
-// After reading the histograms the arrays used for the random event
-// selction are created. If a MStatusDisplay is set the histograms are
-// displayed there.
-//
-void MFEventSelector2::PrepareHistograms()
-{
-    TH1 &ho = fHistOrig->GetHist();
-
-    //-------------------
-    // if requested
-    // set the nominal distribution equal to the original distribution
-
-    const Bool_t useorigdist = fHistNom->GetHist().GetEntries()==0;
-    TH1 *hnp =  useorigdist ? (TH1*)(fHistOrig->GetHist()).Clone() : &fHistNom->GetHist();
-
-    TH1 &hn = *hnp;
-    //--------------------
-
-    // normalize to number of counts in primary distribution
-    hn.Scale(1./hn.Integral());
-
-    MH3 *h3 = NULL;
-    TH1 &hist = InitHistogram(h3);
-
-    hist.Divide(&hn, &ho);
-    hist.Scale(1./hist.GetMaximum());
-
-    if (fCanvas)
-    {
-        fCanvas->Clear();
-        fCanvas->Divide(2,2);
-
-        fCanvas->cd(1);
-        gPad->SetBorderMode(0);
-        hn.DrawCopy();
-
-        fCanvas->cd(2);
-        gPad->SetBorderMode(0);
-        ho.DrawCopy();
-    }
-    hn.Multiply(&ho, &hist);
-    hn.SetTitle("Resulting Nominal Distribution");
-
-    if (fNumMax>0)
-    {
-        *fLog << inf;
-        *fLog << "MFEventSelector2::PrepareHistograms:" << endl;
-        *fLog << " - requested number of events = " << fNumMax << endl;
-        *fLog << " - maximum number of events possible = " << hn.Integral() << endl;
-
-        if (fNumMax > hn.Integral())
-	{
-            *fLog << warn << "WARNING - Requested no.of events (" << fNumMax;
-            *fLog << ") is too high... reduced to " << hn.Integral() << endl;
-	}
-        else
-            hn.Scale(fNumMax/hn.Integral());
-    }
-
-    hn.SetEntries(hn.Integral()+0.5);
-    if (fCanvas)
-    {
-        fCanvas->cd(3);
-        gPad->SetBorderMode(0);
-        hn.DrawCopy();
-
-        fCanvas->cd(4);
-        gPad->SetBorderMode(0);
-        fHistRes->Draw();
-    }
-    delete h3;
-
-    const Int_t num = fHistRes->GetNbins();
-    fIs.Set(num);
-    fNom.Set(num);
-    for (int i=0; i<num; i++)
-    {
-        fIs[i]  = (Long_t)(ho.GetBinContent(i+1)+0.5);
-        fNom[i] = (Long_t)(hn.GetBinContent(i+1)+0.5);
-    }
-
-    if (useorigdist)
-      delete hnp;
-}
-
-// --------------------------------------------------------------------------
-//
-// PreProcess the data rules extracted from the MH3 nominal distribution
-//
-Bool_t MFEventSelector2::PreProcessData(MParList *parlist)
-{
-    switch (fHistNom->GetDimension())
-    {
-    case 3:
-        if (!fDataZ.PreProcess(parlist))
-        {
-            *fLog << err << "Preprocessing of rule for z-axis failed... abort." << endl;
-            return kFALSE;
-        }
-        // FALLTHROUGH!
-    case 2:
-        if (!fDataY.PreProcess(parlist))
-        {
-            *fLog << err << "Preprocessing of rule for y-axis failed... abort." << endl;
-            return kFALSE;
-        }
-        // FALLTHROUGH!
-    case 1:
-        if (!fDataX.PreProcess(parlist))
-        {
-            *fLog << err << "Preprocessing of rule for x-axis failed... abort." << endl;
-            return kFALSE;
-        }
-    }
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// PreProcess the filter. Means:
-//  1) Preprocess the rules
-//  2) Read The present distribution from the file.
-//  3) Initialize the histogram for the resulting distribution
-//  4) Prepare the random selection
-//  5) Repreprocess the reading task.
-//
-Int_t MFEventSelector2::PreProcess(MParList *parlist)
-{
-    memset(fCounter, 0, sizeof(fCounter));
-
-    MTaskList *tasklist = (MTaskList*)parlist->FindObject("MTaskList");
-    if (!tasklist)
-    {
-        *fLog << err << "MTaskList not found... abort." << endl;
-        return kFALSE;
-    }
-
-    MRead *read = (MRead*)tasklist->FindObject("MRead");
-    if (!read)
-    {
-        *fLog << err << "MRead not found... abort." << endl;
-        return kFALSE;
-    }
-
-    if (!PreProcessData(parlist))
-        return kFALSE;
-
-    InitHistogram(fHistOrig);
-    InitHistogram(fHistRes);
-
-    fHistNom->SetTitle("Users Nominal Distribution");
-    fHistOrig->SetTitle("Primary Distribution");
-    fHistRes->SetTitle("Resulting Distribution");
-
-    // Initialize online display if requested
-    fCanvas = fDisplay ? &fDisplay->AddTab(GetName()) : NULL;
-    if (fCanvas)
-        fHistOrig->Draw();
-
-    // Generate primary distribution
-    if (!ReadDistribution(*read))
-        return kFALSE;
-
-    // Prepare histograms and arrays for selection
-    PrepareHistograms();
-
-    return read->CallPreProcess(parlist);
-}
-
-// --------------------------------------------------------------------------
-//
-// Part of Process(). Select() at the end checks whether a selection should
-// be done or not. Under-/Overflowbins are rejected.
-//
-Bool_t MFEventSelector2::Select(Int_t bin)
-{
-    // under- and overflow bins are not counted
-    if (bin<0)
-        return kFALSE;
-
-    Bool_t rc = kFALSE;
-
-    if (gRandom->Rndm()*fIs[bin]<=fNom[bin])
-    {
-        // how many events do we still want to read in this bin
-        fNom[bin] -= 1;
-        rc = kTRUE;
-
-        // fill bin (same as Fill(valx, valy, valz))
-        TH1 &h = fHistRes->GetHist();
-        h.AddBinContent(bin+1);
-        h.SetEntries(h.GetEntries()+1);
-    }
-
-    // how many events are still pending to be read
-    fIs[bin] -= 1;
-
-    return rc;
-}
-
-// --------------------------------------------------------------------------
-//
-// fIs[i] contains the distribution of the events still to be read from
-// the file. fNom[i] contains the number of events in each bin which
-// are requested.
-// The events are selected by:
-//     gRandom->Rndm()*fIs[bin]<=fNom[bin]
-//
-Int_t MFEventSelector2::Process()
-{
-    // get x,y and z (0 if fData not valid)
-    const Double_t valx=fDataX.GetValue();
-    const Double_t valy=fDataY.GetValue();
-    const Double_t valz=fDataZ.GetValue();
-
-    // Get corresponding bin number and check
-    // whether a selection should be made
-    fResult = Select(fHistNom->FindFixBin(valx, valy, valz)-1);
-
-    fCounter[fResult ? 1 : 0]++;
-
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Update online display if set.
-//
-Int_t MFEventSelector2::PostProcess()
-{
-    //---------------------------------
-
-    if (GetNumExecutions()>0)
-    {
-      *fLog << inf << endl;
-      *fLog << GetDescriptor() << " execution statistics:" << endl;
-      *fLog << dec << setfill(' ');
-      *fLog << " " << setw(7) << fCounter[1] << " (" << setw(3)
-            << (int)(fCounter[0]*100/GetNumExecutions())
-            << "%) Events not selected" << endl;
-
-      *fLog << " " << fCounter[0] << " ("
-            << (int)(fCounter[1]*100/GetNumExecutions())
-            << "%) Events selected" << endl;
-      *fLog << endl;
-    }
-
-    //---------------------------------
-
-    if (fDisplay && fDisplay->HasCanvas(fCanvas))
-    {
-        fCanvas->cd(4);
-        fHistRes->DrawClone("nonew");
-        fCanvas->Modified();
-        fCanvas->Update();
-    }
-
-    return kTRUE;
-}
Index: trunk/MagicSoft/Mars/mfilter/MFEventSelector2.h
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFEventSelector2.h	(revision 3329)
+++ 	(revision )
@@ -1,68 +1,0 @@
-#ifndef MARS_MFEventSelector2
-#define MARS_MFEventSelector2
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MFEventSelector2                                                        //
-//                                                                         //
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef MARS_MFilter
-#include "MFilter.h"
-#endif
-#ifndef ROOT_TArrayL
-#include <TArrayL.h>
-#endif
-#ifndef MARS_MDataChain
-#include "MDataChain.h"
-#endif
-
-class TH1;
-class TCanvas;
-
-class MH3;
-class MRead;
-
-class MFEventSelector2 : public MFilter
-{
-private:
-    static const TString gsDefName;
-    static const TString gsDefTitle;
-
-    MH3       *fHistOrig; // original distribution of the events
-    MH3       *fHistNom;  // nominal distribution
-    MH3       *fHistRes;  // resulting distribution
-    MDataChain fDataX;    // data rule for the x-axis
-    MDataChain fDataY;    // data rule for the y-axis
-    MDataChain fDataZ;    // data rule for the z-axis
-    Long_t     fNumMax;   // Maximum number of selected events
-    TArrayL    fIs;       //! array storing the original distribution
-    TArrayL    fNom;      //! array storing the nominal distribution
-    TCanvas   *fCanvas;   //! canvas for online display
-
-    Bool_t fResult;
-    Int_t  fCounter[2];
-
-    TH1   &InitHistogram(MH3* &hist);
-    Bool_t ReadDistribution(MRead &read);
-    void   PrepareHistograms();
-    Bool_t PreProcessData(MParList *parlist);
-    Bool_t Select(Int_t bin);
-
-    Int_t PreProcess(MParList *parlist);
-    Int_t Process();
-    Int_t PostProcess();
-
-public:
-    MFEventSelector2(MH3 &hist, const char *name=NULL, const char *title=NULL);
-    ~MFEventSelector2();
-
-    MH3 *GetHistOrig() { return fHistOrig; }
-
-    void SetNumMax(Long_t max=-1) { fNumMax = max; }
-    Bool_t IsExpressionTrue() const { return fResult; }
-
-    ClassDef(MFEventSelector2, 0) // FIMXE!
-};
-
-#endif
Index: trunk/MagicSoft/Mars/mfilter/MFRealTimePeriod.cc
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFRealTimePeriod.cc	(revision 3329)
+++ 	(revision )
@@ -1,59 +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): Thomas Bretz, 10/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2003
-!
-!
-\* ======================================================================== */
-
-/////////////////////////////////////////////////////////////////////////////
-//
-//  MFRealTimePeriod
-//
-//  This filter allows the execution of tasks in real time intervals. If
-//  a timeout (given in milliseconds in the constructor) was exceeded
-//  the return value for IsExpression is set to kTRUE and the timer is
-//  reset.
-//
-/////////////////////////////////////////////////////////////////////////////
-#include "MFRealTimePeriod.h"
-
-#include <TTime.h>
-#include <TSystem.h>
-
-ClassImp(MFRealTimePeriod);
-
-// --------------------------------------------------------------------------
-//
-// Check, whether the current time is greater than the stored time plus
-// the timeout time. If this is the case the return value of
-// IsExpressionTrue is set to kTRUE and the stored time is reset to the
-// current time. To get the current time gSystem->Now() is used.
-//
-Int_t MFRealTimePeriod::Process()
-{
-    const ULong_t t = (ULong_t)gSystem->Now();
-
-    fResult = t>fTime+fMilliSec;
-
-    if (fResult)
-        fTime=t;
-
-    return kTRUE;
-}
Index: trunk/MagicSoft/Mars/mfilter/MFRealTimePeriod.h
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFRealTimePeriod.h	(revision 3329)
+++ 	(revision )
@@ -1,31 +1,0 @@
-#ifndef MARS_MFRealTimePeriod
-#define MARS_MFRealTimePeriod
-
-#ifndef MARS_MFilter
-#include "MFilter.h"
-#endif
-
-class MFRealTimePeriod : public MFilter
-{
-private:
-    ULong_t fTime;     //!
-    Bool_t  fResult;   //!
-
-    ULong_t fMilliSec;
-
-public:
-    MFRealTimePeriod(UInt_t millis=1000) : fTime(0), fMilliSec(millis)
-    {
-        fName  = "MFRealTimePeriod";
-        fTitle = "Filter allowing execution of a task only after a given real time interval";
-    }
-
-    void SetTime(UInt_t millis) { fMilliSec = millis; }
-
-    Int_t Process();
-    Bool_t IsExpressionTrue() const { return fResult; }
-
-    ClassDef(MFRealTimePeriod, 0) //Filter allowing execution of a task only after a given real time interval
-};
-
-#endif
Index: trunk/MagicSoft/Mars/mfilter/MFilterList.cc
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFilterList.cc	(revision 3329)
+++ 	(revision )
@@ -1,380 +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): Thomas Bretz, 07/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2003
-!
-!
-\* ======================================================================== */
-
-/////////////////////////////////////////////////////////////////////////////
-//
-//   MFilterList
-//
-// A filter list can be used to concatenate filter (derived from MFilter)
-// by a logical or bitwise operator. For more details see the constructor.
-//
-// The list is setup by adding filters to the list calling AddToList().
-// For example in the case of the default constructor ("&&") all results
-// are logically and'd together and the result of this and is returned.
-//
-// Because the meaning of all filters can be inverted calling SetInverted()
-// which is defined in the base class MFilter you can use this list to
-// invert the meaning of a filter, by eg:
-//
-//   MF anyfilter("MHillas.fAlpha");
-//
-//   MFilterList alist;
-//   alist.AddToList(&anyfilter);
-//
-//   alist.SetInverted();
-//
-// Adding the filterlist to the eventloop will process all contained filters.
-// Doing this as early as possible is a simple way of processing all filters.
-//
-// If you want to make the list delete all contained filters you may make
-// the list owner of the filters by calling SetOwner()
-//
-/////////////////////////////////////////////////////////////////////////////
-#include "MFilterList.h"
-
-#include <fstream>
-
-#include <TString.h>
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-#include "MIter.h"
-
-ClassImp(MFilterList);
-
-using namespace std;
-
-static const TString gsDefName  = "MFilterList";
-static const TString gsDefTitle = "List combining filters logically.";
-
-// --------------------------------------------------------------------------
-//
-//   Constructor.
-//
-//   Specify the boolean operation which is used to evaluate the
-//   result of this list. If no operation is specified "land" is
-//   used.
-//
-//   Options:
-//      and, &   : is a bitwise and
-//      or, |    : is a bitwise or
-//      xor, ^   : is a bitwise exclusive or
-//      land, && : is a logical and
-//      lor, ||  : is a logical or
-//
-MFilterList::MFilterList(const char *type, const char *name, const char *title)
-{
-    fName  = name  ? name  : gsDefName.Data();
-    fTitle = title ? title : gsDefTitle.Data();
-
-    gROOT->GetListOfCleanups()->Add(&fFilters);
-    fFilters.SetBit(kMustCleanup);
-
-    fFilterType = kEAnd;
-
-    TString str(type);
-
-    if (!str.CompareTo("OR", TString::kIgnoreCase)  || !str.CompareTo("|"))
-        fFilterType = kEOr;
-    if (!str.CompareTo("XOR", TString::kIgnoreCase) || !str.CompareTo("^"))
-        fFilterType = kEXor;
-    if (!str.CompareTo("LAND", TString::kIgnoreCase) || !str.CompareTo("&&"))
-        fFilterType = kELAnd;
-    if (!str.CompareTo("LOR", TString::kIgnoreCase) || !str.CompareTo("||"))
-        fFilterType = kELOr;
-}
-
-// --------------------------------------------------------------------------
-//
-//   CopyConstructor
-//
-MFilterList::MFilterList(MFilterList &ts)
-{
-    fFilters.AddAll(&ts.fFilters);
-    fFilterType = ts.fFilterType;
-}
-
-// --------------------------------------------------------------------------
-//
-//  Evaluates and returns the result of the filter list.
-//  The expression is evaluated step by step, eg:
-//  ((filter[0] # filter[1]) # filter[3]) # filter[4])
-//  The '#' stands for the boolean operation which is specified in
-//  the constructor.
-//
-Bool_t MFilterList::IsExpressionTrue() const
-{
-    TIter Next(&fFilters);
-
-    MFilter *filter=(MFilter*)Next();
-
-    if (!filter)
-        return kTRUE;
-
-    Bool_t rc = filter->IsConditionTrue();
-
-    //
-    // loop over all filters
-    //
-    switch (fFilterType)
-    {
-    case kEAnd:
-        while ((filter=(MFilter*)Next()))
-            rc &= filter->IsConditionTrue();
-        break;
-
-    case kEOr:
-        while ((filter=(MFilter*)Next()))
-            rc |= filter->IsConditionTrue();
-        break;
-
-    case kEXor:
-        while ((filter=(MFilter*)Next()))
-            rc ^= filter->IsConditionTrue();
-        break;
-
-    case kELAnd:
-        while ((filter=(MFilter*)Next()))
-            rc = (rc && filter->IsConditionTrue());
-        break;
-
-    case kELOr:
-        while ((filter=(MFilter*)Next()))
-            rc = (rc || filter->IsConditionTrue());
-        break;
-    }
-    return rc;
-}
-
-// --------------------------------------------------------------------------
-//
-// If you want to add a new filter to the list call this function with the
-// pointer to the filter to be added. 
-//
-Bool_t MFilterList::AddToList(MFilter *filter)
-{
-    if (!filter)
-        return kTRUE;
-
-    const char *name = filter->GetName();
-
-    if (fFilters.FindObject(filter))
-    {
-        *fLog << warn << dbginf << "Filter already existing... skipped." << endl;
-        return kTRUE;
-    }
-
-    if (fFilters.FindObject(name))
-        *fLog << warn << "MFilterList::AddToList - '" << name << "' exists in List already..." << endl;
-
-    *fLog << inf << "Adding " << name << " to " << GetName() << "... " << flush;
-
-    filter->SetBit(kMustCleanup);
-    fFilters.Add(filter);
-
-    *fLog << "Done." << endl;
-
-    return kTRUE;
-}
-
-
-// --------------------------------------------------------------------------
-//
-// PreProcesses all filters in the list
-//
-Int_t MFilterList::PreProcess(MParList *pList)
-{
-    TIter Next(&fFilters);
-
-    MFilter *filter=NULL;
-
-    //
-    // loop over all filters
-    //
-    while ((filter=(MFilter*)Next()))
-        if (!filter->CallPreProcess(pList))
-        {
-            *fLog << err << "Error - Preprocessing Filter ";
-            *fLog << filter->GetName() << " in " << fName << endl;
-            return kFALSE;
-        }
-
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Processes (updates) all filters in the list.
-//
-Int_t MFilterList::Process()
-{
-    TIter Next(&fFilters);
-
-    MFilter *filter=NULL;
-
-    //
-    // loop over all filters
-    //
-    while ((filter=(MFilter*)Next()))
-        if (!filter->CallProcess())
-            return kFALSE;
-
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// PostProcesses all filters in the list.
-//
-Int_t MFilterList::PostProcess()
-{
-    TIter Next(&fFilters);
-
-    MFilter *filter=NULL;
-
-    //
-    // loop over all filters
-    //
-    while ((filter=(MFilter*)Next()))
-        if (!filter->CallPostProcess())
-            return kFALSE;
-
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// If you want to use a verbose output ("and") instead of a symbolic ("&")
-// one the option string must conatin a "v"
-//
-void MFilterList::Print(Option_t *opt) const
-{
-    *fLog << all << GetRule(opt) << flush;
-}
-
-// --------------------------------------------------------------------------
-//
-// Implementation of SavePrimitive. Used to write the call to a constructor
-// to a macro. In the original root implementation it is used to write
-// gui elements to a macro-file.
-//
-void MFilterList::StreamPrimitive(ofstream &out) const
-{
-    out << "   MFilterList " << ToLower(fName) << "(\"";
-
-    switch (fFilterType)
-    {
-    case kEAnd:
-        out << "&";
-        break;
-
-    case kEOr:
-        out  << "|";
-        break;
-
-    case kEXor:
-        out  << "^";
-        break;
-
-    case kELAnd:
-        out << "&&";
-        break;
-
-    case kELOr:
-        out << "||";
-        break;
-    }
-
-    out << "\"";
-
-    if (fName!=gsDefName || fTitle!=gsDefTitle)
-    {
-        out << ", \"" << fName << "\"";
-        if (fTitle!=gsDefTitle)
-            out << ", \"" << fTitle << "\"";
-    }
-    out << ");" << endl << endl;
-
-    MIter Next(&fFilters);
-
-    MParContainer *cont = NULL;
-    while ((cont=Next()))
-    {
-        cont->SavePrimitive(out, "");
-
-        out << "   " << ToLower(fName) << ".AddToList(&";
-        out << cont->GetUniqueName() << ");" << endl << endl;
-    }
-}
-
-TString MFilterList::GetRule(Option_t *opt) const
-{
-    TString str(opt);
-    const Bool_t verbose = str.Contains("V", TString::kIgnoreCase);
-
-    TString ret = "(";
-
-    TIter Next(&fFilters);
-
-    MFilter *filter=(MFilter*)Next();
-
-    //
-    // loop over all filters
-    //
-    if (!filter)
-        return "<empty>";
-
-    ret += filter->GetRule();
-
-    while ((filter=(MFilter*)Next()))
-    {
-        switch (fFilterType)
-        {
-        case kEAnd:
-            ret += (verbose?" and ":" & ");
-            break;
-
-        case kEOr:
-            ret += (verbose?" or ":" | ");
-            break;
-
-        case kEXor:
-            ret += (verbose?" xor ":" ^ ");
-            break;
-
-        case kELAnd:
-            ret += (verbose?" land ":" && ");
-            break;
-
-        case kELOr:
-            ret += (verbose?" lor ":" || ");
-            break;
-        }
-
-        ret += filter->GetRule();
-    }
-
-    return ret+")";
-}
Index: trunk/MagicSoft/Mars/mfilter/MFilterList.h
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFilterList.h	(revision 3329)
+++ 	(revision )
@@ -1,58 +1,0 @@
-#ifndef MARS_MFilterList
-#define MARS_MFilterList
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-//  MFilterList                                                            //
-//                                                                         //
-//  List of several filters                                                //
-//                                                                         //
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef ROOT_TOrdCollection
-#include <TOrdCollection.h>
-#endif
-#ifndef MARS_MFilter
-#include "MFilter.h"
-#endif
-
-class MParList;
-
-class MFilterList : public MFilter
-{
-private:
-    TOrdCollection fFilters;	// Container for the filters
-
-    typedef enum { kEAnd, kEOr, kEXor, kELAnd, kELOr } FilterType_t;
-    FilterType_t fFilterType;
-
-    enum { kIsOwner = BIT(14) };
-
-    void StreamPrimitive(ofstream &out) const;
-
-public:
-    MFilterList(const char *type="&&", const char *name=NULL, const char *title=NULL);
-    MFilterList(MFilterList &ts);
-    ~MFilterList()
-    {
-        if (TestBit(kIsOwner))
-            fFilters.SetOwner();
-    }
-
-    Bool_t AddToList(MFilter *filter);
-    void SetOwner(Bool_t enable=kTRUE) { enable ? SetBit(kIsOwner) : ResetBit(kIsOwner); }
-
-    Bool_t IsExpressionTrue() const;
-
-    void Print(Option_t *opt = "") const;
-    TString GetRule() const { return GetRule(""); }
-    TString GetRule(Option_t *opt) const;
-
-    Int_t PreProcess(MParList *pList);
-    Int_t Process();
-    Int_t PostProcess();
-
-    ClassDef(MFilterList, 1)		// List to combine several filters logically
-};
-
-#endif
