source: trunk/MagicSoft/Mars/mjobs/MJOptimize.h@ 6964

Last change on this file since 6964 was 6948, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 5.3 KB
Line 
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
12class TMinuit;
13
14class MAlphaFitter;
15
16class MEvtLoop;
17class MParList;
18class MFilter;
19class MFilterList;
20class MFitParameters;
21class MFitParametersCalc;
22
23class MHMatrix;
24class MGeomCam;
25class MRead;
26class MReadTree;
27
28class MJOptimize : public MJob
29{
30public:
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
42private:
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 Int_t fTestTrain;
87
88 Bool_t Optimize(MEvtLoop &evtloop);
89
90public:
91 MJOptimize();
92
93 // I/O
94 void AddSequenceOn(const char *fname, const char *dir="");
95 void AddSequenceOff(const char *fname, const char *dir="");
96
97 void ResetSequences();
98
99 // Interface for filter cuts
100 Int_t AddParameter(const char *rule);
101 void AddFilter(const char *rule);
102 void AddPreCut(const char *rule);
103 void AddPreCut(MFilter *f);
104
105 // Steering of optimization
106 void SetNumEvents(UInt_t n);
107 void SetDebug(UInt_t n);
108 void SetNameOut(const char *name="") { fNameOut = name; }
109 void SetOptimizer(Optimizer_t o);
110 void SetNumMaxCalls(UInt_t num=0) { fNumMaxCalls=num; }
111 void SetTolerance(Float_t tol=0) { fTolerance=tol; }
112 void EnableTestTrain(Int_t b=2) { fTestTrain=b; }
113
114 // Parameter access
115 void SetParameters(const TArrayD &par);
116 void SetParameter(Int_t idx, Double_t start, Double_t lo=0, Double_t up=0, Double_t step=-1)
117 {
118 if (fParameters.GetSize()<=idx)
119 {
120 fParameters.Set(idx+1);
121 fLimLo.Set(idx+1);
122 fLimUp.Set(idx+1);
123 fStep.Set(idx+1);
124 }
125
126 fParameters[idx] = start;
127 fLimLo[idx] = lo;
128 fLimUp[idx] = up;
129 if (step<=0)
130 fStep[idx] = start==0 ? 0.1 : TMath::Abs(start*0.15);
131 else
132 fStep[idx] = step;
133 }
134 void FixParameter(Int_t idx, Double_t start, Double_t lo=0, Double_t up=0, Double_t step=-1)
135 {
136 if (fParameters.GetSize()<=idx)
137 {
138 fParameters.Set(idx+1);
139 fLimLo.Set(idx+1);
140 fLimUp.Set(idx+1);
141 fStep.Set(idx+1);
142 }
143
144 fParameters[idx] = start;
145 fLimLo[idx] = 0;
146 fLimUp[idx] = 0;
147 fStep[idx] = 0;
148 }
149
150 const TArrayD &GetParameters() const { return fParameters; }
151
152 // Generalized optimizing routines
153 Bool_t Optimize(MParList &list);
154
155 // Special optimizing routines
156 Bool_t Run(const char *fname, MFilter *filter, MAlphaFitter *fit=0);
157 Bool_t Run(const char *fname, MAlphaFitter *fit=0)
158 {
159 return Run(fname, 0, fit);
160 }
161
162 Bool_t Run(MFilter *filter, MAlphaFitter *fit=0)
163 {
164 return Run(0, filter, fit);
165 }
166 Bool_t Run(MAlphaFitter *fit=0)
167 {
168 return Run(0, 0, fit);
169 }
170
171 Bool_t RunOnOff(const char *fname, MFilter *filter, MAlphaFitter *fit=0, const char *tree="Events");
172 Bool_t RunOnOff(const char *fname, MAlphaFitter *fit=0, const char *tree="Events")
173 {
174 return RunOnOff(fname, 0, fit, tree);
175 }
176 Bool_t RunEnergy(const char *fname, const char *rule);
177
178 Bool_t RunOnOff(MFilter *filter, MAlphaFitter *fit=0, const char *tree="Events")
179 {
180 return RunOnOff(0, filter, fit, tree);
181 }
182 Bool_t RunOnOff(MAlphaFitter *fit=0, const char *tree="Events")
183 {
184 return RunOnOff(fit, tree);
185 }
186 Bool_t RunEnergy(const char *rule)
187 {
188 return RunEnergy(0, rule);
189 }
190
191 ClassDef(MJOptimize, 0) // Class for optimization of the Supercuts
192};
193
194#endif
Note: See TracBrowser for help on using the repository browser.