Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
FitConfig.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Author: L. Moneta Thu Sep 21 16:21:29 2006
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for class FitConfig
12
13#ifndef ROOT_Fit_FitConfig
14#define ROOT_Fit_FitConfig
15
16
18
20
22
23#include "TMath.h"
24
25#include <vector>
26#include <string>
27
28namespace ROOT {
29
30 namespace Math {
31
32 class Minimizer;
33 class MinimizerOptions;
34 }
35
36 namespace Fit {
37
38 class FitResult;
39
40//___________________________________________________________________________________
41/**
42 Class describing the configuration of the fit, options and parameter settings
43 using the ROOT::Fit::ParameterSettings class
44
45 @see ROOT::Math::MinimizerOptions::SetDefaultMinimizer
46
47 @ingroup FitMain
48*/
49class FitConfig {
50
51public:
52
53 /**
54 Default constructor
55 */
56 FitConfig (unsigned int npar = 0);
57
58
59 /*
60 Copy constructor
61 */
62 FitConfig(const FitConfig & rhs);
63
64 /**
65 Destructor
66 */
67 ~FitConfig ();
68
69 /*
70 Assignment operator
71 */
73
74
75 /**
76 get the parameter settings for the i-th parameter (const method)
77 */
78 const ParameterSettings & ParSettings(unsigned int i) const { return fSettings.at(i); }
79
80 /**
81 get the parameter settings for the i-th parameter (non-const method)
82 */
83 ParameterSettings & ParSettings(unsigned int i) { return fSettings.at(i); }
84
85 /**
86 get the vector of parameter settings (const method)
87 */
88 const std::vector<ROOT::Fit::ParameterSettings> & ParamsSettings() const { return fSettings; }
89
90 /**
91 get the vector of parameter settings (non-const method)
92 */
93 std::vector<ROOT::Fit::ParameterSettings> & ParamsSettings() { return fSettings; }
94
95 /**
96 number of parameters settings
97 */
98 unsigned int NPar() const { return fSettings.size(); }
99
100 /**
101 return a vector of stored parameter values (i.e initial fit parameters)
102 */
103 std::vector<double> ParamsValues() const;
104
105
106 /**
107 set the parameter settings from a model function.
108 Create always new parameter setting list from a given model function
109 */
110 template <class T>
112 // initialize from model function
113 // set the parameters values from the function
114 unsigned int npar = func.NPar();
115 const double *begin = func.Parameters();
116 if (!begin) {
117 fSettings = std::vector<ParameterSettings>(npar);
118 return;
119 }
120
121 fSettings.clear();
122 fSettings.reserve(npar);
123 const double *end = begin + npar;
124 unsigned int i = 0;
125 for (const double *ipar = begin; ipar != end; ++ipar) {
126 double val = *ipar;
127 double step = 0.3 * fabs(val); // step size is 30% of par value
128 // double step = 2.0*fabs(val); // step size is 30% of par value
129 if (val == 0) step = 0.3;
130
131 fSettings.push_back(ParameterSettings(func.ParameterName(i), val, step));
132#ifdef DEBUG
133 std::cout << "FitConfig: add parameter " << func.ParameterName(i) << " val = " << val << std::endl;
134#endif
135 i++;
136 }
137 }
138
139 /**
140 set the parameter settings from number of parameters and a vector of values and optionally step values. If there are not existing or number of parameters does not match existing one, create a new parameter setting list.
141 */
142 void SetParamsSettings(unsigned int npar, const double * params, const double * vstep = nullptr);
143
144 /*
145 Set the parameter settings from a vector of parameter settings
146 */
147 void SetParamsSettings (const std::vector<ROOT::Fit::ParameterSettings>& pars) {
148 fSettings = pars;
149 }
150
151
152 /*
153 Set the parameter settings from a fit Result
154 */
155 void SetFromFitResult (const FitResult & rhs);
156
157
158
159 /**
160 create a new minimizer according to chosen configuration
161 */
163
164
165
166 /**
167 access to the minimizer control parameter (non const method)
168 */
170
171
172 /**
173 set all the minimizer options using class ROOT::Math::MinimizerOptions
174 @see ROOT::Math::MinimizerOptions::SetDefaultMinimizer
175 */
177
178
179 /**
180 set minimizer type and algorithm
181 @see ROOT::Math::MinimizerOptions::SetDefaultMinimizer
182 */
183 void SetMinimizer(const char *type, const char *algo = nullptr) {
186 }
187
188 /**
189 return type of minimizer package
190 */
191 const std::string & MinimizerType() const { return fMinimizerOpts.MinimizerType(); }
192
193 /**
194 return type of minimizer algorithms
195 */
196 const std::string & MinimizerAlgoType() const { return fMinimizerOpts.MinimizerAlgorithm(); }
197
198 /**
199 * return Minimizer full name (type / algorithm)
200 */
201 std::string MinimizerName() const;
202
203 /**
204 flag to check if resulting errors are be normalized according to chi2/ndf
205 */
206 bool NormalizeErrors() const { return fNormErrors; }
207
208 ///do analysis for parabolic errors
209 bool ParabErrors() const { return fParabErrors; }
210
211 ///do minos errors analysis on the parameters
212 bool MinosErrors() const { return fMinosErrors; }
213
214 ///Update configuration after a fit using the FitResult
215 bool UpdateAfterFit() const { return fUpdateAfterFit; }
216
217 ///Apply Weight correction for error matrix computation
218 bool UseWeightCorrection() const { return fWeightCorr; }
219
220
221 /// return vector of parameter indices for which the Minos Error will be computed
222 const std::vector<unsigned int> & MinosParams() const { return fMinosParams; }
223
224 /**
225 set the option to normalize the error on the result according to chi2/ndf
226 */
227 void SetNormErrors(bool on = true) { fNormErrors= on; }
228
229 ///set parabolic errors
230 void SetParabErrors(bool on = true) { fParabErrors = on; }
231
232 ///set Minos errors computation to be performed after fitting
233 void SetMinosErrors(bool on = true) { fMinosErrors = on; }
234
235 ///apply the weight correction for error matrix computation
236 void SetWeightCorrection(bool on = true) { fWeightCorr = on; }
237
238 /// set parameter indices for running Minos
239 /// this can be used for running Minos on a subset of parameters - otherwise is run on all of them
240 /// if MinosErrors() is set
241 void SetMinosErrors(const std::vector<unsigned int> & paramInd ) {
242 fMinosErrors = true;
244 }
245
246 ///Update configuration after a fit using the FitResult
247 void SetUpdateAfterFit(bool on = true) { fUpdateAfterFit = on; }
248
249
250 /**
251 static function to control default minimizer type and algorithm
252 */
253 static void SetDefaultMinimizer(const char *type, const char *algo = nullptr);
254
255
256
257
258protected:
259
260
261private:
262
263 bool fNormErrors; ///< flag for error normalization
264 bool fParabErrors; ///< get correct parabolic errors estimate (call Hesse after minimizing)
265 bool fMinosErrors; ///< do full error analysis using Minos
266 bool fUpdateAfterFit; ///< update the configuration after a fit using the result
267 bool fWeightCorr; ///< apply correction to errors for weights fits
268
269 std::vector<ROOT::Fit::ParameterSettings> fSettings; ///< vector with the parameter settings
270 std::vector<unsigned int> fMinosParams; ///< vector with the parameter indices for running Minos
271
272 ROOT::Math::MinimizerOptions fMinimizerOpts; ///< minimizer control parameters including name and algo type
273
274};
275
276 } // end namespace Fit
277
278} // end namespace ROOT
279
280
281#endif /* ROOT_Fit_FitConfig */
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::Pa...
Definition FitConfig.h:49
const std::vector< unsigned int > & MinosParams() const
return vector of parameter indices for which the Minos Error will be computed
Definition FitConfig.h:222
ParameterSettings & ParSettings(unsigned int i)
get the parameter settings for the i-th parameter (non-const method)
Definition FitConfig.h:83
bool UpdateAfterFit() const
Update configuration after a fit using the FitResult.
Definition FitConfig.h:215
std::vector< unsigned int > fMinosParams
vector with the parameter indices for running Minos
Definition FitConfig.h:270
FitConfig(unsigned int npar=0)
Default constructor.
Definition FitConfig.cxx:40
void SetMinimizer(const char *type, const char *algo=nullptr)
set minimizer type and algorithm
Definition FitConfig.h:183
void SetMinosErrors(bool on=true)
set Minos errors computation to be performed after fitting
Definition FitConfig.h:233
bool fNormErrors
flag for error normalization
Definition FitConfig.h:263
std::vector< double > ParamsValues() const
return a vector of stored parameter values (i.e initial fit parameters)
const std::string & MinimizerAlgoType() const
return type of minimizer algorithms
Definition FitConfig.h:196
std::vector< ROOT::Fit::ParameterSettings > & ParamsSettings()
get the vector of parameter settings (non-const method)
Definition FitConfig.h:93
void SetNormErrors(bool on=true)
set the option to normalize the error on the result according to chi2/ndf
Definition FitConfig.h:227
void SetParamsSettings(const std::vector< ROOT::Fit::ParameterSettings > &pars)
Definition FitConfig.h:147
bool NormalizeErrors() const
flag to check if resulting errors are be normalized according to chi2/ndf
Definition FitConfig.h:206
void SetMinosErrors(const std::vector< unsigned int > &paramInd)
set parameter indices for running Minos this can be used for running Minos on a subset of parameters ...
Definition FitConfig.h:241
bool ParabErrors() const
do analysis for parabolic errors
Definition FitConfig.h:209
void SetMinimizerOptions(const ROOT::Math::MinimizerOptions &minopt)
set all the minimizer options using class ROOT::Math::MinimizerOptions
void SetWeightCorrection(bool on=true)
apply the weight correction for error matrix computation
Definition FitConfig.h:236
unsigned int NPar() const
number of parameters settings
Definition FitConfig.h:98
void SetUpdateAfterFit(bool on=true)
Update configuration after a fit using the FitResult.
Definition FitConfig.h:247
void SetParamsSettings(unsigned int npar, const double *params, const double *vstep=nullptr)
set the parameter settings from number of parameters and a vector of values and optionally step value...
std::vector< ROOT::Fit::ParameterSettings > fSettings
vector with the parameter settings
Definition FitConfig.h:269
std::string MinimizerName() const
return Minimizer full name (type / algorithm)
bool UseWeightCorrection() const
Apply Weight correction for error matrix computation.
Definition FitConfig.h:218
const std::vector< ROOT::Fit::ParameterSettings > & ParamsSettings() const
get the vector of parameter settings (const method)
Definition FitConfig.h:88
bool fParabErrors
get correct parabolic errors estimate (call Hesse after minimizing)
Definition FitConfig.h:264
ROOT::Math::MinimizerOptions fMinimizerOpts
minimizer control parameters including name and algo type
Definition FitConfig.h:272
~FitConfig()
Destructor.
Definition FitConfig.cxx:52
ROOT::Math::Minimizer * CreateMinimizer()
create a new minimizer according to chosen configuration
void SetParabErrors(bool on=true)
set parabolic errors
Definition FitConfig.h:230
bool fMinosErrors
do full error analysis using Minos
Definition FitConfig.h:265
static void SetDefaultMinimizer(const char *type, const char *algo=nullptr)
static function to control default minimizer type and algorithm
void SetFromFitResult(const FitResult &rhs)
Definition FitConfig.cxx:80
void CreateParamsSettings(const ROOT::Math::IParamMultiFunctionTempl< T > &func)
set the parameter settings from a model function.
Definition FitConfig.h:111
const std::string & MinimizerType() const
return type of minimizer package
Definition FitConfig.h:191
bool fWeightCorr
apply correction to errors for weights fits
Definition FitConfig.h:267
const ParameterSettings & ParSettings(unsigned int i) const
get the parameter settings for the i-th parameter (const method)
Definition FitConfig.h:78
bool fUpdateAfterFit
update the configuration after a fit using the result
Definition FitConfig.h:266
FitConfig & operator=(const FitConfig &rhs)
Definition FitConfig.cxx:62
ROOT::Math::MinimizerOptions & MinimizerOptions()
access to the minimizer control parameter (non const method)
Definition FitConfig.h:169
bool MinosErrors() const
do minos errors analysis on the parameters
Definition FitConfig.h:212
class containing the result of the fit and all the related information (fitted parameter values,...
Definition FitResult.h:47
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
void SetMinimizerType(const char *type)
set minimizer type
const std::string & MinimizerAlgorithm() const
type of algorithm
const std::string & MinimizerType() const
type of minimizer
void SetMinimizerAlgorithm(const char *type)
set minimizer algorithm
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2,...
Definition Minimizer.h:121
RooCmdArg Minimizer(const char *type, const char *alg=nullptr)
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition HFitImpl.cxx:133
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...