Index: trunk/MagicSoft/Mars/mtools/MTFillMatrix.cc
===================================================================
--- trunk/MagicSoft/Mars/mtools/MTFillMatrix.cc	(revision 7642)
+++ trunk/MagicSoft/Mars/mtools/MTFillMatrix.cc	(revision 7687)
@@ -183,4 +183,17 @@
 //------------------------------------------------------------------------
 //
+// Function serving AddPreCuts, AddPreTasks and AddPostTasks
+//
+void MTFillMatrix::Add(const TList &src, const TClass *cls, TList &dest)
+{
+    TIter Next(&src);
+    TObject *obj=0;
+    while ((obj=Next()))
+        if (obj->InheritsFrom(cls))
+            dest.Add(obj);
+}
+
+//------------------------------------------------------------------------
+//
 // Add a cut which is used to fill the matrix, eg "MMcEvt.fOartId<1.5"
 // (The rule is applied, nit inverted: The matrix is filled with
@@ -211,9 +224,45 @@
 void MTFillMatrix::AddPreCuts(const TList &list)
 {
-    TIter Next(&list);
-    TObject *obj=0;
-    while ((obj=Next()))
-        if (obj->InheritsFrom(MFilter::Class()))
-            fPreCuts.Add(obj);
+    Add(list, MFilter::Class(), fPreCuts);
+}
+
+//------------------------------------------------------------------------
+//
+// Add a task which is executed before the precuts. If kCanDelete is set
+// MJOptimize takes the ownership.
+//
+void MTFillMatrix::AddPreTask(MTask *t)
+{
+    fPreTasks.Add(t);
+}
+
+//------------------------------------------------------------------------
+//
+// Add all entries deriving from MTask from list to PreTasks.
+// The ownership is not affected.
+//
+void MTFillMatrix::AddPreTasks(const TList &list)
+{
+    Add(list, MTask::Class(), fPreTasks);
+}
+
+//------------------------------------------------------------------------
+//
+// Add a task which is executed after the precuts. If kCanDelete is set
+// MJOptimize takes the ownership.
+//
+void MTFillMatrix::AddPostTask(MTask *t)
+{
+    fPostTasks.Add(t);
+}
+
+//------------------------------------------------------------------------
+//
+// Add all entries deriving from MTask from list to PostTasks.
+// The ownership is not affected.
+//
+void MTFillMatrix::AddPostTasks(const TList &list)
+{
+    Add(list, MTask::Class(), fPostTasks);
 }
 
@@ -315,12 +364,10 @@
     MFillH fill1(fDestMatrix1);
     MFillH fill2(fDestMatrix2);
-    if (selector)
-    {
-        fill1.SetFilter(&split);
-        fill2.SetFilter(&invsplit);
-    }
+    fill1.SetFilter(&split);
+    fill2.SetFilter(&invsplit);
 
     // entries in MTaskList
     tlist.AddToList(fReader);        // Read events
+    tlist.AddToList(fPreTasks);      // PreTasks
     if (fPreCuts.GetEntries()>0)
         tlist.AddToList(&cont0);     // PreCuts
@@ -328,4 +375,5 @@
         tlist.AddToList(&cont);      // select a sample of events
     tlist.AddToList(&invsplit);      // process invsplit (which implicitly processes split)
+    tlist.AddToList(fPostTasks);     // PostTasks
     if (fDestMatrix1)
         tlist.AddToList(&fill1);     // fill matrix 1
Index: trunk/MagicSoft/Mars/mtools/MTFillMatrix.h
===================================================================
--- trunk/MagicSoft/Mars/mtools/MTFillMatrix.h	(revision 7642)
+++ trunk/MagicSoft/Mars/mtools/MTFillMatrix.h	(revision 7687)
@@ -31,4 +31,8 @@
 
     TList     fPreCuts;
+    TList     fPreTasks;
+    TList     fPostTasks;
+
+    void Add(const TList &src, const TClass *cls, TList &dest);
 
     Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
@@ -80,4 +84,10 @@
     void AddPreCuts(const TList &list);
 
+    void AddPreTask(MTask *t);
+    void AddPreTasks(const TList &list);
+
+    void AddPostTask(MTask *t);
+    void AddPostTasks(const TList &list);
+
     Bool_t Process(const MParList &plist=MParList());
     Bool_t WriteMatrix1(const TString &fname) const { return WriteMatrix(fDestMatrix1, fname, 1); }
