Loading [MathJax]/extensions/tex2jax.js
ROOT  6.07/01
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ParameterSettings.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: L. Moneta Thu Sep 21 16:21:48 2006
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Header file for class ParameterSettings
12 
13 #ifndef ROOT_Fit_ParameterSettings
14 #define ROOT_Fit_ParameterSettings
15 
16 #include <string>
17 
18 #ifndef ROOT_Math_Error
19 #include "Math/Error.h"
20 #endif
21 
22 
23 namespace ROOT {
24 
25  namespace Fit {
26 
27 
28 //___________________________________________________________________________________
29 /**
30  Class, describing value, limits and step size of the parameters
31  Provides functionality also to set/retrieve values, step sizes, limits and fix the
32  parameters.
33 
34  To be done: add constraints (equality and inequality) as functions of the parameters
35 
36  @ingroup FitMain
37 */
39 
40 public:
41 
42  /**
43  Default constructor
44  */
46  fValue(0.), fStepSize(0.1), fFix(false),
48  fName("")
49  {}
50 
51 
52  ///constructor for unlimited named Parameter
53  ParameterSettings(const std::string & name, double val, double err) :
54  fValue(val), fStepSize(err), fFix(false),
56  fName(name)
57  {}
58 
59  ///constructor for double limited Parameter
60  ParameterSettings(const std::string & name, double val, double err,
61  double min, double max) :
62  fValue(val), fStepSize(err), fFix(false),
64  fName(name)
65  {
66  SetLimits(min,max);
67  }
68 
69  ///constructor for fixed Parameter
70  ParameterSettings(const std::string & name, double val) :
71  fValue(val), fStepSize(0), fFix(true),
73  fName(name)
74  {}
75 
76 
77 
78 
79  /// set value and name (unlimited parameter)
80  void Set(const std::string & name, double value, double step) {
81  SetName(name);
82  SetValue(value);
83  SetStepSize(step);
84  }
85 
86  /// set a limited parameter
87  void Set(const std::string & name, double value, double step, double lower, double upper ) {
88  SetName(name);
89  SetValue(value);
90  SetStepSize(step);
91  SetLimits(lower,upper);
92  }
93 
94  /// set a fixed parameter
95  void Set(const std::string & name, double value) {
96  SetName(name);
97  SetValue(value);
98  Fix();
99  }
100 
101 
102  /**
103  Destructor (no operations)
104  */
106 
107  /// copy constructor and assignment operators (leave them to the compiler)
108 
109 public:
110 
111  /// return parameter value
112  double Value() const { return fValue; }
113  /// return step size
114  double StepSize() const { return fStepSize; }
115  /// return lower limit value
116  double LowerLimit() const {return fLowerLimit;}
117  /// return upper limit value
118  double UpperLimit() const {return fUpperLimit;}
119  /// check if is fixed
120  bool IsFixed() const { return fFix; }
121  /// check if parameter has lower limit
122  bool HasLowerLimit() const {return fHasLowerLimit; }
123  /// check if parameter has upper limit
124  bool HasUpperLimit() const {return fHasUpperLimit; }
125  /// check if is bound
126  bool IsBound() const { return fHasLowerLimit || fHasUpperLimit; }
127  /// check if is double bound (upper AND lower limit)
128  bool IsDoubleBound() const { return fHasLowerLimit && fHasUpperLimit; }
129  /// return name
130  const std::string & Name() const { return fName; }
131 
132  /** interaction **/
133 
134  /// set name
135  void SetName(const std::string & name ) { fName = name; }
136 
137  /// fix the parameter
138  void Fix() {fFix = true;}
139  /// release the parameter
140  void Release() {fFix = false;}
141  /// set the value
142  void SetValue(double val) {fValue = val;}
143  /// set the step size
144  void SetStepSize(double err) {fStepSize = err;}
145  /// set a double side limit,
146  /// if low == up the parameter is fixed if low > up the limits are removed
147  void SetLimits(double low, double up) {
148 
149  if ( low > up ) {
150  RemoveLimits();
151  return;
152  }
153  if (low == up && low == fValue) {
154  Fix();
155  return;
156  }
157  if (low > fValue || up < fValue) {
158  MATH_INFO_MSG("ParameterSettings","lower/upper bounds outside current parameter value. The value will be set to (low+up)/2 ");
159  fValue = 0.5 * (up+low);
160  }
161  fLowerLimit = low;
162  fUpperLimit = up;
163  fHasLowerLimit = true;
164  fHasUpperLimit = true;
165  }
166  /// set a single upper limit
167  void SetUpperLimit(double up) {
168  fLowerLimit = 0.;
169  fUpperLimit = up;
170  fHasLowerLimit = false;
171  fHasUpperLimit = true;
172  }
173  /// set a single lower limit
174  void SetLowerLimit(double low) {
175  fLowerLimit = low;
176  fUpperLimit = 0.;
177  fHasLowerLimit = true;
178  fHasUpperLimit = false;
179  }
180 
181  /// remove all limit
182  void RemoveLimits() {
183  fLowerLimit = 0.;
184  fUpperLimit = 0.;
185  fHasLowerLimit = false;
186  fHasUpperLimit = false;
187  }
188 
189 
190 
191 protected:
192 
193 
194 private:
195 
196  double fValue; // parameter value
197  double fStepSize; // parameter step size (used by minimizer)
198  bool fFix; // flag to control if parameter is fixed
199  double fLowerLimit; // lower parameter limit
200  double fUpperLimit; // upper parameter limit
201  bool fHasLowerLimit; // flag to control lower parameter limit
202  bool fHasUpperLimit; // flag to control upper parameter limit
203 
204  std::string fName; // parameter name
205 
206 };
207 
208  } // end namespace Fit
209 
210 } // end namespace ROOT
211 
212 
213 #endif /* ROOT_Fit_ParameterSettings */
void RemoveLimits()
remove all limit
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
Definition: vector.h:433
ParameterSettings(const std::string &name, double val, double err)
constructor for unlimited named Parameter
void Release()
release the parameter
bool IsFixed() const
check if is fixed
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
double LowerLimit() const
return lower limit value
static const float upper
Definition: main.cpp:49
ClassImp(TIterator) Bool_t TIterator return false
Compare two iterator objects.
Definition: TIterator.cxx:21
void SetValue(double val)
set the value
void Fix()
fix the parameter
void SetName(const std::string &name)
interaction
void SetLowerLimit(double low)
set a single lower limit
#define MATH_INFO_MSG(loc, str)
Definition: Error.h:44
void Set(const std::string &name, double value)
set a fixed parameter
void SetStepSize(double err)
set the step size
bool IsDoubleBound() const
check if is double bound (upper AND lower limit)
const std::string & Name() const
return name
double UpperLimit() const
return upper limit value
~ParameterSettings()
Destructor (no operations)
void Set(const std::string &name, double value, double step)
set value and name (unlimited parameter)
bool HasUpperLimit() const
check if parameter has upper limit
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
ParameterSettings(const std::string &name, double val, double err, double min, double max)
constructor for double limited Parameter
ParameterSettings(const std::string &name, double val)
constructor for fixed Parameter
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
#define name(a, b)
Definition: linkTestLib0.cpp:5
double StepSize() const
return step size
void Set(const std::string &name, double value, double step, double lower, double upper)
set a limited parameter
double Value() const
copy constructor and assignment operators (leave them to the compiler)
void SetUpperLimit(double up)
set a single upper limit
bool HasLowerLimit() const
check if parameter has lower limit
void SetLimits(double low, double up)
set a double side limit, if low == up the parameter is fixed if low > up the limits are removed ...
bool IsBound() const
check if is bound
float value
Definition: math.cpp:443
ParameterSettings()
Default constructor.
static const float lower
Definition: main.cpp:48