source: trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.cc@ 7970

Last change on this file since 7970 was 7749, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 3.5 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 Bretz 11/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2005-2006
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MJTrainRanForest
28//
29// Base class for classes training a random forest
30//
31/////////////////////////////////////////////////////////////////////////////
32#include "MJTrainRanForest.h"
33
34#include <TFile.h>
35
36#include "MLog.h"
37#include "MLogManip.h"
38
39#include "MF.h"
40#include "MParameterCalc.h"
41
42#include "MStatusDisplay.h"
43
44ClassImp(MJTrainRanForest);
45
46using namespace std;
47
48//------------------------------------------------------------------------
49//
50// Add a cut which is used to fill the matrix, eg "MMcEvt.fPartId<1.5"
51// (The rule is applied, not inverted: The matrix is filled with
52// the events fullfilling the condition)
53//
54void MJTrainRanForest::AddCut(TList &l, const char *rule)
55{
56 MFilter *f = new MF(rule);
57 f->SetBit(kCanDelete); //FIXME!!!! Why does not any other list delete it???
58 Add(l, f);
59}
60
61//------------------------------------------------------------------------
62//
63// Add an additional parameter (MParameterCalc), eg "0.5", "MWeight"
64// The default container name is "MWeight"
65//
66void MJTrainRanForest::AddPar(TList &l, const char *rule, const char *pname)
67{
68 TString tname(pname);
69 tname += "Calc";
70
71 MParameterCalc *par = new MParameterCalc(rule, tname);
72 par->SetNameParameter(pname);
73// par->SetBit(kCanDelete); //FIXME!!!! MTaskList is deleting it
74 Add(l, par);
75}
76
77//------------------------------------------------------------------------
78//
79// Add a task/cut which is used to fill the matrix. If kCanDelete is set
80// MJOptimize takes the ownership.
81//
82void MJTrainRanForest::Add(TList &l, MTask *f)
83{
84 l.Add(f);
85}
86
87//------------------------------------------------------------------------
88//
89// Add a parameter used in your filters (see AddFilter) The parameter
90// index is returned,
91//
92// Int_t idx = AddParameter("log10(MHillas.fSize)");
93//
94// The indices are starting with 0 always.
95//
96Int_t MJTrainRanForest::AddParameter(const char *rule)
97{
98 fRules.Add(new TNamed(rule, ""));
99 return fRules.GetSize()-1;
100}
101
102Bool_t MJTrainRanForest::WriteDisplay(const char *fname) const
103{
104 TFile file(fname, "UPDATE");
105 if (!file.IsOpen())
106 {
107 *fLog << err << "ERROR - Couldn't open file " << fname << " for writing." << endl;
108 return kFALSE;
109 }
110
111 *fLog << inf << "Wrinting to " << fname << ":" << endl;
112 *fLog << " - MStatusDisplay..." << flush;
113 if (fDisplay && fDisplay->Write()<=0)
114 {
115 *fLog << err << "Unable to write MStatusDisplay to " << fname << endl;
116 return kFALSE;
117 }
118 *fLog << inf << "ok." << endl;
119
120 return kTRUE;
121}
Note: See TracBrowser for help on using the repository browser.