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