source: trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc@ 7413

Last change on this file since 7413 was 7412, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 5.8 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// MJTrainSeparation
28//
29////////////////////////////////////////////////////////////////////////////
30#include "MJTrainSeparation.h"
31
32#include "MHMatrix.h"
33
34#include "MLog.h"
35#include "MLogManip.h"
36
37// tools
38#include "MDataSet.h"
39#include "MTFillMatrix.h"
40#include "MChisqEval.h"
41
42// eventloop
43#include "MParList.h"
44#include "MTaskList.h"
45#include "MEvtLoop.h"
46
47// tasks
48#include "MReadMarsFile.h"
49#include "MContinue.h"
50#include "MFillH.h"
51#include "MRanForestCalc.h"
52#include "MParameterCalc.h"
53
54// container
55#include "MMcEvt.hxx"
56#include "MParameters.h"
57
58// histograms
59#include "MBinning.h"
60#include "MH3.h"
61#include "MHHadronness.h"
62
63// filter
64#include "MF.h"
65#include "MFilterList.h"
66
67ClassImp(MJTrainSeparation);
68
69using namespace std;
70
71Bool_t MJTrainSeparation::Train(const char *out)
72{
73 if (!fDataSetTrain.IsValid())
74 {
75 *fLog << err << "ERROR - DataSet for training invalid!" << endl;
76 return kFALSE;
77 }
78 if (!fDataSetTest.IsValid())
79 {
80 *fLog << err << "ERROR - DataSet for testing invalid!" << endl;
81 return kFALSE;
82 }
83
84 // --------------------- Setup files --------------------
85 MReadMarsFile read("Events");
86 MReadMarsFile read2("Events");
87 MReadMarsFile read3("Events");
88 read.DisableAutoScheme();
89 read2.DisableAutoScheme();
90 read3.DisableAutoScheme();
91
92 fDataSetTrain.AddFilesOn(read);
93 fDataSetTrain.AddFilesOff(read3);
94
95 fDataSetTest.AddFilesOff(read2);
96 fDataSetTest.AddFilesOn(read2);
97
98 read2.VetoBranch("MMcTrig");
99 read2.VetoBranch("MTime");
100 read2.VetoBranch("MMcRunHeader");
101 read2.VetoBranch("MMcTrigHeader");
102 read2.VetoBranch("MMcFadcHeader");
103 read2.VetoBranch("MMcCorsikaRunHeader");
104 read2.VetoBranch("MMcConfigRunHeader");
105
106
107 // ----------------------- Setup RF ----------------------
108 MHMatrix train("Train");
109 train.AddColumns(fRules);
110 train.AddColumn("MHadronness.fVal");
111
112 // ----------------------- Fill Matrix RF ----------------------
113
114 MParameterD had("MHadronness");
115
116 MParList plistx;
117 plistx.AddToList(&had);
118
119 MTFillMatrix fill;
120 fill.SetLogStream(fLog);
121 fill.SetDisplay(fDisplay);
122 fill.AddPreCuts(fPreCuts);
123 fill.AddPreCuts(fTrainCuts);
124
125 // Set classifier for gammas
126 had.SetVal(0);
127 fill.SetName("FillGammas");
128 fill.SetDestMatrix1(&train, fNumTrainOn);
129 fill.SetReader(&read);
130 if (!fill.Process(plistx))
131 return kFALSE;
132
133 // Set classifier for hadrons
134 had.SetVal(1);
135 fill.SetName("FillBackground");
136 fill.SetDestMatrix1(&train, fNumTrainOff);
137 fill.SetReader(&read3);
138 if (!fill.Process(plistx))
139 return kFALSE;
140
141 // ------------------------ Train RF --------------------------
142
143 MRanForestCalc rf;
144 rf.SetNumObsoleteVariables(1);
145 rf.SetDebug(fDebug);
146 rf.SetDisplay(fDisplay);
147 rf.SetLogStream(fLog);
148 rf.SetFileName(out);
149 rf.SetNameOutput("MHadronness");
150
151 //MBinning b(2, -0.5, 1.5, "BinningHadronness", "lin");
152
153 //if (!rf.TrainMultiRF(train, b.GetEdgesD())) // classification
154 // return;
155
156 //if (!rf.TrainSingleRF(train, b.GetEdgesD())) // classification
157 // return;
158
159 if (!rf.TrainSingleRF(train)) // regression
160 return kFALSE;
161
162 // --------------------- Display result ----------------------
163
164 gLog.Separator("Test");
165
166 MParList plist;
167 MTaskList tlist;
168 plist.AddToList(this);
169 plist.AddToList(&tlist);
170
171 MMcEvt mcevt;
172 plist.AddToList(&mcevt);
173
174 MBinning binsy(100, 0 , 1, "BinningMH3Y", "lin");
175 MBinning binsx(100, 10, 100000, "BinningMH3X", "log");
176
177 plist.AddToList(&binsx);
178 plist.AddToList(&binsy);
179
180 MH3 h31("MHillas.fSize", "MHadronness.fVal");
181 MH3 h32("MHillas.fSize", "MHadronness.fVal");
182 h31.SetTitle("Background probability vs. Size:Size [phe]:Hadronness");
183 h32.SetTitle("Background probability vs. Size:Size [phe]:Hadronness");
184
185 MF f("MRawRunHeader.fRunType>255");
186 MFilterList list;
187 list.SetInverted();
188 list.AddToList(&f);
189
190 MHHadronness hist;
191
192 MFillH fillh(&hist, "", "FillHadronness");
193 MFillH fillh1(&h31, "", "FillGammas");
194 MFillH fillh2(&h32, "", "FillBackground");
195 fillh1.SetNameTab("Gammas");
196 fillh2.SetNameTab("Background");
197
198 fillh1.SetFilter(&f);
199 fillh2.SetFilter(&list);
200
201 MFilterList precuts;
202 precuts.AddToList(fPreCuts);
203 precuts.AddToList(fTestCuts);
204
205 MContinue c0(&precuts);
206 c0.SetInverted();
207
208 tlist.AddToList(&read2);
209 tlist.AddToList(&c0);
210 tlist.AddToList(&rf);
211 tlist.AddToList(&fillh);
212 tlist.AddToList(&list);
213 tlist.AddToList(&fillh1);
214 tlist.AddToList(&fillh2);
215
216 MEvtLoop loop;
217 loop.SetDisplay(fDisplay);
218 loop.SetLogStream(fLog);
219 loop.SetParList(&plist);
220
221 if (!loop.Eventloop())
222 return kFALSE;
223
224 if (!WriteDisplay(out))
225 return kFALSE;
226
227 return kTRUE;
228}
229
Note: See TracBrowser for help on using the repository browser.