Logo ROOT  
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 */
36 class ParameterSettings {
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  */
103  ~ParameterSettings () {}
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;
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 */
ROOT::Fit::ParameterSettings::fValue
double fValue
Definition: ParameterSettings.h:211
ROOT::Fit::ParameterSettings::fHasUpperLimit
bool fHasUpperLimit
Definition: ParameterSettings.h:217
ROOT::Fit::ParameterSettings::fName
std::string fName
Definition: ParameterSettings.h:219
HFit::Fit
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
ROOT::Fit::ParameterSettings::SetLowerLimit
void SetLowerLimit(double low)
set a single lower limit
Definition: ParameterSettings.h:189
ROOT::Fit::ParameterSettings::IsFixed
bool IsFixed() const
check if is fixed
Definition: ParameterSettings.h:133
ROOT::Fit::ParameterSettings::Value
double Value() const
copy constructor and assignment operators (leave them to the compiler)
Definition: ParameterSettings.h:125
ROOT::Fit::ParameterSettings::HasUpperLimit
bool HasUpperLimit() const
check if parameter has upper limit
Definition: ParameterSettings.h:137
ROOT::Fit::ParameterSettings::SetName
void SetName(const std::string &name)
interaction
Definition: ParameterSettings.h:148
ROOT::Fit::ParameterSettings::fLowerLimit
double fLowerLimit
Definition: ParameterSettings.h:214
ROOT::Fit::ParameterSettings::Release
void Release()
release the parameter
Definition: ParameterSettings.h:153
ROOT::Fit::ParameterSettings::Fix
void Fix()
fix the parameter
Definition: ParameterSettings.h:151
ROOT::Fit::ParameterSettings::ParameterSettings
ParameterSettings()
Default constructor.
Definition: ParameterSettings.h:58
ROOT::Fit::ParameterSettings::StepSize
double StepSize() const
return step size
Definition: ParameterSettings.h:127
ROOT::Fit::ParameterSettings::HasLowerLimit
bool HasLowerLimit() const
check if parameter has lower limit
Definition: ParameterSettings.h:135
ROOT::Fit::ParameterSettings::Name
const std::string & Name() const
return name
Definition: ParameterSettings.h:143
ROOT::Fit::ParameterSettings::SetStepSize
void SetStepSize(double err)
set the step size
Definition: ParameterSettings.h:157
ROOT::Fit::ParameterSettings::UpperLimit
double UpperLimit() const
return upper limit value
Definition: ParameterSettings.h:131
ROOT::Fit::ParameterSettings::SetValue
void SetValue(double val)
set the value
Definition: ParameterSettings.h:155
ROOT::Fit::ParameterSettings::RemoveLimits
void RemoveLimits()
remove all limit
Definition: ParameterSettings.h:197
Error.h
ROOT::Fit::ParameterSettings::SetUpperLimit
void SetUpperLimit(double up)
set a single upper limit
Definition: ParameterSettings.h:182
ROOT::Fit::ParameterSettings::SetLimits
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...
Definition: ParameterSettings.h:162
ROOT::Fit::ParameterSettings::Set
void Set(const std::string &name, double value, double step)
set value and name (unlimited parameter)
Definition: ParameterSettings.h:93
ROOT::Fit::ParameterSettings::IsBound
bool IsBound() const
check if is bound
Definition: ParameterSettings.h:139
ROOT::Fit::ParameterSettings::fUpperLimit
double fUpperLimit
Definition: ParameterSettings.h:215
ROOT::Fit::ParameterSettings::fFix
bool fFix
Definition: ParameterSettings.h:213
MATH_INFO_MSG
#define MATH_INFO_MSG(loc, str)
Pre-processor macro to report messages which can be configured to use ROOT error or simply an std::io...
Definition: Error.h:77
ROOT::Fit::ParameterSettings::fHasLowerLimit
bool fHasLowerLimit
Definition: ParameterSettings.h:216
ROOT::Fit::ParameterSettings::LowerLimit
double LowerLimit() const
return lower limit value
Definition: ParameterSettings.h:129
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Fit::ParameterSettings::fStepSize
double fStepSize
Definition: ParameterSettings.h:212
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Fit::ParameterSettings::~ParameterSettings
~ParameterSettings()
Destructor (no operations)
Definition: ParameterSettings.h:118
ROOT::Fit::ParameterSettings::IsDoubleBound
bool IsDoubleBound() const
check if is double bound (upper AND lower limit)
Definition: ParameterSettings.h:141