Changeset 2862 for trunk/MagicSoft/Mars


Ignore:
Timestamp:
01/20/04 17:49:06 (21 years ago)
Author:
hengsteb
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r2861 r2862  
    44
    55                                                 -*-*- END OF LINE -*-*-
     6
     7 2004/01/20: Thomas Hengstebeck
     8
     9   * mranforest/MRanForestCalc.[h,cc]
     10     - Added member functions Grow (training of RF) and Fill (reading in
     11       trained forest from file) which simplify macros.
     12       One just needs to call them instead of using MRanForestGrow and
     13       MRanForestFill (and the related training and fill loops) in a
     14       macro.
    615
    716 2004/01/20: Abelardo moralejo
  • trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc

    r2296 r2862  
    4949#include "MHadronness.h"
    5050
     51#include "MEvtLoop.h"
     52#include "MTaskList.h"
     53#include "MFillH.h"
     54#include "MStatusDisplay.h"
     55#include "MRanForestGrow.h"
     56#include "MRanForestFill.h"
     57
     58#include "MWriteRootFile.h"
     59#include "MReadTree.h"
     60
    5161ClassImp(MRanForestCalc);
    5262
     
    149159}
    150160
     161Bool_t MRanForestCalc::Grow(MHMatrix *matrixg,MHMatrix *matrixh,Int_t ntree,
     162                            Int_t numtry,Int_t ndsize,const char* treefile=0,
     163                            const char* treename=0,const char* contname=0,
     164                            const char* hgininame=0)
     165{
     166
     167    treename  = treename  ? treename  : "Tree";
     168    contname  = contname  ? contname  : "MRanTree";
     169    hgininame  = hgininame  ? hgininame  : "MHRanForestGini";
     170
     171    if (!matrixg->IsValid())
     172    {
     173        *fLog << err << dbginf << " MRanForestCalc::Grow - ERROR: matrixg not valid." << endl;
     174        return kFALSE;
     175    }
     176    if(!matrixh->IsValid())
     177    {
     178        *fLog << err << dbginf << " MRanForestCalc::Grow - ERROR: matrixh not valid." << endl;
     179        return kFALSE;
     180    }
     181
     182    MEvtLoop run(GetName());
     183    MTaskList tlist;
     184    MParList plist;
     185    plist.AddToList(&tlist);
     186    plist.AddToList(matrixg);
     187    plist.AddToList(matrixh);
     188
     189    // creating training task and setting parameters
     190    MRanForestGrow rfgrow;
     191    rfgrow.SetNumTrees(ntree); // number of trees
     192    rfgrow.SetNumTry(numtry);  // number of trials in random split selection
     193    rfgrow.SetNdSize(ndsize);  // limit for nodesize
     194    tlist.AddToList(&rfgrow);
     195
     196    if(treefile){
     197        MWriteRootFile rfwrite(treefile);
     198        rfwrite.AddContainer(contname,treename);
     199        tlist.AddToList(&rfwrite);
     200    }
     201
     202    MFillH fillh(hgininame);
     203    tlist.AddToList(&fillh);
     204
     205    run.SetParList(&plist);
     206   
     207    // Execute tree growing
     208    if (!run.Eventloop())
     209    {
     210        *fLog << err << dbginf << "Evtloop in MRanForestCalc::Grow failed." << endl;
     211        return kFALSE;
     212    }
     213    tlist.PrintStatistics(0, kTRUE);
     214
     215    if (TestBit(kEnableGraphicalOutput))
     216        plist.FindObject(hgininame)->DrawClone();
     217
     218    return kTRUE;
     219}
     220
     221Bool_t MRanForestCalc::Fill(Int_t ntree,const char* treefile=0,const char* treename=0)
     222{
     223    treefile  = treefile  ? treefile  : "RF.root";
     224    treename  = treename  ? treename  : "Tree";
     225
     226    MParList  plist;
     227
     228    MTaskList tlist;
     229    plist.AddToList(&tlist);
     230
     231    MReadTree read(treename,treefile);
     232    read.DisableAutoScheme();
     233
     234    MRanForestFill rffill;
     235    rffill.SetNumTrees(ntree);
     236
     237    tlist.AddToList(&read);
     238    tlist.AddToList(&rffill);
     239
     240    MEvtLoop run(GetName());
     241    run.SetParList(&plist);
     242
     243    //
     244    // Execute tree reading
     245    //
     246    if (!run.Eventloop())
     247    {
     248        *fLog << err << dbginf << "Evtloop in MRanForestCalc::Fill failed." << endl;
     249        return kFALSE;
     250    }
     251    tlist.PrintStatistics(0, kTRUE);
     252
     253    return kTRUE;
     254}
  • trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h

    r2207 r2862  
    44#ifndef MARS_MTask
    55#include "MTask.h"
     6#endif
     7
     8#ifndef MARS_MHMatrix
     9#include "MHMatrix.h"
    610#endif
    711
     
    3640    void SetUseNumTrees(UShort_t n=100) { fNum = n; }
    3741
     42    Bool_t Grow(MHMatrix *matrixg,MHMatrix *matrixh,Int_t ntree,
     43                Int_t numtry,Int_t ndsize,const char* treefile=0,
     44                const char* treename=0,const char* contname=0,
     45                const char* hgininame=0);
     46
     47    Bool_t Fill(Int_t ntree,const char* treefile=0,const char* treename=0);
     48
     49
    3850    ClassDef(MRanForestCalc, 0) // Task
    3951};
  • trunk/MagicSoft/Mars/mranforest/Makefile

    r2800 r2862  
    2222#  connect the include files defined in the config.mk file
    2323#
    24 INCLUDES = -I. -I../mbase -I../mhbase -I../mdata -I../manalysis -I../mmc
     24INCLUDES = -I. -I../mbase -I../mhbase -I../mdata -I../manalysis -I../mmc -I../mfileio
    2525#               MParContainer MH     MDataArray MHadronness    MMcEvt
    26 
    2726#------------------------------------------------------------------------------
    2827
Note: See TracChangeset for help on using the changeset viewer.