Ignore:
Timestamp:
07/08/05 18:14:35 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mranforest
Files:
2 edited

Legend:

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

    r7169 r7178  
    6969//
    7070MRFEnergyEst::MRFEnergyEst(const char *name, const char *title)
    71     : fNumTrees(-1), fNumTry(-1), fNdSize(-1), fDebug(kFALSE),
    72     fData(0), fEnergyEst(0), fTestMatrix(0), fEstimationMode(kMean)
     71    : fDebug(kFALSE), fData(0), fEnergyEst(0),
     72    fNumTrees(-1), fNumTry(-1), fNdSize(-1),
     73    fTestMatrix(0), fEstimationMode(kMean)
    7374{
    7475    fName  = name  ? name  : gsDefName.Data();
    7576    fTitle = title ? title : gsDefTitle.Data();
     77}
     78
     79MRFEnergyEst::~MRFEnergyEst()
     80{
     81    fEForests.Delete();
    7682}
    7783
     
    163169        MHMatrix matrix1(mat1, "MatrixHadrons");
    164170        MHMatrix matrix0(mat0, "MatrixGammas");
    165 
    166         //matrix1.AddColumns(&usedrules);
    167         //matrix0.AddColumns(&usedrules);
    168171
    169172        // training of RF
     
    191194            gLog.SetNullOutput(kFALSE);
    192195
    193         const Double_t E = (log10(grid[ie])+log10(grid[ie+1]))/2;
     196        // Calculate bin center
     197        const Double_t E = (TMath::Log10(grid[ie])+TMath::Log10(grid[ie+1]))/2;
    194198
    195199        // save whole forest
    196200        MRanForest *forest=(MRanForest*)plist.FindObject("MRanForest");
    197         const TString title = Form("%.10f", E);
    198         forest->SetTitle(title);
    199         forest->Write(title);
     201        forest->SetUserVal(E);
     202        forest->Write(Form("%.10f", E));
    200203    }
    201204
     
    203206    usedrules.Write("rules");
    204207
    205     fileRF.Close();
    206 
    207208    return kTRUE;
    208209}
     
    210211Int_t MRFEnergyEst::ReadForests(MParList &plist)
    211212{
    212     TFile fileRF(fFileName,"read");
     213    TFile fileRF(fFileName, "read");
    213214    if (!fileRF.IsOpen())
    214215    {
     
    218219
    219220    fEForests.Delete();
    220 
    221     Int_t i=0;
    222221
    223222    TIter Next(fileRF.GetListOfKeys());
     
    230229            continue;
    231230
    232         forest->SetTitle(o->GetTitle());
    233         forest->SetBit(kCanDelete);
    234 
    235         fBinning.Set(i+1);
    236         fBinning[i++] = atof(o->GetTitle());
     231        forest->SetUserVal(atof(o->GetName()));
    237232
    238233        fEForests.Add(forest);
     
    283278//
    284279//
     280#include <TGraph.h>
     281#include <TF1.h>
    285282Int_t MRFEnergyEst::Process()
    286283{
     284    static TF1 f1("f1", "gaus");
     285
    287286    TVector event;
    288287    if (fTestMatrix)
     
    291290        *fData >> event;
    292291
    293     Double_t eest = 0;
    294     Double_t hsum = 0;
     292    Double_t sume = 0;
     293    Double_t sumh = 0;
    295294    Double_t maxh = 0;
    296295    Double_t maxe = 0;
    297296
    298     Int_t i=0;
     297    Double_t max  = -1e10;
     298    Double_t min  =  1e10;
     299
     300    //TH1C h("", "", fEForests.GetSize(), 0, 1);
    299301
    300302    TIter Next(&fEForests);
    301303    MRanForest *rf = 0;
     304
     305    TGraph g;
    302306    while ((rf=(MRanForest*)Next()))
    303307    {
    304308        const Double_t h = rf->CalcHadroness(event);
    305         const Double_t e = fBinning[i++];
    306 
    307         hsum += h;
    308         eest += e*h;
     309        const Double_t e = rf->GetUserVal();
     310        g.SetPoint(g.GetN(), e, h);
     311        sume += e*h;
     312        sumh += h;
    309313        if (h>maxh)
    310314        {
     
    312316            maxe = e;
    313317        }
     318        if (e>max)
     319            max = e;
     320        if (e<min)
     321            min = e;
    314322    }
    315323
     
    317325    {
    318326    case kMean:
    319         fEnergyEst->SetVal(pow(10, eest/hsum));
     327        fEnergyEst->SetVal(pow(10, sume/sumh));
    320328        break;
    321329    case kMaximum:
    322330        fEnergyEst->SetVal(pow(10, maxe));
    323331        break;
     332    case kFit:
     333        f1.SetParameter(0, maxh);
     334        f1.SetParameter(1, maxe);
     335        f1.SetParameter(2, 0.125);
     336        g.Fit(&f1, "Q0N");
     337        fEnergyEst->SetVal(pow(10, f1.GetParameter(1)));
     338        break;
     339
    324340    }
    325341    fEnergyEst->SetReadyToSave();
     
    353369        if (txt==(TString)"maximum")
    354370            fEstimationMode = kMaximum;
     371        if (txt==(TString)"fit")
     372            fEstimationMode = kFit;
    355373        rc = kTRUE;
    356374    }
  • trunk/MagicSoft/Mars/mranforest/MRFEnergyEst.h

    r7169 r7178  
    2323    {
    2424        kMean,
    25         kMaximum
     25        kMaximum,
     26        kFit
    2627    };
    2728private:
    28     Int_t        fNumTrees;  // Training parameters
    29     Int_t        fNumTry;    // Training parameters
    30     Int_t        fNdSize;    // Training parameters
     29    Bool_t       fDebug;      // Debugging of eventloop while training on/off
    3130
    32     Bool_t       fDebug;     // Debugging of eventloop while training on/off
    33 
    34     TString      fFileName;
    35     TObjArray    fEForests;
     31    TString      fFileName;   // File name to forest
     32    TObjArray    fEForests;   // List of forests
    3633
    3734    MDataArray  *fData;       //! Used to store the MDataChains to get the event values
    3835    MParameterD *fEnergyEst;  //! Used to storeestimated energy
    3936
    40     MHMatrix *fTestMatrix;
     37    Int_t        fNumTrees;   //! Training parameters
     38    Int_t        fNumTry;     //! Training parameters
     39    Int_t        fNdSize;     //! Training parameters
    4140
    42     TArrayD   fBinning;
     41    MHMatrix    *fTestMatrix; //! Test Matrix
    4342
    4443    EstimationMode_t fEstimationMode;
    4544
     45    // MRFEnergyEst
     46    Int_t ReadForests(MParList &plist);
     47
     48    // MTask
    4649    Int_t PreProcess(MParList *plist);
    4750    Int_t Process();
    4851
    49     Int_t ReadForests(MParList &plist);
    50 
     52    // MParContainer
    5153    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
    5254
    5355public:
    5456    MRFEnergyEst(const char *name=NULL, const char *title=NULL);
     57    ~MRFEnergyEst();
    5558
     59    // Setter for estimation
    5660    void  SetFileName(TString str)     { fFileName = str; }
     61    void  SetEstimationMode(EstimationMode_t op) { fEstimationMode = op; }
    5762
     63    // Setter for training
    5864    void  SetNumTrees(Int_t n=-1)      { fNumTrees = n; }
    5965    void  SetNdSize(Int_t n=-1)        { fNdSize   = n; }
    6066    void  SetNumTry(Int_t n=-1)        { fNumTry   = n; }
     67    void  SetDebug(Bool_t b=kTRUE)     { fDebug = b; }
    6168
     69    // Train Interface
     70    Int_t Train(const MHMatrix &n, const TArrayD &grid);
     71
     72    // Test Interface
    6273    void  SetTestMatrix(MHMatrix *m=0) { fTestMatrix=m; }
    6374    void  InitMapping(MHMatrix *m=0)   { fTestMatrix=m; }
    64 
    65     void  SetDebug(Bool_t b=kTRUE)     { fDebug = b; }
    66 
    67     void  SetEstimationMode(EstimationMode_t op) { fEstimationMode = op; }
    68 
    69     Int_t Train(const MHMatrix &n, const TArrayD &grid);
    7075
    7176    ClassDef(MRFEnergyEst, 0) // Task
Note: See TracChangeset for help on using the changeset viewer.