source: releases/Mars.2014.05.26/mjoptim/MJOptimize.h@ 19602

Last change on this file since 19602 was 8643, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 4.2 KB
Line 
1#ifndef MARS_MJOptimize
2#define MARS_MJOptimize
3
4#ifndef MARS_MJOptimizeBase
5#include "MJOptimizeBase.h"
6#endif
7
8#ifndef ROOT_TArrayD
9#include <TArrayD.h>
10#endif
11
12class TMinuit;
13
14class MAlphaFitter;
15
16class MTask;
17class MEvtLoop;
18class MParList;
19class MFilter;
20class MFilterList;
21class MFitParameters;
22class MFitParametersCalc;
23
24class MHMatrix;
25class MGeomCam;
26class MRead;
27class MReadTree;
28
29class MJOptimize : public MJOptimizeBase
30{
31public:
32 enum Optimizer_t
33 {
34 kMigrad, // Minimize by the method of Migrad
35 kSimplex, // Minimize by the method of Simplex
36 kMinimize, // Migrad + Simplex (if Migrad fails)
37 kMinos, // Minos error determination
38 kImprove, // Local minimum search
39 kSeek, // Minimize by the method of Monte Carlo
40 kNone // Skip optimization
41 };
42
43private:
44 Int_t fNumEvents;
45
46 TList fFilter;
47
48 void AddPoint(TList *l, Int_t idx, Float_t val) const;
49 TList *GetPlots() const;
50
51 MEvtLoop *fEvtLoop; //!
52
53 // Minuit Interface
54 static void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
55 Double_t Fcn(const TArrayD &par, TMinuit *minuit=0);
56
57 Int_t Minuit(TMinuit &minuit, const char *cmd) const;
58 Int_t Migrad(TMinuit &minuit) const { return Minuit(minuit, "MIGRAD"); }
59 Int_t Simplex(TMinuit &minuit) const { return Minuit(minuit, "SIMPLEX"); }
60 Int_t Minimize(TMinuit &minuit) const { return Minuit(minuit, "MINIMIZE"); }
61 Int_t Seek(TMinuit &minuit) const { return Minuit(minuit, "SEEK"); }
62 Int_t Improve(TMinuit &minuit) const { return Minuit(minuit, "IMPROVE"); }
63 Int_t Minos(TMinuit &minuit) const { return Minuit(minuit, "MINOS"); }
64
65 TArrayD fParameters; //!
66 TArrayD fLimLo; //!
67 TArrayD fLimUp; //!
68 TArrayD fStep; //!
69
70 Optimizer_t fType;
71 UInt_t fNumMaxCalls;
72 Float_t fTolerance;
73 Int_t fTestTrain;
74 TString fNameMinimizationValue;
75
76 Bool_t Optimize(MEvtLoop &evtloop);
77
78protected:
79 TList fNamesOn;
80 TList fNamesOff;
81
82 TString fNameOut;
83
84 void AddRulesToMatrix(MHMatrix &m) const;
85 void SetupFilters(MFilterList &list, MFilter *filter=0) const;
86 Bool_t AddSequences(MRead &read, TList &list) const;
87 Bool_t FillMatrix(MReadTree &read, MParList &l, Bool_t userules=kFALSE);
88
89public:
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 void AddFilter(const char *rule);
100
101 // Steering of optimization
102 void SetNumEvents(UInt_t n);
103 void SetDebug(UInt_t n);
104 void SetNameOut(const char *name="") { fNameOut = name; }
105 void SetOptimizer(Optimizer_t o);
106 void SetNumMaxCalls(UInt_t num=0) { fNumMaxCalls=num; }
107 void SetTolerance(Float_t tol=0) { fTolerance=tol; }
108 void EnableTestTrain(Int_t b=1) { fTestTrain=b; } // Use 1 and -1
109 void SetNameMinimizationValue(const char *name="MinimizationValue") { fNameMinimizationValue = name; }
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, Double_t lo=0, Double_t up=0, Double_t step=-1)
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 ClassDef(MJOptimize, 0) // Class for optimization of the Supercuts
153};
154
155#endif
Note: See TracBrowser for help on using the repository browser.