Logo ROOT   6.13/01
Reference Guide
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 #include "Math/Error.h"
19 
20 
21 namespace ROOT {
22 
23  namespace Fit {
24 
25 
26 //___________________________________________________________________________________
27 /**
28  Class, describing value, limits and step size of the parameters
29  Provides functionality also to set/retrieve values, step sizes, limits and fix the
30  parameters.
31 
32  To be done: add constraints (equality and inequality) as functions of the parameters
33 
34  @ingroup FitMain
35 */
37 
38 public:
39 
40  /**
41  Default constructor
42  */
44  fValue(0.), fStepSize(0.1), fFix(false),
45  fLowerLimit(0.), fUpperLimit(0.), fHasLowerLimit(false), fHasUpperLimit(false),
46  fName("")
47  {}
48 
49 
50  ///constructor for unlimited named Parameter
51  ParameterSettings(const std::string & name, double val, double err) :
52  fValue(val), fStepSize(err), fFix(false),
53  fLowerLimit(0.), fUpperLimit(0.), fHasLowerLimit(false), fHasUpperLimit(false),
54  fName(name)
55  {}
56 
57  ///constructor for double limited Parameter. The given value should be within the given limits [min,max]
58  ParameterSettings(const std::string & name, double val, double err,
59  double min, double max) :
60  fValue(val), fStepSize(err), fFix(false),
61  fLowerLimit(0.), fUpperLimit(0.), fHasLowerLimit(false), fHasUpperLimit(false),
62  fName(name)
63  {
64  SetLimits(min,max);
65  }
66 
67  ///constructor for fixed Parameter
68  ParameterSettings(const std::string & name, double val) :
69  fValue(val), fStepSize(0), fFix(true),
70  fLowerLimit(0.), fUpperLimit(0.), fHasLowerLimit(false), fHasUpperLimit(false),
71  fName(name)
72  {}
73 
74 
75 
76 
77  /// set value and name (unlimited parameter)
78  void Set(const std::string & name, double value, double step) {
79  SetName(name);
80  SetValue(value);
81  SetStepSize(step);
82  }
83 
84  /// set a limited parameter. The given value should be within the given limits [min,max]
85  void Set(const std::string & name, double value, double step, double lower, double upper ) {
86  SetName(name);
87  SetValue(value);
88  SetStepSize(step);
89  SetLimits(lower,upper);
90  }
91 
92  /// set a fixed parameter
93  void Set(const std::string & name, double value) {
94  SetName(name);
95  SetValue(value);
96  Fix();
97  }
98 
99 
100  /**
101  Destructor (no operations)
102  */
104 
105  /// copy constructor and assignment operators (leave them to the compiler)
106 
107 public:
108 
109  /// return parameter value
110  double Value() const { return fValue; }
111  /// return step size
112  double StepSize() const { return fStepSize; }
113  /// return lower limit value
114  double LowerLimit() const {return fLowerLimit;}
115  /// return upper limit value
116  double UpperLimit() const {return fUpperLimit;}
117  /// check if is fixed
118  bool IsFixed() const { return fFix; }
119  /// check if parameter has lower limit
120  bool HasLowerLimit() const {return fHasLowerLimit; }
121  /// check if parameter has upper limit
122  bool HasUpperLimit() const {return fHasUpperLimit; }
123  /// check if is bound
124  bool IsBound() const { return fHasLowerLimit || fHasUpperLimit; }
125  /// check if is double bound (upper AND lower limit)
126  bool IsDoubleBound() const { return fHasLowerLimit && fHasUpperLimit; }
127  /// return name
128  const std::string & Name() const { return fName; }
129 
130  /** interaction **/
131 
132  /// set name
133  void SetName(const std::string & name ) { fName = name; }
134 
135  /// fix the parameter
136  void Fix() {fFix = true;}
137  /// release the parameter
138  void Release() {fFix = false;}
139  /// set the value
140  void SetValue(double val) {fValue = val;}
141  /// set the step size
142  void SetStepSize(double err) {fStepSize = err;}
143  /// set a double side limit,
144  /// if low == up the parameter is fixed if low > up the limits are removed
145  /// The current parameter value should be within the given limits [low,up].
146  /// If the value is outside the limits, then a new parameter value is set to = (up+low)/2
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 */
bool IsFixed() const
check if is fixed
void RemoveLimits()
remove all limit
ParameterSettings(const std::string &name, double val, double err)
constructor for unlimited named Parameter
Namespace for new ROOT classes and functions.
Definition: TFoamSampler.h:19
void Release()
release the parameter
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
double Value() const
copy constructor and assignment operators (leave them to the compiler)
void SetValue(double val)
set the value
void Fix()
fix the parameter
void SetName(const std::string &name)
interaction
double StepSize() const
return step size
void SetLowerLimit(double low)
set a single lower limit
bool IsDoubleBound() const
check if is double bound (upper AND 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 HasUpperLimit() const
check if parameter has upper limit
~ParameterSettings()
Destructor (no operations)
void Set(const std::string &name, double value, double step)
set value and name (unlimited parameter)
double UpperLimit() const
return upper limit value
const std::string & Name() const
return name
ParameterSettings(const std::string &name, double val, double err, double min, double max)
constructor for double limited Parameter. The given value should be within the given limits [min...
ParameterSettings(const std::string &name, double val)
constructor for fixed Parameter
void Set(const std::string &name, double value, double step, double lower, double upper)
set a limited parameter. The given value should be within the given limits [min,max] ...
void SetUpperLimit(double up)
set a single upper limit
double LowerLimit() const
return lower limit value
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 The c...
bool IsBound() const
check if is bound
ParameterSettings()
Default constructor.
bool HasLowerLimit() const
check if parameter has lower limit