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;
 
