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

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