Logo ROOT  
Reference Guide
MinuitParameter.h
Go to the documentation of this file.
1 // @(#)root/minuit2:$Id$
2 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
7  * *
8  **********************************************************************/
9 
10 #ifndef ROOT_Minuit2_MinuitParameter
11 #define ROOT_Minuit2_MinuitParameter
12 
13 #include <algorithm>
14 #include <memory>
15 #include <cassert>
16 #include <string>
17 
18 namespace ROOT {
19 
20  namespace Minuit2 {
21 
22 //____________________________________________________________________________
23 /**
24  class for the individual Minuit Parameter with Name and number;
25  contains the input numbers for the minimization or the output result
26  from minimization;
27  possible interactions: Fix/release, set/remove limits, set Value/error;
28 
29  From version 5.20: use string to store the name to avoid limitation of
30  name length of 20 characters
31  */
32 
33 class MinuitParameter {
34 
35 public:
36 
37  //default constructor standard with value/error = 0
38  MinuitParameter() :
39  fNum(0), fValue(0), fError(0.), fConst(false), fFix(false),
40  fLoLimit(0.), fUpLimit(0.), fLoLimValid(false), fUpLimValid(false),
41  fName("")
42  {}
43 
44  //constructor for constant Parameter
45  MinuitParameter(unsigned int num, const std::string & name, double val) :
46  fNum(num), fValue(val), fError(0.), fConst(true), fFix(false),
47  fLoLimit(0.), fUpLimit(0.), fLoLimValid(false), fUpLimValid(false),
48  fName(name)
49  {}
50 
51  //constructor for standard Parameter
52  MinuitParameter(unsigned int num, const std::string & name, double val, double err) :
53  fNum(num), fValue(val), fError(err), fConst(false), fFix(false),
54  fLoLimit(0.), fUpLimit(0.), fLoLimValid(false), fUpLimValid(false),
55  fName(name)
56  {}
57 
58  //constructor for limited Parameter
59  MinuitParameter(unsigned int num, const std::string & name, double val, double err,
60  double min, double max) :
61  fNum(num),fValue(val), fError(err), fConst(false), fFix(false),
62  fLoLimit(min), fUpLimit(max), fLoLimValid(true), fUpLimValid(true),
63  fName(name)
64  {
65  assert(min != max);
66  if(min > max) {
67  fLoLimit = max;
68  fUpLimit = min;
69  }
70  }
71 
72  ~MinuitParameter() {}
73 
74  MinuitParameter(const MinuitParameter& par) :
75  fNum(par.fNum), fValue(par.fValue), fError(par.fError),
76  fConst(par.fConst), fFix(par.fFix), fLoLimit(par.fLoLimit),
79  fName(par.fName )
80  {}
81 
83  if(this != &par) {
84  fNum = par.fNum;
85  fName = par.fName;
86  fValue = par.fValue;
87  fError = par.fError;
88  fConst = par.fConst;
89  fFix = par.fFix;
90  fLoLimit = par.fLoLimit;
91  fUpLimit = par.fUpLimit;
92  fLoLimValid = par.fLoLimValid;
93  fUpLimValid = par.fUpLimValid;
94  }
95  return *this;
96  }
97 
98  //access methods
99  unsigned int Number() const {return fNum;}
100  // new API returning a string
101  const std::string & GetName() const { return fName; }
102  // return const char * for mantaining backward compatibility
103  const char * Name() const {return fName.c_str();}
104 
105  double Value() const {return fValue;}
106  double Error() const {return fError;}
107 
108  //interaction
109  void SetName(const std::string &name) { fName = name; }
110 
111  void SetValue(double val) {fValue = val;}
112  void SetError(double err) {fError = err;}
113  void SetLimits(double low, double up) {
114  assert(low != up);
115  fLoLimit = low;
116  fUpLimit = up;
117  fLoLimValid = true;
118  fUpLimValid = true;
119  if(low > up) {
120  fLoLimit = up;
121  fUpLimit = low;
122  }
123  }
124 
125  void SetUpperLimit(double up) {
126  fLoLimit = 0.;
127  fUpLimit = up;
128  fLoLimValid = false;
129  fUpLimValid = true;
130  }
131 
132  void SetLowerLimit(double low) {
133  fLoLimit = low;
134  fUpLimit = 0.;
135  fLoLimValid = true;
136  fUpLimValid = false;
137  }
138 
139  void RemoveLimits() {
140  fLoLimit = 0.;
141  fUpLimit = 0.;
142  fLoLimValid = false;
143  fUpLimValid = false;
144  }
145 
146  void Fix() {fFix = true;}
147  void Release() {fFix = false;}
148 
149  //state of Parameter (fixed/const/limited)
150  bool IsConst() const {return fConst;}
151  bool IsFixed() const {return fFix;}
152 
153  bool HasLimits() const {return fLoLimValid || fUpLimValid; }
154  bool HasLowerLimit() const {return fLoLimValid; }
155  bool HasUpperLimit() const {return fUpLimValid; }
156  double LowerLimit() const {return fLoLimit;}
157  double UpperLimit() const {return fUpLimit;}
158 
159 private:
160 
161  unsigned int fNum;
162  double fValue;
163  double fError;
164  bool fConst;
165  bool fFix;
166  double fLoLimit;
167  double fUpLimit;
170  std::string fName;
171 
172 private:
173 
174 // void SetName(const std::string & name) {
175 // int l = std::min(int(strlen(name)), 11);
176 // memset(fName, 0, 11*sizeof(char));
177 // memcpy(fName, name, l*sizeof(char));
178 // fName[10] = '\0';
179 // }
180 
181 };
182 
183  } // namespace Minuit2
184 
185 } // namespace ROOT
186 
187 #endif // ROOT_Minuit2_MinuitParameter
ROOT::Minuit2::MinuitParameter
class for the individual Minuit Parameter with Name and number; contains the input numbers for the mi...
Definition: MinuitParameter.h:41
ROOT::Minuit2::MinuitParameter::SetLowerLimit
void SetLowerLimit(double low)
Definition: MinuitParameter.h:144
ROOT::Minuit2::MinuitParameter::UpperLimit
double UpperLimit() const
Definition: MinuitParameter.h:169
ROOT::Minuit2::MinuitParameter::operator=
MinuitParameter & operator=(const MinuitParameter &par)
Definition: MinuitParameter.h:94
ROOT::Minuit2::MinuitParameter::SetError
void SetError(double err)
Definition: MinuitParameter.h:124
ROOT::Minuit2::MinuitParameter::SetLimits
void SetLimits(double low, double up)
Definition: MinuitParameter.h:125
ROOT::Minuit2::MinuitParameter::GetName
const std::string & GetName() const
Definition: MinuitParameter.h:113
ROOT::Minuit2::MinuitParameter::Release
void Release()
Definition: MinuitParameter.h:159
ROOT::Minuit2::MinuitParameter::SetName
void SetName(const std::string &name)
Definition: MinuitParameter.h:121
ROOT::Minuit2::MinuitParameter::HasUpperLimit
bool HasUpperLimit() const
Definition: MinuitParameter.h:167
ROOT::Minuit2::MinuitParameter::Fix
void Fix()
Definition: MinuitParameter.h:158
ROOT::Minuit2::MinuitParameter::~MinuitParameter
~MinuitParameter()
Definition: MinuitParameter.h:84
ROOT::Minuit2::MinuitParameter::fUpLimValid
bool fUpLimValid
Definition: MinuitParameter.h:181
ROOT::Minuit2::MinuitParameter::fConst
bool fConst
Definition: MinuitParameter.h:176
ROOT::Minuit2::MinuitParameter::SetUpperLimit
void SetUpperLimit(double up)
Definition: MinuitParameter.h:137
ROOT::Minuit2::MinuitParameter::IsConst
bool IsConst() const
Definition: MinuitParameter.h:162
ROOT::Minuit2::MinuitParameter::MinuitParameter
MinuitParameter()
Definition: MinuitParameter.h:50
ROOT::Minuit2::MinuitParameter::fLoLimit
double fLoLimit
Definition: MinuitParameter.h:178
ROOT::Minuit2::MinuitParameter::fValue
double fValue
Definition: MinuitParameter.h:174
ROOT::Minuit2::MinuitParameter::fUpLimit
double fUpLimit
Definition: MinuitParameter.h:179
ROOT::Minuit2::MinuitParameter::fError
double fError
Definition: MinuitParameter.h:175
ROOT::Minuit2::MinuitParameter::RemoveLimits
void RemoveLimits()
Definition: MinuitParameter.h:151
ROOT::Minuit2::MinuitParameter::SetValue
void SetValue(double val)
Definition: MinuitParameter.h:123
ROOT::Minuit2::MinuitParameter::IsFixed
bool IsFixed() const
Definition: MinuitParameter.h:163
ROOT::Minuit2::MinuitParameter::Value
double Value() const
Definition: MinuitParameter.h:117
ROOT::Minuit2::MinuitParameter::fFix
bool fFix
Definition: MinuitParameter.h:177
ROOT::Minuit2::MinuitParameter::HasLimits
bool HasLimits() const
Definition: MinuitParameter.h:165
ROOT::Minuit2::MinuitParameter::Error
double Error() const
Definition: MinuitParameter.h:118
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Minuit2::MinuitParameter::LowerLimit
double LowerLimit() const
Definition: MinuitParameter.h:168
ROOT::Minuit2::MinuitParameter::fLoLimValid
bool fLoLimValid
Definition: MinuitParameter.h:180
ROOT::Minuit2::MinuitParameter::fName
std::string fName
Definition: MinuitParameter.h:182
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Minuit2::MinuitParameter::Name
const char * Name() const
Definition: MinuitParameter.h:115
ROOT::Minuit2::MinuitParameter::HasLowerLimit
bool HasLowerLimit() const
Definition: MinuitParameter.h:166
ROOT::Minuit2::MinuitParameter::fNum
unsigned int fNum
Definition: MinuitParameter.h:173
ROOT::Minuit2::MinuitParameter::Number
unsigned int Number() const
Definition: MinuitParameter.h:111