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 |
|
---|
25 | void 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", '=', kGAMMA);
|
---|
41 | tlist.AddToList(&fgamma);
|
---|
42 |
|
---|
43 | MFParticleId fhadrons("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(50);
|
---|
106 | rfgrow2.SetNumTry(3);
|
---|
107 | rfgrow2.SetNdSize(1);
|
---|
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 | //
|
---|
118 | // Execute tree growing (now the eventloop is actually a treeloop)
|
---|
119 | //
|
---|
120 | if (!evtloop.Eventloop())
|
---|
121 | return;
|
---|
122 |
|
---|
123 | tlist2.PrintStatistics();
|
---|
124 |
|
---|
125 | plist.FindObject("MHRanForestGini")->DrawClone();
|
---|
126 |
|
---|
127 | // ---------------------------------------------------------------
|
---|
128 | // ---------------------------------------------------------------
|
---|
129 | // third event loop: the control sample (star2.root) is processed
|
---|
130 | // through the previously grown random forest,
|
---|
131 | //
|
---|
132 | // the histograms MHHadronness (quality of g/h-separation) and
|
---|
133 | // MHRanForest are created and displayed.
|
---|
134 | // MHRanForest shows the convergence of the classification error
|
---|
135 | // as function of the number of grown (and combined) trees
|
---|
136 | // and tells the user how many trees are actually needed in later
|
---|
137 | // classification tasks.
|
---|
138 | // ---------------------------------------------------------------
|
---|
139 | // ---------------------------------------------------------------
|
---|
140 |
|
---|
141 | MTaskList tlist3;
|
---|
142 |
|
---|
143 | plist.Replace(&tlist3);
|
---|
144 |
|
---|
145 | MReadMarsFile read3("Events", "~/MagicData/data1/CT1Data/ONTest/*.root");
|
---|
146 | read3.DisableAutoScheme();
|
---|
147 | tlist3.AddToList(&read3);
|
---|
148 |
|
---|
149 | MRanForestCalc calc;
|
---|
150 | tlist3.AddToList(&calc);
|
---|
151 |
|
---|
152 | MFillH fillh3a("MHHadronness");
|
---|
153 | MFillH fillh3b("MHRanForest");
|
---|
154 |
|
---|
155 | tlist3.AddToList(&fillh3a);
|
---|
156 | tlist3.AddToList(&fillh3b);
|
---|
157 |
|
---|
158 | MProgressBar bar;
|
---|
159 | evtloop.SetProgressBar(&bar);
|
---|
160 |
|
---|
161 | //
|
---|
162 | // Execute your analysis
|
---|
163 | //
|
---|
164 | if (!evtloop.Eventloop())
|
---|
165 | return;
|
---|
166 |
|
---|
167 | tlist3.PrintStatistics();
|
---|
168 |
|
---|
169 | plist.FindObject("MHRanForest")->DrawClone();
|
---|
170 | plist.FindObject("MHHadronness")->DrawClone();
|
---|
171 | plist.FindObject("MHHadronness")->Print();//*/
|
---|
172 | }
|
---|