// @(#)root/mathcore:$Id$
// Author: L. Moneta Thu Sep 21 16:21:29 2006

/**********************************************************************
 *                                                                    *
 * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
 *                                                                    *
 *                                                                    *
 **********************************************************************/

// Header file for class FitConfig

#ifndef ROOT_Fit_FitConfig
#define ROOT_Fit_FitConfig


#ifndef ROOT_Fit_ParameterSettings
#include "Fit/ParameterSettings.h"
#endif

#ifndef ROOT_Math_MinimizerOptions
#include "Math/MinimizerOptions.h"
#endif

#ifndef ROOT_Math_IParamFunctionfwd
#include "Math/IParamFunctionfwd.h"
#endif


#include <vector>

namespace ROOT {

   namespace Math {

      class Minimizer;
      class MinimizerOptions;
   }

   namespace Fit {

      class FitResult;

//___________________________________________________________________________________
/**
   Class describing the configuration of the fit, options and parameter settings
   using the ROOT::Fit::ParameterSettings class

   @ingroup FitMain
*/
class FitConfig {

public:

   /**
      Default constructor
   */
   FitConfig (unsigned int npar = 0);


   /*
     Copy constructor
    */
   FitConfig(const FitConfig & rhs);

   /**
      Destructor
   */
   ~FitConfig ();

   /*
     Assignment operator
   */
   FitConfig & operator= (const FitConfig & rhs);


   /**
      get the parameter settings for the i-th parameter (const method)
   */
   const ParameterSettings & ParSettings(unsigned int i) const { return fSettings.at(i); }

   /**
      get the parameter settings for the i-th parameter (non-const method)
   */
   ParameterSettings & ParSettings(unsigned int i) { return fSettings.at(i); }

   /**
      get the vector of parameter settings  (const method)
   */
   const std::vector<ROOT::Fit::ParameterSettings> & ParamsSettings() const { return fSettings; }

   /**
      get the vector of parameter settings  (non-const method)
   */
   std::vector<ROOT::Fit::ParameterSettings> & ParamsSettings() { return fSettings; }

   /**
      number of parameters settings
    */
   unsigned int NPar() const { return fSettings.size(); }

   /**
      set the parameter settings from a model function.
      Create always new parameter setting list from a given model function
   */
   void CreateParamsSettings(const ROOT::Math::IParamMultiFunction & func);

   /**
      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.
   */
   void SetParamsSettings(unsigned int npar, const double * params, const double * vstep = 0);

   /*
     Set the parameter settings from a vector of parameter settings
   */
   void SetParamsSettings (const std::vector<ROOT::Fit::ParameterSettings>& pars ) {
      fSettings = pars;
   }


   /*
     Set the parameter settings from a fit Result
   */
   void SetFromFitResult (const FitResult & rhs);



   /**
      create a new minimizer according to chosen configuration
   */
   ROOT::Math::Minimizer * CreateMinimizer();



   /**
      access to the minimizer  control parameter (non const method)
   */
   ROOT::Math::MinimizerOptions & MinimizerOptions()  { return fMinimizerOpts; }


#ifndef __CINT__   // this method fails on Windows
   /**
      set all the minimizer options using class MinimizerOptions
    */
   void SetMinimizerOptions(const ROOT::Math::MinimizerOptions & minopt);
#endif


   /**
      set minimizer type
   */
   void SetMinimizer(const char * type, const char * algo = 0) {
      if (type) fMinimizerOpts.SetMinimizerType(type);
      if (algo) fMinimizerOpts.SetMinimizerAlgorithm(algo);
   }

   /**
      return type of minimizer package
   */
   const std::string & MinimizerType() const { return fMinimizerOpts.MinimizerType(); }

   /**
      return type of minimizer algorithms
   */
   const std::string & MinimizerAlgoType() const { return fMinimizerOpts.MinimizerAlgorithm(); }


   /**
      flag to check if resulting errors are be normalized according to chi2/ndf
   */
   bool NormalizeErrors() const { return fNormErrors; }

   ///do analysis for parabolic errors
   bool ParabErrors() const { return fParabErrors; }

   ///do minos errros analysis on the  parameters
   bool MinosErrors() const { return fMinosErrors; }

   ///Update configuration after a fit using the FitResult
   bool UpdateAfterFit() const { return fUpdateAfterFit; }

   ///Apply Weight correction for error matrix computation
   bool UseWeightCorrection() const { return fWeightCorr; }


