Index: trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc	(revision 7685)
+++ 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 7685)
+++ 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
