source: trunk/Mars/macros/optim/rfenergyest.C@ 18579

Last change on this file since 18579 was 7401, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 3.4 KB
Line 
1void rfenergyest()
2{
3 MSequence seqtst("~/Software/mc/sequencemc-test.txt");
4 MSequence seqtrn("~/Software/mc/sequencemc-train.txt");
5
6 if (!seqtst.IsValid())
7 {
8 cout << "Test sequence not valid" << endl;
9 return;
10 }
11 if (!seqtrn.IsValid())
12 {
13 cout << "Train sequence not valid" << endl;
14 return;
15 }
16
17 // --------------------- Setup files --------------------
18 MReadMarsFile read("Events");
19 MReadMarsFile read2("Events");
20 read.DisableAutoScheme();
21 read2.DisableAutoScheme();
22
23 MDirIter iter, iter2;
24 seqtrn.SetupDatRuns(iter, MSequence::kImages, "~/Software/mc/img-abs");
25 seqtst.SetupDatRuns(iter2, MSequence::kImages, "~/Software/mc/img-abs");
26
27 read.AddFiles(iter);
28 read2.AddFiles(iter2);
29
30 // ----------------------- Setup RF ----------------------
31 MHMatrix train("Train");
32 train.AddColumn("MHillas.fSize");
33 train.AddColumn("MHillasSrc.fDist");
34 train.AddColumn("MPointingPos.fZd");
35 /*
36 train.AddColumn("MImagePar.fSizeSinglePixels");
37 train.AddColumn("MHillas.GetArea");
38 train.AddColumn("MNewImagePar.fLeakage1");
39 train.AddColumn("MHillasExt.fM3Long*sign(MHillasSrc.fCosDeltaAlpha)");
40 */
41
42 // ------------------------------------------------------------
43
44 // Last column must contain energy
45 train.AddColumn("MMcEvt.fImpact/100");
46 train.AddColumn("MMcEvt.fTelescopeTheta*kRad2Deg");
47 train.AddColumn("MMcEvt.fEnergy");
48
49 MStatusDisplay *d = new MStatusDisplay;
50
51 // ----------------------- Fill Matrix RF ----------------------
52
53 if(gRandom)
54 delete gRandom;
55 gRandom = new TRandom3();
56
57 MTFillMatrix fill;
58 fill.SetDisplay(d);
59 fill.SetDestMatrix1(&train, 10000);//99999999);
60 fill.SetReader(&read);
61
62 /* ---------- It doesn't seem to improve anything ----------
63 MFMagicCuts cuts;
64
65 cuts.SetHadronnessCut(MFMagicCuts::kArea);
66 cuts.SetThetaCut(MFMagicCuts::kOn);
67
68 TArrayD arr(10);
69 arr[0]= 1.3245;
70 arr[1]= 0.208700;
71 arr[2]= 0.229200;
72 arr[3]= 5.305200;
73 arr[4]= 0.098930;
74 arr[5]= -0.082950;
75 arr[6]= 8.2957;
76 arr[7]= 0.8677;
77
78 cuts.SetVariables(arr);
79
80 fill.AddPreCut(&cuts);
81
82 --------------- Use the cuts also in test-loop ----------------
83 */
84
85 if (!fill.Process())
86 return;
87
88 // ------------------------ Train RF --------------------------
89
90 MRFEnergyEst rf;
91 rf.SetDisplay(d);
92 rf.SetFileName("rfenergys.root");
93
94 MBinning b(32, 10, 100000, "BinningEnergyEst", "log");
95 /*
96 if (!rf.TrainMultiRF(train, b.GetEdgesD())) // classification with one tree per bin
97 return;
98
99 if (!rf.TrainSingleRF(train, b.GetEdgesD())) // classification into different bins
100 return;
101 */
102 if (!rf.TrainSingleRF(train)) // regression (best choice)
103 return;
104
105
106 gLog.Separator("Test");
107
108 // --------------------- Display result ----------------------
109 MParList plist;
110 MTaskList tlist;
111 plist.AddToList(&tlist);
112 plist.AddToList(&b);
113
114 MHEnergyEst hist;
115 //MContinue cont(&cuts);
116 //cont.SetInverted();
117 MFillH fillh(&hist);
118
119 tlist.AddToList(&read2);
120 //tlist.AddToList(&cont);
121 tlist.AddToList(&rf);
122 tlist.AddToList(&fillh);
123
124 MEvtLoop loop;
125 loop.SetDisplay(d);
126 loop.SetParList(&plist);
127
128 if (!loop.Eventloop())
129 return;
130
131 //d->SaveAsPS("rfenergys.ps");
132}
Note: See TracBrowser for help on using the repository browser.