Logo ROOT  
Reference Guide
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
27namespace ROOT {
28
29 namespace Math {
30
31 class Minimizer;
32 class MinimizerOptions;
33 }
34
35 namespace Fit {
36
37 class FitResult;
38
39//___________________________________________________________________________________
40/**
41 Class describing the configuration of the fit, options and parameter settings
42 using the ROOT::Fit::ParameterSettings class
43
44 @ingroup FitMain
45*/
46class FitConfig {
47
48public:
49
50 /**
51 Default constructor
52 */
53 FitConfig (unsigned int npar = 0);
54
55
56 /*
57 Copy constructor
58 */
59 FitConfig(const FitConfig & rhs);
60
61 /**
62 Destructor
63 */
64 ~FitConfig ();
65
66 /*
67 Assignment operator
68 */
69 FitConfig & operator= (const FitConfig & rhs);
70
71
72 /**
73 get the parameter settings for the i-th parameter (const method)
74 */
75 const ParameterSettings & ParSettings(unsigned int i) const { return fSettings.at(i); }
76
77 /**
78 get the parameter settings for the i-th parameter (non-const method)
79 */
80 ParameterSettings & ParSettings(unsigned int i) { return fSettings.at(i); }
81
82 /**
83 get the vector of parameter settings (const method)
84 */
85 const std::vector<ROOT::Fit::ParameterSettings> & ParamsSettings() const { return fSettings; }
86
87 /**
88 get the vector of parameter settings (non-const method)
89 */
90 std::vector<ROOT::Fit::ParameterSettings> & ParamsSettings() { return fSettings; }
91
92 /**
93 number of parameters settings
94 */
95 unsigned int NPar() const { return fSettings.size(); }
96
97 /**
98 return a vector of stored parameter values (i.e initial fit parameters)
99 */
100 std::vector<double> ParamsValues() const;
101
102
103 /**
104 set the parameter settings from a model function.
105 Create always new parameter setting list from a given model function
106 */
107 template <class T>
109 // initialize from model function
110 // set the parameters values from the function
111 unsigned int npar = func.NPar();
112 const double *begin = func.Parameters();
113 if (begin == 0) {
114 fSettings = std::vector<ParameterSettings>(npar);
115 return;
116 }
117
118 fSettings.clear();
119 fSettings.reserve(npar);
120 const double *end = begin + npar;
121 unsigned int i = 0;
122 for (const double *ipar = begin; ipar != end; ++ipar) {
123 double val = *ipar;
124 double step = 0.3 * fabs(val); // step size is 30% of par value
125 // double step = 2.0*fabs(val); // step size is 30% of par value
126 if (val == 0) step = 0.3;
127
128 fSettings.push_back(ParameterSettings(func.ParameterName(i), val, step));
129#ifdef DEBUG
130 std::cout << "FitConfig: add parameter " << func.ParameterName(i) << " val = " << val << std::endl;
131#endif
132 i++;
133 }
134 }
135
136 /**
137 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.
138 */
139 void SetParamsSettings(unsigned int npar, const double * params, const double * vstep = 0);
140
141 /*
142 Set the parameter settings from a vector of parameter settings
143 */
144 void SetParamsSettings (const std::vector<ROOT::Fit::ParameterSettings>& pars ) {
145 fSettings = pars;
146 }
147
148
149 /*
150 Set the parameter settings from a fit Result
151 */
152 void SetFromFitResult (const FitResult & rhs);
153
154
155
156 /**
157 create a new minimizer according to chosen configuration
158 */
160
161
162
163 /**
164 access to the minimizer control parameter (non const method)
165 */
167
168
169#ifndef __CINT__ // this method fails on Windows
170 /**
171 set all the minimizer options using class MinimizerOptions
172 */
174#endif
175
176
177 /**
178 set minimizer type
179 */
180 void SetMinimizer(const char * type, const char * algo = 0) {
183 }
184
185 /**
186 return type of minimizer package
187 */
188 const std::string & MinimizerType() const { return fMinimizerOpts.MinimizerType(); }
189
190 /**
191 return type of minimizer algorithms
192 */
193 const std::string & MinimizerAlgoType() const { return fMinimizerOpts.MinimizerAlgorithm(); }
194
195 /**
196 * return Minimizer full name (type / algorithm)
197 */
198 std::string MinimizerName() const;
199
200 /**
201 flag to check if resulting errors are be normalized according to chi2/ndf
202 */
203 bool NormalizeErrors() const { return fNormErrors; }
204
205 ///do analysis for parabolic errors
206 bool ParabErrors() const { return fParabErrors; }
207
208 ///do minos errros analysis on the parameters
209 bool MinosErrors() const { return fMinosErrors; }
210
211 ///Update configuration after a fit using the FitResult
212 bool UpdateAfterFit() const { return fUpdateAfterFit; }
213
214 ///Apply Weight correction for error matrix computation
215 bool UseWeightCorrection() const { return fWeightCorr; }
216
217
218 /// return vector of parameter indeces for which the Minos Error will be computed
219 const std::vector<unsigned int> & MinosParams() const { return fMinosParams; }
220
221 /**
222 set the option to normalize the error on the result according to chi2/ndf
223 */
224 void SetNormErrors(bool on = true) { fNormErrors= on; }
225
226 ///set parabolic erros
227 void SetParabErrors(bool on = true) { fParabErrors = on; }
228
229 ///set Minos erros computation to be performed after fitting
230 void SetMinosErrors(bool on = true) { fMinosErrors = on; }
231
232 ///apply the weight correction for error matric computation
233 void SetWeightCorrection(bool on = true) { fWeightCorr = on; }
234
235 /// set parameter indeces for running Minos
236 /// this can be used for running Minos on a subset of parameters - otherwise is run on all of them
237 /// if MinosErrors() is set
238 void SetMinosErrors(const std::vector<unsigned int> & paramInd ) {
239 fMinosErrors = true;
240 fMinosParams = paramInd;
241 }
242
243 ///Update configuration after a fit using the FitResult
244 void SetUpdateAfterFit(bool on = true) { fUpdateAfterFit = on; }
245
246
247 /**
248 static function to control default minimizer type and algorithm
249 */
250 static void SetDefaultMinimizer(const char * type, const char * algo = 0);
251
252
253
254
255protected:
256
257
258private:
259
260 bool fNormErrors; // flag for error normalization
261 bool fParabErrors; // get correct parabolic errors estimate (call Hesse after minimizing)
262 bool fMinosErrors; // do full error analysis using Minos
263 bool fUpdateAfterFit; // update the configuration after a fit using the result
264 bool fWeightCorr; // apply correction to errors for weights fits
265
266 std::vector<ROOT::Fit::ParameterSettings> fSettings; // vector with the parameter settings
267 std::vector<unsigned int> fMinosParams; // vector with the parameter indeces for running Minos
268
269 ROOT::Math::MinimizerOptions fMinimizerOpts; //minimizer control parameters including name and algo type
270
271};
272
273 } // end namespace Fit
274
275} // end namespace ROOT
276
277
278#endif /* ROOT_Fit_FitConfig */
int type
Definition: TGX11.cxx:120
Class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::Pa...
Definition: FitConfig.h:46
const std::vector< unsigned int > & MinosParams() const
return vector of parameter indeces for which the Minos Error will be computed
Definition: FitConfig.h:219
void SetParamsSettings(unsigned int npar, const double *params, const double *vstep=0)
set the parameter settings from number of parameters and a vector of values and optionally step value...
Definition: FitConfig.cxx:136
ParameterSettings & ParSettings(unsigned int i)
get the parameter settings for the i-th parameter (non-const method)
Definition: FitConfig.h:80
bool UpdateAfterFit() const
Update configuration after a fit using the FitResult.
Definition: FitConfig.h:212
std::vector< unsigned int > fMinosParams
Definition: FitConfig.h:267
FitConfig(unsigned int npar=0)
Default constructor.
Definition: FitConfig.cxx:41
void SetMinosErrors(bool on=true)
set Minos erros computation to be performed after fitting
Definition: FitConfig.h:230
std::vector< double > ParamsValues() const
return a vector of stored parameter values (i.e initial fit parameters)
Definition: FitConfig.cxx:261
const std::string & MinimizerAlgoType() const
return type of minimizer algorithms
Definition: FitConfig.h:193
std::vector< ROOT::Fit::ParameterSettings > & ParamsSettings()
get the vector of parameter settings (non-const method)
Definition: FitConfig.h:90
void SetNormErrors(bool on=true)
set the option to normalize the error on the result according to chi2/ndf
Definition: FitConfig.h:224
void SetParamsSettings(const std::vector< ROOT::Fit::ParameterSettings > &pars)
Definition: FitConfig.h:144
void SetMinimizer(const char *type, const char *algo=0)
set minimizer type
Definition: FitConfig.h:180
bool NormalizeErrors() const
flag to check if resulting errors are be normalized according to chi2/ndf
Definition: FitConfig.h:203
void SetMinosErrors(const std::vector< unsigned int > &paramInd)
set parameter indeces for running Minos this can be used for running Minos on a subset of parameters ...
Definition: FitConfig.h:238
bool ParabErrors() const
do analysis for parabolic errors
Definition: FitConfig.h:206
void SetMinimizerOptions(const ROOT::Math::MinimizerOptions &minopt)
set all the minimizer options using class MinimizerOptions
Definition: FitConfig.cxx:256
void SetWeightCorrection(bool on=true)
apply the weight correction for error matric computation
Definition: FitConfig.h:233
unsigned int NPar() const
number of parameters settings
Definition: FitConfig.h:95
void SetUpdateAfterFit(bool on=true)
Update configuration after a fit using the FitResult.
Definition: FitConfig.h:244
std::vector< ROOT::Fit::ParameterSettings > fSettings
Definition: FitConfig.h:266
std::string MinimizerName() const
return Minimizer full name (type / algorithm)
Definition: FitConfig.cxx:238
bool UseWeightCorrection() const
Apply Weight correction for error matrix computation.
Definition: FitConfig.h:215
const std::vector< ROOT::Fit::ParameterSettings > & ParamsSettings() const
get the vector of parameter settings (const method)
Definition: FitConfig.h:85
ROOT::Math::MinimizerOptions fMinimizerOpts
Definition: FitConfig.h:269
~FitConfig()
Destructor.
Definition: FitConfig.cxx:53
ROOT::Math::Minimizer * CreateMinimizer()
create a new minimizer according to chosen configuration
Definition: FitConfig.cxx:174
void SetParabErrors(bool on=true)
set parabolic erros
Definition: FitConfig.h:227
void SetFromFitResult(const FitResult &rhs)
Definition: FitConfig.cxx:81
void CreateParamsSettings(const ROOT::Math::IParamMultiFunctionTempl< T > &func)
set the parameter settings from a model function.
Definition: FitConfig.h:108
static void SetDefaultMinimizer(const char *type, const char *algo=0)
static function to control default minimizer type and algorithm
Definition: FitConfig.cxx:251
const std::string & MinimizerType() const
return type of minimizer package
Definition: FitConfig.h:188
const ParameterSettings & ParSettings(unsigned int i) const
get the parameter settings for the i-th parameter (const method)
Definition: FitConfig.h:75
FitConfig & operator=(const FitConfig &rhs)
Definition: FitConfig.cxx:63
ROOT::Math::MinimizerOptions & MinimizerOptions()
access to the minimizer control parameter (non const method)
Definition: FitConfig.h:166
bool MinosErrors() const
do minos errros analysis on the parameters
Definition: FitConfig.h:209
class containg 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...
virtual const double * Parameters() const =0
Access the parameter values.
virtual std::string ParameterName(unsigned int i) const
Return the name of the i-th parameter (starting from zero) Overwrite if want to avoid the default nam...
virtual unsigned int NPar() const =0
Return the number of Parameters.
IParamFunction interface (abstract class) describing multi-dimensional parameteric functions It is a ...
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:78
RooCmdArg Minimizer(const char *type, const char *alg=0)
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition: HFitImpl.cxx:134
Namespace for new Math classes and functions.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: StringConv.hxx:21