Index: trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc	(revision 7412)
@@ -0,0 +1,235 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Thomas Bretz 11/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2005
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MJTrainDisp
+//
+//
+// Example:
+// --------
+//
+//    // SequencesOn are used for training, SequencesOff for Testing
+//    MDataSet set("mctesttrain.txt");
+//    set.SetNumAnalysis(1);  // Must have a number
+//    MJTrainDisp opt;
+//    //opt.SetDebug();
+//    opt.AddParameter("MHillas.fLength");
+//    opt.AddParameter("MHillas.fWidth");
+//    MStatusDisplay *d = new MStatusDisplay;
+//    opt.SetDisplay(d);
+//    opt.AddPreCut("MHillasSrc.fDCA*MGeomCam.fConvMm2Deg<0.3");
+//    opt.Train("rf-disp.root", set, 30000); // Number of train events
+//
+//
+// Random Numbers:
+// ---------------
+//   Use:
+//         if(gRandom)
+//             delete gRandom;
+//         gRandom = new TRandom3();
+//   in advance to change the random number generator.
+//
+////////////////////////////////////////////////////////////////////////////
+#include "MJTrainDisp.h"
+
+#include "MHMatrix.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+// tools
+#include "MDataSet.h"
+#include "MTFillMatrix.h"
+#include "MChisqEval.h"
+
+// eventloop
+#include "MParList.h"
+#include "MTaskList.h"
+#include "MEvtLoop.h"
+
+// tasks
+#include "MReadMarsFile.h"
+#include "MContinue.h"
+#include "MFillH.h"
+#include "MRanForestCalc.h"
+#include "MParameterCalc.h"
+
+// container
+#include "MParameters.h"
+
+// histograms
+#include "MBinning.h"
+#include "MH3.h"
+#include "MHThetaSq.h"
+
+// filter
+#include "MFilterList.h"
+
+ClassImp(MJTrainDisp);
+
+using namespace std;
+
+Bool_t MJTrainDisp::Train(const char *out, const MDataSet &set, Int_t num)
+{
+    if (!set.IsValid())
+    {
+        *fLog << err << "ERROR - DataSet invalid!" << endl;
+        return kFALSE;
+    }
+
+    *fLog << inf;
+    fLog->Separator(GetDescriptor());
+
+    // --------------------- Setup files --------------------
+    MReadMarsFile readtrn("Events");
+    MReadMarsFile readtst("Events");
+    readtrn.DisableAutoScheme();
+    readtst.DisableAutoScheme();
+
+    set.AddFilesOn(readtrn);
+    set.AddFilesOff(readtst);
+
+    // ----------------------- Setup Matrix ------------------
+    MHMatrix train("Train");
+    train.AddColumns(fRules);
+    //train.AddColumn("MHillasSrc.fDist*MGeomCam.fConvMm2Deg");
+    train.AddColumn("TMath::Hypot(MHillasSrc.fDCA, MHillasSrc.fDist)*MGeomCam.fConvMm2Deg");
+
+    // ----------------------- Fill Matrix RF ----------------------
+    MTFillMatrix fill;
+    fill.SetDisplay(fDisplay);
+    fill.SetLogStream(fLog);
+    fill.SetDestMatrix1(&train, num);
+    fill.SetReader(&readtrn);
+    fill.AddPreCuts(&fPreCuts);
+    fill.AddPreCuts(&fTrainCuts);
+    if (!fill.Process())
+        return kFALSE;
+
+    // ------------------------ Train RF --------------------------
+    MRanForestCalc rf;
+    rf.SetNumObsoleteVariables(1);
+    rf.SetDisplay(fDisplay);
+    rf.SetLogStream(fLog);
+    rf.SetFileName(out);
+    rf.SetDebug(fDebug);
+    rf.SetNameOutput("Disp");
+
+    /*
+    MBinning b(32, 10, 100000, "BinningEnergyEst", "log");
+
+    if (!rf.TrainMultiRF(train, b.GetEdgesD()))    // classification with one tree per bin
+        return;
+
+    if (!rf.TrainSingleRF(train, b.GetEdgesD()))   // classification into different bins
+        return;
+    */
+    if (!rf.TrainSingleRF(train))                  // regression (best choice)
+        return kFALSE;
+
+    // --------------------- Display result ----------------------
+
+    gLog.Separator("Test");
+
+    MParList  plist;
+    MTaskList tlist;
+    plist.AddToList(this);
+    plist.AddToList(&tlist);
+    //plist.AddToList(&b);
+
+    MParameterD par("ThetaSquaredCut");
+    par.SetVal(0.2);
+    plist.AddToList(&par);
+
+    MAlphaFitter fit;
+    fit.SetPolynomOrder(0);
+    fit.SetSignalFitMax(0.8);
+    fit.EnableBackgroundFit(kFALSE);
+    fit.SetSignalFunction(MAlphaFitter::kThetaSq);
+    fit.SetMinimizationStrategy(MAlphaFitter::kGaussSigma);
+    plist.AddToList(&fit);
+
+    MFilterList list;
+    if (!list.AddToList(fPreCuts))
+        *fLog << err << "ERROR - Calling MFilterList::AddToList for fPreCuts failed!" << endl;
+    if (!list.AddToList(fTestCuts))
+        *fLog << err << "ERROR - Calling MFilterList::AddToList for fTestCuts failed!" << endl;
+
+    MContinue cont(&list);
+    cont.SetInverted();
+
+    MHThetaSq hist;
+    hist.SkipHistTime();
+    hist.SkipHistTheta();
+    hist.SkipHistEnergy();
+
+    MFillH fillh(&hist, "", "FillThetaSq");
+
+    const char *rule = "(MHillasSrc.fDist*MGeomCam.fConvMm2Deg)^2 + (Disp.fVal)^2 - (2*MHillasSrc.fDist*MGeomCam.fConvMm2Deg*Disp.fVal*cos(MHillasSrc.fAlpha*kDeg2Rad))";
+
+    MParameterCalc calcthetasq(rule, "MThetaSqCalc");
+    calcthetasq.SetNameParameter("ThetaSquared");
+
+    MChisqEval eval;
+    eval.SetY1("sqrt(ThetaSquared.fVal)");
+
+    MH3 hdisp("MHillas.fSize", "sqrt(ThetaSquared.fVal)");
+    hdisp.SetTitle("\\vartheta distribution vs. Size:Size [phe]:\\vartheta [\\circ]");
+
+    MBinning binsx(100, 10, 100000, "BinningMH3X", "log");
+    MBinning binsy(100, 0,  2,      "BinningMH3Y", "lin");
+
+    plist.AddToList(&binsx);
+    plist.AddToList(&binsy);
+
+    MFillH fillh2(&hdisp, "", "FillMH3");
+    fillh2.SetDrawOption("blue profx");
+
+    tlist.AddToList(&readtst);
+    tlist.AddToList(&cont);
+    tlist.AddToList(&rf);
+    tlist.AddToList(&calcthetasq);
+    tlist.AddToList(&fillh);
+    tlist.AddToList(&fillh2);
+    tlist.AddToList(&eval);
+
+    MEvtLoop loop;
+    loop.SetLogStream(fLog);
+    loop.SetDisplay(fDisplay);
+    loop.SetParList(&plist);
+
+    if (!loop.Eventloop())
+        return kFALSE;
+
+    // Print the result
+    *fLog << inf << "Rule: " << rule << endl;
+    hist.GetAlphaFitter().Print("result");
+
+    if (!WriteDisplay(out))
+        return kFALSE;
+
+    return kTRUE;
+}
+
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.h
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.h	(revision 7412)
@@ -0,0 +1,19 @@
+#ifndef MARS_MJTrainDisp
+#define MARS_MJTrainDisp
+
+#ifndef MARS_MJTrainRanForest
+#include "MJTrainRanForest.h"
+#endif
+
+class MDataSet;
+
+class MJTrainDisp : public MJTrainRanForest
+{
+public:
+    MJTrainDisp() { }
+    Bool_t Train(const char *out, const MDataSet &set, Int_t num);
+
+    ClassDef(MJTrainDisp, 0)//Class to train Random Forest disp estimator
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc	(revision 7412)
@@ -0,0 +1,185 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Thomas Bretz 11/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2005
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MJTrainEnergy
+//
+//
+// Example:
+// --------
+//
+//    // SequencesOn are used for training, SequencesOff for Testing
+//    MDataSet set("mctesttrain.txt");
+//    set.SetNumAnalysis(1);  // Must have a number
+//    MJTrainEnergy opt;
+//    //opt.SetDebug();
+//    opt.AddParameter("MHillas.fSize");
+//    opt.AddParameter("MHillasSrc.fDist");
+//    MStatusDisplay *d = new MStatusDisplay;
+//    opt.SetDisplay(d);
+//    opt.AddPreCut("MHillasSrc.fDCA*MGeomCam.fConvMm2Deg<0.3");
+//    opt.Train("rf-energy.root", set, 30000); // Number of train events
+//
+// Random Numbers:
+// ---------------
+//   Use:
+//         if(gRandom)
+//             delete gRandom;
+//         gRandom = new TRandom3();
+//   in advance to change the random number generator.
+//
+////////////////////////////////////////////////////////////////////////////
+#include "MJTrainEnergy.h"
+
+#include "MHMatrix.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+// tools
+#include "MDataSet.h"
+#include "MTFillMatrix.h"
+
+// eventloop
+#include "MParList.h"
+#include "MTaskList.h"
+#include "MEvtLoop.h"
+
+// tasks
+#include "MReadMarsFile.h"
+#include "MContinue.h"
+#include "MFillH.h"
+#include "MRanForestCalc.h"
+
+// histograms
+#include "MHEnergyEst.h"
+
+// filter
+#include "MFilterList.h"
+
+ClassImp(MJTrainEnergy);
+
+using namespace std;
+
+Bool_t MJTrainEnergy::Train(const char *out, const MDataSet &set, Int_t num)
+{
+    if (!set.IsValid())
+    {
+        *fLog << err << "ERROR - DataSet invalid!" << endl;
+        return kFALSE;
+    }
+
+    *fLog << inf;
+    fLog->Separator(GetDescriptor());
+
+    // --------------------- Setup files --------------------
+    MReadMarsFile readtrn("Events");
+    MReadMarsFile readtst("Events");
+    readtrn.DisableAutoScheme();
+    readtst.DisableAutoScheme();
+
+    set.AddFilesOn(readtrn);
+    set.AddFilesOff(readtst);
+
+    // ----------------------- Setup Matrix ------------------
+    MHMatrix train("Train");
+    train.AddColumns(fRules);
+    train.AddColumn("MMcEvt.fImpact/100");
+    train.AddColumn("MMcEvt.fTelescopeTheta*kRad2Deg");
+    train.AddColumn("MMcEvt.fEnergy");
+
+
+    // ----------------------- Fill Matrix RF ----------------------
+    MTFillMatrix fill;
+    fill.SetDisplay(fDisplay);
+    fill.SetLogStream(fLog);
+    fill.SetDestMatrix1(&train, num);
+    fill.SetReader(&readtrn);
+    fill.AddPreCuts(&fPreCuts);
+    fill.AddPreCuts(&fTrainCuts);
+    if (!fill.Process())
+        return kFALSE;
+
+    // ------------------------ Train RF --------------------------
+    MRanForestCalc rf;
+    rf.SetNumObsoleteVariables(3);
+    rf.SetDisplay(fDisplay);
+    rf.SetLogStream(fLog);
+    rf.SetFileName(out);
+    rf.SetDebug(fDebug);
+    rf.SetNameOutput("MEnergyEst");
+
+    /*
+    MBinning b(32, 10, 100000, "BinningEnergyEst", "log");
+
+    if (!rf.TrainMultiRF(train, b.GetEdgesD()))    // classification with one tree per bin
+        return;
+
+    if (!rf.TrainSingleRF(train, b.GetEdgesD()))   // classification into different bins
+        return;
+    */
+    if (!rf.TrainSingleRF(train))                  // regression (best choice)
+        return kFALSE;
+
+    // --------------------- Display result ----------------------
+
+    gLog.Separator("Test");
+
+    MParList  plist;
+    MTaskList tlist;
+    plist.AddToList(this);
+    plist.AddToList(&tlist);
+    //plist.AddToList(&b);
+
+    MFilterList list;
+    if (!list.AddToList(fPreCuts))
+        *fLog << err << "ERROR - Calling MFilterList::AddToList for fPreCuts failed!" << endl;
+    if (!list.AddToList(fTestCuts))
+        *fLog << err << "ERROR - Calling MFilterList::AddToList for fTestCuts failed!" << endl;
+
+    MContinue cont(&list);
+    cont.SetInverted();
+
+    MHEnergyEst hist;
+    MFillH fillh(&hist);
+
+    tlist.AddToList(&readtst);
+    tlist.AddToList(&cont);
+    tlist.AddToList(&rf);
+    tlist.AddToList(&fillh);
+
+    MEvtLoop loop;
+    loop.SetLogStream(fLog);
+    loop.SetDisplay(fDisplay);
+    loop.SetParList(&plist);
+
+    if (!loop.Eventloop())
+        return kFALSE;
+
+    if (!WriteDisplay(out))
+        return kFALSE;
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.h
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.h	(revision 7412)
@@ -0,0 +1,20 @@
+#ifndef MARS_MJTrainEnergy
+#define MARS_MJTrainEnergy
+
+#ifndef MARS_MJTrainRanForest
+#include "MJTrainRanForest.h"
+#endif
+
+class MDataSet;
+
+class MJTrainEnergy : public MJTrainRanForest
+{
+public:
+    MJTrainEnergy() { }
+    Bool_t Train(const char *out, const MDataSet &set, Int_t num);
+
+    ClassDef(MJTrainEnergy, 0)//Class to train Random Forest energy estimator
+};
+
+
+#endif
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.cc
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.cc	(revision 7412)
@@ -0,0 +1,94 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Thomas Bretz 11/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2005
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MJTrainRanForest
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MJTrainRanForest.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MStatusDisplay.h"
+
+#include "MF.h"
+
+ClassImp(MJTrainRanForest);
+
+using namespace std;
+
+//------------------------------------------------------------------------
+//
+// 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
+// the events fullfilling the condition)
+//
+void MJTrainRanForest::AddCut(TList &l, const char *rule)
+{
+    MFilter *f = new MF(rule);
+    f->SetBit(kCanDelete);
+    AddCut(l, f);
+}
+
+//------------------------------------------------------------------------
+//
+// Add a cut which is used to fill the matrix. If kCanDelete is set
+// MJOptimize takes the ownership.
+//
+void MJTrainRanForest::AddCut(TList &l, MFilter *f)
+{
+    l.Add(f);
+}
+
+//------------------------------------------------------------------------
+//
+// Add a parameter used in your filters (see AddFilter) The parameter
+// index is returned,
+//
+//   Int_t idx = AddParameter("log10(MHillas.fSize)");
+//
+// The indices area starting with 0 always.
+//
+Int_t MJTrainRanForest::AddParameter(const char *rule)
+{
+    fRules.Add(new TNamed(rule, ""));
+    return fRules.GetSize()-1;
+}
+
+Bool_t MJTrainRanForest::WriteDisplay(const char *fname) const
+{
+    TFile file(fname, "UPDATE");
+
+    *fLog << inf << " - MStatusDisplay..." << flush;
+    if (fDisplay && fDisplay->Write()<=0)
+    {
+        *fLog << err << "Unable to write MStatusDisplay to " << fname << endl;
+        return kFALSE;
+    }
+    *fLog << inf << "ok." << endl;
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.h
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.h	(revision 7412)
@@ -0,0 +1,45 @@
+#ifndef MARS_MJTrainRanForest
+#define MARS_MJTrainRanForest
+
+#ifndef MARS_MJob
+#include "MJob.h"
+#endif
+
+class MFilter;
+
+class MJTrainRanForest : public MJob
+{
+protected:
+    Bool_t fDebug;
+
+    TList fRules;
+
+    TList fPreCuts;
+    TList fTrainCuts;
+    TList fTestCuts;
+
+    Bool_t WriteDisplay(const char *fname) const;
+
+    void AddCut(TList &l, const char *rule);
+    void AddCut(TList &l, MFilter *f);
+
+public:
+    MJTrainRanForest() : fDebug(kFALSE) { }
+
+    void SetDebug(Bool_t b=kTRUE) { fDebug = b; }
+
+    void AddPreCut(const char *rule)   { AddCut(fPreCuts, rule); }
+    void AddPreCut(MFilter *f)         { AddCut(fPreCuts, f); }
+
+    void AddTrainCut(const char *rule) { AddCut(fTrainCuts, rule); }
+    void AddTrainCut(MFilter *f)       { AddCut(fTrainCuts, f); }
+
+    void AddTestCut(const char *rule)  { AddCut(fTestCuts, rule); }
+    void AddTestCut(MFilter *f)        { AddCut(fTestCuts, f); }
+
+    Int_t AddParameter(const char *rule);
+
+    ClassDef(MJTrainRanForest, 0)//Base class for Random Forest training classes
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc	(revision 7412)
@@ -0,0 +1,229 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Thomas Bretz 11/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2005
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MJTrainSeparation
+//
+////////////////////////////////////////////////////////////////////////////
+#include "MJTrainSeparation.h"
+
+#include "MHMatrix.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+// tools
+#include "MDataSet.h"
+#include "MTFillMatrix.h"
+#include "MChisqEval.h"
+
+// eventloop
+#include "MParList.h"
+#include "MTaskList.h"
+#include "MEvtLoop.h"
+
+// tasks
+#include "MReadMarsFile.h"
+#include "MContinue.h"
+#include "MFillH.h"
+#include "MRanForestCalc.h"
+#include "MParameterCalc.h"
+
+// container
+#include "MMcEvt.hxx"
+#include "MParameters.h"
+
+// histograms
+#include "MBinning.h"
+#include "MH3.h"
+#include "MHHadronness.h"
+
+// filter
+#include "MF.h"
+#include "MFilterList.h"
+
+ClassImp(MJTrainSeparation);
+
+using namespace std;
+
+Bool_t MJTrainSeparation::Train(const char *out)
+{
+    if (!fDataSetTrain.IsValid())
+    {
+        *fLog << err << "ERROR - DataSet for training invalid!" << endl;
+        return kFALSE;
+    }
+    if (!fDataSetTest.IsValid())
+    {
+        *fLog << err << "ERROR - DataSet for testing invalid!" << endl;
+        return kFALSE;
+    }
+
+    // --------------------- Setup files --------------------
+    MReadMarsFile read("Events");
+    MReadMarsFile read2("Events");
+    MReadMarsFile read3("Events");
+    read.DisableAutoScheme();
+    read2.DisableAutoScheme();
+    read3.DisableAutoScheme();
+
+    fDataSetTrain.AddFilesOn(read);
+    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");
+
+
+    // ----------------------- Setup RF ----------------------
+    MHMatrix train("Train");
+    train.AddColumns(fRules);
+    train.AddColumn("MHadronness.fVal");
+
+    // ----------------------- Fill Matrix RF ----------------------
+
+    MParameterD had("MHadronness");
+
+    MParList plistx;
+    plistx.AddToList(&had);
+
+    MTFillMatrix fill;
+    fill.SetLogStream(fLog);
+    fill.SetDisplay(fDisplay);
+    fill.AddPreCuts(fPreCuts);
+    fill.AddPreCuts(fTrainCuts);
+
+    // Set classifier for gammas
+    had.SetVal(0);
+    fill.SetName("FillGammas");
+    fill.SetDestMatrix1(&train, fNumTrainOn);
+    fill.SetReader(&read);
+    if (!fill.Process(plistx))
+        return kFALSE;
+
+    // Set classifier for hadrons
+    had.SetVal(1);
+    fill.SetName("FillBackground");
+    fill.SetDestMatrix1(&train, fNumTrainOff);
+    fill.SetReader(&read3);
+    if (!fill.Process(plistx))
+        return kFALSE;
+
+    // ------------------------ Train RF --------------------------
+
+    MRanForestCalc rf;
+    rf.SetNumObsoleteVariables(1);
+    rf.SetDebug(fDebug);
+    rf.SetDisplay(fDisplay);
+    rf.SetLogStream(fLog);
+    rf.SetFileName(out);
+    rf.SetNameOutput("MHadronness");
+
+    //MBinning b(2, -0.5, 1.5, "BinningHadronness", "lin");
+
+    //if (!rf.TrainMultiRF(train, b.GetEdgesD()))    // classification
+    //    return;
+
+    //if (!rf.TrainSingleRF(train, b.GetEdgesD()))   // classification
+    //    return;
+
+    if (!rf.TrainSingleRF(train))                  // regression
+        return kFALSE;
+
+    // --------------------- Display result ----------------------
+
+    gLog.Separator("Test");
+
+    MParList  plist;
+    MTaskList tlist;
+    plist.AddToList(this);
+    plist.AddToList(&tlist);
+
+    MMcEvt mcevt;
+    plist.AddToList(&mcevt);
+
+    MBinning binsy(100, 0 , 1,      "BinningMH3Y", "lin");
+    MBinning binsx(100, 10, 100000, "BinningMH3X", "log");
+
+    plist.AddToList(&binsx);
+    plist.AddToList(&binsy);
+
+    MH3 h31("MHillas.fSize", "MHadronness.fVal");
+    MH3 h32("MHillas.fSize", "MHadronness.fVal");
+    h31.SetTitle("Background probability vs. Size:Size [phe]:Hadronness");
+    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);
+
+    MFilterList precuts;
+    precuts.AddToList(fPreCuts);
+    precuts.AddToList(fTestCuts);
+
+    MContinue c0(&precuts);
+    c0.SetInverted();
+
+    tlist.AddToList(&read2);
+    tlist.AddToList(&c0);
+    tlist.AddToList(&rf);
+    tlist.AddToList(&fillh);
+    tlist.AddToList(&list);
+    tlist.AddToList(&fillh1);
+    tlist.AddToList(&fillh2);
+
+    MEvtLoop loop;
+    loop.SetDisplay(fDisplay);
+    loop.SetLogStream(fLog);
+    loop.SetParList(&plist);
+
+    if (!loop.Eventloop())
+        return kFALSE;
+
+    if (!WriteDisplay(out))
+        return kFALSE;
+
+    return kTRUE;
+}
+
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.h
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.h	(revision 7412)
@@ -0,0 +1,40 @@
+#ifndef MARS_MJTrainSeparation
+#define MARS_MJTrainSeparation
+
+#ifndef MARS_MJTrainRanForest
+#include "MJTrainRanForest.h"
+#endif
+
+#ifndef MARS_MDataSet
+#include "MDataSet.h"
+#endif
+
+class MJTrainSeparation : public MJTrainRanForest
+{
+private:
+    MDataSet fDataSetTest;
+    MDataSet fDataSetTrain;
+
+    UInt_t fNumTrainOn;
+    UInt_t fNumTrainOff;
+
+public:
+    MJTrainSeparation() { }
+
+    void SetDataSetTrain(const MDataSet &ds, UInt_t non, UInt_t noff)
+    {
+        ds.Copy(fDataSetTrain);
+        fNumTrainOn = non;
+        fNumTrainOff = noff;
+    }
+    void SetDataSetTest(const MDataSet &ds)
+    {
+        ds.Copy(fDataSetTest);
+    }
+
+    Bool_t Train(const char *out);
+
+    ClassDef(MJTrainSeparation, 0)//Class to train Random Forest gamma-/background-separation
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mjtrain/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/Makefile	(revision 7412)
+++ trunk/MagicSoft/Mars/mjtrain/Makefile	(revision 7412)
@@ -0,0 +1,36 @@
+##################################################################
+#
+#   makefile
+# 
+#   for the MARS software
+#
+##################################################################
+include ../Makefile.conf.$(OSTYPE)
+include ../Makefile.conf.general
+
+#------------------------------------------------------------------------------
+
+#
+# Handling name of the Root Dictionary Files
+#
+CINT  = Train
+
+#
+#  connect the include files defined in the config.mk file
+#
+INCLUDES = -I. -I../mbase -I../mhbase -I../mfbase -I../mdata -I../mfileio \
+           -I../manalysis -I../mfilter -I../mjobs -I../mtools \
+           -I../mranforest -I../mhflux -I../mmc -I../mhist
+
+SRCFILES = MJTrainRanForest.cc \
+	   MJTrainEnergy.cc \
+           MJTrainDisp.cc \
+           MJTrainSeparation.cc
+
+############################################################
+
+all: $(OBJS)
+
+include ../Makefile.rules
+
+mrproper:	clean rmbak
Index: trunk/MagicSoft/Mars/mjtrain/TrainIncl.h
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/TrainIncl.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mjtrain/TrainIncl.h	(revision 7412)
@@ -0,0 +1,3 @@
+#ifndef __CINT__
+
+#endif // __CINT__
Index: trunk/MagicSoft/Mars/mjtrain/TrainLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/TrainLinkDef.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mjtrain/TrainLinkDef.h	(revision 7412)
@@ -0,0 +1,12 @@
+#ifdef __CINT__
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class MJTrainRanForest+;
+#pragma link C++ class MJTrainEnergy+;
+#pragma link C++ class MJTrainDisp+;
+#pragma link C++ class MJTrainSeparation+;
+
+#endif
