source: branches/removing_cpp11_features/macros/RanForest.C@ 20086

Last change on this file since 20086 was 5560, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 5.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 Hengstebeck 3/2003 <mailto:hengsteb@alwa02.physik.uni-siegen.de>!
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25void RanForest()
26{
27 //
28 // Create a empty Parameter List and an empty Task List
29 // The tasklist is identified in the eventloop by its name
30 //
31 MParList plist;
32
33 MTaskList tlist;
34 plist.AddToList(&tlist);
35
36 MReadMarsFile read("Events", "~/MagicData/data1/CT1Data/ONTrain/*.root");
37 read.DisableAutoScheme();
38 tlist.AddToList(&read);
39
40 MFParticleId fgamma("MMcEvt", '=', MMcEvt::kGAMMA);
41 tlist.AddToList(&fgamma);
42
43 MFParticleId fhadrons("MMcEvt", '!', MMcEvt::kGAMMA);
44 tlist.AddToList(&fhadrons);
45
46 MHMatrix matrixg("MatrixGammas");
47 matrixg.AddColumn("cos(MMcEvt.fTelescopeTheta)");
48 matrixg.AddColumn("MSigmabar.fSigmabar");
49 matrixg.AddColumn("log10(Hillas.fSize)");
50 matrixg.AddColumn("HillasSrc.fDist");
51 matrixg.AddColumn("Hillas.fWidth");
52 matrixg.AddColumn("Hillas.fLength");
53 matrixg.AddColumn("log10(Hillas.fSize)/Hillas.fWidth*Hillas.fLength");
54 matrixg.AddColumn("abs(Hillas.fM3Long)");
55 matrixg.AddColumn("Hillas.fConc");
56 matrixg.AddColumn("Hillas.fConc1");
57
58 //matrixg.AddColumn("abs(Hillas.fAsym)");
59 //matrixg.AddColumn("abs(Hillas.fM3Trans)");
60 //matrixg.AddColumn("abs(HillasSrc.fHeadTail)");
61 //matrixg.AddColumn("abs(HillasSrc.fAlpha)");
62
63 plist.AddToList(&read);
64
65 plist.AddToList(&matrixg);
66
67 MHMatrix matrixh("MatrixHadrons");
68 matrixh.AddColumns(matrixg.GetColumns());
69 plist.AddToList(&matrixh);
70
71 MFillH fillmatg("MatrixGammas");
72 fillmatg.SetFilter(&fgamma);
73 tlist.AddToList(&fillmatg);
74
75 MFillH fillmath("MatrixHadrons");
76 fillmath.SetFilter(&fhadrons);
77 tlist.AddToList(&fillmath);
78
79 //
80 // Create and setup the eventloop
81 //
82 MEvtLoop evtloop;
83 evtloop.SetParList(&plist);
84
85 //
86 // Execute your analysis
87 //
88 if (!evtloop.Eventloop())
89 return;
90
91 tlist.PrintStatistics();
92
93 // ---------------------------------------------------------------
94 // ---------------------------------------------------------------
95 // second event loop: the trees of the random forest are grown,
96 // the event loop is now actually a tree loop (loop of training
97 // process)
98 // ---------------------------------------------------------------
99 // ---------------------------------------------------------------
100
101 MTaskList tlist2;
102 plist.Replace(&tlist2);
103
104 MRanForestGrow rfgrow2;
105 rfgrow2.SetNumTrees(10);
106 rfgrow2.SetNumTry(3);
107 rfgrow2.SetNdSize(10);
108
109 MWriteRootFile rfwrite2("RF.root");
110 rfwrite2.AddContainer("MRanTree","Tree"); //save all trees
111 MFillH fillh2("MHRanForestGini");
112
113 tlist2.AddToList(&rfgrow2);
114 tlist2.AddToList(&rfwrite2);
115 tlist2.AddToList(&fillh2);
116
117 // gRandom is accessed from MRanForest (-> bootstrap aggregating)
118 // and MRanTree (-> random split selection) and should be initialized
119 // here if you want to set a certain random number generator
120 if(gRandom)
121 delete gRandom;
122 gRandom = new TRandom3(0);
123
124 //
125 // Execute tree growing (now the eventloop is actually a treeloop)
126 //
127 if (!evtloop.Eventloop())
128 return;
129
130 tlist2.PrintStatistics();
131
132 plist.FindObject("MHRanForestGini")->DrawClone();
133
134 // ---------------------------------------------------------------
135 // ---------------------------------------------------------------
136 // third event loop: the control sample (star2.root) is processed
137 // through the previously grown random forest,
138 //
139 // the histograms MHHadronness (quality of g/h-separation) and
140 // MHRanForest are created and displayed.
141 // MHRanForest shows the convergence of the classification error
142 // as function of the number of grown (and combined) trees
143 // and tells the user how many trees are actually needed in later
144 // classification tasks.
145 // ---------------------------------------------------------------
146 // ---------------------------------------------------------------
147
148 MTaskList tlist3;
149
150 plist.Replace(&tlist3);
151
152 MReadMarsFile read3("Events", "~/MagicData/data1/CT1Data/ONTest/*.root");
153 read3.DisableAutoScheme();
154 tlist3.AddToList(&read3);
155
156 MRanForestCalc calc;
157 tlist3.AddToList(&calc);
158
159 MFillH fillh3a("MHHadronness");
160 MFillH fillh3b("MHRanForest");
161
162 tlist3.AddToList(&fillh3a);
163 tlist3.AddToList(&fillh3b);
164
165 MProgressBar bar;
166 evtloop.SetProgressBar(&bar);
167
168 //
169 // Execute your analysis
170 //
171 if (!evtloop.Eventloop())
172 return;
173
174 tlist3.PrintStatistics();
175
176 plist.FindObject("MHRanForest")->DrawClone();
177 plist.FindObject("MHHadronness")->DrawClone();
178 plist.FindObject("MHHadronness")->Print();//*/
179}
Note: See TracBrowser for help on using the repository browser.