Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 8703)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 8704)
@@ -18,4 +18,47 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+
+ 2007/08/24 Thomas Bretz
+
+   * mdata/MDataMember.cc:
+     - added a sanity check in GetValue()
+
+   * mdata/MDataPhrase.[h,cc]:
+     - Allow to use MDataPhrase also with variables x,y,z and t
+     - Allow evaluation of the function with given x,y,z,t 
+
+   * mjobs/MJSpectrum.h:
+     - commented IntermediateLoop, was unused
+
+   * mjoptim/MJOptimize.cc:
+     - added two comments
+
+   * mjtrain/MJTrainDisp.cc:
+     - added new MHn to display more information about the test
+     - improved result-histogram
+     - added PreTasks, PostTasks and TestTasks to testing tasklist
+     - some fixes if the user closed the display
+
+   * mjtrain/MJTrainEnergy.cc
+     - added new MHn to display more information about the test
+     - allow to set fTrainParameter and fResultFunction from
+       outside, this allows to train on whatever you like
+     - added TestTasks to testing tasklist
+     - added new member functions to set Train parameter and
+       evaluation function: SetTrainLog/Log and SetTrainFunc
+
+   * mranforest/MRanForestCalc.[h,cc]:
+     - changed evaluatio function-type from TF1 to MDataPhrase
+
+   * mraw/MRawEvtData.cc:
+     - initialize fNumBytesPerSample with 1
+
+   * mraw/MRawRunHeader.[h,cc]
+     - set default FADC type to 1 (Siegen)
+     - it turned out that we use 1/2 and not 0/1 as expected
+
+
+
 
 
Index: /trunk/MagicSoft/Mars/NEWS
===================================================================
--- /trunk/MagicSoft/Mars/NEWS	(revision 8703)
+++ /trunk/MagicSoft/Mars/NEWS	(revision 8704)
@@ -30,4 +30,18 @@
      for example in testing after optimizations or training to produce
      user defined histograms.
+
+   - general: The Random Forest now allows attaching an evaluation
+     function which is applied to its output. This allows to train
+     on whatever you like (eg. train on log10(energy), but return
+     energy)
+
+   - general: TheRandom Forest training of energy (trainenergy.c) and
+     disp (traindisp.C) has been improved by more graphical output to
+     judge the result. 
+
+   - general: The training of energy (trainenergy.C) has been improved
+     a lot by training on a different quantity than energy. It gives
+     a result which is highly independant of the source spectrum
+     and shows lower bias than all other options.
 
    - merpp: Merpp can read file format version 9 now. Please realize
