source: trunk/MagicSoft/Mars/mranforest/MRanForestGrow.cc@ 2124

Last change on this file since 2124 was 2071, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 4.2 KB
Line 
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
44ClassImp(MRanForestGrow);
45
46static const TString gsDefName = "MRanForestGrow";
47static const TString gsDefTitle = "Tree Classification Loop 1/2";
48
49// --------------------------------------------------------------------------
50//
51// Setup histograms and the number of distances which are used for
52// avaraging in CalcDist
53//
54MRanForestGrow::MRanForestGrow(const char *name, const char *title)
55 : fNumTrees(100),fNumTry(3),fNdSize(1)
56{
57 //
58 // set the name and title of this object
59 //
60 fName = name ? name : gsDefName.Data();
61 fTitle = title ? title : gsDefTitle.Data();
62}
63
64// --------------------------------------------------------------------------
65//
66// Needs:
67// - MatrixGammas [MHMatrix]
68// - MatrixHadrons {MHMatrix]
69// - MHadroness
70// - all data containers used to build the matrixes
71//
72// The matrix object can be filles using MFillH. And must be of the same
73// number of columns (with the same meaning).
74//
75Bool_t MRanForestGrow::PreProcess(MParList *plist)
76{
77 fMGammas = (MHMatrix*)plist->FindObject("MatrixGammas", "MHMatrix");
78 if (!fMGammas)
79 {
80 *fLog << err << dbginf << "MatrixGammas [MHMatrix] not found... aborting." << endl;
81 return kFALSE;
82 }
83
84 fMHadrons = (MHMatrix*)plist->FindObject("MatrixHadrons", "MHMatrix");
85 if (!fMHadrons)
86 {
87 *fLog << err << dbginf << "MatrixHadrons [MHMatrix] not found... aborting." << endl;
88 return kFALSE;
89 }
90
91 if (fMGammas->GetM().GetNcols() != fMHadrons->GetM().GetNcols())
92 {
93 *fLog << err << dbginf << "Error matrices have different numbers of columns... aborting." << endl;
94 return kFALSE;
95 }
96
97 fRanTree = (MRanTree*)plist->FindCreateObj("MRanTree");
98 if (!fRanTree)
99 {
100 *fLog << err << dbginf << "MRanTree not found... aborting." << endl;
101 return kFALSE;
102 }
103
104 fRanForest = (MRanForest*)plist->FindCreateObj("MRanForest");
105 if (!fRanForest)
106 {
107 *fLog << err << dbginf << "MRanForest not found... aborting." << endl;
108 return kFALSE;
109 }
110
111 fRanTree->SetNumTry(fNumTry);
112 fRanTree->SetNdSize(fNdSize);
113 fRanForest->SetCurTree(fRanTree);
114 fRanForest->SetNumTrees(fNumTrees);
115
116 return fRanForest->SetupGrow(fMHadrons,fMGammas);
117}
118
119// --------------------------------------------------------------------------
120//
121//
122Bool_t MRanForestGrow::Process()
123{
124 Bool_t not_last=fRanForest->GrowForest();
125 fRanTree->SetReadyToSave();
126
127 return not_last;
128}
129
130Bool_t MRanForestGrow::PostProcess()
131{
132 fRanTree->SetReadyToSave();
133 fRanForest->SetReadyToSave();
134
135 return kTRUE;
136}
Note: See TracBrowser for help on using the repository browser.