Index: trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc	(revision 8643)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc	(revision 8644)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz 11/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2005
+!   Copyright: MAGIC Software Development, 2005-2007
 !
 !
@@ -55,4 +55,7 @@
 #include "MJTrainDisp.h"
 
+#include <TLine.h>
+#include <TCanvas.h>
+
 #include "MHMatrix.h"
 
@@ -64,4 +67,5 @@
 #include "MTFillMatrix.h"
 #include "MChisqEval.h"
+#include "MStatusDisplay.h"
 
 // eventloop
@@ -92,6 +96,104 @@
 using namespace std;
 
+const TString MJTrainDisp::fgTrainParameter = "MHillasSrc.fDist*MGeomCam.fConvMm2Deg";
+
+// --------------------------------------------------------------------------
+//
+// Display a result histogram either vs. size or energy
+// FIXME: Could be moved into a new histogram class.
+//
+void MJTrainDisp::DisplayHist(TCanvas &c, Int_t i, MH3 &mh3) const
+{
+    MH::SetPalette("pretty");
+
+    TH1 &hist = *(TH1*)mh3.GetHist().Clone();
+    hist.SetBit(TH1::kNoStats);
+    hist.SetDirectory(0);
+
+    TLine line;
+    line.SetLineStyle(kDashed);
+    line.SetLineWidth(1);
+
+    c.cd(i);
+    gPad->SetBorderMode(0);
+    gPad->SetFrameBorderMode(0);
+    //gPad->SetFillColor(kWhite);
+    gPad->SetLogx();
+    gPad->SetGridx();
+    gPad->SetGridy();
+    //gPad->SetLeftMargin(0.12);
+    //gPad->SetRightMargin(0.12);
+
+    for (int x=0; x<=hist.GetNbinsX(); x++)
+    {
+        Float_t n = 0;
+        for (int y=1; y<=2; y++)
+            n += hist.GetBinContent(x,y);
+
+        if (n==0)
+            continue;
+
+        for (int y=0; y<=hist.GetNbinsY(); y++)
+            hist.SetBinContent(x, y, 200*hist.GetBinContent(x,y)/n);
+    }
+
+    hist.SetMaximum(100);
+    hist.DrawCopy("colz");
+
+    line.DrawLine(10, 0.04, 31623, 0.04);
+
+    c.cd(i+2);
+    gPad->SetBorderMode(0);
+    gPad->SetFrameBorderMode(0);
+    //gPad->SetFillColor(kWhite);
+    gPad->SetLogx();
+    gPad->SetGridx();
+    gPad->SetGridy();
+    //gPad->SetLeftMargin(0.12);
+    //gPad->SetRightMargin(0.12);
+
+    for (int x=0; x<=hist.GetNbinsX(); x++)
+    {
+        Float_t n = 0;
+        for (int y=0; y<=hist.GetNbinsY(); y++)
+            n += hist.GetBinContent(x,y);
+
+        if (n==0)
+            continue;
+
+        for (int y=0; y<=hist.GetNbinsY(); y++)
+            hist.SetBinContent(x, y, 100*hist.GetBinContent(x,y)/n);
+    }
+
+    hist.SetMaximum(25);
+    hist.DrawCopy("colz");
+
+    line.DrawLine(10, 0.04, 31623, 0.04);
+}
+
+// --------------------------------------------------------------------------
+//
+// Display the result histograms in a new tab.
+//
+void MJTrainDisp::DisplayResult(MH3 &hsize, MH3 &henergy)
+{
+    TCanvas &c = fDisplay->AddTab("Disp");
+    c.Divide(2,2);
+
+    DisplayHist(c, 1, hsize);
+    DisplayHist(c, 2, henergy);
+}
+
+// --------------------------------------------------------------------------
+//
+// Run Disp optimization
+//
 Bool_t MJTrainDisp::Train(const char *out, const MDataSet &set, Int_t num)
 {
+    SetTitle(Form("TrainDisp: %s", out));
+
+    if (fDisplay)
+        fDisplay->SetTitle(fTitle);
+
     if (!set.IsValid())
     {
@@ -99,4 +201,7 @@
         return kFALSE;
     }
+
+    if (!HasWritePermission(out))
+        return kFALSE;
 
     *fLog << inf;
@@ -119,9 +224,8 @@
     if (fEnableWeights)
         train.AddColumn("MWeight.fVal");
-    train.AddColumn("MHillasSrc.fDist*MGeomCam.fConvMm2Deg");
-    //train.AddColumn("TMath::Hypot(MHillasSrc.fDCA, MHillasSrc.fDist)*MGeomCam.fConvMm2Deg");
+    train.AddColumn(fgTrainParameter);
 
     // ----------------------- Fill Matrix RF ----------------------
-    MTFillMatrix fill;
+    MTFillMatrix fill(fTitle);
     fill.SetDisplay(fDisplay);
     fill.SetLogStream(fLog);
@@ -136,5 +240,5 @@
 
     // ------------------------ Train RF --------------------------
-    MRanForestCalc rf;
+    MRanForestCalc rf(fTitle);
     rf.SetNumTrees(fNumTrees);
     rf.SetNdSize(fNdSize);
@@ -212,11 +316,11 @@
     eval.SetY1("sqrt(ThetaSquared.fVal)");
 
-    MH3 hdisp1("MHillas.fSize",  "sqrt(ThetaSquared.fVal)");
-    MH3 hdisp2("MMcEvt.fEnergy", "sqrt(ThetaSquared.fVal)");
+    MH3 hdisp1("MHillas.fSize",  "ThetaSquared.fVal");
+    MH3 hdisp2("MMcEvt.fEnergy", "ThetaSquared.fVal");
     hdisp1.SetTitle("\\vartheta distribution vs. Size:Size [phe]:\\vartheta [\\circ]");
     hdisp2.SetTitle("\\vartheta distribution vs. Energy:Enerhy [GeV]:\\vartheta [\\circ]");
 
-    MBinning binsx(50, 10, 100000, "BinningMH3X", "log");
-    MBinning binsy(50, 0,  1,      "BinningMH3Y", "lin");
+    MBinning binsx( 70, 10, 31623, "BinningMH3X", "log");
+    MBinning binsy( 75, 0,  0.3,   "BinningMH3Y", "lin");
 
     plist.AddToList(&binsx);
@@ -239,8 +343,10 @@
     tlist.AddToList(&eval);
 
-    MEvtLoop loop;
+    MEvtLoop loop(fTitle);
     loop.SetLogStream(fLog);
     loop.SetDisplay(fDisplay);
     loop.SetParList(&plist);
+    //if (!SetupEnv(loop))
+    //    return kFALSE;
 
     if (!loop.Eventloop())
@@ -251,5 +357,8 @@
     hist.GetAlphaFitter().Print("result");
 
-    if (!WriteDisplay(out, "UPDATE"))
+    DisplayResult(hdisp1, hdisp2);
+
+    SetPathOut(out);
+    if (!WriteDisplay(0, "UPDATE"))
         return kFALSE;
 
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.h
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.h	(revision 8643)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.h	(revision 8644)
@@ -6,10 +6,24 @@
 #endif
 
+class TCanvas;
+
+class MH3;
 class MDataSet;
 
 class MJTrainDisp : public MJTrainRanForest
 {
+private:
+    static const TString fgTrainParameter;
+
+    TString fTrainParameter;
+
+    void DisplayHist(TCanvas &c, Int_t i, MH3 &mh3) const;
+    void DisplayResult(MH3 &hsize, MH3 &henergy);
+
 public:
-    MJTrainDisp() { }
+    MJTrainDisp() : fTrainParameter(fgTrainParameter) { }
+
+    void SetTrainParameter(const char *txt) { fTrainParameter=txt; }
+
     Bool_t Train(const char *out, const MDataSet &set, Int_t num);
 
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc	(revision 8643)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc	(revision 8644)
@@ -62,4 +62,5 @@
 #include "MDataSet.h"
 #include "MTFillMatrix.h"
+#include "MStatusDisplay.h"
 
 // eventloop
@@ -86,4 +87,9 @@
 Bool_t MJTrainEnergy::Train(const char *out, const MDataSet &set, Int_t num)
 {
+    SetTitle(Form("TrainEnergy: %s", out));
+
+    if (fDisplay)
+        fDisplay->SetTitle(fTitle);
+
     if (!set.IsValid())
     {
@@ -91,4 +97,7 @@
         return kFALSE;
     }
+
+    if (!HasWritePermission(out))
+        return kFALSE;
 
     *fLog << inf;
@@ -102,7 +111,13 @@
 
     if (!set.AddFilesOn(readtrn))
-        return kFALSE;
+    {
+        *fLog << err << "ERROR - Adding SequencesOn." << endl;
+        return kFALSE;
+    }
     if (!set.AddFilesOff(readtst))
-        return kFALSE;
+    {
+        *fLog << err << "ERROR - Adding SequencesOff." << endl;
+        return kFALSE;
+    }
 
     // ----------------------- Setup Matrix ------------------
@@ -117,5 +132,5 @@
 
     // ----------------------- Fill Matrix RF ----------------------
-    MTFillMatrix fill;
+    MTFillMatrix fill(fTitle);
     fill.SetDisplay(fDisplay);
     fill.SetLogStream(fLog);
@@ -130,5 +145,5 @@
 
     // ------------------------ Train RF --------------------------
-    MRanForestCalc rf;
+    MRanForestCalc rf(fTitle);
     rf.SetNumTrees(fNumTrees);
     rf.SetNdSize(fNdSize);
@@ -185,13 +200,16 @@
     tlist.AddToList(&fillh);
 
-    MEvtLoop loop;
+    MEvtLoop loop(fTitle);
     loop.SetLogStream(fLog);
     loop.SetDisplay(fDisplay);
     loop.SetParList(&plist);
+    //if (!SetupEnv(loop))
+    //   return kFALSE;
 
     if (!loop.Eventloop())
         return kFALSE;
 
-    if (!WriteDisplay(out, "UPDATE"))
+    SetPathOut(out);
+    if (!WriteDisplay(0, "UPDATE"))
         return kFALSE;
 
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc	(revision 8643)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc	(revision 8644)
@@ -589,4 +589,7 @@
 Bool_t MJTrainSeparation::Train(const char *out)
 {
+    if (fDisplay)
+        fDisplay->SetTitle(out);
+
     if (!fDataSetTrain.IsValid())
     {
@@ -606,5 +609,8 @@
     }
 
-    TStopwatch clock;
+    if (!HasWritePermission(out))
+        return kFALSE;
+
+        TStopwatch clock;
     clock.Start();
 
@@ -939,4 +945,6 @@
     loop.SetLogStream(fLog);
     loop.SetParList(&plist);
+    //if (!SetupEnv(loop))
+    //   return kFALSE;
 
     wgt.SetVal(1);
@@ -1039,5 +1047,6 @@
 
     // Write the display
-    if (!WriteDisplay(out, "UPDATE"))
+    SetPathOut(out);
+    if (!WriteDisplay(0, "UPDATE"))
         return kFALSE;
 
