Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 2573)
+++ trunk/MagicSoft/Mars/Changelog	(revision 2574)
@@ -4,4 +4,41 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+
+
+  2003/11/27: Wolfgang Wittek
+
+  * mfilter/MFEventSelector2.cc
+    - if number of requested events is too high 
+      reduce it to the maximum number possible
+    - introduce the flag 'fUseOrigDistribution';
+      if it is set to kTRUE (by SetOrigDistribution()) the original
+      distribution will be used as the nominal distribution
+    - add the member functions SetUseOrigDistribution()
+                               GetHistOrig()
+
+  * mfilter/MFRandomSplit.[h,cc]
+    - a filter which gives fResult = kTRUE with a certain probability
+
+  * mfilter/MFAntiFilter.[h,cc]
+    - a filter which checks the result of a given filter and returns 
+      the opposite result;
+      Thomas : could you please add a code which puts the filter whose 
+               result is checked into the task list ?
+
+  * mfilter/Makefile
+            FilterLinkDef.h
+    - add MFRandomSplit and MFAntiFilter
+
+  * manalysis/MCT1FindSupercuts.[h,cc]
+    - in 'DefineTrainMatrix', 'DefineTestMatrix', and 
+      'DefineTrainTestMatrix()' :
+      replace call to 'MFEventSelector' by call to 'MFEventSelector2'
+    - add member function SetUseOrigDistribution(Bool_t b);
+      if b = kTRUE the events for the training and test samples are
+      selected randomnly from the input file
+
+
+
  2003/11/27: Abelardo Moralejo
 
@@ -11,4 +48,5 @@
        where the parameter containers for each telescope are tagged 
        with a ';' followed by the telescope number. 
+
 
  2003/11/26: Thomas Bretz
Index: trunk/MagicSoft/Mars/manalysis/MCT1FindSupercuts.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCT1FindSupercuts.cc	(revision 2573)
+++ trunk/MagicSoft/Mars/manalysis/MCT1FindSupercuts.cc	(revision 2574)
@@ -58,4 +58,5 @@
 #include "MFillH.h"
 //#include "MGeomCamCT1Daniel.h"
+#include "MFRandomSplit.h"
 #include "MGeomCamCT1.h"
 #include "MH3.h"
@@ -246,4 +247,6 @@
     fTitle = title ? title : "Optimizer of the supercuts";
 
+    fUseOrigDistribution = kFALSE;
+
     //---------------------------
     // camera geometry is needed for conversion mm ==> degree
@@ -277,4 +280,17 @@
 }
 
+
+// --------------------------------------------------------------------------
+//
+// 
+//
+void MCT1FindSupercuts::SetUseOrigDistribution(Bool_t b)
+{
+  fUseOrigDistribution = b;
+
+  *fLog << "MCT1FindSupercuts : when defining training and test matrices use the original distribution" 
+        << endl;
+}
+
 // --------------------------------------------------------------------------
 //
@@ -285,7 +301,7 @@
 //
 //
