Index: trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc	(revision 7420)
@@ -115,6 +115,6 @@
     MHMatrix train("Train");
     train.AddColumns(fRules);
-    //train.AddColumn("MHillasSrc.fDist*MGeomCam.fConvMm2Deg");
-    train.AddColumn("TMath::Hypot(MHillasSrc.fDCA, MHillasSrc.fDist)*MGeomCam.fConvMm2Deg");
+    train.AddColumn("MHillasSrc.fDist*MGeomCam.fConvMm2Deg");
+    //train.AddColumn("TMath::Hypot(MHillasSrc.fDCA, MHillasSrc.fDist)*MGeomCam.fConvMm2Deg");
 
     // ----------------------- Fill Matrix RF ----------------------
@@ -147,5 +147,5 @@
         return;
     */
-    if (!rf.TrainSingleRF(train))                  // regression (best choice)
+    if (!rf.TrainRegression(train))                  // regression (best choice)
         return kFALSE;
 
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc	(revision 7420)
@@ -141,5 +141,5 @@
         return;
     */
-    if (!rf.TrainSingleRF(train))                  // regression (best choice)
+    if (!rf.TrainRegression(train))                  // regression (best choice)
         return kFALSE;
 
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.cc
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.cc	(revision 7420)
@@ -26,4 +26,6 @@
 //
 // MJTrainRanForest
+//
+// Base class for classes training a random forest
 //
 /////////////////////////////////////////////////////////////////////////////
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc	(revision 7420)
@@ -30,4 +30,8 @@
 #include "MJTrainSeparation.h"
 
+#include <TH2.h>
+#include <TGraph.h>
+#include <TVirtualPad.h>
+
 #include "MHMatrix.h"
 
@@ -36,7 +40,9 @@
 
 // tools
+#include "MMath.h"
 #include "MDataSet.h"
 #include "MTFillMatrix.h"
 #include "MChisqEval.h"
+#include "MStatusDisplay.h"
 
 // eventloop
@@ -63,4 +69,5 @@
 // filter
 #include "MF.h"
+#include "MFEventSelector.h"
 #include "MFilterList.h"
 
@@ -68,4 +75,64 @@
 
 using namespace std;
+
+void MJTrainSeparation::DisplayResult(MH3 &h31, MH3 &h32)
+{
+    TH2 &g = (TH2&)h32.GetHist();
+    TH2 &h = (TH2&)h31.GetHist();
+
+    h.SetMarkerColor(kRed);
+    g.SetMarkerColor(kGreen);
+
+    const Int_t nx = h.GetNbinsX();
+    const Int_t ny = h.GetNbinsY();
+
+    gROOT->SetSelectedPad(NULL);
+
+    TGraph gr1;
+    TGraph gr2;
+    for (int x=0; x<nx; x++)
+    {
+        TH1 *hx = h.ProjectionY("H_py", x+1, x+1);
+        TH1 *gx = g.ProjectionY("G_py", x+1, x+1);
+
+        Double_t max1 = -1;
+        Double_t max2 = -1;
+        Int_t maxy1 = 0;
+        Int_t maxy2 = 0;
+        for (int y=0; y<ny; y++)
+        {
+            const Float_t s = gx->Integral(1, y+1);
+            const Float_t b = hx->Integral(1, y+1);
+            const Float_t sig1 = MMath::SignificanceLiMa(s+b, b);
+            const Float_t sig2 = s<1 ? 0 : MMath::SignificanceLiMa(s+b, b)*TMath::Log10(s);
+            if (sig1>max1)
+            {
+                maxy1 = y;
+                max1 = sig1;
+            }
+            if (sig2>max2)
+            {
+                maxy2 = y;
+                max2 = sig2;
+            }
+        }
+
+        gr1.SetPoint(x, h.GetXaxis()->GetBinCenter(x+1), h.GetYaxis()->GetBinCenter(maxy1+1));
+        gr2.SetPoint(x, h.GetXaxis()->GetBinCenter(x+1), h.GetYaxis()->GetBinCenter(maxy2+1));
+
+        delete hx;
+        delete gx;
+    }
+
+    fDisplay->AddTab("OptCut");
+    gPad->SetLogx();
+    h.DrawCopy();
+    g.DrawCopy("same");
+    gr1.SetMarkerStyle(kFullDotMedium);
+    gr1.DrawClone("LP")->SetBit(kCanDelete);
+    gr2.SetLineColor(kBlue);
+    gr2.SetMarkerStyle(kFullDotMedium);
+    gr2.DrawClone("LP")->SetBit(kCanDelete);
+}
 
 Bool_t MJTrainSeparation::Train(const char *out)
@@ -83,25 +150,18 @@
 
     // --------------------- Setup files --------------------
-    MReadMarsFile read("Events");
+    MReadMarsFile read1("Events");
     MReadMarsFile read2("Events");
     MReadMarsFile read3("Events");
-    read.DisableAutoScheme();
+    MReadMarsFile read4("Events");
+    read1.DisableAutoScheme();
     read2.DisableAutoScheme();
     read3.DisableAutoScheme();
-
-    fDataSetTrain.AddFilesOn(read);
+    read4.DisableAutoScheme();
+
+    fDataSetTrain.AddFilesOn(read1);
     fDataSetTrain.AddFilesOff(read3);
 
     fDataSetTest.AddFilesOff(read2);
