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