Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 2861)
+++ trunk/MagicSoft/Mars/Changelog	(revision 2862)
@@ -4,4 +4,13 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2004/01/20: Thomas Hengstebeck
+
+   * mranforest/MRanForestCalc.[h,cc]
+     - Added member functions Grow (training of RF) and Fill (reading in
+       trained forest from file) which simplify macros. 
+       One just needs to call them instead of using MRanForestGrow and 
+       MRanForestFill (and the related training and fill loops) in a
+       macro.
 
  2004/01/20: Abelardo moralejo
Index: trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc	(revision 2861)
+++ trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc	(revision 2862)
@@ -49,4 +49,14 @@
 #include "MHadronness.h"
 
+#include "MEvtLoop.h"
+#include "MTaskList.h"
+#include "MFillH.h"
+#include "MStatusDisplay.h"
+#include "MRanForestGrow.h"
+#include "MRanForestFill.h"
+
+#include "MWriteRootFile.h"
+#include "MReadTree.h"
+
 ClassImp(MRanForestCalc);
 
@@ -149,2 +159,96 @@
 }
 
+Bool_t MRanForestCalc::Grow(MHMatrix *matrixg,MHMatrix *matrixh,Int_t ntree,
+                            Int_t numtry,Int_t ndsize,const char* treefile=0,
+                            const char* treename=0,const char* contname=0,
+                            const char* hgininame=0)
+{
+
+    treename  = treename  ? treename  : "Tree";
+    contname  = contname  ? contname  : "MRanTree";
+    hgininame  = hgininame  ? hgininame  : "MHRanForestGini";
+
+    if (!matrixg->IsValid())
+    {
+        *fLog << err << dbginf << " MRanForestCalc::Grow - ERROR: matrixg not valid." << endl;
+        return kFALSE;
+    }
+    if(!matrixh->IsValid())
+    {
+        *fLog << err << dbginf << " MRanForestCalc::Grow - ERROR: matrixh not valid." << endl;
+        return kFALSE;
+    }
+
+    MEvtLoop run(GetName());
+    MTaskList tlist;
+    MParList plist;
+    plist.AddToList(&tlist);
+    plist.AddToList(matrixg);
+    plist.AddToList(matrixh);
+
+    // creating training task and setting parameters
+    MRanForestGrow rfgrow;
+    rfgrow.SetNumTrees(ntree); // number of trees
+    rfgrow.SetNumTry(numtry);  // number of trials in random split selection
+    rfgrow.SetNdSize(ndsize);  // limit for nodesize
+    tlist.AddToList(&rfgrow);
+
+    if(treefile){
+        MWriteRootFile rfwrite(treefile);
+        rfwrite.AddContainer(contname,treename);
+        tlist.AddToList(&rfwrite);
+    }
+
+    MFillH fillh(hgininame);
+    tlist.AddToList(&fillh);
+
+    run.SetParList(&plist);
+    
+    // Execute tree growing
+    if (!run.Eventloop())
+    {
+        *fLog << err << dbginf << "Evtloop in MRanForestCalc::Grow failed." << endl;
+        return kFALSE;
+    }
+    tlist.PrintStatistics(0, kTRUE);
+
+    if (TestBit(kEnableGraphicalOutput))
+        plist.FindObject(hgininame)->DrawClone();
+
+    return kTRUE;
+}
+
+Bool_t MRanForestCalc::Fill(Int_t ntree,const char* treefile=0,const char* treename=0)
+{
+    treefile  = treefile  ? treefile  : "RF.root";
+    treename  = treename  ? treename  : "Tree";
+
+    MParList  plist;
+
+    MTaskList tlist;
+    plist.AddToList(&tlist);
+
+    MReadTree read(treename,treefile);
+    read.DisableAutoScheme();
+
+    MRanForestFill rffill;
+    rffill.SetNumTrees(ntree);
+
+    tlist.AddToList(&read);
+    tlist.AddToList(&rffill);
+
+    MEvtLoop run(GetName());
+    run.SetParList(&plist);
+
+    //
+    // Execute tree reading
+    //
+    if (!run.Eventloop())
+    {
+        *fLog << err << dbginf << "Evtloop in MRanForestCalc::Fill failed." << endl;
+        return kFALSE;
+    }
+    tlist.PrintStatistics(0, kTRUE);
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h	(revision 2861)
+++ trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h	(revision 2862)
@@ -4,4 +4,8 @@
 #ifndef MARS_MTask
 #include "MTask.h"
+#endif
+
+#ifndef MARS_MHMatrix
+#include "MHMatrix.h"
 #endif
 
@@ -36,4 +40,12 @@
     void SetUseNumTrees(UShort_t n=100) { fNum = n; }
 
+    Bool_t Grow(MHMatrix *matrixg,MHMatrix *matrixh,Int_t ntree,
+                Int_t numtry,Int_t ndsize,const char* treefile=0,
+                const char* treename=0,const char* contname=0,
+                const char* hgininame=0);
+
+    Bool_t Fill(Int_t ntree,const char* treefile=0,const char* treename=0);
+
+
     ClassDef(MRanForestCalc, 0) // Task
 };
Index: trunk/MagicSoft/Mars/mranforest/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mranforest/Makefile	(revision 2861)
+++ trunk/MagicSoft/Mars/mranforest/Makefile	(revision 2862)
@@ -22,7 +22,6 @@
 #  connect the include files defined in the config.mk file
 #
-INCLUDES = -I. -I../mbase -I../mhbase -I../mdata -I../manalysis -I../mmc
+INCLUDES = -I. -I../mbase -I../mhbase -I../mdata -I../manalysis -I../mmc -I../mfileio
 #               MParContainer MH     MDataArray MHadronness    MMcEvt
-
 #------------------------------------------------------------------------------
 
