| 1 | #ifndef MARS_MRanForest | 
|---|
| 2 | #define MARS_MRanForest | 
|---|
| 3 |  | 
|---|
| 4 | #ifndef MARS_MParContainer | 
|---|
| 5 | #include "MParContainer.h" | 
|---|
| 6 | #endif | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef ROOT_TArrayI | 
|---|
| 9 | #include <TArrayI.h> | 
|---|
| 10 | #endif | 
|---|
| 11 |  | 
|---|
| 12 | #ifndef ROOT_TArrayF | 
|---|
| 13 | #include <TArrayF.h> | 
|---|
| 14 | #endif | 
|---|
| 15 |  | 
|---|
| 16 | #ifndef ROOT_TArrayD | 
|---|
| 17 | #include <TArrayD.h> | 
|---|
| 18 | #endif | 
|---|
| 19 |  | 
|---|
| 20 | #ifndef ROOT_TMatrix | 
|---|
| 21 | #include <TMatrix.h> | 
|---|
| 22 | #endif | 
|---|
| 23 |  | 
|---|
| 24 | #ifndef ROOT_TVector | 
|---|
| 25 | #include <TVector.h> | 
|---|
| 26 | #endif | 
|---|
| 27 |  | 
|---|
| 28 | class TObjArray; | 
|---|
| 29 |  | 
|---|
| 30 | class MArrayI; | 
|---|
| 31 | class MArrayF; | 
|---|
| 32 |  | 
|---|
| 33 | class MRanTree; | 
|---|
| 34 | class MDataArray; | 
|---|
| 35 | class MHMatrix; | 
|---|
| 36 | class MParList; | 
|---|
| 37 |  | 
|---|
| 38 | class MRanForest : public MParContainer | 
|---|
| 39 | { | 
|---|
| 40 | private: | 
|---|
| 41 | Bool_t fClassify; | 
|---|
| 42 |  | 
|---|
| 43 | Int_t fNumTrees;       // Number of trees | 
|---|
| 44 | Int_t fNumTry;         // Number of tries | 
|---|
| 45 | Int_t fNdSize;         // Size of node | 
|---|
| 46 |  | 
|---|
| 47 | Int_t fTreeNo;         //! Number of tree | 
|---|
| 48 |  | 
|---|
| 49 | MRanTree   *fRanTree;  //! Pointer to some tree | 
|---|
| 50 | MDataArray *fRules;    //! Pointer to corresponding rules | 
|---|
| 51 | TObjArray  *fForest;   //  Array containing forest | 
|---|
| 52 |  | 
|---|
| 53 | // training data | 
|---|
| 54 | TMatrix *fMatrix;      //! | 
|---|
| 55 |  | 
|---|
| 56 | // true  and estimated hadronness | 
|---|
| 57 | TArrayI fClass;        //! | 
|---|
| 58 | TArrayD fGrid;         //! | 
|---|
| 59 | TArrayF fHadTrue;      //! | 
|---|
| 60 | TArrayF fHadEst;       //! | 
|---|
| 61 |  | 
|---|
| 62 | // data sorted according to parameters | 
|---|
| 63 | TArrayI fDataSort;     //! | 
|---|
| 64 | TArrayI fDataRang;     //! | 
|---|
| 65 | TArrayI fClassPop;     //! | 
|---|
| 66 |  | 
|---|
| 67 | // weights | 
|---|
| 68 | TArrayF fWeight;       //! | 
|---|
| 69 | TArrayI fNTimesOutBag; //! | 
|---|
| 70 |  | 
|---|
| 71 | // estimates for classification error of growing forest | 
|---|
| 72 | TArrayD fTreeHad;      //! Hadronness values (buffer for MHRanForest) | 
|---|
| 73 |  | 
|---|
| 74 | Double_t fUserVal;     // A user value describing this tree (eg E-mc) | 
|---|
| 75 |  | 
|---|
| 76 | protected: | 
|---|
| 77 | // create and modify (->due to bagging) fDataSort | 
|---|
| 78 | Bool_t CreateDataSort(); | 
|---|
| 79 | void ModifyDataSort(MArrayI &datsortinbag, const MArrayI &jinbag); | 
|---|
| 80 |  | 
|---|
| 81 | public: | 
|---|
| 82 | MRanForest(const char *name=NULL, const char *title=NULL); | 
|---|
| 83 | MRanForest(const MRanForest &rf); | 
|---|
| 84 | ~MRanForest(); | 
|---|
| 85 |  | 
|---|
| 86 | void Print(Option_t *o="") const; //*MENU* | 
|---|
| 87 |  | 
|---|
| 88 | void SetGrid(const TArrayD &grid); | 
|---|
| 89 | void SetWeights(const TArrayF &weights); | 
|---|
| 90 | void SetNumTrees(Int_t n); | 
|---|
| 91 |  | 
|---|
| 92 | void SetNumTry(Int_t n); | 
|---|
| 93 | void SetNdSize(Int_t n); | 
|---|
| 94 |  | 
|---|
| 95 | void SetClassify(Bool_t n){ fClassify=n; } | 
|---|
| 96 | void PrepareClasses(); | 
|---|
| 97 |  | 
|---|
| 98 | // tree growing | 
|---|
| 99 | Bool_t SetupGrow(MHMatrix *mat,MParList *plist); | 
|---|
| 100 | Bool_t GrowForest(); | 
|---|
| 101 | void   SetCurTree(MRanTree *rantree) { fRanTree=rantree; } | 
|---|
| 102 | Bool_t AddTree(MRanTree *rantree); | 
|---|
| 103 | void   SetUserVal(Double_t d) { fUserVal = d; } | 
|---|
| 104 |  | 
|---|
| 105 | // getter methods | 
|---|
| 106 | TObjArray  *GetForest() const      { return fForest; } | 
|---|
| 107 | MRanTree   *GetCurTree() const     { return fRanTree; } | 
|---|
| 108 | MRanTree   *GetTree(Int_t i) const; | 
|---|
| 109 | MDataArray *GetRules() const       { return fRules; } | 
|---|
| 110 |  | 
|---|
| 111 |  | 
|---|
| 112 | Int_t      GetNumTrees() const { return fNumTrees; } | 
|---|
| 113 | Int_t      GetNumData()  const; | 
|---|
| 114 | Int_t      GetNumDim()   const; | 
|---|
| 115 | Int_t      GetNdSize() const { return fNdSize; } | 
|---|
| 116 | Int_t      GetNclass()   const; | 
|---|
| 117 | Double_t   GetTreeHad(Int_t i) const { return fTreeHad.At(i); } | 
|---|
| 118 | Double_t   GetUserVal() const { return fUserVal; } | 
|---|
| 119 | Bool_t     IsClassify() const { return fClassify; } | 
|---|
| 120 |  | 
|---|
| 121 | // use forest to calculate hadronness of event | 
|---|
| 122 | Double_t CalcHadroness(const TVector &event); | 
|---|
| 123 | Double_t CalcHadroness(); | 
|---|
| 124 |  | 
|---|
| 125 | Bool_t AsciiWrite(ostream &out) const; | 
|---|
| 126 |  | 
|---|
| 127 | ClassDef(MRanForest, 1) // Storage container for tree structure | 
|---|
| 128 | }; | 
|---|
| 129 |  | 
|---|
| 130 | #endif | 
|---|