-Bool_t MCT1FindSupercuts::DefineTrainMatrix(const TString &nametrain,
-	                  const Int_t howmanytrain, MH3 &hreftrain,
-                          const TString &filetrain)
+Bool_t MCT1FindSupercuts::DefineTrainMatrix(
+			  const TString &nametrain, MH3 &hreftrain,
+	                  const Int_t howmanytrain, const TString &filetrain)
 {
     if (nametrain.IsNull() || howmanytrain <= 0)
@@ -295,6 +311,14 @@
     *fLog << "fill training matrix from file '" << nametrain 
           << "',   select " << howmanytrain 
-          << " events according to a distribution given by the MH3 object '"
-          << hreftrain.GetName() << "'" << endl;
+          << " events " << endl;
+    if (!fUseOrigDistribution)
+    {
+      *fLog << "     according to a distribution given by the MH3 object '"
+            << hreftrain.GetName() << "'" << endl;
+    }
+    else
+    {
+      *fLog << "     randomly" << endl;
+    }
 
 
@@ -305,11 +329,13 @@
     read.DisableAutoScheme();
 
-    //MFEventSelector2 seltrain(hreftrain);
-    //seltrain.SetNumMax(howmanytrain);
-    MFEventSelector seltrain;
-    seltrain.SetNumSelectEvts(howmanytrain);
+    MFEventSelector2 seltrain(hreftrain);
+    seltrain.SetNumMax(howmanytrain);
+    seltrain.SetName("selectTrain");
+    if (fUseOrigDistribution)
+      seltrain.SetUseOrigDistribution(kTRUE);
 
     MFillH filltrain(fMatrixTrain);
     filltrain.SetFilter(&seltrain);
+    filltrain.SetName("fillMatrixTrain");
 
     //******************************
@@ -379,7 +405,7 @@
 //
 //
-Bool_t MCT1FindSupercuts::DefineTestMatrix(const TString &nametest,
-	                  const Int_t howmanytest, MH3 &hreftest,
-                          const TString &filetest)
+Bool_t MCT1FindSupercuts::DefineTestMatrix(
+			  const TString &nametest, MH3 &hreftest,
+	                  const Int_t howmanytest, const TString &filetest)
 {
     if (nametest.IsNull() || howmanytest<=0)
@@ -389,6 +415,14 @@
     *fLog << "fill test matrix from file '" << nametest 
           << "',   select " << howmanytest 
-          << " events according to a distribution given by the MH3 object '"
-          << hreftest.GetName() << "'" << endl;
+          << " events " << endl;
+    if (!fUseOrigDistribution)
+    {
+      *fLog << "     according to a distribution given by the MH3 object '"
+            << hreftest.GetName() << "'" << endl;
+    }
+    else
+    {
+      *fLog << "     randomly" << endl;
+    }
 
 
@@ -399,9 +433,10 @@
     read.DisableAutoScheme();
 
-    //MFEventSelector2 seltest(hreftest);
-    //seltest.SetNumMax(howmanytest);
-    MFEventSelector seltest;
-    seltest.SetNumSelectEvts(howmanytest);
-
+    MFEventSelector2 seltest(hreftest);
+    seltest.SetNumMax(howmanytest);
+    seltest.SetName("selectTest");
+    if (fUseOrigDistribution)
+      seltest.SetUseOrigDistribution(kTRUE);
+ 
     MFillH filltest(fMatrixTest);
     filltest.SetFilter(&seltest);
@@ -471,19 +506,21 @@
 //
 Bool_t MCT1FindSupercuts::DefineTrainTestMatrix(
-                          const TString &name,
-	                  const Int_t howmanytrain, MH3 &hreftrain,
-	                  const Int_t howmanytest,  MH3 &hreftest,
+			  const TString &name, MH3 &href,
+	                  const Int_t howmanytrain, const Int_t howmanytest,
                           const TString &filetrain, const TString &filetest)
 {
     *fLog << "=============================================" << endl;
-    *fLog << "fill training matrix from file '" << name 
-          << "',   select " << howmanytrain 
-          << " events for the training according to a distribution given by the MH3 object '"
-          << hreftrain.GetName() << "'" << endl;
-
-    *fLog << "fill test matrix from the same file '" << name 
-          << "',   select " << howmanytest 
-          << " events for the training according to a distribution given by the MH3 object '"
-          << hreftest.GetName() << "'" << endl;
+    *fLog << "fill training and test matrix from file '" << name 
+          << "',   select "   << howmanytrain 
+          << " training and " << howmanytest << " test events " << endl;
+    if (!fUseOrigDistribution)
+    {
+      *fLog << "     according to a distribution given by the MH3 object '"
+            << href.GetName() << "'" << endl;
+    }
+    else
+    {
+      *fLog << "     randomly" << endl;
+    }
 
 
@@ -494,32 +531,32 @@
     read.DisableAutoScheme();
 
-    //MFEventSelector2 seltrain(hreftrain);
-    //seltrain.SetNumMax(howmanytrain);
-    MFEventSelector seltrain;
-    seltrain.SetName("SelTrain");
-    seltrain.SetNumSelectEvts(howmanytrain);
+    MFEventSelector2 selector(href);
+    selector.SetNumMax(howmanytrain+howmanytest);
+    selector.SetName("selectTrainTest");
+    selector.SetInverted();
+    if (fUseOrigDistribution)
+      selector.SetUseOrigDistribution(kTRUE);
+
+    MContinue cont(&selector);
+    cont.SetName("ContTrainTest");
+
+    Double_t prob =  ( (Double_t) howmanytrain )
+                   / ( (Double_t)(howmanytrain+howmanytest) );
+    MFRandomSplit split(prob);
 
     MFillH filltrain(fMatrixTrain);
+    filltrain.SetFilter(&split);
     filltrain.SetName("fillMatrixTrain");
-    filltrain.SetFilter(&seltrain);
+
 
     // consider this event as candidate for a test event 
     // only if event was not accepted as a training event
-    MContinue cont(&seltrain);
-
-    const Float_t fcorr = (Float_t)read.GetEntries() / (read.GetEntries()-howmanytrain);
-
-    *fLog << "entries, howmanytrain, fcorr = " << read.GetEntries()
-          << ",  " << howmanytrain << ",  " << fcorr << endl;
-
-    //MFEventSelector2 seltest(hreftest);
-    //seltrain.SetNumMax(howmanytest*fcorr);
-    MFEventSelector seltest;
-    seltest.SetName("SelTest");
-    seltest.SetNumSelectEvts((Int_t)(fcorr*howmanytest));
+
+    MContinue conttrain(&split);
+    conttrain.SetName("ContTrain");
 
     MFillH filltest(fMatrixTest);
     filltest.SetName("fillMatrixTest");
-    filltest.SetFilter(&seltest);
+
 
     //******************************
@@ -535,10 +572,10 @@
 
     tlist.AddToList(&read);
-    tlist.AddToList(&seltrain);
+    tlist.AddToList(&cont);
+
+    tlist.AddToList(&split);
     tlist.AddToList(&filltrain);
-
-    tlist.AddToList(&cont);
-
-    tlist.AddToList(&seltest);
+    tlist.AddToList(&conttrain);
+
     tlist.AddToList(&filltest);
 
Index: trunk/MagicSoft/Mars/manalysis/MCT1FindSupercuts.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCT1FindSupercuts.h	(revision 2573)
+++ trunk/MagicSoft/Mars/manalysis/MCT1FindSupercuts.h	(revision 2574)
@@ -37,4 +37,6 @@
   Int_t   fHowManyTrain;
   Int_t   fHowManyTest;
+
+  Bool_t  fUseOrigDistribution;
 
   TString  fFilenameParam;
@@ -88,14 +90,15 @@
   void SetMatrixFilter(MFilter *filter)          {fMatrixFilter = filter;}
 
-  Bool_t DefineTrainMatrix(const TString &name, const Int_t howmany,
-                           MH3 &href, const TString &filetrain); 
+  Bool_t DefineTrainMatrix(const TString &name, MH3 &href,
+                           const Int_t howmany, const TString &filetrain); 
 
-  Bool_t DefineTestMatrix(const TString &name, const Int_t howmany,
-                          MH3 &href,  const TString &filetest);
+  Bool_t DefineTestMatrix(const TString &name, MH3 &href,
+                          const Int_t howmany, const TString &filetest);
 
-  Bool_t DefineTrainTestMatrix(const TString &name, 
-			 const Int_t howmanytrain, MH3 &hreftrain,
-                 	 const Int_t howmanytest,  MH3 &hreftest,
+  Bool_t DefineTrainTestMatrix(const TString &name, MH3 &href,
+			 const Int_t howmanytrain, const Int_t howmanytest, 
                          const TString &filetrain, const TString &filetest);
+
+  void SetUseOrigDistribution(Bool_t b);
 
   MHMatrix *GetMatrixTrain() { return fMatrixTrain; }
Index: trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h	(revision 2573)
+++ trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h	(revision 2574)
@@ -24,4 +24,6 @@
 
 #pragma link C++ class MFEnergySlope+;
+#pragma link C++ class MFRandomSplit+;
+#pragma link C++ class MFAntiFilter+;
 
 #endif
Index: trunk/MagicSoft/Mars/mfilter/MFAntiFilter.cc
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFAntiFilter.cc	(revision 2574)
+++ trunk/MagicSoft/Mars/mfilter/MFAntiFilter.cc	(revision 2574)
@@ -0,0 +1,106 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Wolfgang Wittek  11/2003 <mailto:wittek@mppmu.mpg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+//   MFAntiFilter                                                          //
+//                                                                         //
+//   it checks the result of the filter 'fFilter' and returns the opposite //
+//   of the result                                                         //
+//                                                                         //
+//   Note : when this class is used both the original filter and its       //
+//          opposite are available; this is not the case when              //
+//          SetInverted() is used;                                         //
+//                                                                         //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#include "MFAntiFilter.h"
+
+#include <math.h>
+#include <fstream>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+
+#include "MFilter.h"
+
+ClassImp(MFAntiFilter);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+MFAntiFilter::MFAntiFilter(MFilter &filter, 
+                 const char *name, const char *title)
+{
+    fName  = name  ? name  : "MFAntiFilter";
+    fTitle = title ? title : "Filter returning the opposite of a given filter";
+
+    fFilter = &filter;
+}
+
+
+// --------------------------------------------------------------------------
+//
+Int_t MFAntiFilter::PreProcess(MParList *pList)
+{
+  fNumSelectedEvts = 0;
+
+  return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+Int_t MFAntiFilter::Process()
+{
+  fResult = !fFilter->IsConditionTrue();
+
+  if (!fResult)
+    return kTRUE;
+
+  fNumSelectedEvts++;
+
+  return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+Int_t MFAntiFilter::PostProcess()
+{
+  *fLog << "MFAntiFilter::PostProcess; "   << fNumSelectedEvts 
+        << " events were selected out of " << GetNumExecutions() << endl;
+
+  return kTRUE;
+}
+
+//=========================================================================
+
+
+
+
+
+
+
Index: trunk/MagicSoft/Mars/mfilter/MFAntiFilter.h
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFAntiFilter.h	(revision 2574)
+++ trunk/MagicSoft/Mars/mfilter/MFAntiFilter.h	(revision 2574)
@@ -0,0 +1,49 @@
+#ifndef MARS_MFAntiFilter
+#define MARS_MFAntiFilter
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MFAntiFilter                                                            //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef MARS_MFilter
+#include "MFilter.h"
+#endif
+
+class MParList;
+class MFilter;
+
+class MFAntiFilter : public MFilter
+{
+private:
+
+    Int_t   fNumSelectedEvts;
+    MFilter *fFilter;
+
+    Bool_t  fResult; //!
+
+    Int_t PreProcess(MParList *pList);
+    Int_t Process();
+    Int_t PostProcess();
+
+public:
+    MFAntiFilter(MFilter &filter,
+                 const char *name=NULL, const char *title=NULL);
+
+    Bool_t IsExpressionTrue() const { return fResult; }
+
+    ClassDef(MFAntiFilter, 1) // A filter which returns the opposite of a given filter
+};
+
+#endif
+
+
+
+
+
+
+
+
+
+
Index: trunk/MagicSoft/Mars/mfilter/MFEventSelector2.cc
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFEventSelector2.cc	(revision 2573)
+++ trunk/MagicSoft/Mars/mfilter/MFEventSelector2.cc	(revision 2574)
@@ -16,5 +16,6 @@
 !
 !
-!   Author(s): Thomas Bretz, 01/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Thomas Bretz,   01/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!              Wolfgang Wittek 11/2003 <mailto:wittek@mppmu.mpg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2003
@@ -135,4 +136,11 @@
 //     would result in redistributing cos(Theta).
 //
+//  If 'fUseOrigDistribution' is set to kTRUE (by SetUseOrigDistribution())
+//     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),
@@ -142,17 +150,31 @@
     fName  = name  ? (TString)name  : gsDefName;
     fTitle = title ? (TString)title : gsDefTitle;
-}
-
-// --------------------------------------------------------------------------
-//
-// Destructor. Deletes fHistRes if allocated.
+ 
+    fUseOrigDistribution = kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
+// 
 //
 MFEventSelector2::~MFEventSelector2()
 {
-    if (fHistRes)
-        delete fHistRes;
-}
-
-// --------------------------------------------------------------------------
+  if (fHistRes)
+    delete fHistRes;
+}
+
+// --------------------------------------------------------------------------
+//
+// 
+//
+void MFEventSelector2::SetUseOrigDistribution(Bool_t b)
+{
+  fUseOrigDistribution = b;
+ 
+  *fLog << "MFEventSelector2 : use the distribution from the input file as the target distribution"
+        << endl;
+}
+
+//---------------------------------------------------------------------------
 //
 // Recreate a MH3 from fHistNom used as a template. Copy the Binning
@@ -189,5 +211,6 @@
 
     *fLog << "-------------------------" << endl;
-    *fLog << "MFEventSelector2::ReadDistribution; read input file to generate the original distribution" << endl;
+    *fLog << "MFEventSelector2 : Start of eventloop to generate the original distribution" 
+          << endl;
 
     MEvtLoop run(GetName());
@@ -214,5 +237,5 @@
     if (!run.Eventloop())
     {
-        *fLog << err << dbginf << "Evtloop failed." << endl;
+        *fLog << err << dbginf << "Evtloop in MFEventSelector2::ReadDistribution failed." << endl;
         return kFALSE;
     }
@@ -222,4 +245,6 @@
     *fLog << "MFEventSelector2::ReadDistribution; Original distribution has " 
           << fHistOrig->GetHist().GetEntries() << " entries" << endl;
+    *fLog << "MFEventSelector2 : End of eventloop to generate the original distribution" 
+          << endl;
     *fLog << "-------------------------" << endl;
 
@@ -229,5 +254,5 @@
 // --------------------------------------------------------------------------
 //
-// After reading the histograms and arrays used for the random event
+// After reading the histograms the arrays used for the random event
 // selction are created. If a MStatusDisplay is set the histograms are
 // displayed there.
@@ -236,8 +261,17 @@
 {
     TH1 &ho = fHistOrig->GetHist();
-    TH1 &hn = fHistNom->GetHist();
-
-    fHistNom->SetTitle("Users Nominal Distribution");
-    fHistRes->SetTitle("Resulting Distribution");
+
+    //-------------------
+    // if requested
+    // set the nominal distribution equal to the original distribution
+
+    TH1 *hnp;
+    if (fUseOrigDistribution)
+      hnp = (TH1*)(fHistOrig->GetHist()).Clone();
+    else
+      hnp = &fHistNom->GetHist();
+
+    TH1 &hn = *hnp;
+    //--------------------
 
     // normalize to number of counts in primary distribution
@@ -268,10 +302,18 @@
     if (fNumMax>0)
     {
-        *fLog << "MFEventSelector2::PrepareHistograms; SCALE : fNumMax = "
-              << fNumMax << ",  hn.Integral() = "      << hn.Integral()
-              << ",  fNumMax/hn.Integral() = " << fNumMax/hn.Integral() 
-              << endl;
-
-        hn.Scale(fNumMax/hn.Integral());
+        *fLog << "MFEventSelector2::PrepareHistograms; requested no.of events = "
+              << fNumMax << ",  maximum no.of events possible = "      
+              << hn.Integral() << endl;
+
+        if (fNumMax > hn.Integral())
+	{
+          *fLog << "MFEventSelector2::PrepareHistograms; requested no.of events ("
+                << fNumMax << ") is too high" << endl;
+          *fLog << "                                     reduce it to "
+                << hn.Integral() << endl;
+	}
+
+        else 
+          hn.Scale(fNumMax/hn.Integral());
     }
 
@@ -297,4 +339,7 @@
         fNom[i] = (Long_t)(hn.GetBinContent(i+1)+0.5);
     }
+
+    if (fUseOrigDistribution)
+      delete hnp;
 }
 
@@ -362,5 +407,7 @@
     InitHistogram(fHistRes);
 
+    fHistNom->SetTitle("Users Nominal Distribution");
     fHistOrig->SetTitle("Primary Distribution");
+    fHistRes->SetTitle("Resulting Distribution");
 
     // Initialize online display if requested
@@ -369,5 +416,5 @@
         fHistOrig->Draw();
 
-    // Read primary distribution
+    // Generate primary distribution
     if (!ReadDistribution(*read))
         return kFALSE;
@@ -467,2 +514,11 @@
     return kTRUE;
 }
+
+
+
+
+
+
+
+
+
Index: trunk/MagicSoft/Mars/mfilter/MFEventSelector2.h
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFEventSelector2.h	(revision 2573)
+++ trunk/MagicSoft/Mars/mfilter/MFEventSelector2.h	(revision 2574)
@@ -41,4 +41,6 @@
     TCanvas   *fCanvas;   //! canvas for online display
 
+    Bool_t fUseOrigDistribution;
+
     Bool_t fResult;
     Int_t fErrors[2];
@@ -57,4 +59,7 @@
     ~MFEventSelector2();
 
+    void SetUseOrigDistribution(Bool_t b=kTRUE);
+    MH3 *GetHistOrig()                       { return fHistOrig; }
+
     void SetNumMax(Long_t max=-1) { fNumMax = max; }
     Bool_t IsExpressionTrue() const { return fResult; }
@@ -64,2 +69,5 @@
 
 #endif
+
+
+
Index: trunk/MagicSoft/Mars/mfilter/MFRandomSplit.cc
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFRandomSplit.cc	(revision 2574)
+++ trunk/MagicSoft/Mars/mfilter/MFRandomSplit.cc	(revision 2574)
@@ -0,0 +1,117 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Wolfgang Wittek  11/2003 <mailto:wittek@mppmu.mpg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+//   MFRandomSplit                                                         //
+//                                                                         //
+//  A filter which gives fResult = kTRUE with the probability fProb        //
+//                                                                         //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#include "MFRandomSplit.h"
+
+#include <fstream>
+#include <TRandom.h>
+
+#include "MParList.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MFRandomSplit);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+//     Constructor
+//
+MFRandomSplit::MFRandomSplit(Double_t f, const char *name, const char *title)
+{
+  fName  = name  ? name  : "MFRandomSplit";
+  fTitle = title ? title : "Filter for random splitting";
+
+  fProb = f;
+  if (fProb <= 0.0)
+    *fLog << "MFRandomSplit : fProb is less than 0" << endl;
+
+  if (fProb > 1.0)
+    *fLog << "MFRandomSplit : fProb is greater than 1" << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+//   Preprocess
+//  
+//
+Int_t MFRandomSplit::PreProcess(MParList *pList)
+{
+  fNumSelectedEvts = 0;
+
+  return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//  
+//  Select events randomly according to the probability fProb
+//
+Int_t MFRandomSplit::Process()
+{
+  fResult = gRandom->Uniform() < fProb;
+
+  if (!fResult)
+      return kTRUE;
+
+  fNumSelectedEvts++;
+
+  return kTRUE;
+}
+
+
+// --------------------------------------------------------------------------
+//  
+//  PostProcess
+//
+Int_t MFRandomSplit::PostProcess()
+{
+  *fLog << "MFRandomSplit::PostProcess; " << fNumSelectedEvts 
+        << " were selected out of "       << GetNumExecutions() << endl;
+
+  return kTRUE;
+}
+
+//============================================================================
+
+
+
+
+
+
+
+
+
+
+
+
Index: trunk/MagicSoft/Mars/mfilter/MFRandomSplit.h
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFRandomSplit.h	(revision 2574)
+++ trunk/MagicSoft/Mars/mfilter/MFRandomSplit.h	(revision 2574)
@@ -0,0 +1,46 @@
+#ifndef MARS_MFRandomSplit
+#define MARS_MFRandomSplit
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MFRandomSplit                                                           //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef MARS_MF
+#include "MF.h"
+#endif
+
+#ifndef MARS_MFilter
+#include "MFilter.h"
+#endif
+
+class MParList;
+
+class MFRandomSplit : public MF
+{
+private:
+
+    Int_t    fNumSelectedEvts;
+    Double_t fProb;   // probability with which the result should be kTRUE
+
+    Bool_t fResult;  // Result returned by IsExpressionTrue
+
+    Int_t PreProcess(MParList *pList);
+    Int_t Process();
+    Int_t PostProcess();
+
+public:
+    MFRandomSplit(Double_t f, const char *name=NULL, const char *title=NULL);
+
+    Bool_t IsExpressionTrue() const { return fResult; }
+
+    ClassDef(MFRandomSplit, 0) // A Filter giving kTRUE with a certain probability
+};
+
+#endif
+
+
+
+
+
+
Index: trunk/MagicSoft/Mars/mfilter/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mfilter/Makefile	(revision 2573)
+++ trunk/MagicSoft/Mars/mfilter/Makefile	(revision 2574)
@@ -48,5 +48,7 @@
 	   MFCT1SelStandard.cc \
 	   MFCT1SelFinal.cc \
-	   MFEnergySlope.cc
+	   MFEnergySlope.cc \
+	   MFRandomSplit.cc \
+	   MFAntiFilter.cc
 
 SRCS    = $(SRCFILES)