Index: /trunk/MagicSoft/Mars/mdata/MDataMember.cc
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataMember.cc	(revision 8703)
+++ /trunk/MagicSoft/Mars/mdata/MDataMember.cc	(revision 8704)
@@ -97,4 +97,11 @@
 Double_t MDataMember::GetValue() const
 {
+    if (!fObject)
+    {
+        *fLog << err << "ERROR - MDataMember::GetValue: fObject not initialized ";
+        *fLog << "(not PreProcessed)... returning 0." << endl;
+        return 0;
+    }
+
     if (!fCall)
     {
@@ -138,5 +145,5 @@
     // the original statement "if (fCall)" is replaced by the statement
     if (fCall && !fObject)
-            return kTRUE;
+        return kTRUE;
 
     TString cname(fDataMember);
Index: /trunk/MagicSoft/Mars/mdata/MDataPhrase.cc
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataPhrase.cc	(revision 8703)
+++ /trunk/MagicSoft/Mars/mdata/MDataPhrase.cc	(revision 8704)
@@ -469,5 +469,5 @@
 //  Evaluates and returns the result of the member list.
 //
-Double_t MDataPhrase::GetValue() const
+Double_t MDataPhrase::Eval(const Double_t *x) const
 {
     const Int_t n = fMembers.GetEntriesFast();
@@ -490,5 +490,5 @@
 
     // Evaluate function
-    return fFormula->EvalPar(0, arr);
+    return fFormula->EvalPar(x, arr);
 }
 
Index: /trunk/MagicSoft/Mars/mdata/MDataPhrase.h
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataPhrase.h	(revision 8703)
+++ /trunk/MagicSoft/Mars/mdata/MDataPhrase.h	(revision 8704)
@@ -46,5 +46,11 @@
     Bool_t   IsValid() const;
     Bool_t   HasValidRule() const { return fFormula ? kTRUE : kFALSE; }
-    Double_t GetValue() const;
+    Double_t GetValue() const { return Eval((Double_t*)NULL); }
+    Double_t Eval(const Double_t *x) const;
+    Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
+    {
+        const Double_t xx[4] = { x, y, z, t };
+        return Eval(xx);
+    }
     TString  GetRule() const;
     TString  GetRuleRaw() const;
Index: /trunk/MagicSoft/Mars/mjoptim/MJOptimize.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjoptim/MJOptimize.cc	(revision 8703)
+++ /trunk/MagicSoft/Mars/mjoptim/MJOptimize.cc	(revision 8704)
@@ -665,4 +665,5 @@
     gMinuit = 0;
 
+    // Test with training data
     fEvtLoop->SetDisplay(fDisplay);
     if (!Fcn(fParameters))
@@ -674,4 +675,5 @@
         return kTRUE;
 
+    // Test with test-data
     loop->SetOperationMode(fTestTrain<0?MMatrixLoop::kEven:MMatrixLoop::kOdd);
 
Index: /trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc	(revision 8703)
+++ /trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc	(revision 8704)
@@ -87,4 +87,5 @@
 #include "MBinning.h"
 #include "MH3.h"
+#include "MHn.h"
 #include "MHThetaSq.h"
 
@@ -115,5 +116,40 @@
     line.SetLineWidth(1);
 
-    c.cd(i);
+    c.cd(i+4);
+    gPad->SetBorderMode(0);
+    gPad->SetFrameBorderMode(0);
+    //gPad->SetFillColor(kWhite);
+    gPad->SetLogx();
+    gPad->SetGridx();
+    gPad->SetGridy();
+    //gPad->SetLeftMargin(0.12);
+    //gPad->SetRightMargin(0.12);
+
+    const Float_t cutval = hist.GetYaxis()->GetBinLowEdge(4);
+
+    TH1D heff;
+    heff.SetName(Form("Eff%s", hist.GetName()));
+    heff.SetTitle(Form("Cut efficiency vs. %s for \\vartheta<%.3f", hist.GetName(), TMath::Sqrt(cutval)));
+    heff.SetDirectory(0);
+    heff.SetXTitle(hist.GetXaxis()->GetTitle());
+    heff.SetYTitle("Efficiency");
+
+    MH::SetBinning(&heff, hist.GetXaxis());
+
+
+    for (int x=0; x<=hist.GetNbinsX()+1; x++)
+    {
+        const Double_t n0 = hist.Integral(x, x, -1, -1);
+        if (n0>0)
+            heff.SetBinContent(x, hist.Integral(x, x, -1, 3)/n0);
+    }
+
+    heff.SetMinimum(0);
+    heff.SetMaximum(1);
+    heff.DrawCopy();
+
+    line.DrawLine(10, 0.5, 31623, 0.5);
+
+    c.cd(i+0);
     gPad->SetBorderMode(0);
     gPad->SetFrameBorderMode(0);
@@ -179,5 +215,5 @@
 {
     TCanvas &c = fDisplay->AddTab("Disp");
-    c.Divide(2,2);
+    c.Divide(2,3);
 
     DisplayHist(c, 1, hsize);
@@ -215,7 +251,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 ------------------
@@ -277,5 +319,5 @@
 
     MParameterD par("ThetaSquaredCut");
-    par.SetVal(0.2);
+    par.SetVal(0.215*0.215);
     plist.AddToList(&par);
 
@@ -297,4 +339,37 @@
     cont.SetInverted();
 
+    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)");
+
+    // ----------- Setup binnings ----------------
+    MBinning binsS(50,  10,    100000, "BinningSize",         "log");
+    MBinning binsE(70,  10,    31623,  "BinningEnergy",       "log");
+    MBinning binsG(50, -10,    10,     "BinningSlope",        "lin");
+    MBinning binsX(50, -1,     1,      "BinningResidualDist", "lin");
+    MBinning binsL(50,  0,     0.3,    "BinningLeakage",      "lin");
+    MBinning binsT(51, -0.005, 0.505,  "BinningTheta",        "asin");
+    MBinning binsC(50,  1e-2,  1,      "BinningConc",         "log");
+    MBinning binsW(50,  0,     0.5,    "BinningLength",       "lin");
+    MBinning binsM(50,  0,     0.3,    "BinningWidth",        "lin");
+    MBinning binsV(75,  0, par.GetVal()*25, "BinningThetaSq", "lin");
+
+    plist.AddToList(&binsG);
+    plist.AddToList(&binsS);
+    plist.AddToList(&binsX);
+    plist.AddToList(&binsE);
+    plist.AddToList(&binsL);
+    plist.AddToList(&binsT);
+    plist.AddToList(&binsC);
+    plist.AddToList(&binsV);
+    plist.AddToList(&binsW);
+    plist.AddToList(&binsM);
+
+    // ----------- Setup some histograms ----------------
+
     MHThetaSq hist;
     hist.SkipHistTime();
@@ -302,46 +377,89 @@
     hist.SkipHistEnergy();
 
-    MFillH fillh(&hist, "", "FillThetaSq");
-
-    // 0 =  disp^2 - 2*disp*dist*cos(alpha) + dist^2
-
-    // cos^2 -1 = - sin^2
-
-    // disp = +dist* (cos(alpha) +/- sqrt(cos^2(alpha) - 1) )
-
-    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)");
+    // To speed it up we could precalculate it.
+    const char *res = "Disp.fVal-MHillasSrc.fDist*3.37e-3";
+
+    MHn hres1("Disp1", "Xi Residual (Dist/Disp)");
+    hres1.AddHist("MHillas.fSize", res);
+    hres1.InitName("ResSize;Size;ResidualDist");
+    hres1.InitTitle(";S [phe];Disp-Dist [\\circ];");
+    hres1.SetDrawOption("colz profx");
+    hres1.AddHist("MHillasExt.fSlopeLong*sign(MHillasSrc.fCosDeltaAlpha)/3.37e-3", res);
+    hres1.InitName("ResSlope;Slope;ResidualDist");
+    hres1.InitTitle(";Slope;Disp-Dist [\\circ];");
+    hres1.SetDrawOption("colz profx");
+    hres1.AddHist("MNewImagePar.fLeakage1", res);
+    hres1.InitName("ResLeak;Leakage;ResidualDist");
+    hres1.InitTitle(";Leak;Disp-Dist [\\circ];");
+    hres1.SetDrawOption("colz profx");
+    hres1.AddHist("MPointingPos.fZd", res);
+    hres1.InitName("ResTheta;Theta;ResidualDist");
+    hres1.InitTitle(";Zd [\\circ];Disp-Dist [\\circ];");
+    hres1.SetDrawOption("colz profx");
+
+    MHn hres2("Disp2", "Dist Residual (Disp-Dist)");
+    hres2.AddHist("MHillas.fLength*3.37e-3", res);
+    hres2.InitName("ResLength;Length;ResidualDist");
+    hres2.InitTitle(";L [\\circ];Disp-Dist [\\circ];");
+    hres2.SetDrawOption("colz profx");
+    hres2.AddHist("MNewImagePar.fConc1", res);
+    hres2.InitName("ResConc1;Conc;ResidualDist");
+    hres2.InitTitle(";C;Disp-Dist [\\circ];");
+    hres2.SetDrawOption("colz profx");
+    hres2.AddHist("MHillas.fWidth*3.37e-3", res);
+    hres2.InitName("ResWidth;Width;ResidualDist");
+    hres2.InitTitle(";W [\\circ];Disp-Dist [\\circ];");
+    hres2.SetDrawOption("colz profx");
+    hres2.AddHist("MMcEvt.fEnergy", res);
+    hres2.InitName("ResEmc;Energy;ResidualDist");
+    hres2.InitTitle(";E_{mc} [GeV];Disp-Dist [\\circ];");
+    hres2.SetDrawOption("colz profx");
 
     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( 70, 10, 31623, "BinningMH3X", "log");
-    MBinning binsy( 75, 0,  0.3,   "BinningMH3Y", "lin");
-
-    plist.AddToList(&binsx);
-    plist.AddToList(&binsy);
-
-    MFillH fillh2a(&hdisp1, "", "FillSize");
-    MFillH fillh2b(&hdisp2, "", "FillEnergy");
-    fillh2a.SetDrawOption("colz profx");
-    fillh2b.SetDrawOption("colz profx");
-    fillh2a.SetNameTab("Size");
-    fillh2b.SetNameTab("Energy");
+    hdisp1.SetName("Size;Size;ThetaSq");
+    hdisp2.SetName("Energy;Energy;ThetaSq");
+    hdisp1.SetTitle("\\vartheta distribution vs. Size:Size [phe]:\\vartheta^2 [\\circ]");
+    hdisp2.SetTitle("\\vartheta distribution vs. Energy:Energy [GeV]:\\vartheta^2 [\\circ]");
+
+    // -------------- Setup fill tasks ----------------
+
+    MFillH fillh(&hist, "", "FillThetaSq");
+    MFillH fillh2a(&hres1, "", "FillResiduals1");
+    MFillH fillh2b(&hres2, "", "FillResiduals2");
+    MFillH fillh2c(&hdisp1, "", "FillSize");
+    MFillH fillh2d(&hdisp2, "", "FillEnergy");
+    fillh2c.SetBit(MFillH::kDoNotDisplay);
+    fillh2d.SetBit(MFillH::kDoNotDisplay);
+
+    // --------------- Setup weighting -------------------
+
+    if (fEnableWeights)
+    {
+        fillh.SetWeight();
+        fillh2a.SetWeight();
+        fillh2b.SetWeight();
+        fillh2c.SetWeight();
+        fillh2d.SetWeight();
+        eval.SetNameWeight();
+    }
+
+    // --------------- Setup tasklist -------------------
 
     tlist.AddToList(&readtst);
+    tlist.AddToList(fPreTasks);
     tlist.AddToList(&cont);
     tlist.AddToList(&rf);
     tlist.AddToList(&calcthetasq);
+    tlist.AddToList(fPostTasks);
     tlist.AddToList(&fillh);
     tlist.AddToList(&fillh2a);
     tlist.AddToList(&fillh2b);
+    tlist.AddToList(&fillh2c);
+    tlist.AddToList(&fillh2d);
+    tlist.AddToList(fTestTasks);
     tlist.AddToList(&eval);
+
+    // ------------- Setup/run eventloop -----------------
 
     MEvtLoop loop(fTitle);
@@ -355,4 +473,6 @@
         return kFALSE;
 
+    // ---------------- Prepare result -------------------
+
     // Print the result
     *fLog << inf;
@@ -361,11 +481,12 @@
     hist.GetAlphaFitter().Print("result");
 
+    // The user has closed the display
+    if (!fDisplay)
+        return kTRUE;
+
     DisplayResult(hdisp1, hdisp2);
 
     SetPathOut(out);
-    if (!WriteDisplay(0, "UPDATE"))
-        return kFALSE;
-
-    return kTRUE;
+    return WriteDisplay(0, "UPDATE");
 }
 
