Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 7686)
+++ trunk/MagicSoft/Mars/Changelog	(revision 7687)
@@ -46,4 +46,15 @@
    * mraw/MRawRunHeader.cc:
      - removed an obsolete Print() which enetered for debugging
+
+   * mimage/MHNewImagePar.cc:
+     - the plots for CocCOG and ConcCore had the same color... fixed
+
+   * mranforest/MRanForestCalc.[h,cc]:
+     - allow to set weights for each event
+
+   * mtools/MTFillMatrix.[h,cc]:
+     - implemented the possibility to set pre- and post-tasks
+       executed in the eventloop
+
 
 
Index: trunk/MagicSoft/Mars/mimage/MHNewImagePar.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHNewImagePar.cc	(revision 7686)
+++ trunk/MagicSoft/Mars/mimage/MHNewImagePar.cc	(revision 7687)
@@ -362,7 +362,7 @@
         fHistUsedPix.SetLineColor(kCyan);
         fHistConc1.SetLineColor(kMagenta);
-        fHistConcCOG.SetLineColor(kCyan);
+        fHistConc.SetLineColor(kCyan);
+        fHistConcCOG.SetLineColor(kMagenta);
         fHistConcCore.SetLineColor(kCyan);
-        fHistConc.SetLineColor(kCyan);
         fHistCoreArea.SetLineColor(kMagenta);
         fHistUsedArea.SetLineColor(kCyan);
Index: trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc	(revision 7686)
+++ trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc	(revision 7687)
@@ -63,4 +63,5 @@
     : fData(0), fRFOut(0), fTestMatrix(0),
     fNumTrees(-1), fNumTry(-1), fNdSize(-1), fNumObsoleteVariables(1),
+    fLastDataColumnHasWeights(kFALSE),
     fNameOutput(gsNameOutput), fDebug(kFALSE), fEstimationMode(kMean)
 {
@@ -116,8 +117,11 @@
     }
 
-    const Int_t nobs = fNumObsoleteVariables; // Number of obsolete columns
+    // The number of columns which have to be removed for the training
+    // The last data column may contain weight which also have to be removed
+    const Int_t nobs = fNumObsoleteVariables + (fLastDataColumnHasWeights?1:0); // Number of obsolete columns
 
     const MDataArray &dcol = *matrixtrain.GetColumns();
 
+    // Make a copy of the rules for accessing the train-data
     MDataArray usedrules;
     for (Int_t i=0; i<ncols; i++)
@@ -127,11 +131,13 @@
             *fLog << inf << "Skipping " << dcol[i].GetRule() << " for training" << endl;
 
+    // In the case of regression store the rule to be regessed in the
+    // last entry of your rules
     MDataArray rules(usedrules);
     rules.AddEntry(ver<3?"Classification":dcol[ncols-1].GetRule());
 
-    // prepare matrix for current energy bin
+    // prepare train-matrix finally used
     TMatrix mat(matrixtrain.GetM());
 
-    // last column must be removed (true energy col.)
+    // Resize it such that the obsolete columns are removed
     mat.ResizeTo(nrows, ncols-nobs+1);
 
@@ -139,16 +145,32 @@
         gLog.SetNullOutput(kTRUE);
 
+    // In the case one independant RF is trained for each bin (e.g.
+    // energy-bin) train all of them
     const Int_t nbins = ver>0 ? 1 : grid.GetSize()-1;
     for (Int_t ie=0; ie<nbins; ie++)
     {
+        // In the case weights should be used initialize the
+        // corresponding array
+        TArrayF weights(nrows);
+        if (fLastDataColumnHasWeights)
+            for (Int_t j=0; j<nrows; j++)
+            {
+                weights[j] = matrixtrain.GetM()(j, ncols-nobs);
+                if (j%100==0)
+                    cout << weights[j] << " ";
+            }
+
+        // Setup the matrix such that the last comlumn contains
+        // the classifier or the regeression target value
         switch (ver)
         {
-        case 0: // Replace last column by a classification
+        case 0: // Replace last column by a classification which is 1 in
+                // the case the event belongs to this bin, 0 otherwise
             {
                 Int_t irows=0;
                 for (Int_t j=0; j<nrows; j++)
                 {
-                    const Double_t energy = matrixtrain.GetM()(j,ncols-1);
-                    const Bool_t   inside = energy>grid[ie] && energy<=grid[ie+1];
+                    const Double_t value  = matrixtrain.GetM()(j,ncols-1);
+                    const Bool_t   inside = value>grid[ie] && value<=grid[ie+1];
 
                     mat(j, ncols-nobs) = inside ? 1 : 0;
@@ -162,5 +184,5 @@
                     *fLog << inf << "Training RF for";
 
-                *fLog << " energy bin " << ie << " (" << grid[ie] << ", " << grid[ie+1] << ") " << irows << "/" << nrows << endl;
+                *fLog << " bin " << ie << " (" << grid[ie] << ", " << grid[ie+1] << ") " << irows << "/" << nrows << endl;
 
                 if (irows==0)
@@ -191,4 +213,6 @@
         if (ver==1)
             rf.SetGrid(grid);
+        if (fLastDataColumnHasWeights)
+            rf.SetWeights(weights);
 
         plist.AddToList(&rf);
Index: trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h	(revision 7686)
+++ trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h	(revision 7687)
@@ -44,4 +44,5 @@
 
     Int_t        fNumObsoleteVariables; //! Training parameters
+    Bool_t       fLastDataColumnHasWeights; //! Training parameters
 
     TString      fFileName;             // File name to forest
@@ -84,5 +85,6 @@
     void SetDebug(Bool_t b=kTRUE)    { fDebug    = b; }
 
-    void SetNumObsoleteVariables(Int_t n=1) { fNumObsoleteVariables = n; }
+    void SetNumObsoleteVariables(Int_t n=1)          { fNumObsoleteVariables = n; }
+    void SetLastDataColumnHasWeights(Bool_t b=kTRUE) { fLastDataColumnHasWeights = b; }
 
     // Train Interface
Index: trunk/MagicSoft/Mars/mtools/MTFillMatrix.cc
===================================================================
--- trunk/MagicSoft/Mars/mtools/MTFillMatrix.cc	(revision 7686)
+++ 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 7686)
+++ 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); }
