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 | using namespace std;
|
---|
54 |
|
---|
55 | static const TString gsDefName = "MRanForestCalc";
|
---|
56 | static const TString gsDefTitle = "Tree Classification Loop 1/2";
|
---|
57 |
|
---|
58 | // --------------------------------------------------------------------------
|
---|
59 | //
|
---|
60 | // Setup histograms and the number of distances which are used for
|
---|
61 | // avaraging in CalcDist
|
---|
62 | //
|
---|
63 | MRanForestCalc::MRanForestCalc(const char *name, const char *title)
|
---|
64 | : fNum(100), fHadronnessName("MHadronness"), fData(NULL)
|
---|
65 | {
|
---|
66 | //
|
---|
67 | // set the name and title of this object
|
---|
68 | //
|
---|
69 | fName = name ? name : gsDefName.Data();
|
---|
70 | fTitle = title ? title : gsDefTitle.Data();
|
---|
71 | }
|
---|
72 |
|
---|
73 | // --------------------------------------------------------------------------
|
---|
74 | //
|
---|
75 | // Delete the data chains
|
---|
76 | //
|
---|
77 | MRanForestCalc::~MRanForestCalc()
|
---|
78 | {
|
---|
79 | // delete fData;
|
---|
80 | }
|
---|
81 |
|
---|
82 | // --------------------------------------------------------------------------
|
---|
83 | //
|
---|
84 | // Needs:
|
---|
85 | // - MatrixGammas [MHMatrix]
|
---|
86 | // - MatrixHadrons [MHMatrix]
|
---|
87 | // - MHadronness
|
---|
88 | // - all data containers used to build the matrixes
|
---|
89 | //
|
---|
90 | // The matrix object can be filles using MFillH. And must be of the same
|
---|
91 | // number of columns (with the same meaning).
|
---|
92 | //
|
---|
93 | Int_t MRanForestCalc::PreProcess(MParList *plist)
|
---|
94 | {
|
---|
95 | fRanForest = (MRanForest*)plist->FindObject("MRanForest");
|
---|
96 | if (!fRanForest)
|
---|
97 | {
|
---|
98 | *fLog << err << dbginf << "MRanForest not found... aborting." << endl;
|
---|
99 | return kFALSE;
|
---|
100 | }
|
---|
101 |
|
---|
102 | fRanTree = (MRanTree*)plist->FindObject("MRanTree");
|
---|
103 | if (!fRanTree)
|
---|
104 | {
|
---|
105 | *fLog << err << dbginf << "MRanTree not found... aborting." << endl;
|
---|
106 | return kFALSE;
|
---|
107 | }
|
---|
108 |
|
---|
109 | /*if(!fRanForest->GetCurTree())
|
---|
110 | {
|
---|
111 | *fLog << err << dbginf << "MRanForest does not contain trees... aborting." << endl;
|
---|
112 | return kFALSE;
|
---|
113 | }*/
|
---|
114 |
|
---|
115 | fData = fRanTree->GetRules();
|
---|
116 |
|
---|
117 | if (!fData)
|
---|
118 | {
|
---|
119 | *fLog << err << dbginf << "Error matrix doesn't contain columns... aborting." << endl;
|
---|
120 | return kFALSE;
|
---|
121 | }
|
---|
122 |
|
---|
123 | if (!fData->PreProcess(plist))
|
---|
124 | {
|
---|
125 | *fLog << err << dbginf << "PreProcessing of the MDataArray failed for the columns failed... aborting." << endl;
|
---|
126 | return kFALSE;
|
---|
127 | }
|
---|
128 |
|
---|
129 | fHadroness = (MHadronness*)plist->FindCreateObj("MHadronness", fHadronnessName);
|
---|
130 | if (!fHadroness)
|
---|
131 | return kFALSE;
|
---|
132 |
|
---|
133 | return kTRUE;
|
---|
134 | }
|
---|
135 |
|
---|
136 | // --------------------------------------------------------------------------
|
---|
137 | //
|
---|
138 | //
|
---|
139 | Int_t MRanForestCalc::Process()
|
---|
140 | {
|
---|
141 | // first copy the data from the data array to a vector event
|
---|
142 | TVector event;
|
---|
143 | *fData >> event;
|
---|
144 |
|
---|
145 | Double_t hadroness=fRanForest->CalcHadroness(event);
|
---|
146 | fHadroness->SetHadronness(hadroness);
|
---|
147 |
|
---|
148 | return kTRUE;
|
---|
149 | }
|
---|
150 |
|
---|