Index: /trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc	(revision 8703)
+++ /trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc	(revision 8704)
@@ -76,4 +76,6 @@
 
 // histograms
+#include "MHn.h"
+#include "MBinning.h"
 #include "MHEnergyEst.h"
 
@@ -128,5 +130,5 @@
     train.AddColumn("MMcEvt.fImpact/100");
     train.AddColumn("MMcEvt.fTelescopeTheta*TMath::RadToDeg()");
-    train.AddColumn("MMcEvt.fEnergy");
+    train.AddColumn(fTrainParameter);
 
 
@@ -156,4 +158,5 @@
     rf.SetDebug(fDebug>1);
     rf.SetNameOutput("MEnergyEst");
+    rf.SetFunction(fResultFunction);
 
     /*
@@ -188,8 +191,76 @@
     cont.SetInverted();
 
+    // -------------------------------------------------------------
+    MBinning binsS(50, 10,     100000, "BinningSize",           "log");
+    MBinning binsE(70, 10,     31623,  "BinningEnergy",         "log");
+    MBinning binsG(50,-10,     10,     "BinningSlope",          "lin");
+    MBinning binsR(50, -1,     1,      "BinningEnergyResidual", "lin");
+    MBinning binsL(50,  0,     0.3,    "BinningLeakage",        "lin");
+    MBinning binsT(51, -0.005, 0.505,  "BinningTheta",          "asin");
+    MBinning binsD(50,  0,     1.6,    "BinningDist",           "lin");
+    MBinning binsC(50,  1e-2,  1,      "BinningConc",           "log");
+
+    plist.AddToList(&binsG);
+    plist.AddToList(&binsS);
+    plist.AddToList(&binsR);
+    plist.AddToList(&binsE);
+    plist.AddToList(&binsL);
+    plist.AddToList(&binsT);
+    plist.AddToList(&binsD);
+    plist.AddToList(&binsC);
+
     MHEnergyEst hist;
+
+    // To speed it up we could precalculate it.
+    const char *res = "log10(MEnergyEst.fVal)-log10(MMcEvt.fEnergy)";
+
+    MHn hres1("Energy1", "Energy Residual (lg E_{est} - lg E_{mc})");
+    hres1.AddHist("MHillas.fSize", res);
+    hres1.InitName("ResSize;Size;EnergyResidual");
+    hres1.InitTitle(";S [phe];\\Delta lg E;");
+    hres1.SetDrawOption("colz profx");
+    hres1.AddHist("MHillasExt.fSlopeLong*sign(MHillasSrc.fCosDeltaAlpha)/3.37e-3", res);
+    hres1.InitName("ResSlope;Slope;EnergyResidual");
+    hres1.InitTitle(";Slope;\\Delta lg E;");
+    hres1.SetDrawOption("colz profx");
+    hres1.AddHist("MNewImagePar.fLeakage1", res);
+    hres1.InitName("ResLeak;Leakage;EnergyResidual");
+    hres1.InitTitle(";Leak;\\Delta lg E;");
+    hres1.SetDrawOption("colz profx");
+    hres1.AddHist("MHillasSrc.fDist*3.37e-3", res);
+    hres1.InitName("ResDist;Dist;EnergyResidual");
+    hres1.InitTitle(";D [\\circ];\\Delta lg E;");
+    hres1.SetDrawOption("colz profx");
+
+    MHn hres2("Energy2", "Energy Residual (lg E_{est} - lg E_{mc})");
+    hres2.AddHist("MMcEvt.fEnergy", res);
+    hres2.InitName("ResEmc;Energy;EnergyResidual");
+    hres2.InitTitle(";E_{mc} [GeV];\\Delta lg E;");
+    hres2.SetDrawOption("colz profx");
+    hres2.SetAutoRange(kFALSE, kFALSE, kFALSE);
+    hres2.AddHist("MPointingPos.fZd", res);
+    hres2.InitName("ResTheta;Theta;EnergyResidual");
+    hres2.InitTitle(";Zd [\\circ];\\Delta lg E;");
+    hres2.SetDrawOption("colz profx");
+    hres2.AddHist("MEnergyEst.fVal", res);
+    hres2.InitName("ResEest;Energy;EnergyResidual");
+    hres2.InitTitle(";E_{est} [GeV];\\Delta lg E;");
+    hres2.SetDrawOption("colz profx");
+    hres2.SetAutoRange(kFALSE, kFALSE, kFALSE);
+    hres2.AddHist("MNewImagePar.fConc1", res);
+    hres2.InitName("ResConc1;Conc;EnergyResidual");
+    hres2.InitTitle(";C;\\Delta lg E;");
+    hres2.SetDrawOption("colz profx");
+
     MFillH fillh(&hist);
+    MFillH fillh1(&hres1, "", "FillResiduals1");
+    MFillH fillh2(&hres2, "", "FillResiduals2");
+
     if (fEnableWeights)
+    {
         fillh.SetWeight();
+        fillh1.SetWeight();
+        fillh2.SetWeight();
+    }
 
     tlist.AddToList(&readtst);
@@ -199,4 +270,7 @@
     tlist.AddToList(fPostTasks);
     tlist.AddToList(&fillh);
+    tlist.AddToList(&fillh1);
+    tlist.AddToList(&fillh2);
+    tlist.AddToList(fTestTasks);
 
     MEvtLoop loop(fTitle);
Index: /trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.h
===================================================================
--- /trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.h	(revision 8703)
+++ /trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.h	(revision 8704)
@@ -10,6 +10,20 @@
 class MJTrainEnergy : public MJTrainRanForest
 {
+private:
+    TString fTrainParameter;
+    TString fResultFunction;
+
 public:
-    MJTrainEnergy() { }
+    MJTrainEnergy() { SetTrainLin(); }
+
+    void SetTrainLog() { SetTrainFunc("log10(MMcEvt.fEnergy)", "pow(10, x)"); }
+    void SetTrainLin() { SetTrainFunc("MMcEvt.fEnergy", "x"); }
+
+    void SetTrainFunc(const char *par, const char *res)
+    {
+        fTrainParameter = par;
+        fResultFunction = res;
+    }
+
     Bool_t Train(const char *out, const MDataSet &set, Int_t num);
 
Index: /trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc	(revision 8703)
+++ /trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc	(revision 8704)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MRanForestCalc.cc,v 1.28 2007-08-23 10:25:08 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MRanForestCalc.cc,v 1.29 2007-08-24 08:33:48 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -63,8 +63,9 @@
 const TString MRanForestCalc::gsDefTitle   = "RF for energy estimation";
 
-const TString MRanForestCalc::gsNameOutput = "RanForestOut";
+const TString MRanForestCalc::gsNameOutput   = "RanForestOut";
+const TString MRanForestCalc::gsNameEvalFunc = "EvalFunction";
 
 MRanForestCalc::MRanForestCalc(const char *name, const char *title)
-    : fData(0), fRFOut(0), fTestMatrix(0), fFunc("Function", "x"),
+    : fData(0), fRFOut(0), fTestMatrix(0), fFunc("x"),
     fNumTrees(-1), fNumTry(-1), fNdSize(-1), fNumObsoleteVariables(1),
     fLastDataColumnHasWeights(kFALSE),
@@ -73,6 +74,4 @@
     fName  = name  ? name  : gsDefName.Data();
     fTitle = title ? title : gsDefTitle.Data();
-
-    gROOT->GetListOfFunctions()->Remove(&fFunc);
 
     // FIXME:
@@ -93,5 +92,5 @@
 Bool_t MRanForestCalc::SetFunction(const char *func)
 {
-    return !fFunc.Compile(func);
+    return !fFunc.SetRule(func);
 }
 
@@ -267,4 +266,6 @@
     usedrules.Write("rules");
 
+    fFunc.Write(gsNameEvalFunc);
+
     return kTRUE;
 }
@@ -302,6 +303,14 @@
     }
 
-    if (fileRF.GetListOfKeys()->FindObject("Function"))
-        fFunc.Read("Function");
+    if (fileRF.GetListOfKeys()->FindObject(gsNameEvalFunc))
+    {
+        if (fFunc.Read(gsNameEvalFunc)<=0)
+        {
+            *fLog << err << "ERROR - Reading '" << gsNameEvalFunc << "' from file " << fFileName << endl;
+            return kFALSE;
+        }
+
+        *fLog << inf << "Evaluation function found in file: " << fFunc.GetRule() << endl;
+    }
 
     return kTRUE;
@@ -325,4 +334,10 @@
 
     *fLog << inf << "RF read from " << fFileName << endl;
+
+    if (!fFunc.PreProcess(plist))
+    {
+        *fLog << err << "PreProcessing of evaluation function failed... aborting." << endl;
+        return kFALSE;
+    }
 
     if (fTestMatrix)
Index: /trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h	(revision 8703)
+++ /trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h	(revision 8704)
@@ -14,6 +14,6 @@
 #endif
 
-#ifndef ROOT_TF1
-#include <TF1.h>
+#ifndef ROOT_MDataPhrase
+#include "MDataPhrase.h"
 #endif
 
@@ -33,12 +33,13 @@
 
 private:
-    static const TString gsDefName;     //! Default Name
-    static const TString gsDefTitle;    //! Default Title
-    static const TString gsNameOutput;  //! Default Output name
+    static const TString gsDefName;      //! Default Name
+    static const TString gsDefTitle;     //! Default Title
+    static const TString gsNameOutput;   //! Default Output name
+    static const TString gsNameEvalFunc; //! Evaluation function name
 
     MDataArray  *fData;                 //! Used to store the MDataChains to get the event values
     MParameterD *fRFOut;                //! Used to store result
     MHMatrix    *fTestMatrix;           //! Test Matrix used in Process (together with MMatrixLoop)
-    TF1          fFunc;                 //! Function to apply to the result
+    MDataPhrase  fFunc;                 //! Function to apply to the result
 
     TObjArray    fEForests;             //! List of forests read or to be written
Index: /trunk/MagicSoft/Mars/mraw/MRawEvtData.cc
===================================================================
--- /trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 8703)
+++ /trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 8704)
@@ -108,5 +108,5 @@
 //
 MRawEvtData::MRawEvtData(const char *name, const char *title)
-    : fRunHeader(0)
+    : fRunHeader(0), fNumBytesPerSample(1)
 {
     fName  = name  ? name  : "MRawEvtData";
Index: /trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc
===================================================================
--- /trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 8703)
+++ /trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 8704)
@@ -157,5 +157,5 @@
     fTelescopeNumber=1;
     fCameraVersion=1;
-    fFadcType=0;
+    fFadcType=1;
     fRunType=kRTNone;  // use 0xffff for invalidation, 0 means: Data run
     fRunNumber=0;
@@ -415,5 +415,5 @@
 
 
-    fFadcType = 0;
+    fFadcType = 1;
     if (fFormatVersion>7)
         fin.read((char*)&fFadcType, 2);
@@ -573,5 +573,12 @@
         *fLog << "Telescope:    " << fTelescopeNumber << endl;
     if (fFormatVersion>7)
-        *fLog << "FadcType:     " << fFadcType << endl;
+        *fLog << "FadcType:     " << fFadcType << " (";
+    switch (fFadcType)
+    {
+    case 1: *fLog << "Siegen"; break;
+    case 2: *fLog << "MUX"; break;
+    default: *fLog << "unknown";
+    }
+    *fLog << ")" << endl;
     *fLog << "RunNumber:    " << fRunNumber << " (Type=" << GetRunTypeStr() << ")" << endl;
     *fLog << "ProjectName: '" << fProjectName << "'" << endl;
Index: /trunk/MagicSoft/Mars/mraw/MRawRunHeader.h
===================================================================
--- /trunk/MagicSoft/Mars/mraw/MRawRunHeader.h	(revision 8703)
+++ /trunk/MagicSoft/Mars/mraw/MRawRunHeader.h	(revision 8704)
@@ -41,5 +41,5 @@
     UShort_t  fFormatVersion;        // File format version
     UShort_t  fSoftVersion;          // DAQ software version
-    UShort_t  fFadcType;             // FADC type (0=Siegen, 1=MUX)
+    UShort_t  fFadcType;             // FADC type (1=Siegen, 2=MUX)
     UShort_t  fCameraVersion;        // Camera Version (1=MAGIC I)
     UShort_t  fTelescopeNumber;      // Telescope number (1=Magic I)
