1 | #ifndef MARS_MJOptimize
|
---|
2 | #define MARS_MJOptimize
|
---|
3 |
|
---|
4 | #ifndef MARS_MJob
|
---|
5 | #include "MJob.h"
|
---|
6 | #endif
|
---|
7 |
|
---|
8 | #ifndef ROOT_TArrayD
|
---|
9 | #include <TArrayD.h>
|
---|
10 | #endif
|
---|
11 |
|
---|
12 | class TMinuit;
|
---|
13 |
|
---|
14 | class MAlphaFitter;
|
---|
15 |
|
---|
16 | class MEvtLoop;
|
---|
17 | class MParList;
|
---|
18 | class MFilter;
|
---|
19 | class MFilterList;
|
---|
20 | class MFitParameters;
|
---|
21 | class MFitParametersCalc;
|
---|
22 |
|
---|
23 | class MHMatrix;
|
---|
24 | class MGeomCam;
|
---|
25 | class MRead;
|
---|
26 | class MReadTree;
|
---|
27 |
|
---|
28 | class MJOptimize : public MJob
|
---|
29 | {
|
---|
30 | public:
|
---|
31 | enum Optimizer_t
|
---|
32 | {
|
---|
33 | kMigrad, // Minimize by the method of Migrad
|
---|
34 | kSimplex, // Minimize by the method of Simplex
|
---|
35 | kMinimize, // Migrad + Simplex (if Migrad fails)
|
---|
36 | kMinos, // Minos error determination
|
---|
37 | kImprove, // Local minimum search
|
---|
38 | kSeek, // Minimize by the method of Monte Carlo
|
---|
39 | kNone // Skip optimization
|
---|
40 | };
|
---|
41 |
|
---|
42 | private:
|
---|
43 | Int_t fDebug; // -1 no output, 0 MJOptimize output, 1 PrintStatistics output
|
---|
44 | Int_t fNumEvents;
|
---|
45 |
|
---|
46 | TList fRules;
|
---|
47 | TList fFilter;
|
---|
48 | TList fPreCuts;
|
---|
49 |
|
---|
50 | TList fNamesOn;
|
---|
51 | TList fNamesOff;
|
---|
52 |
|
---|
53 | TString fNameOut;
|
---|
54 |
|
---|
55 | void AddPoint(TList *l, Int_t idx, Float_t val) const;
|
---|
56 | TList *GetPlots() const;
|
---|
57 |
|
---|
58 | void AddRulesToMatrix(MHMatrix &m) const;
|
---|
59 | void SetupFilters(MFilterList &list, MFilter *filter=0) const;
|
---|
60 | Bool_t FillMatrix(MReadTree &read, MParList &l, Bool_t userules=kFALSE);
|
---|
61 |
|
---|
62 | MEvtLoop *fEvtLoop; //!
|
---|
63 |
|
---|
64 | Bool_t AddSequences(MRead &read, TList &list) const;
|
---|
65 |
|
---|
66 | // Minuit Interface
|
---|
67 | static void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
|
---|
68 | Double_t Fcn(const TArrayD &par, TMinuit *minuit=0);
|
---|
69 |
|
---|
70 | Int_t Minuit(TMinuit &minuit, const char *cmd) const;
|
---|
71 | Int_t Migrad(TMinuit &minuit) const { return Minuit(minuit, "MIGRAD"); }
|
---|
72 | Int_t Simplex(TMinuit &minuit) const { return Minuit(minuit, "SIMPLEX"); }
|
---|
73 | Int_t Minimize(TMinuit &minuit) const { return Minuit(minuit, "MINIMIZE"); }
|
---|
74 | Int_t Seek(TMinuit &minuit) const { return Minuit(minuit, "SEEK"); }
|
---|
75 | Int_t Improve(TMinuit &minuit) const { return Minuit(minuit, "IMPROVE"); }
|
---|
76 | Int_t Minos(TMinuit &minuit) const { return Minuit(minuit, "MINOS"); }
|
---|
77 |
|
---|
78 | TArrayD fParameters; //!
|
---|
79 | TArrayD fLimLo; //!
|
---|
80 | TArrayD fLimUp; //!
|
---|
81 | TArrayD fStep; //!
|
---|
82 |
|
---|
83 | Optimizer_t fType;
|
---|
84 | UInt_t fNumMaxCalls;
|
---|
85 | Float_t fTolerance;
|
---|
86 |
|
---|
87 | Bool_t Optimize(MEvtLoop &evtloop);
|
---|
88 |
|
---|
89 | public:
|
---|
90 | MJOptimize();
|
---|
91 |
|
---|
92 | // I/O
|
---|
93 | void AddSequenceOn(const char *fname, const char *dir="");
|
---|
94 | void AddSequenceOff(const char *fname, const char *dir="");
|
---|
95 |
|
---|
96 | void ResetSequences();
|
---|
97 |
|
---|
98 | // Interface for filter cuts
|
---|
99 | Int_t AddParameter(const char *rule);
|
---|
100 | void AddFilter(const char *rule);
|
---|
101 | void AddPreCut(const char *rule);
|
---|
102 |
|
---|
103 | // Steering of optimization
|
---|
104 | void SetNumEvents(UInt_t n);
|
---|
105 | void SetDebug(UInt_t n);
|
---|
106 | void SetNameOut(const char *name="") { fNameOut = name; }
|
---|
107 | void SetOptimizer(Optimizer_t o);
|
---|
108 | void SetNumMaxCalls(UInt_t num=0) { fNumMaxCalls=num; }
|
---|
109 | void SetTolerance(Float_t tol=0) { fTolerance=tol; }
|
---|
110 |
|
---|
111 | // Parameter access
|
---|
112 | void SetParameters(const TArrayD &par);
|
---|
113 | void SetParameter(Int_t idx, Double_t start, Double_t lo=0, Double_t up=0, Double_t step=-1)
|
---|
114 | {
|
---|
115 | if (fParameters.GetSize()<=idx)
|
---|
116 | {
|
---|
117 | fParameters.Set(idx+1);
|
---|
118 | fLimLo.Set(idx+1);
|
---|
119 | fLimUp.Set(idx+1);
|
---|
120 | fStep.Set(idx+1);
|
---|
121 | }
|
---|
122 |
|
---|
123 | fParameters[idx] = start;
|
---|
124 | fLimLo[idx] = lo;
|
---|
125 | fLimUp[idx] = up;
|
---|
126 | if (step<=0)
|
---|
127 | fStep[idx] = start==0 ? 0.1 : TMath::Abs(start*0.15);
|
---|
128 | else
|
---|
129 | fStep[idx] = step;
|
---|
130 | }
|
---|
131 | void FixParameter(Int_t idx, Double_t start)
|
---|
132 | {
|
---|
133 | if (fParameters.GetSize()<=idx)
|
---|
134 | {
|
---|
135 | fParameters.Set(idx+1);
|
---|
136 | fLimLo.Set(idx+1);
|
---|
137 | fLimUp.Set(idx+1);
|
---|
138 | fStep.Set(idx+1);
|
---|
139 | }
|
---|
140 |
|
---|
141 | fParameters[idx] = start;
|
---|
142 | fLimLo[idx] = 0;
|
---|
143 | fLimUp[idx] = 0;
|
---|
144 | fStep[idx] = 0;
|
---|
145 | }
|
---|
146 |
|
---|
147 | const TArrayD &GetParameters() const { return fParameters; }
|
---|
148 |
|
---|
149 | // Generalized optimizing routines
|
---|
150 | Bool_t Optimize(MParList &list);
|
---|
151 |
|
---|
152 | // Special optimizing routines
|
---|
153 | Bool_t Run(const char *fname, MFilter *filter, MAlphaFitter *fit=0);
|
---|
154 | Bool_t Run(const char *fname, MAlphaFitter *fit=0)
|
---|
155 | {
|
---|
156 | return Run(fname, 0, fit);
|
---|
157 | }
|
---|
158 |
|
---|
159 | Bool_t Run(MFilter *filter, MAlphaFitter *fit=0)
|
---|
160 | {
|
---|
161 | return Run(0, filter, fit);
|
---|
162 | }
|
---|
163 | Bool_t Run(MAlphaFitter *fit=0)
|
---|
164 | {
|
---|
165 | return Run(0, 0, fit);
|
---|
166 | }
|
---|
167 |
|
---|
168 | Bool_t RunOnOff(const char *fname, MFilter *filter, MAlphaFitter *fit=0, const char *tree="Events");
|
---|
169 | Bool_t RunOnOff(const char *fname, MAlphaFitter *fit=0, const char *tree="Events")
|
---|
170 | {
|
---|
171 | return RunOnOff(fname, 0, fit, tree);
|
---|
172 | }
|
---|
173 | Bool_t RunEnergy(const char *fname, const char *rule);
|
---|
174 |
|
---|
175 | Bool_t RunOnOff(MFilter *filter, MAlphaFitter *fit=0, const char *tree="Events")
|
---|
176 | {
|
---|
177 | return RunOnOff(0, filter, fit, tree);
|
---|
178 | }
|
---|
179 | Bool_t RunOnOff(MAlphaFitter *fit=0, const char *tree="Events")
|
---|
180 | {
|
---|
181 | return RunOnOff(fit, tree);
|
---|
182 | }
|
---|
183 | Bool_t RunEnergy(const char *rule)
|
---|
184 | {
|
---|
185 | return RunEnergy(0, rule);
|
---|
186 | }
|
---|
187 |
|
---|
188 | ClassDef(MJOptimize, 0) // Class for optimization of the Supercuts
|
---|
189 | };
|
---|
190 |
|
---|
191 | #endif
|
---|