Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:09

0001 // @(#)root/mathcore:$Id$
0002 // Author: L. Moneta Thu Sep 21 16:21:48 2006
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
0007  *                                                                    *
0008  *                                                                    *
0009  **********************************************************************/
0010 
0011 // Header file for class ParameterSettings
0012 
0013 #ifndef ROOT_Fit_ParameterSettings
0014 #define ROOT_Fit_ParameterSettings
0015 
0016 #include <string>
0017 
0018 namespace ROOT {
0019 
0020    namespace Fit {
0021 
0022 
0023 //___________________________________________________________________________________
0024 /**
0025    Class, describing value, limits and step size of the parameters
0026    Provides functionality also to set/retrieve values, step sizes, limits and fix the
0027    parameters.
0028 
0029    To be done: add constraints (equality and inequality) as functions of the parameters
0030 
0031    @ingroup FitMain
0032 */
0033 class ParameterSettings {
0034 
0035 public:
0036 
0037    /**
0038       Default constructor
0039    */
0040    ParameterSettings () :
0041     fValue(0.), fStepSize(0.1), fFix(false),
0042     fLowerLimit(0.), fUpperLimit(0.), fHasLowerLimit(false), fHasUpperLimit(false),
0043     fName("")
0044    {}
0045 
0046 
0047   ///constructor for unlimited named Parameter
0048    ParameterSettings(const std::string & name, double val, double err) :
0049     fValue(val), fStepSize(err), fFix(false),
0050     fLowerLimit(0.), fUpperLimit(0.), fHasLowerLimit(false), fHasUpperLimit(false),
0051     fName(name)
0052    {}
0053 
0054    ///constructor for double limited Parameter. The given value should be within the given limits [min,max]
0055    ParameterSettings(const std::string &  name, double val, double err,
0056                      double min, double max) :
0057       fValue(val), fStepSize(err), fFix(false),
0058       fLowerLimit(0.), fUpperLimit(0.), fHasLowerLimit(false), fHasUpperLimit(false),
0059       fName(name)
0060    {
0061       SetLimits(min,max);
0062    }
0063 
0064    ///constructor for fixed Parameter
0065    ParameterSettings(const std::string &  name, double val) :
0066     fValue(val), fStepSize(0), fFix(true),
0067     fLowerLimit(0.), fUpperLimit(0.), fHasLowerLimit(false), fHasUpperLimit(false),
0068     fName(name)
0069    {}
0070 
0071 
0072 
0073 
0074    /// set value and name (unlimited parameter)
0075    void Set(const std::string & name, double value, double step) {
0076       SetName(name);
0077       SetValue(value);
0078       SetStepSize(step);
0079    }
0080 
0081    /// set a limited parameter. The given value should be within the given limits [min,max]
0082    void Set(const std::string & name, double value, double step, double lower, double upper ) {
0083       SetName(name);
0084       SetValue(value);
0085       SetStepSize(step);
0086       SetLimits(lower,upper);
0087    }
0088 
0089    /// set a fixed parameter
0090    void Set(const std::string & name, double value) {
0091       SetName(name);
0092       SetValue(value);
0093       Fix();
0094    }
0095 
0096 
0097    /**
0098       Destructor (no operations)
0099    */
0100    ~ParameterSettings ()  {}
0101 
0102    /// copy constructor and assignment operators (leave them to the compiler)
0103 
0104 public:
0105 
0106    /// return parameter value
0107    double Value() const { return fValue; }
0108    /// return step size
0109    double StepSize() const { return fStepSize; }
0110    /// return lower limit value
0111    double LowerLimit() const {return fLowerLimit;}
0112    /// return upper limit value
0113    double UpperLimit() const {return fUpperLimit;}
0114    /// check if is fixed
0115    bool IsFixed() const { return fFix; }
0116    /// check if parameter has lower limit
0117    bool HasLowerLimit() const {return fHasLowerLimit; }
0118    /// check if parameter has upper limit
0119    bool HasUpperLimit() const {return fHasUpperLimit; }
0120    /// check if is bound
0121    bool IsBound() const {   return fHasLowerLimit || fHasUpperLimit;  }
0122    /// check if is double bound (upper AND lower limit)
0123    bool IsDoubleBound() const { return fHasLowerLimit && fHasUpperLimit;  }
0124    /// return name
0125    const std::string & Name() const { return fName; }
0126 
0127    /** interaction **/
0128 
0129    /// set name
0130    void SetName(const std::string & name ) { fName = name; }
0131 
0132    /// fix  the parameter
0133    void Fix() {fFix = true;}
0134    /// release the parameter
0135    void Release() {fFix = false;}
0136    /// set the value
0137    void SetValue(double val) {fValue = val;}
0138    /// set the step size
0139    void SetStepSize(double err) {fStepSize = err;}
0140    void SetLimits(double low, double up);
0141    /// set a single upper limit
0142    void SetUpperLimit(double up) {
0143     fLowerLimit = 0.;
0144     fUpperLimit = up;
0145     fHasLowerLimit = false;
0146     fHasUpperLimit = true;
0147    }
0148    /// set a single lower limit
0149    void SetLowerLimit(double low) {
0150       fLowerLimit = low;
0151       fUpperLimit = 0.;
0152       fHasLowerLimit = true;
0153       fHasUpperLimit = false;
0154    }
0155 
0156    /// remove all limit
0157    void RemoveLimits() {
0158       fLowerLimit = 0.;
0159       fUpperLimit = 0.;
0160       fHasLowerLimit = false;
0161       fHasUpperLimit = false;
0162    }
0163 
0164 
0165 
0166 protected:
0167 
0168 
0169 private:
0170 
0171    double fValue;        ///< parameter value
0172    double fStepSize;     ///< parameter step size (used by minimizer)
0173    bool fFix;            ///< flag to control if parameter is fixed
0174    double fLowerLimit;   ///< lower parameter limit
0175    double fUpperLimit;   ///< upper parameter limit
0176    bool fHasLowerLimit;  ///< flag to control lower parameter limit
0177    bool fHasUpperLimit;  ///< flag to control upper parameter limit
0178 
0179    std::string fName;    ///< parameter name
0180 
0181 };
0182 
0183    } // end namespace Fit
0184 
0185 } // end namespace ROOT
0186 
0187 
0188 #endif /* ROOT_Fit_ParameterSettings */