File indexing completed on 2025-09-16 09:09:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef ROOT_TMinuitMinimizer
0014 #define ROOT_TMinuitMinimizer
0015
0016 #include "Math/Minimizer.h"
0017
0018 #include "Rtypes.h"
0019
0020 #include <vector>
0021 #include <string>
0022
0023 class TMinuit;
0024
0025 namespace ROOT {
0026
0027 namespace Minuit {
0028
0029
0030
0031 enum EMinimizerType {
0032 kMigrad,
0033 kSimplex,
0034 kCombined,
0035 kMigradImproved,
0036 kScan,
0037 kSeek
0038 };
0039
0040 }
0041 }
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 class TMinuitMinimizer : public ROOT::Math::Minimizer {
0052
0053 public:
0054
0055
0056
0057
0058 TMinuitMinimizer ( ROOT::Minuit::EMinimizerType type = ROOT::Minuit::kMigrad, unsigned int ndim = 0);
0059
0060
0061
0062
0063 TMinuitMinimizer ( const char * type , unsigned int ndim = 0);
0064
0065
0066
0067
0068 ~TMinuitMinimizer () override;
0069
0070
0071 void SetFunction(const ROOT::Math::IMultiGenFunction & func) override;
0072
0073
0074 bool SetVariable(unsigned int ivar, const std::string & name, double val, double step) override;
0075
0076
0077 bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double , double ) override;
0078
0079
0080 bool SetLowerLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double lower ) override;
0081
0082
0083 bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper ) override;
0084
0085
0086 bool SetFixedVariable(unsigned int , const std::string & , double ) override;
0087
0088
0089 bool SetVariableValue(unsigned int , double ) override;
0090
0091
0092 bool SetVariableStepSize(unsigned int , double ) override;
0093
0094 bool SetVariableLowerLimit(unsigned int , double ) override;
0095
0096 bool SetVariableUpperLimit(unsigned int , double ) override;
0097
0098 bool SetVariableLimits(unsigned int ivar, double lower, double upper) override;
0099
0100 bool FixVariable(unsigned int) override;
0101
0102 bool ReleaseVariable(unsigned int) override;
0103
0104
0105 bool IsFixedVariable(unsigned int) const override;
0106
0107 bool GetVariableSettings(unsigned int, ROOT::Fit::ParameterSettings & ) const override;
0108
0109
0110
0111 bool Minimize() override;
0112
0113
0114 double MinValue() const override;
0115
0116
0117 double Edm() const override;
0118
0119
0120 const double * X() const override { return &fParams.front(); }
0121
0122
0123 const double * MinGradient() const override { return nullptr; }
0124
0125
0126 unsigned int NCalls() const override;
0127
0128
0129
0130 unsigned int NDim() const override { return fDim; }
0131
0132
0133
0134 unsigned int NFree() const override;
0135
0136
0137 bool ProvidesError() const override { return true; }
0138
0139
0140 const double * Errors() const override { return &fErrors.front(); }
0141
0142
0143
0144
0145
0146 double CovMatrix(unsigned int i, unsigned int j) const override {
0147 return ( fCovar.size() > (i + fDim* j) ) ? fCovar[i + fDim* j] : 0;
0148 }
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158 bool GetCovMatrix(double * cov) const override;
0159
0160
0161
0162
0163
0164
0165
0166
0167 bool GetHessianMatrix(double * h) const override;
0168
0169
0170 int CovMatrixStatus() const override;
0171
0172
0173 double GlobalCC(unsigned int ) const override;
0174
0175
0176 bool GetMinosError(unsigned int i, double & errLow, double & errUp, int = 0) override;
0177
0178
0179
0180
0181
0182 int MinosStatus() const override { return fMinosStatus; }
0183
0184
0185
0186
0187 bool Hesse() override;
0188
0189
0190
0191
0192
0193 bool Scan(unsigned int i, unsigned int &nstep, double * x, double * y, double xmin = 0, double xmax = 0) override;
0194
0195
0196
0197
0198
0199 bool Contour(unsigned int i, unsigned int j, unsigned int & npoints, double *xi, double *xj) override;
0200
0201
0202 void PrintResults() override;
0203
0204
0205
0206
0207
0208 std::string VariableName(unsigned int ivar) const override;
0209
0210
0211
0212 int VariableIndex(const std::string & name) const override;
0213
0214
0215
0216 bool static UseStaticMinuit(bool on = true);
0217
0218
0219
0220 void SuppressMinuitWarnings(bool nowarn=true);
0221
0222
0223 bool SetDebug(bool on = true);
0224
0225 protected:
0226
0227
0228 static void Fcn( int &, double * , double & f, double * , int);
0229
0230 static void FcnGrad( int &, double * g, double & f, double * , int);
0231
0232
0233 void InitTMinuit(int ndim);
0234
0235
0236 void DoClear();
0237
0238
0239 void DoReleaseFixParameter( int ivar);
0240
0241
0242 void RetrieveParams();
0243
0244
0245 void RetrieveErrorMatrix();
0246
0247
0248 bool CheckMinuitInstance() const;
0249
0250
0251 bool CheckVarIndex(unsigned int ivar) const;
0252
0253
0254 private:
0255
0256 bool fUsed;
0257 bool fMinosRun;
0258 unsigned int fDim;
0259 int fMinosStatus = -1;
0260 std::vector<double> fParams;
0261 std::vector<double> fErrors;
0262 std::vector<double> fCovar;
0263
0264 ROOT::Minuit::EMinimizerType fType;
0265 TMinuit * fMinuit;
0266
0267 static TMinuit * fgMinuit;
0268
0269 static bool fgUsed;
0270 static bool fgUseStaticMinuit;
0271
0272 ClassDef(TMinuitMinimizer,1)
0273
0274 };
0275
0276
0277
0278 #endif