-    fDataSetTest.AddFilesOn(read2);
-
-    read2.VetoBranch("MMcTrig");
-    read2.VetoBranch("MTime");
-    read2.VetoBranch("MMcRunHeader");
-    read2.VetoBranch("MMcTrigHeader");
-    read2.VetoBranch("MMcFadcHeader");
-    read2.VetoBranch("MMcCorsikaRunHeader");
-    read2.VetoBranch("MMcConfigRunHeader");
-
+    fDataSetTest.AddFilesOn(read4);
 
     // ----------------------- Setup RF ----------------------
@@ -116,4 +176,5 @@
     MParList plistx;
     plistx.AddToList(&had);
+    plistx.AddToList(this);
 
     MTFillMatrix fill;
@@ -127,5 +188,5 @@
     fill.SetName("FillGammas");
     fill.SetDestMatrix1(&train, fNumTrainOn);
-    fill.SetReader(&read);
+    fill.SetReader(&read1);
     if (!fill.Process(plistx))
         return kFALSE;
@@ -160,6 +221,7 @@
         return kFALSE;
 
+    //fDisplay = rf.GetDisplay();
+
     // --------------------- Display result ----------------------
-
     gLog.Separator("Test");
 
@@ -172,6 +234,7 @@
     plist.AddToList(&mcevt);
 
+    // ----- Setup histograms -----
     MBinning binsy(100, 0 , 1,      "BinningMH3Y", "lin");
-    MBinning binsx(100, 10, 100000, "BinningMH3X", "log");
+    MBinning binsx( 50, 10, 100000, "BinningMH3X", "log");
 
     plist.AddToList(&binsx);
@@ -183,20 +246,15 @@
     h32.SetTitle("Background probability vs. Size:Size [phe]:Hadronness");
 
-    MF f("MRawRunHeader.fRunType>255");
-    MFilterList list;
-    list.SetInverted();
-    list.AddToList(&f);
-
     MHHadronness hist;
 
-    MFillH fillh(&hist, "", "FillHadronness");
-    MFillH fillh1(&h31, "", "FillGammas");
-    MFillH fillh2(&h32, "", "FillBackground");
-    fillh1.SetNameTab("Gammas");
-    fillh2.SetNameTab("Background");
-
-    fillh1.SetFilter(&f);
-    fillh2.SetFilter(&list);
-
+    // ----- Setup tasks -----
+    MFillH fillh0(&hist, "", "FillHadronness");
+    MFillH fillh1(&h31);
+    MFillH fillh2(&h32);
+    fillh1.SetNameTab("Background");
+    fillh2.SetNameTab("Gammas");
+    fillh0.SetBit(MFillH::kDoNotDisplay);
+
+    // ----- Setup filter -----
     MFilterList precuts;
     precuts.AddToList(fPreCuts);
@@ -204,14 +262,22 @@
 
     MContinue c0(&precuts);
+    c0.SetName("PreCuts");
     c0.SetInverted();
 
+    MFEventSelector sel;
+    sel.SetNumSelectEvts(fNumTestOn);
+
+    MContinue c1(&sel);
+    c1.SetInverted();
+
+    // ----- Setup tasklist -----
     tlist.AddToList(&read2);
     tlist.AddToList(&c0);
+    tlist.AddToList(&c1);
     tlist.AddToList(&rf);
-    tlist.AddToList(&fillh);
-    tlist.AddToList(&list);
+    tlist.AddToList(&fillh0);
     tlist.AddToList(&fillh1);
-    tlist.AddToList(&fillh2);
-
+
+    // ----- Run eventloop on gammas -----
     MEvtLoop loop;
     loop.SetDisplay(fDisplay);
@@ -222,4 +288,16 @@
         return kFALSE;
 
+    // ----- Setup and run eventloop on background -----
+    sel.SetNumSelectEvts(fNumTestOff);
+    fillh0.ResetBit(MFillH::kDoNotDisplay);
+
+    tlist.Replace(&read4);
+    tlist.Replace(&fillh2);
+
+    if (!loop.Eventloop())
+        return kFALSE;
+
+    DisplayResult(h31, h32);
+
     if (!WriteDisplay(out))
         return kFALSE;
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.h
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.h	(revision 7420)
@@ -10,4 +10,6 @@
 #endif
 
+class MH3;
+
 class MJTrainSeparation : public MJTrainRanForest
 {
@@ -19,8 +21,15 @@
     UInt_t fNumTrainOff;
 
+    UInt_t fNumTestOn;
+    UInt_t fNumTestOff;
+
+    void DisplayResult(MH3 &h31, MH3 &h32);
+
 public:
-    MJTrainSeparation() { }
+    MJTrainSeparation() :
+        fNumTrainOn((UInt_t)-1), fNumTrainOff((UInt_t)-1), fNumTestOn((UInt_t)-1), fNumTestOff((UInt_t)-1)
+    { }
 
-    void SetDataSetTrain(const MDataSet &ds, UInt_t non, UInt_t noff)
+    void SetDataSetTrain(const MDataSet &ds, UInt_t non=(UInt_t)-1, UInt_t noff=(UInt_t)-1)
     {
         ds.Copy(fDataSetTrain);
@@ -28,7 +37,9 @@
         fNumTrainOff = noff;
     }
-    void SetDataSetTest(const MDataSet &ds)
+    void SetDataSetTest(const MDataSet &ds, UInt_t non=(UInt_t)-1, UInt_t noff=(UInt_t)-1)
     {
         ds.Copy(fDataSetTest);
+        fNumTestOn = non;
+        fNumTestOff = noff;
     }
 
