1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Hengstebeck 3/2003 <mailto:hengsteb@alwa02.physik.uni-siegen.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2003
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | // //
|
---|
27 | // MRanForestGrow //
|
---|
28 | // //
|
---|
29 | // Grows a random forest. //
|
---|
30 | // //
|
---|
31 | /////////////////////////////////////////////////////////////////////////////
|
---|
32 | #include "MRanForestGrow.h"
|
---|
33 |
|
---|
34 | #include "MHMatrix.h" // must be before MLogManip.h
|
---|
35 |
|
---|
36 | #include "MLog.h"
|
---|
37 | #include "MLogManip.h"
|
---|
38 |
|
---|
39 | #include "MParList.h"
|
---|
40 |
|
---|
41 | #include "MRanTree.h"
|
---|
42 | #include "MRanForest.h"
|
---|
43 |
|
---|
44 | ClassImp(MRanForestGrow);
|
---|
45 |
|
---|
46 | using namespace std;
|
---|
47 |
|
---|
48 | static const TString gsDefName = "MRanForestGrow";
|
---|
49 | static const TString gsDefTitle = "Tree Classification Loop 1/2";
|
---|
50 |
|
---|
51 | // --------------------------------------------------------------------------
|
---|
52 | //
|
---|
53 | // Setup histograms and the number of distances which are used for
|
---|
54 | // avaraging in CalcDist
|
---|
55 | //
|
---|
56 | MRanForestGrow::MRanForestGrow(const char *name, const char *title)
|
---|
57 | : fNumTrees(100),fNumTry(3),fNdSize(1)
|
---|
58 | {
|
---|
59 | //
|
---|
60 | // set the name and title of this object
|
---|
61 | //
|
---|
62 | fName = name ? name : gsDefName.Data();
|
---|
63 | fTitle = title ? title : gsDefTitle.Data();
|
---|
64 | }
|
---|
65 |
|
---|
66 | // --------------------------------------------------------------------------
|
---|
67 | //
|
---|
68 | // Needs:
|
---|
69 | // - MatrixGammas [MHMatrix]
|
---|
70 | // - MatrixHadrons {MHMatrix]
|
---|
71 | // - MHadroness
|
---|
72 | // - all data containers used to build the matrixes
|
---|
73 | //
|
---|
74 | // The matrix object can be filles using MFillH. And must be of the same
|
---|
75 | // number of columns (with the same meaning).
|
---|
76 | //
|
---|
77 | Int_t MRanForestGrow::PreProcess(MParList *plist)
|
---|
78 | {
|
---|
79 | fMGammas = (MHMatrix*)plist->FindObject("MatrixGammas", "MHMatrix");
|
---|
80 | if (!fMGammas)
|
---|
81 | {
|
---|
82 | *fLog << err << dbginf << "MatrixGammas [MHMatrix] not found... aborting." << endl;
|
---|
83 | return kFALSE;
|
---|
84 | }
|
---|
85 |
|
---|
86 | fMHadrons = (MHMatrix*)plist->FindObject("MatrixHadrons", "MHMatrix");
|
---|
87 | if (!fMHadrons)
|
---|
88 | {
|
---|
89 | *fLog << err << dbginf << "MatrixHadrons [MHMatrix] not found... aborting." << endl;
|
---|
90 | return kFALSE;
|
---|
91 | }
|
---|
92 |
|
---|
93 | if (fMGammas->GetM().GetNcols() != fMHadrons->GetM().GetNcols())
|
---|
94 | {
|
---|
95 | *fLog << err << dbginf << "Error matrices have different numbers of columns... aborting." << endl;
|
---|
96 | return kFALSE;
|
---|
97 | }
|
---|
98 |
|
---|
99 | fRanTree = (MRanTree*)plist->FindCreateObj("MRanTree");
|
---|
100 | if (!fRanTree)
|
---|
101 | {
|
---|
102 | *fLog << err << dbginf << "MRanTree not found... aborting." << endl;
|
---|
103 | return kFALSE;
|
---|
104 | }
|
---|
105 |
|
---|
106 | fRanForest = (MRanForest*)plist->FindCreateObj("MRanForest");
|
---|
107 | if (!fRanForest)
|
---|
108 | {
|
---|
109 | *fLog << err << dbginf << "MRanForest not found... aborting." << endl;
|
---|
110 | return kFALSE;
|
---|
111 | }
|
---|
112 |
|
---|
113 | fRanTree->SetNumTry(fNumTry);
|
---|
114 | fRanTree->SetNdSize(fNdSize);
|
---|
115 | fRanForest->SetCurTree(fRanTree);
|
---|
116 | fRanForest->SetNumTrees(fNumTrees);
|
---|
117 |
|
---|
118 | return fRanForest->SetupGrow(fMHadrons,fMGammas);
|
---|
119 | }
|
---|
120 |
|
---|
121 | // --------------------------------------------------------------------------
|
---|
122 | //
|
---|
123 | //
|
---|
124 | Int_t MRanForestGrow::Process()
|
---|
125 | {
|
---|
126 | Bool_t not_last=fRanForest->GrowForest();
|
---|
127 | fRanTree->SetReadyToSave();
|
---|
128 |
|
---|
129 | return not_last;
|
---|
130 | }
|
---|
131 |
|
---|
132 | Int_t MRanForestGrow::PostProcess()
|
---|
133 | {
|
---|
134 | fRanTree->SetReadyToSave();
|
---|
135 | fRanForest->SetReadyToSave();
|
---|
136 |
|
---|
137 | return kTRUE;
|
---|
138 | }
|
---|