Logo ROOT   6.10/09
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 
24 #include <vector>
25 
26 namespace ROOT {
27 
28  namespace Math {
29 
30  class Minimizer;
31  class MinimizerOptions;
32  }
33 
34  namespace Fit {
35 
36  class FitResult;
37 
38 //___________________________________________________________________________________
39 /**
40  Class describing the configuration of the fit, options and parameter settings
41  using the ROOT::Fit::ParameterSettings class
42 
43  @ingroup FitMain
44 */
45 class FitConfig {
46 
47 public:
48 
49  /**
50  Default constructor
51  */
52  FitConfig (unsigned int npar = 0);
53 
54 
55  /*
56  Copy constructor
57  */
58  FitConfig(const FitConfig & rhs);
59 
60  /**
61  Destructor
62  */
63  ~FitConfig ();
64 
65  /*
66  Assignment operator
67  */
68  FitConfig & operator= (const FitConfig & rhs);
69 
70 
71  /**
72  get the parameter settings for the i-th parameter (const method)
73  */
74  const ParameterSettings & ParSettings(unsigned int i) const { return fSettings.at(i); }
75 
76  /**
77  get the parameter settings for the i-th parameter (non-const method)
78  */
79  ParameterSettings & ParSettings(unsigned int i) { return fSettings.at(i); }
80 
81  /**
82  get the vector of parameter settings (const method)
83  */
84  const std::vector<ROOT::Fit::ParameterSettings> & ParamsSettings() const { return fSettings; }
85 
86  /**
87  get the vector of parameter settings (non-const method)
88  */
89  std::vector<ROOT::Fit::ParameterSettings> & ParamsSettings() { return fSettings; }
90 
91  /**
92  number of parameters settings
93  */
94  unsigned int NPar() const { return fSettings.size(); }
95 
96  /**
97  return a vector of stored parameter values (i.e initial fit parameters)
98  */
99  std::vector<double> ParamsValues() const;
100 
101 
102  /**
103  set the parameter settings from a model function.
104  Create always new parameter setting list from a given model function
105  */
106  void CreateParamsSettings(const ROOT::Math::IParamMultiFunction & func);
107 
108  /**
109  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.
110  */
111  void SetParamsSettings(unsigned int npar, const double * params, const double * vstep = 0);
112 
113  /*
114  Set the parameter settings from a vector of parameter settings
115  */
116  void SetParamsSettings (const std::vector<ROOT::Fit::ParameterSettings>& pars ) {
117  fSettings = pars;
118  }
119 
120 
121  /*
122  Set the parameter settings from a fit Result
123  */
124  void SetFromFitResult (const FitResult & rhs);
125 
126 
127 
128  /**
129  create a new minimizer according to chosen configuration
130  */
131  ROOT::Math::Minimizer * CreateMinimizer();
132 
133 
134 
135  /**
136  access to the minimizer control parameter (non const method)
137  */
138  ROOT::Math::MinimizerOptions & MinimizerOptions() { return fMinimizerOpts; }
139 
140 
141 #ifndef __CINT__ // this method fails on Windows
142  /**
143  set all the minimizer options using class MinimizerOptions
144  */
145  void SetMinimizerOptions(const ROOT::Math::MinimizerOptions & minopt);
146 #endif
147 
148 
149  /**
150  set minimizer type
151  */
152  void SetMinimizer(const char * type, const char * algo = 0) {
153  if (type) fMinimizerOpts.SetMinimizerType(type);
154  if (algo) fMinimizerOpts.SetMinimizerAlgorithm(algo);
155  }
156 
157  /**
158  return type of minimizer package
159  */
160  const std::string & MinimizerType() const { return fMinimizerOpts.MinimizerType(); }
161 
162  /**
163  return type of minimizer algorithms
164  */
165  const std::string & MinimizerAlgoType() const { return fMinimizerOpts.MinimizerAlgorithm(); }
166 
167 
168  /**
169  flag to check if resulting errors are be normalized according to chi2/ndf
170  */
171  bool NormalizeErrors() const { return fNormErrors; }
172 
173  ///do analysis for parabolic errors
174  bool ParabErrors() const { return fParabErrors; }
175 
176  ///do minos errros analysis on the parameters
177  bool MinosErrors() const { return fMinosErrors; }
178 
179  ///Update configuration after a fit using the FitResult
180  bool UpdateAfterFit() const { return fUpdateAfterFit; }
181 
182  ///Apply Weight correction for error matrix computation
183  bool UseWeightCorrection() const { return fWeightCorr; }
184 
185 
186  /// return vector of parameter indeces for which the Minos Error will be computed
187  const std::vector<unsigned int> & MinosParams() const { return fMinosParams; }
188 
189  /**
190  set the option to normalize the error on the result according to chi2/ndf
191  */
192  void SetNormErrors(bool on = true) { fNormErrors= on; }
193 
194  ///set parabolic erros
195  void SetParabErrors(bool on = true) { fParabErrors = on; }
196 
197  ///set Minos erros computation to be performed after fitting
198  void SetMinosErrors(bool on = true) { fMinosErrors = on; }
199 
200  ///apply the weight correction for error matric computation
201  void SetWeightCorrection(bool on = true) { fWeightCorr = on; }
202 
203  /// set parameter indeces for running Minos
204  /// this can be used for running Minos on a subset of parameters - otherwise is run on all of them
205  /// if MinosErrors() is set
206  void SetMinosErrors(const std::vector<unsigned int> & paramInd ) {
207  fMinosErrors = true;
208  fMinosParams = paramInd;
209  }
210 
211  ///Update configuration after a fit using the FitResult
212  void SetUpdateAfterFit(bool on = true) { fUpdateAfterFit = on; }
213 
214 
215  /**
216  static function to control default minimizer type and algorithm
217  */
218  static void SetDefaultMinimizer(const char * type, const char * algo = 0);
219 
220 
221 
222 
223 protected:
224 
225 
226 private:
227 
228  bool fNormErrors; // flag for error normalization
229  bool fParabErrors; // get correct parabolic errors estimate (call Hesse after minimizing)
230  bool fMinosErrors; // do full error analysis using Minos
231  bool fUpdateAfterFit; // update the configuration after a fit using the result
232  bool fWeightCorr; // apply correction to errors for weights fits
233 
234  std::vector<ROOT::Fit::ParameterSettings> fSettings; // vector with the parameter settings
235  std::vector<unsigned int> fMinosParams; // vector with the parameter indeces for running Minos
236 
237  ROOT::Math::MinimizerOptions fMinimizerOpts; //minimizer control parameters including name and algo type
238 
239 };
240 
241  } // end namespace Fit
242 
243 } // end namespace ROOT
244 
245 
246 #endif /* ROOT_Fit_FitConfig */
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:206
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
void SetUpdateAfterFit(bool on=true)
Update configuration after a fit using the FitResult.
Definition: FitConfig.h:212
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
bool NormalizeErrors() const
flag to check if resulting errors are be normalized according to chi2/ndf
Definition: FitConfig.h:171
const std::vector< unsigned int > & MinosParams() const
return vector of parameter indeces for which the Minos Error will be computed
Definition: FitConfig.h:187
unsigned int NPar() const
number of parameters settings
Definition: FitConfig.h:94
ROOT::Math::MinimizerOptions fMinimizerOpts
Definition: FitConfig.h:237
ROOT::Math::MinimizerOptions & MinimizerOptions()
access to the minimizer control parameter (non const method)
Definition: FitConfig.h:138
const ParameterSettings & ParSettings(unsigned int i) const
get the parameter settings for the i-th parameter (const method)
Definition: FitConfig.h:74
bool UseWeightCorrection() const
Apply Weight correction for error matrix computation.
Definition: FitConfig.h:183
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2, Minuit, GSL, etc..) Plug-in&#39;s exist in ROOT to be able to instantiate the derived classes like ROOT::Math::GSLMinimizer or ROOT::Math::Minuit2Minimizer via the plug-in manager.
Definition: Minimizer.h:78
bool UpdateAfterFit() const
Update configuration after a fit using the FitResult.
Definition: FitConfig.h:180
bool ParabErrors() const
do analysis for parabolic errors
Definition: FitConfig.h:174
ParameterSettings & ParSettings(unsigned int i)
get the parameter settings for the i-th parameter (non-const method)
Definition: FitConfig.h:79
void SetMinosErrors(bool on=true)
set Minos erros computation to be performed after fitting
Definition: FitConfig.h:198
void SetMinimizer(const char *type, const char *algo=0)
set minimizer type
Definition: FitConfig.h:152
RooCmdArg Minimizer(const char *type, const char *alg=0)
const std::vector< ROOT::Fit::ParameterSettings > & ParamsSettings() const
get the vector of parameter settings (const method)
Definition: FitConfig.h:84
class containg the result of the fit and all the related information (fitted parameter values...
Definition: FitResult.h:48
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
int type
Definition: TGX11.cxx:120
void SetWeightCorrection(bool on=true)
apply the weight correction for error matric computation
Definition: FitConfig.h:201
const std::string & MinimizerType() const
return type of minimizer package
Definition: FitConfig.h:160
double func(double *x, double *p)
Definition: stressTF1.cxx:213
std::vector< ROOT::Fit::ParameterSettings > & ParamsSettings()
get the vector of parameter settings (non-const method)
Definition: FitConfig.h:89
Namespace for new Math classes and functions.
Binding & operator=(OUT(*fun)(void))
bool MinosErrors() const
do minos errros analysis on the parameters
Definition: FitConfig.h:177
void SetParamsSettings(const std::vector< ROOT::Fit::ParameterSettings > &pars)
Definition: FitConfig.h:116
void SetNormErrors(bool on=true)
set the option to normalize the error on the result according to chi2/ndf
Definition: FitConfig.h:192
std::vector< ROOT::Fit::ParameterSettings > fSettings
Definition: FitConfig.h:234
void SetParabErrors(bool on=true)
set parabolic erros
Definition: FitConfig.h:195
std::vector< unsigned int > fMinosParams
Definition: FitConfig.h:235
Class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::Pa...
Definition: FitConfig.h:45
const std::string & MinimizerAlgoType() const
return type of minimizer algorithms
Definition: FitConfig.h:165