source: trunk/MagicSoft/Mars/mjoptim/MJOptimize.h@ 8213

Last change on this file since 8213 was 7152, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 4.4 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
49 void AddPoint(TList *l, Int_t idx, Float_t val) const;
50 TList *GetPlots() const;
51
52 MEvtLoop *fEvtLoop; //!
53
54 // Minuit Interface
55 static void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
56 Double_t Fcn(const TArrayD &par, TMinuit *minuit=0);
57
58 Int_t Minuit(TMinuit &minuit, const char *cmd) const;
59 Int_t Migrad(TMinuit &minuit) const { return Minuit(minuit, "MIGRAD"); }
60 Int_t Simplex(TMinuit &minuit) const { return Minuit(minuit, "SIMPLEX"); }
61 Int_t Minimize(TMinuit &minuit) const { return Minuit(minuit, "MINIMIZE"); }
62 Int_t Seek(TMinuit &minuit) const { return Minuit(minuit, "SEEK"); }
63 Int_t Improve(TMinuit &minuit) const { return Minuit(minuit, "IMPROVE"); }
64 Int_t Minos(TMinuit &minuit) const { return Minuit(minuit, "MINOS"); }
65
66 TArrayD fParameters; //!
67 TArrayD fLimLo; //!
68 TArrayD fLimUp; //!
69 TArrayD fStep; //!
70
71 Optimizer_t fType;
72 UInt_t fNumMaxCalls;
73 Float_t fTolerance;
74 Int_t fTestTrain;
75 TString fNameMinimizationValue;
76
77 Bool_t Optimize(MEvtLoop &evtloop);
78
79protected:
80 TList fPreCuts;
81
82 TList fNamesOn;
83 TList fNamesOff;
84
85 TString fNameOut;
86
87 void AddRulesToMatrix(MHMatrix &m) const;
88 void SetupFilters(MFilterList &list, MFilter *filter=0) const;
89 Bool_t AddSequences(MRead &read, TList &list) const;
90 Bool_t FillMatrix(MReadTree &read, MParList &l, Bool_t userules=kFALSE);
91
92public:
93 MJOptimize();
94
95 // I/O
96 void AddSequenceOn(const char *fname, const char *dir="");
97 void AddSequenceOff(const char *fname, const char *dir="");
98
99 void ResetSequences();
100
101 // Interface for filter cuts
102 Int_t AddParameter(const char *rule);
103 void AddFilter(const char *rule);
104 void AddPreCut(const char *rule);
105 void AddPreCut(MFilter *f);
106
107 // Steering of optimization
108 void SetNumEvents(UInt_t n);
109 void SetDebug(UInt_t n);
110 void SetNameOut(const char *name="") { fNameOut = name; }
111 void SetOptimizer(Optimizer_t o);
112 void SetNumMaxCalls(UInt_t num=0) { fNumMaxCalls=num; }
113 void SetTolerance(Float_t tol=0) { fTolerance=tol; }
114 void EnableTestTrain(Int_t b=1) { fTestTrain=b; } // Use 1 and -1
115 void SetNameMinimizationValue(const char *name="MinimizationValue") { fNameMinimizationValue = name; }
116
117 // Parameter access
118 void SetParameters(const TArrayD &par);
119 void SetParameter(Int_t idx, Double_t start, Double_t lo=0, Double_t up=0, Double_t step=-1)
120 {
121 if (fParameters.GetSize()<=idx)
122 {
123 fParameters.Set(idx+1);
124 fLimLo.Set(idx+1);
125 fLimUp.Set(idx+1);
126 fStep.Set(idx+1);
127 }
128
129 fParameters[idx] = start;
130 fLimLo[idx] = lo;
131 fLimUp[idx] = up;
132 if (step<=0)
133 fStep[idx] = start==0 ? 0.1 : TMath::Abs(start*0.15);
134 else
135 fStep[idx] = step;
136 }
137 void FixParameter(Int_t idx, Double_t start, Double_t lo=0, Double_t up=0, Double_t step=-1)
138 {
139 if (fParameters.GetSize()<=idx)
140 {
141 fParameters.Set(idx+1);
142 fLimLo.Set(idx+1);
143 fLimUp.Set(idx+1);
144 fStep.Set(idx+1);
145 }
146
147 fParameters[idx] = start;
148 fLimLo[idx] = 0;
149 fLimUp[idx] = 0;
150 fStep[idx] = 0;
151 }
152
153 const TArrayD &GetParameters() const { return fParameters; }
154
155 // Generalized optimizing routines
156 Bool_t Optimize(MParList &list);
157
158 ClassDef(MJOptimize, 0) // Class for optimization of the Supercuts
159};
160
161#endif
Note: See TracBrowser for help on using the repository browser.