Ignore:
Timestamp:
08/23/07 11:26:38 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mranforest
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc

    r8646 r8698  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: MRanForestCalc.cc,v 1.27 2007-07-26 11:13:00 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: MRanForestCalc.cc,v 1.28 2007-08-23 10:25:08 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    6666
    6767MRanForestCalc::MRanForestCalc(const char *name, const char *title)
    68     : fData(0), fRFOut(0), fTestMatrix(0),
     68    : fData(0), fRFOut(0), fTestMatrix(0), fFunc("Function", "x"),
    6969    fNumTrees(-1), fNumTry(-1), fNdSize(-1), fNumObsoleteVariables(1),
    7070    fLastDataColumnHasWeights(kFALSE),
     
    7373    fName  = name  ? name  : gsDefName.Data();
    7474    fTitle = title ? title : gsDefTitle.Data();
     75
     76    gROOT->GetListOfFunctions()->Remove(&fFunc);
    7577
    7678    // FIXME:
     
    8385{
    8486    fEForests.Delete();
     87}
     88
     89// --------------------------------------------------------------------------
     90//
     91// Set a function which is applied to the output of the random forest
     92//
     93Bool_t MRanForestCalc::SetFunction(const char *func)
     94{
     95    return !fFunc.Compile(func);
    8596}
    8697
     
    291302    }
    292303
     304    if (fileRF.GetListOfKeys()->FindObject("Function"))
     305        fFunc.Read("Function");
     306
    293307    return kTRUE;
    294308}
     
    326340}
    327341
    328 Int_t MRanForestCalc::Process()
     342Double_t MRanForestCalc::Eval() const
    329343{
    330344    TVector event;
     
    338352    {
    339353        MRanForest *rf = static_cast<MRanForest*>(fEForests.UncheckedAt(0));
    340         fRFOut->SetVal(rf->CalcHadroness(event));
    341         fRFOut->SetReadyToSave();
    342 
    343         return kTRUE;
     354        return rf->CalcHadroness(event);
    344355    }
    345356
     
    383394    {
    384395    case kMean:
    385         fRFOut->SetVal(pow(10, sume/sumh));
    386         break;
     396        return sume/sumh;
    387397    case kMaximum:
    388         fRFOut->SetVal(pow(10, maxe));
    389         break;
     398        return maxe;
    390399    case kFit:
    391400        f1.SetParameter(0, maxh);
     
    393402        f1.SetParameter(2, 0.125);
    394403        g.Fit(&f1, "Q0N");
    395         fRFOut->SetVal(pow(10, f1.GetParameter(1)));
    396         break;
    397     }
    398 
     404        return f1.GetParameter(1);
     405    }
     406
     407    return 0;
     408}
     409
     410Int_t MRanForestCalc::Process()
     411{
     412    const Double_t val = Eval();
     413
     414    fRFOut->SetVal(fFunc.Eval(val));
    399415    fRFOut->SetReadyToSave();
    400416
  • trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h

    r7687 r8698  
    1212#ifndef ROOT_TArrayD
    1313#include <TArrayD.h>
     14#endif
     15
     16#ifndef ROOT_TF1
     17#include <TF1.h>
    1418#endif
    1519
     
    3640    MParameterD *fRFOut;                //! Used to store result
    3741    MHMatrix    *fTestMatrix;           //! Test Matrix used in Process (together with MMatrixLoop)
     42    TF1          fFunc;                 //! Function to apply to the result
    3843
    3944    TObjArray    fEForests;             //! List of forests read or to be written
     
    6065    // MRanForestCalc
    6166    Int_t ReadForests(MParList &plist);
     67    Double_t Eval() const;
    6268
    6369    // MParContainer
     
    8490    void SetNumTry(UShort_t n=0)     { fNumTry   = n; }
    8591    void SetDebug(Bool_t b=kTRUE)    { fDebug    = b; }
     92
     93    Bool_t SetFunction(const char *name="x");
    8694
    8795    void SetNumObsoleteVariables(Int_t n=1)          { fNumObsoleteVariables = n; }
Note: See TracChangeset for help on using the changeset viewer.