   /// return vector of parameter indeces for which the Minos Error will be computed
   const std::vector<unsigned int> & MinosParams() const { return fMinosParams; }

   /**
      set the option to normalize the error on the result  according to chi2/ndf
   */
   void SetNormErrors(bool on = true) { fNormErrors= on; }

   ///set parabolic erros
   void SetParabErrors(bool on = true) { fParabErrors = on; }

   ///set Minos erros computation to be performed after fitting
   void SetMinosErrors(bool on = true) { fMinosErrors = on; }

   ///apply the weight correction for error matric computation
   void SetWeightCorrection(bool on = true) { fWeightCorr = on; }

   /// set parameter indeces for running Minos
   /// this can be used for running Minos on a subset of parameters - otherwise is run on all of them
   /// if MinosErrors() is set
   void SetMinosErrors(const std::vector<unsigned int> & paramInd ) {
      fMinosErrors = true;
      fMinosParams = paramInd;
   }

   ///Update configuration after a fit using the FitResult
   void SetUpdateAfterFit(bool on = true) { fUpdateAfterFit = on; }


   /**
      static function to control default minimizer type and algorithm
   */
   static void SetDefaultMinimizer(const char * type, const char * algo = 0);




protected:


private:

   bool fNormErrors;       // flag for error normalization
   bool fParabErrors;      // get correct parabolic errors estimate (call Hesse after minimizing)
   bool fMinosErrors;      // do full error analysis using Minos
   bool fUpdateAfterFit;   // update the configuration after a fit using the result
   bool fWeightCorr;       // apply correction to errors for weights fits

   std::vector<ROOT::Fit::ParameterSettings> fSettings;  // vector with the parameter settings
   std::vector<unsigned int> fMinosParams;               // vector with the parameter indeces for running Minos

   ROOT::Math::MinimizerOptions fMinimizerOpts;   //minimizer control parameters including name and algo type

};

   } // end namespace Fit

} // end namespace ROOT


