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 | // MRanForestCalc
|
---|
28 | //
|
---|
29 | // Calculates the hadroness of an event. It calculates a mean value of all
|
---|
30 | // classifications by the trees in a previously grown random forest.
|
---|
31 | //
|
---|
32 | // To use only n trees for your calculation use:
|
---|
33 | // MRanForestCalc::SetUseNumTrees(n);
|
---|
34 | //
|
---|
35 | ////////////////////////////////////////////////////////////////////////////
|
---|
36 | #include "MRanForestCalc.h"
|
---|
37 |
|
---|
38 | #include "MHMatrix.h" // must be before MLogManip.h
|
---|
39 | #include "MDataArray.h"
|
---|
40 |
|
---|
41 | #include "MLog.h"
|
---|
42 | #include "MLogManip.h"
|
---|
43 |
|
---|
44 | #include "MParList.h"
|
---|
45 |
|
---|
46 | #include "MRanTree.h"
|
---|
47 | #include "MRanForest.h"
|
---|
48 |
|
---|
49 | #include "MHadronness.h"
|
---|
50 |
|
---|
51 | ClassImp(MRanForestCalc);
|
---|
52 |
|
---|
53 | static const TString gsDefName = "MRanForestCalc";
|
---|
54 | static const TString gsDefTitle = "Tree Classification Loop 1/2";
|
---|
55 |
|
---|
56 | // --------------------------------------------------------------------------
|
---|
57 | //
|
---|
58 | // Setup histograms and the number of distances which are used for
|
---|
59 | // avaraging in CalcDist
|
---|
60 | //
|
---|
61 | MRanForestCalc::MRanForestCalc(const char *name, const char *title)
|
---|
62 | : fNum(100), fData(NULL)
|
---|
63 | {
|
---|
64 | //
|
---|
65 | // set the name and title of this object
|
---|
66 | //
|
---|
67 | fName = name ? name : gsDefName.Data();
|
---|
68 | fTitle = title ? title : gsDefTitle.Data();
|
---|
69 | }
|
---|
70 |
|
---|
71 | // --------------------------------------------------------------------------
|
---|
72 | //
|
---|
73 | // Delete the data chains
|
---|
74 | //
|
---|
75 | MRanForestCalc::~MRanForestCalc()
|
---|
76 | {
|
---|
77 | // delete fData;
|
---|
78 | }
|
---|
79 |
|
---|
80 | // --------------------------------------------------------------------------
|
---|
81 | //
|
---|
82 | // Needs:
|
---|
83 | // - MatrixGammas [MHMatrix]
|
---|
84 | // - MatrixHadrons {MHMatrix]
|
---|
85 | // - MHadronness
|
---|
86 | // - all data containers used to build the matrixes
|
---|
87 | //
|
---|
88 | // The matrix object can be filles using MFillH. And must be of the same
|
---|
89 | // number of columns (with the same meaning).
|
---|
90 | //
|
---|
91 | Bool_t MRanForestCalc::PreProcess(MParList *plist)
|
---|
92 | {
|
---|
93 | fRanForest = (MRanForest*)plist->FindObject("MRanForest");
|
---|
94 | if (!fRanForest)
|
---|
95 | {
|
---|
96 | *fLog << err << dbginf << "MRanForest not found... aborting." << endl;
|
---|
97 | return kFALSE;
|
---|
98 | }
|
---|
99 |
|
---|
100 | fRanTree = (MRanTree*)plist->FindObject("MRanTree");
|
---|
101 | if (!fRanTree)
|
---|
102 | {
|
---|
103 | *fLog << err << dbginf << "MRanTree not found... aborting." << endl;
|
---|
104 | return kFALSE;
|
---|
105 | }
|
---|
106 |
|
---|
107 | /*if(!fRanForest->GetCurTree())
|
---|
108 | {
|
---|
109 | *fLog << err << dbginf << "MRanForest does not contain trees... aborting." << endl;
|
---|
110 | return kFALSE;
|
---|
111 | }*/
|
---|
112 |
|
---|
113 | fData = fRanTree->GetRules();
|
---|
114 |
|
---|
115 | if (!fData)
|
---|
116 | {
|
---|
117 | *fLog << err << dbginf << "Error matrix doesn't contain columns... aborting." << endl;
|
---|
118 | return kFALSE;
|
---|
119 | }
|
---|
120 |
|
---|
121 | if (!fData->PreProcess(plist))
|
---|
122 | {
|
---|
123 | *fLog << err << dbginf << "PreProcessing of the MDataArray failed for the columns failed... aborting." << endl;
|
---|
124 | return kFALSE;
|
---|
125 | }
|
---|
126 |
|
---|
127 | fHadroness = (MHadronness*)plist->FindCreateObj("MHadronness");
|
---|
128 | if (!fHadroness)
|
---|
129 | return kFALSE;
|
---|
130 |
|
---|
131 | return kTRUE;
|
---|
132 | }
|
---|
133 |
|
---|
134 | // --------------------------------------------------------------------------
|
---|
135 | //
|
---|
136 | //
|
---|
137 | Bool_t MRanForestCalc::Process()
|
---|
138 | {
|
---|
139 | const Double_t ncols = fData->GetNumEntries();
|
---|
140 | TVector event(ncols);
|
---|
141 |
|
---|
142 | for (int i=0; i<fData->GetNumEntries(); i++)
|
---|
143 | event(i) = (*fData)(i);
|
---|
144 |
|
---|
145 | Double_t hadroness=fRanForest->CalcHadroness(event);
|
---|
146 | fHadroness->SetHadronness(hadroness);
|
---|
147 |
|
---|
148 | return kTRUE;
|
---|
149 | }
|
---|
150 |
|
---|