File indexing completed on 2025-09-16 09:08:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef ROOT_Fit_FitConfig
0014 #define ROOT_Fit_FitConfig
0015
0016
0017 #include "Fit/ParameterSettings.h"
0018
0019 #include "Math/MinimizerOptions.h"
0020
0021 #include "Math/IParamFunctionfwd.h"
0022
0023 #include "TMath.h"
0024
0025 #include <vector>
0026 #include <string>
0027
0028 namespace ROOT {
0029
0030 namespace Math {
0031
0032 class Minimizer;
0033 class MinimizerOptions;
0034 }
0035
0036 namespace Fit {
0037
0038 class FitResult;
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 class FitConfig {
0050
0051 public:
0052
0053
0054
0055
0056 FitConfig (unsigned int npar = 0);
0057
0058
0059
0060
0061
0062 FitConfig(const FitConfig & rhs);
0063
0064
0065
0066
0067 ~FitConfig ();
0068
0069
0070
0071
0072 FitConfig & operator= (const FitConfig & rhs);
0073
0074
0075
0076
0077
0078 const ParameterSettings & ParSettings(unsigned int i) const { return fSettings.at(i); }
0079
0080
0081
0082
0083 ParameterSettings & ParSettings(unsigned int i) { return fSettings.at(i); }
0084
0085
0086
0087
0088 const std::vector<ROOT::Fit::ParameterSettings> & ParamsSettings() const { return fSettings; }
0089
0090
0091
0092
0093 std::vector<ROOT::Fit::ParameterSettings> & ParamsSettings() { return fSettings; }
0094
0095
0096
0097
0098 unsigned int NPar() const { return fSettings.size(); }
0099
0100
0101
0102
0103 std::vector<double> ParamsValues() const;
0104
0105
0106
0107
0108
0109
0110 template <class T>
0111 void CreateParamsSettings(const ROOT::Math::IParamMultiFunctionTempl<T> &func) {
0112
0113
0114 unsigned int npar = func.NPar();
0115 const double *begin = func.Parameters();
0116 if (!begin) {
0117 fSettings = std::vector<ParameterSettings>(npar);
0118 return;
0119 }
0120
0121 fSettings.clear();
0122 fSettings.reserve(npar);
0123 const double *end = begin + npar;
0124 unsigned int i = 0;
0125 for (const double *ipar = begin; ipar != end; ++ipar) {
0126 double val = *ipar;
0127 double step = 0.3 * fabs(val);
0128
0129 if (val == 0) step = 0.3;
0130
0131 fSettings.push_back(ParameterSettings(func.ParameterName(i), val, step));
0132 #ifdef DEBUG
0133 std::cout << "FitConfig: add parameter " << func.ParameterName(i) << " val = " << val << std::endl;
0134 #endif
0135 i++;
0136 }
0137 }
0138
0139
0140
0141
0142 void SetParamsSettings(unsigned int npar, const double * params, const double * vstep = nullptr);
0143
0144
0145
0146
0147 void SetParamsSettings (const std::vector<ROOT::Fit::ParameterSettings>& pars) {
0148 fSettings = pars;
0149 }
0150
0151
0152
0153
0154
0155 void SetFromFitResult (const FitResult & rhs);
0156
0157
0158
0159
0160
0161
0162 ROOT::Math::Minimizer * CreateMinimizer();
0163
0164
0165
0166
0167
0168
0169 ROOT::Math::MinimizerOptions & MinimizerOptions() { return fMinimizerOpts; }
0170
0171
0172
0173
0174
0175
0176 void SetMinimizerOptions(const ROOT::Math::MinimizerOptions & minopt);
0177
0178
0179
0180
0181
0182
0183 void SetMinimizer(const char *type, const char *algo = nullptr) {
0184 if (type) fMinimizerOpts.SetMinimizerType(type);
0185 if (algo) fMinimizerOpts.SetMinimizerAlgorithm(algo);
0186 }
0187
0188
0189
0190
0191 const std::string & MinimizerType() const { return fMinimizerOpts.MinimizerType(); }
0192
0193
0194
0195
0196 const std::string & MinimizerAlgoType() const { return fMinimizerOpts.MinimizerAlgorithm(); }
0197
0198
0199
0200
0201 std::string MinimizerName() const;
0202
0203
0204
0205
0206 bool NormalizeErrors() const { return fNormErrors; }
0207
0208
0209 bool ParabErrors() const { return fParabErrors; }
0210
0211
0212 bool MinosErrors() const { return fMinosErrors; }
0213
0214
0215 bool UpdateAfterFit() const { return fUpdateAfterFit; }
0216
0217
0218 bool UseWeightCorrection() const { return fWeightCorr; }
0219
0220
0221
0222 const std::vector<unsigned int> & MinosParams() const { return fMinosParams; }
0223
0224
0225
0226
0227 void SetNormErrors(bool on = true) { fNormErrors= on; }
0228
0229
0230 void SetParabErrors(bool on = true) { fParabErrors = on; }
0231
0232
0233 void SetMinosErrors(bool on = true) { fMinosErrors = on; }
0234
0235
0236 void SetWeightCorrection(bool on = true) { fWeightCorr = on; }
0237
0238
0239
0240
0241 void SetMinosErrors(const std::vector<unsigned int> & paramInd ) {
0242 fMinosErrors = true;
0243 fMinosParams = paramInd;
0244 }
0245
0246
0247 void SetUpdateAfterFit(bool on = true) { fUpdateAfterFit = on; }
0248
0249
0250
0251
0252
0253 static void SetDefaultMinimizer(const char *type, const char *algo = nullptr);
0254
0255
0256
0257
0258 protected:
0259
0260
0261 private:
0262
0263 bool fNormErrors;
0264 bool fParabErrors;
0265 bool fMinosErrors;
0266 bool fUpdateAfterFit;
0267 bool fWeightCorr;
0268
0269 std::vector<ROOT::Fit::ParameterSettings> fSettings;
0270 std::vector<unsigned int> fMinosParams;
0271
0272 ROOT::Math::MinimizerOptions fMinimizerOpts;
0273
0274 };
0275
0276 }
0277
0278 }
0279
0280
0281 #endif