source: trunk/Mars/mjoptim/MJOptimizeBase.cc@ 9872

Last change on this file since 9872 was 9867, checked in by tbretz, 14 years ago
Improved comments in MJOptimizeBase.
File size: 5.9 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-2010
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MJOptimizeBase
28//
29// Base class for classes training a random forest
30//
31// The order when reading a file is:
32// 1) Execution of PreTasks
33// 2) Execution of PreCuts, TestCuts, TrainCuts
34// 3) Selector (calculated from number of requested events)
35// 4) Splitter (if sample is split automatically in test/train)
36// 5) PostTasks (set by user)
37//
38// The split into Pre- and PostTasks is done for speed reason. So, if
39// you calculate a vlue which is not needed for your PreCuts, you can
40// calculate it afterwards, which will speed up execution.
41//
42// void AddPreTask(MTask *t)
43// Add a task which is executed just after reading the events from the file
44// this can be any kind of task or even a task list. You can use dedicated
45// tasks performing some analysis, but also cuts (e.g. MContinue) or a
46// general task to evaluate new parameters (e.g. MParameterCalc)
47//
48// void AddPreTask(const char *rule, const char *name="MWeight")
49// This is a short cut to AddPreTask(MTask*) which will add a
50// MParameterCalc to the list evaluating the given rule and storing the
51// result in a MParameterD with the given name. For the default "MWeight",
52// for example, the value can later be accessed by MWeight.fVal.
53//
54// The same functions are available as
55// void AddPostTask(MTask *t)
56// void AddPostTask(const char *rule, const char *name="MWeight")
57//
58// It is advicable to use these function if the task is not needed for your
59// event selection. The event selection (by number and by PreCuts) is done
60// in between PreTasks and PostTasks, i.e. a task which is not needed for the
61// event selection but needed later is only executed as often as necessary.
62//
63// The event selection (apart from the number of target events) can be setup
64// by the user. Therefore two functions are available
65// void AddPreCut(const char *rule)
66// void AddPreCut(MFilter *f)
67// Both add cuts which are executed after the PreTasks but before the
68// PostTasks. They are executed in both training and testing. To execute cuts
69// only in training or testing use
70// void AddTrainCut(const char *rule)
71// void AddTrainCut(MFilter *f)
72// or
73// void AddTestCut(const char *rule)
74// void AddTestCut(MFilter *f)
75//
76// To weight the events of your train- and test sample the following functions
77// can be used
78// void SetWeights(const char *rule)
79// void SetWeights(MTask *t)
80// This either adds a MParameterCalc to the list of post tasks or a MTask,
81// which is supposed to fill a MParameterD named "MWeight".
82//
83// Last but not least a function if available to add additional tasks to the
84// end of the task list for testing. This can for example be used to add
85// the filling and display of an addition histogram (e.g. add a MFillH)
86// or to do some calculation and write out the result. Basically everything
87// can be done in this way.
88// void AddTestTask(MTask *t)
89// void AddTestTask(const char *rule, const char *name="MWeight")
90//
91//
92// REMARK: Note that the actual behavior might still vary a bit
93// depeding of the implementation in the derived class.
94//
95/////////////////////////////////////////////////////////////////////////////
96#include "MJOptimizeBase.h"
97
98#include <TFile.h>
99
100#include "MLog.h"
101#include "MLogManip.h"
102
103#include "MFDataPhrase.h"
104#include "MParameterCalc.h"
105
106#include "MStatusDisplay.h"
107
108ClassImp(MJOptimizeBase);
109
110using namespace std;
111
112//------------------------------------------------------------------------
113//
114// Add a cut which is used to fill the matrix, eg "MMcEvt.fPartId<1.5"
115// (The rule is applied, not inverted: The matrix is filled with
116// the events fullfilling the condition)
117//
118void MJOptimizeBase::AddCut(TList &l, const char *rule)
119{
120 MFilter *f = new MFDataPhrase(rule);
121 f->SetBit(kCanDelete); //FIXME!!!! Why does not any other list delete it???
122 Add(l, f);
123}
124
125//------------------------------------------------------------------------
126//
127// Add an additional parameter (MParameterCalc), eg "0.5", "MWeight"
128// The default container name is "MWeight"
129//
130void MJOptimizeBase::AddPar(TList &l, const char *rule, const char *pname)
131{
132 TString tname(pname);
133 tname += "Calc";
134
135 MParameterCalc *par = new MParameterCalc(rule, tname);
136 par->SetNameParameter(pname);
137// par->SetBit(kCanDelete); //FIXME!!!! MTaskList is deleting it
138 Add(l, par);
139}
140
141//------------------------------------------------------------------------
142//
143// Add a task/cut which is used to fill the matrix. If kCanDelete is set
144// MJOptimize takes the ownership.
145//
146void MJOptimizeBase::Add(TList &l, MTask *f)
147{
148 l.Add(f);
149}
150
151//------------------------------------------------------------------------
152//
153// Add a parameter to the list of parameters. The index in the list is
154// returned.
155//
156// Int_t idx = AddParameter("log10(MHillas.fSize)");
157//
158// Indices are starting with 0.
159//
160Int_t MJOptimizeBase::AddParameter(const char *rule)
161{
162 fRules.Add(new TNamed(rule, ""));
163 return fRules.GetSize()-1;
164}
Note: See TracBrowser for help on using the repository browser.