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, 9/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MJOptimize
|
---|
28 | //
|
---|
29 | // Class for otimizing the parameters of the supercuts
|
---|
30 | //
|
---|
31 | // Minimization Control
|
---|
32 | // ====================
|
---|
33 | //
|
---|
34 | // To choose the minimization algorithm use:
|
---|
35 | // void SetOptimizer(Optimizer_t o);
|
---|
36 | //
|
---|
37 | // Allowed options are:
|
---|
38 | // enum Optimizer_t
|
---|
39 | // {
|
---|
40 | // kMigrad, // Minimize by the method of Migrad
|
---|
41 | // kSimplex, // Minimize by the method of Simplex
|
---|
42 | // kMinimize, // Migrad + Simplex (if Migrad fails)
|
---|
43 | // kMinos, // Minos error determination
|
---|
44 | // kImprove, // Local minimum search
|
---|
45 | // kSeek, // Minimize by the method of Monte Carlo
|
---|
46 | // kNone // Skip optimization
|
---|
47 | // };
|
---|
48 | //
|
---|
49 | // For more details on the methods see TMinuit.
|
---|
50 | //
|
---|
51 | //
|
---|
52 | // You can change the behaviour of the minimization using
|
---|
53 | //
|
---|
54 | // void SetNumMaxCalls(UInt_t num=0);
|
---|
55 | // void SetTolerance(Float_t tol=0);
|
---|
56 | //
|
---|
57 | // While NumMaxCalls is the first, Tolerance the second arguement.
|
---|
58 | // For more details start root and type
|
---|
59 | //
|
---|
60 | // gMinuit->mnhelp("command")
|
---|
61 | //
|
---|
62 | // while command can be
|
---|
63 | // * MIGRAD
|
---|
64 | // * SIMPLEX
|
---|
65 | // * MINIMIZE
|
---|
66 | // * MINOS
|
---|
67 | // * IMPROVE
|
---|
68 | // * SEEK
|
---|
69 | //
|
---|
70 | // The default (num==0 and tol==0) should always give you the
|
---|
71 | // corresponding defaults used in Minuit.
|
---|
72 | //
|
---|
73 | //
|
---|
74 | // FIXME: Implement changing cut in hadronness...
|
---|
75 | // FIXME: Show MHSignificance on MStatusDisplay during filling...
|
---|
76 | // FIXME: Choose step-size percentage as static data membewr
|
---|
77 | // FIXME: Choose minimization method
|
---|
78 | //
|
---|
79 | /////////////////////////////////////////////////////////////////////////////
|
---|
80 | #include "MJOptimizeEnergy.h"
|
---|
81 |
|
---|
82 | #include "MHMatrix.h"
|
---|
83 |
|
---|
84 | // environment
|
---|
85 | #include "MLog.h"
|
---|
86 | #include "MLogManip.h"
|
---|
87 |
|
---|
88 | // eventloop
|
---|
89 | #include "MParList.h"
|
---|
90 | #include "MTaskList.h"
|
---|
91 | #include "MEvtLoop.h"
|
---|
92 |
|
---|
93 | // parameters
|
---|
94 | #include "MParameters.h"
|
---|
95 | #include "MGeomCamMagic.h"
|
---|
96 |
|
---|
97 | // histograms
|
---|
98 | #include "../mhflux/MHEnergyEst.h"
|
---|
99 |
|
---|
100 | // tasks
|
---|
101 | #include "MReadTree.h"
|
---|
102 | #include "MMatrixLoop.h"
|
---|
103 | #include "MEnergyEstimate.h"
|
---|
104 | #include "MFillH.h"
|
---|
105 |
|
---|
106 | // filters
|
---|
107 | #include "MFDataMember.h"
|
---|
108 |
|
---|
109 | using namespace std;
|
---|
110 |
|
---|
111 | ClassImp(MJOptimizeEnergy);
|
---|
112 |
|
---|
113 | //------------------------------------------------------------------------
|
---|
114 | //
|
---|
115 | // Read all events from file which do match rules and optimize
|
---|
116 | // energy estimator.
|
---|
117 | //
|
---|
118 | Bool_t MJOptimizeEnergy::RunEnergy(const char *fname, const char *rule)
|
---|
119 | {
|
---|
120 | fLog->Separator("Preparing Energy optimization");
|
---|
121 |
|
---|
122 | MParList parlist;
|
---|
123 |
|
---|
124 | MParameterI par("DataType");
|
---|
125 | par.SetVal(1);
|
---|
126 | parlist.AddToList(&par);
|
---|
127 |
|
---|
128 | MFDataMember filter("DataType.fVal", '>', 0.5);
|
---|
129 | fPreCuts.Add(&filter);
|
---|
130 |
|
---|
131 | MGeomCamMagic geom; // For GetConvMm2Deg
|
---|
132 | parlist.AddToList(&geom);
|
---|
133 |
|
---|
134 | MHMatrix m("M");
|
---|
135 | AddRulesToMatrix(m);
|
---|
136 | parlist.AddToList(&m);
|
---|
137 |
|
---|
138 | MHEnergyEst hist;
|
---|
139 | hist.InitMapping(&m);
|
---|
140 |
|
---|
141 | MEnergyEstimate est("MParameters");
|
---|
142 | est.SetRule(rule);
|
---|
143 | parlist.AddToList(&est);
|
---|
144 |
|
---|
145 | MReadTree read("Events");
|
---|
146 | // NECESSARY BECAUSE OF MDataFormula GetRules missing
|
---|
147 | read.DisableAutoScheme();
|
---|
148 | if (fname)
|
---|
149 | read.AddFile(fname);
|
---|
150 | else
|
---|
151 | AddSequences(read, fNamesOn);
|
---|
152 | if (!FillMatrix(read, parlist, kTRUE))
|
---|
153 | return kFALSE;
|
---|
154 |
|
---|
155 | fPreCuts.Remove(&filter);
|
---|
156 |
|
---|
157 | MTaskList tasklist;
|
---|
158 | parlist.Replace(&tasklist);
|
---|
159 |
|
---|
160 | MFillH fill(&hist);
|
---|
161 |
|
---|
162 | MMatrixLoop loop(&m);
|
---|
163 |
|
---|
164 | tasklist.AddToList(&loop);
|
---|
165 | tasklist.AddToList(&est);
|
---|
166 | tasklist.AddToList(&fill);
|
---|
167 |
|
---|
168 | // Optimize with the tasklist in this parameterlist
|
---|
169 | if (!Optimize(parlist))
|
---|
170 | return kFALSE;
|
---|
171 |
|
---|
172 | // Print the result
|
---|
173 | hist.Print();
|
---|
174 |
|
---|
175 | // Store result if requested
|
---|
176 | TObjArray cont;
|
---|
177 | cont.Add(&est);
|
---|
178 | return WriteContainer(cont, fNameOut);
|
---|
179 | }
|
---|