[root] / trunk / math / mathcore / src / FitConfig.cxx Repository:
ViewVC logotype

Diff of /trunk/math/mathcore/src/FitConfig.cxx

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 25485, Mon Sep 22 07:52:52 2008 UTC revision 25486, Mon Sep 22 12:43:03 2008 UTC
# Line 16  Line 16 
16  #include "Math/Util.h"  #include "Math/Util.h"
17    
18  #include "Math/Minimizer.h"  #include "Math/Minimizer.h"
19    #include "Math/MinimizerOptions.h"
20  #include "Math/Factory.h"  #include "Math/Factory.h"
21    
22  #include <cmath>  #include <cmath>
# Line 35  Line 36 
36  namespace Fit {  namespace Fit {
37    
38    
    static std::string fgDefaultMinimizer = "Minuit2";  
    static std::string fgDefaultMinimAlgo = "Migrad";  
   
39    
40  FitConfig::FitConfig(unsigned int npar) :  FitConfig::FitConfig(unsigned int npar) :
41     fNormErrors(false),     fNormErrors(false),
42       fParabErrors(false), // ensure that in any case correct parabolic errors are estimated
43       fMinosErrors(false),    // do full Minos error analysis for all parameters
44     fSettings(std::vector<ParameterSettings>(npar) )     fSettings(std::vector<ParameterSettings>(npar) )
45  {  {
46     // constructor implementation     // constructor implementation
47    
48     // default minimizer type (ue static default values)     // default minimizer type (use static default values)
49     fMinimizerType = fgDefaultMinimizer;     fMinimizerType = ROOT::Math::MinimizerOptions::DefaultMinimizerType();
50     fMinimAlgoType = fgDefaultMinimAlgo;     fMinimAlgoType = ROOT::Math::MinimizerOptions::DefaultMinimizerAlgo();;
51  }  }
52    
53    
# Line 56  Line 56 
56     // destructor implementation. No Op     // destructor implementation. No Op
57  }  }
58    
59  void FitConfig::SetParamsSettings(unsigned int npar, const double *params ) {  void FitConfig::SetParamsSettings(unsigned int npar, const double *params, const double * vstep ) {
60     // initialize fit config from parameter values     // initialize fit config from parameter values
61     if (params == 0) {     if (params == 0) {
62        fSettings =  std::vector<ParameterSettings>(npar);        fSettings =  std::vector<ParameterSettings>(npar);
63        return;        return;
64     }     }
65     // if a vector of parameters is given     // if a vector of parameters is given and parameters are not existing or are of different size
66       bool createNew = false;
67       if (npar != fSettings.size() ) {
68     fSettings.clear();     fSettings.clear();
69     fSettings.reserve(npar);     fSettings.reserve(npar);
70          createNew = true;
71       }
72     unsigned int i = 0;     unsigned int i = 0;
73     const double * end = params+npar;     const double * end = params+npar;
74     for (const double * ipar = params; ipar !=  end; ++ipar) {     for (const double * ipar = params; ipar !=  end; ++ipar) {
75        double val = *ipar;        double val = *ipar;
76        double step = 0.3*std::fabs(val);   // step size is 30% of par value        double step = 0;
77          if (vstep == 0) {
78             step = 0.3*std::fabs(val);   // step size is 30% of par value
79        //double step = 2.0*std::fabs(val);   // step size is 30% of par value        //double step = 2.0*std::fabs(val);   // step size is 30% of par value
80        if (val ==  0) step  =  0.3;        if (val ==  0) step  =  0.3;
81          }
82          else
83             step = vstep[i];
84    
85          if (createNew)
86        fSettings.push_back( ParameterSettings("Par_" + ROOT::Math::Util::ToString(i), val, step ) );        fSettings.push_back( ParameterSettings("Par_" + ROOT::Math::Util::ToString(i), val, step ) );
87  #ifdef DEBUG        else {
88        std::cout << "FitConfig: add parameter " <<  func.ParameterName(i) << " val = " << val << std::endl;           fSettings[i].SetValue(val);
89  #endif           fSettings[i].SetStepSize(step);
90          }
91    
92        i++;        i++;
93     }     }
94  }  }
95    
96  void FitConfig::SetParamsSettings(const ROOT::Math::IParamMultiFunction & func) {  void FitConfig::CreateParamsSettings(const ROOT::Math::IParamMultiFunction & func) {
97     // initialize from model function     // initialize from model function
98     // set the parameters values from the function     // set the parameters values from the function
99     unsigned int npar = func.NPar();     unsigned int npar = func.NPar();
# Line 119  Line 131 
131     if (min == 0) {     if (min == 0) {
132        std::string minim2 = "Minuit2";        std::string minim2 = "Minuit2";
133        if (fMinimizerType != minim2 ) {        if (fMinimizerType != minim2 ) {
134           std::string msg = "Could not create Minimizer " + fMinimizerType + " trying using minimizer " + minim2;           std::string msg = "Could not create the " + fMinimizerType + " minimizer. Try using the minimizer " + minim2;
135           MATH_WARN_MSG("FitConfig::CreateMinimizer",msg.c_str());           MATH_WARN_MSG("FitConfig::CreateMinimizer",msg.c_str());
136           min = ROOT::Math::Factory::CreateMinimizer(minim2);           min = ROOT::Math::Factory::CreateMinimizer(minim2,"Migrad");
137           if (min == 0) {           if (min == 0) {
138              MATH_ERROR_MSG("FitConfig::CreateMinimizer","Could not create the Minuit2 minimizer");              MATH_ERROR_MSG("FitConfig::CreateMinimizer","Could not create the Minuit2 minimizer");
139              return 0;              return 0;
140           }           }
141             fMinimizerType = "Minuit2"; fMinimAlgoType = "Migrad";
142        }        }
143        else {        else {
144           std::string msg = "Could not create the Minimizer " + fMinimizerType;           std::string msg = "Could not create the Minimizer " + fMinimizerType;
# Line 148  Line 161 
161     min->SetMaxFunctionCalls( fMinimizerOpts.MaxFunctionCalls() );     min->SetMaxFunctionCalls( fMinimizerOpts.MaxFunctionCalls() );
162     min->SetMaxIterations( fMinimizerOpts.MaxIterations() );     min->SetMaxIterations( fMinimizerOpts.MaxIterations() );
163     min->SetTolerance( fMinimizerOpts.Tolerance() );     min->SetTolerance( fMinimizerOpts.Tolerance() );
164     min->SetValidError( fMinimizerOpts.ParabErrors() );     min->SetValidError( fParabErrors );
165     min->SetStrategy( fMinimizerOpts.Strategy() );     min->SetStrategy( fMinimizerOpts.Strategy() );
166       min->SetErrorUp( fMinimizerOpts.ErrorDef() );
167    
168    
169     return min;     return min;
170  }  }
171    
172  void FitConfig::SetDefaultMinimizer(const std::string & type, const std::string & algo ) {  void FitConfig::SetDefaultMinimizer(const std::string & type, const std::string & algo ) {
173     // set the default minimizer type and algorithm     // set the default minimizer type and algorithms
174     if (type != "") fgDefaultMinimizer = type;     ROOT::Math::MinimizerOptions::SetDefaultMinimizer(type, algo);
    if (algo != "") fgDefaultMinimAlgo = algo;  
175  }  }
176    
177    void FitConfig::SetMinimizerOptions(const ROOT::Math::MinimizerOptions & minopt) {
178       fMinimizerType = minopt.MinimType;
179       fMinimAlgoType = minopt.AlgoType;
180       fMinimizerOpts.SetTolerance(minopt.Tolerance);
181       fMinimizerOpts.SetMaxFunctionCalls(minopt.MaxFunctionCalls);
182       fMinimizerOpts.SetMaxIterations(minopt.MaxIterations);
183       fMinimizerOpts.SetStrategy(minopt.Strategy);
184       fMinimizerOpts.SetPrintLevel(minopt.PrintLevel);
185       fMinimizerOpts.SetErrorDef(minopt.ErrorDef);
186    
187       // error up should be added as well
188    }
189    
190    
191     } // end namespace Fit     } // end namespace Fit
192    
193  } // end namespace ROOT  } // end namespace ROOT

Legend:
Removed from v.25485  
changed lines
  Added in v.25486

Subversion Admin
ViewVC Help
Powered by ViewVC 1.0.9