#endif /* ROOT_Fit_FitConfig */
 FitConfig.h:1
 FitConfig.h:2
 FitConfig.h:3
 FitConfig.h:4
 FitConfig.h:5
 FitConfig.h:6
 FitConfig.h:7
 FitConfig.h:8
 FitConfig.h:9
 FitConfig.h:10
 FitConfig.h:11
 FitConfig.h:12
 FitConfig.h:13
 FitConfig.h:14
 FitConfig.h:15
 FitConfig.h:16
 FitConfig.h:17
 FitConfig.h:18
 FitConfig.h:19
 FitConfig.h:20
 FitConfig.h:21
 FitConfig.h:22
 FitConfig.h:23
 FitConfig.h:24
 FitConfig.h:25
 FitConfig.h:26
 FitConfig.h:27
 FitConfig.h:28
 FitConfig.h:29
 FitConfig.h:30
 FitConfig.h:31
 FitConfig.h:32
 FitConfig.h:33
 FitConfig.h:34
 FitConfig.h:35
 FitConfig.h:36
 FitConfig.h:37
 FitConfig.h:38
 FitConfig.h:39
 FitConfig.h:40
 FitConfig.h:41
 FitConfig.h:42
 FitConfig.h:43
 FitConfig.h:44
 FitConfig.h:45
 FitConfig.h:46
 FitConfig.h:47
 FitConfig.h:48
 FitConfig.h:49
 FitConfig.h:50
 FitConfig.h:51
 FitConfig.h:52
 FitConfig.h:53
 FitConfig.h:54
 FitConfig.h:55
 FitConfig.h:56
 FitConfig.h:57
 FitConfig.h:58
 FitConfig.h:59
 FitConfig.h:60
 FitConfig.h:61
 FitConfig.h:62
 FitConfig.h:63
 FitConfig.h:64
 FitConfig.h:65
 FitConfig.h:66
 FitConfig.h:67
 FitConfig.h:68
 FitConfig.h:69
 FitConfig.h:70
 FitConfig.h:71
 FitConfig.h:72
 FitConfig.h:73
 FitConfig.h:74
 FitConfig.h:75
 FitConfig.h:76
 FitConfig.h:77
 FitConfig.h:78
 FitConfig.h:79
 FitConfig.h:80
 FitConfig.h:81
 FitConfig.h:82
 FitConfig.h:83
 FitConfig.h:84
 FitConfig.h:85
 FitConfig.h:86
 FitConfig.h:87
 FitConfig.h:88
 FitConfig.h:89
 FitConfig.h:90
 FitConfig.h:91
 FitConfig.h:92
 FitConfig.h:93
 FitConfig.h:94
 FitConfig.h:95
 FitConfig.h:96
 FitConfig.h:97
 FitConfig.h:98
 FitConfig.h:99
 FitConfig.h:100
 FitConfig.h:101
 FitConfig.h:102
 FitConfig.h:103
 FitConfig.h:104
 FitConfig.h:105
 FitConfig.h:106
 FitConfig.h:107
 FitConfig.h:108
 FitConfig.h:109
 FitConfig.h:110
 FitConfig.h:111
 FitConfig.h:112
 FitConfig.h:113
 FitConfig.h:114
 FitConfig.h:115
 FitConfig.h:116
 FitConfig.h:117
 FitConfig.h:118
 FitConfig.h:119
 FitConfig.h:120
 FitConfig.h:121
 FitConfig.h:122
 FitConfig.h:123
 FitConfig.h:124
 FitConfig.h:125
 FitConfig.h:126
 FitConfig.h:127
 FitConfig.h:128
 FitConfig.h:129
 FitConfig.h:130
 FitConfig.h:131
 FitConfig.h:132
 FitConfig.h:133
 FitConfig.h:134
 FitConfig.h:135
 FitConfig.h:136
 FitConfig.h:137
 FitConfig.h:138
 FitConfig.h:139
 FitConfig.h:140
 FitConfig.h:141
 FitConfig.h:142
 FitConfig.h:143
 FitConfig.h:144
 FitConfig.h:145
 FitConfig.h:146
 FitConfig.h:147
 FitConfig.h:148
 FitConfig.h:149
 FitConfig.h:150
 FitConfig.h:151
 FitConfig.h:152
 FitConfig.h:153
 FitConfig.h:154
 FitConfig.h:155
 FitConfig.h:156
 FitConfig.h:157
 FitConfig.h:158
 FitConfig.h:159
 FitConfig.h:160
 FitConfig.h:161
 FitConfig.h:162
 FitConfig.h:163
 FitConfig.h:164
 FitConfig.h:165
 FitConfig.h:166
 FitConfig.h:167
 FitConfig.h:168
 FitConfig.h:169
 FitConfig.h:170
 FitConfig.h:171
 FitConfig.h:172
 FitConfig.h:173
 FitConfig.h:174
 FitConfig.h:175
 FitConfig.h:176
 FitConfig.h:177
 FitConfig.h:178
 FitConfig.h:179
 FitConfig.h:180
 FitConfig.h:181
 FitConfig.h:182
 FitConfig.h:183
 FitConfig.h:184
 FitConfig.h:185
 FitConfig.h:186
 FitConfig.h:187
 FitConfig.h:188
 FitConfig.h:189
 FitConfig.h:190
 FitConfig.h:191
 FitConfig.h:192
 FitConfig.h:193
 FitConfig.h:194
 FitConfig.h:195
 FitConfig.h:196
 FitConfig.h:197
 FitConfig.h:198
 FitConfig.h:199
 FitConfig.h:200
 FitConfig.h:201
 FitConfig.h:202
 FitConfig.h:203
 FitConfig.h:204
 FitConfig.h:205
 FitConfig.h:206
 FitConfig.h:207
 FitConfig.h:208
 FitConfig.h:209
 FitConfig.h:210
 FitConfig.h:211
 FitConfig.h:212
 FitConfig.h:213
 FitConfig.h:214
 FitConfig.h:215
 FitConfig.h:216
 FitConfig.h:217
 FitConfig.h:218
 FitConfig.h:219
 FitConfig.h:220
 FitConfig.h:221
 FitConfig.h:222
 FitConfig.h:223
 FitConfig.h:224
 FitConfig.h:225
 FitConfig.h:226
 FitConfig.h:227
 FitConfig.h:228
 FitConfig.h:229
 FitConfig.h:230
 FitConfig.h:231
 FitConfig.h:232
 FitConfig.h:233
 FitConfig.h:234
 FitConfig.h:235
 FitConfig.h:236
 FitConfig.h:237
 FitConfig.h:238
 FitConfig.h:239
 FitConfig.h:240
 FitConfig.h:241
 FitConfig.h:242
 FitConfig.h:243
 FitConfig.h:244
 FitConfig.h:245
 FitConfig.h:246