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