MinuitParameter.h

Go to the documentation of this file.
00001 // @(#)root/minuit2:$Id: MinuitParameter.h 24400 2008-06-20 07:28:49Z moneta $
00002 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei   2003-2005  
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2005 LCG ROOT Math team,  CERN/PH-SFT                *
00007  *                                                                    *
00008  **********************************************************************/
00009 
00010 #ifndef ROOT_Minuit2_MinuitParameter
00011 #define ROOT_Minuit2_MinuitParameter
00012 
00013 #include <algorithm>
00014 #include <memory>
00015 #include <cassert>
00016 #include <string> 
00017 
00018 namespace ROOT {
00019 
00020    namespace Minuit2 {
00021 
00022 //____________________________________________________________________________
00023 /** 
00024     class for the individual Minuit Parameter with Name and number; 
00025     contains the input numbers for the minimization or the output result
00026     from minimization;
00027     possible interactions: Fix/release, set/remove limits, set Value/error; 
00028 
00029     From version 5.20: use string to store the name to avoid limitation of 
00030     name length of 20 characters 
00031  */
00032 
00033 class MinuitParameter {
00034 
00035 public:
00036   
00037    //constructor for constant Parameter
00038    MinuitParameter(unsigned int num, const std::string & name, double val) : 
00039       fNum(num), fValue(val), fError(0.), fConst(true), fFix(false), 
00040       fLoLimit(0.), fUpLimit(0.), fLoLimValid(false), fUpLimValid(false),
00041       fName(name)
00042    {}
00043   
00044    //constructor for standard Parameter
00045    MinuitParameter(unsigned int num, const std::string & name, double val, double err) :
00046       fNum(num), fValue(val), fError(err), fConst(false), fFix(false), 
00047       fLoLimit(0.), fUpLimit(0.), fLoLimValid(false), fUpLimValid(false),
00048       fName(name)
00049    {}
00050   
00051    //constructor for limited Parameter
00052    MinuitParameter(unsigned int num, const std::string & name, double val, double err, 
00053                    double min, double max) : 
00054       fNum(num),fValue(val), fError(err), fConst(false), fFix(false), 
00055       fLoLimit(min), fUpLimit(max), fLoLimValid(true), fUpLimValid(true), 
00056       fName(name)    
00057    {
00058       assert(min != max);
00059       if(min > max) {
00060          fLoLimit = max;
00061          fUpLimit = min;
00062       }
00063    }
00064 
00065    ~MinuitParameter() {}
00066 
00067    MinuitParameter(const MinuitParameter& par) : 
00068       fNum(par.fNum), fValue(par.fValue), fError(par.fError),
00069       fConst(par.fConst), fFix(par.fFix), fLoLimit(par.fLoLimit), 
00070       fUpLimit(par.fUpLimit), fLoLimValid(par.fLoLimValid), 
00071       fUpLimValid(par.fUpLimValid), 
00072       fName(par.fName ) 
00073    {}
00074   
00075    MinuitParameter& operator=(const MinuitParameter& par) {
00076       fNum = par.fNum;
00077       fName = par.fName;
00078       fValue = par.fValue;
00079       fError = par.fError;
00080       fConst = par.fConst;
00081       fFix = par.fFix;
00082       fLoLimit = par.fLoLimit; 
00083       fUpLimit = par.fUpLimit;
00084       fLoLimValid = par.fLoLimValid; 
00085       fUpLimValid = par.fUpLimValid;
00086       return *this;
00087    }
00088 
00089    //access methods
00090    unsigned int Number() const {return fNum;}
00091    // new API returning a string 
00092    const std::string & GetName() const { return fName; }
00093    // return const char * for mantaining backward compatibility
00094    const char * Name() const {return fName.c_str();}
00095  
00096    double Value() const {return fValue;}
00097    double Error() const {return fError;}
00098 
00099    //interaction
00100    void SetValue(double val) {fValue = val;}
00101    void SetError(double err) {fError = err;}
00102    void SetLimits(double low, double up) {
00103       assert(low != up);
00104       fLoLimit = low; 
00105       fUpLimit = up;
00106       fLoLimValid = true; 
00107       fUpLimValid = true;
00108       if(low > up) {
00109          fLoLimit = up; 
00110          fUpLimit = low;
00111       }
00112    }
00113 
00114    void SetUpperLimit(double up) {
00115       fLoLimit = 0.; 
00116       fUpLimit = up;
00117       fLoLimValid = false; 
00118       fUpLimValid = true;
00119    }
00120 
00121    void SetLowerLimit(double low) {
00122       fLoLimit = low; 
00123       fUpLimit = 0.;
00124       fLoLimValid = true; 
00125       fUpLimValid = false;
00126    }
00127 
00128    void RemoveLimits() {
00129       fLoLimit = 0.; 
00130       fUpLimit = 0.;
00131       fLoLimValid = false; 
00132       fUpLimValid = false;
00133    }
00134 
00135    void Fix() {fFix = true;}
00136    void Release() {fFix = false;}
00137   
00138    //state of Parameter (fixed/const/limited)
00139    bool IsConst() const {return fConst;}
00140    bool IsFixed() const {return fFix;}
00141 
00142    bool HasLimits() const {return fLoLimValid || fUpLimValid; }
00143    bool HasLowerLimit() const {return fLoLimValid; }
00144    bool HasUpperLimit() const {return fUpLimValid; }
00145    double LowerLimit() const {return fLoLimit;}
00146    double UpperLimit() const {return fUpLimit;}
00147 
00148 private:
00149 
00150    unsigned int fNum;
00151    double fValue;
00152    double fError;
00153    bool fConst;
00154    bool fFix;
00155    double fLoLimit; 
00156    double fUpLimit;
00157    bool fLoLimValid; 
00158    bool fUpLimValid;
00159    std::string fName;
00160 
00161 private:
00162 
00163 //    void SetName(const std::string & name) {
00164 //       int l = std::min(int(strlen(name)), 11);
00165 //       memset(fName, 0, 11*sizeof(char));
00166 //       memcpy(fName, name, l*sizeof(char));
00167 //       fName[10] = '\0';
00168 //    }
00169 
00170 };
00171 
00172   }  // namespace Minuit2
00173 
00174 }  // namespace ROOT
00175 
00176 #endif  // ROOT_Minuit2_MinuitParameter

Generated on Tue Jul 5 14:25:43 2011 for ROOT_528-00b_version by  doxygen 1.5.1