Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-24 09:18:44

0001 // @(#)root/minuit2:$Id$
0002 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei   2003-2005
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2005 LCG ROOT Math team,  CERN/PH-SFT                *
0007  *                                                                    *
0008  **********************************************************************/
0009 
0010 #ifndef ROOT_Minuit2_MinuitParameter
0011 #define ROOT_Minuit2_MinuitParameter
0012 
0013 #include <algorithm>
0014 #include <memory>
0015 #include <cassert>
0016 #include <string>
0017 
0018 namespace ROOT {
0019 
0020 namespace Minuit2 {
0021 
0022 //____________________________________________________________________________
0023 /**
0024     class for the individual Minuit Parameter with Name and number;
0025     contains the input numbers for the minimization or the output result
0026     from minimization;
0027     possible interactions: Fix/release, set/remove limits, set Value/error;
0028 
0029     From version 5.20: use string to store the name to avoid limitation of
0030     name length of 20 characters
0031  */
0032 
0033 class MinuitParameter {
0034 
0035 public:
0036    // default constructor standard with value/error = 0
0037    MinuitParameter()
0038       : fNum(0), fValue(0), fError(0.), fConst(false), fFix(false), fLoLimit(0.), fUpLimit(0.), fLoLimValid(false),
0039         fUpLimValid(false), fName("")
0040    {
0041    }
0042 
0043    // constructor for constant Parameter
0044    MinuitParameter(unsigned int num, const std::string &name, double val)
0045       : fNum(num), fValue(val), fError(0.), fConst(true), fFix(false), fLoLimit(0.), fUpLimit(0.), fLoLimValid(false),
0046         fUpLimValid(false), fName(name)
0047    {
0048    }
0049 
0050    // constructor for standard Parameter
0051    MinuitParameter(unsigned int num, const std::string &name, double val, double err)
0052       : fNum(num), fValue(val), fError(err), fConst(false), fFix(false), fLoLimit(0.), fUpLimit(0.), fLoLimValid(false),
0053         fUpLimValid(false), fName(name)
0054    {
0055    }
0056 
0057    // constructor for limited Parameter
0058    MinuitParameter(unsigned int num, const std::string &name, double val, double err, double min, double max)
0059       : fNum(num), fValue(val), fError(err), fConst(false), fFix(false), fLoLimit(min), fUpLimit(max),
0060         fLoLimValid(true), fUpLimValid(true), fName(name)
0061    {
0062       assert(min != max);
0063       if (min > max) {
0064          fLoLimit = max;
0065          fUpLimit = min;
0066       }
0067    }
0068 
0069    MinuitParameter(const MinuitParameter &par)
0070       : fNum(par.fNum), fValue(par.fValue), fError(par.fError), fConst(par.fConst), fFix(par.fFix),
0071         fLoLimit(par.fLoLimit), fUpLimit(par.fUpLimit), fLoLimValid(par.fLoLimValid), fUpLimValid(par.fUpLimValid),
0072         fName(par.fName)
0073    {
0074    }
0075 
0076    MinuitParameter &operator=(const MinuitParameter &par)
0077    {
0078       if (this != &par) {
0079          fNum = par.fNum;
0080          fName = par.fName;
0081          fValue = par.fValue;
0082          fError = par.fError;
0083          fConst = par.fConst;
0084          fFix = par.fFix;
0085          fLoLimit = par.fLoLimit;
0086          fUpLimit = par.fUpLimit;
0087          fLoLimValid = par.fLoLimValid;
0088          fUpLimValid = par.fUpLimValid;
0089       }
0090       return *this;
0091    }
0092 
0093    // access methods
0094    unsigned int Number() const { return fNum; }
0095    // new API returning a string
0096    const std::string &GetName() const { return fName; }
0097    // return const char * for maintaining backward compatibility
0098    const char *Name() const { return fName.c_str(); }
0099 
0100    double Value() const { return fValue; }
0101    double Error() const { return fError; }
0102 
0103    // interaction
0104    void SetName(const std::string &name) { fName = name; }
0105 
0106    void SetValue(double val) {
0107       fValue = val;
0108       if (fLoLimValid && val < fLoLimit)
0109          fValue = fLoLimit;
0110       else if (fUpLimValid && val > fUpLimit)
0111          fValue = fUpLimit;
0112    }
0113    void SetError(double err) { fError = err; }
0114    void SetLimits(double low, double up)
0115    {
0116       assert(low != up);
0117       fLoLimit = low;
0118       fUpLimit = up;
0119       fLoLimValid = true;
0120       fUpLimValid = true;
0121       if (low > up) {
0122          fLoLimit = up;
0123          fUpLimit = low;
0124       }
0125    }
0126 
0127    void SetUpperLimit(double up)
0128    {
0129       fLoLimit = 0.;
0130       fUpLimit = up;
0131       fLoLimValid = false;
0132       fUpLimValid = true;
0133    }
0134 
0135    void SetLowerLimit(double low)
0136    {
0137       fLoLimit = low;
0138       fUpLimit = 0.;
0139       fLoLimValid = true;
0140       fUpLimValid = false;
0141    }
0142 
0143    void RemoveLimits()
0144    {
0145       fLoLimit = 0.;
0146       fUpLimit = 0.;
0147       fLoLimValid = false;
0148       fUpLimValid = false;
0149    }
0150 
0151    void Fix() { fFix = true; }
0152    void Release() { fFix = false; }
0153 
0154    // state of Parameter (fixed/const/limited)
0155    bool IsConst() const { return fConst; }
0156    bool IsFixed() const { return fFix; }
0157 
0158    bool HasLimits() const { return fLoLimValid || fUpLimValid; }
0159    bool HasLowerLimit() const { return fLoLimValid; }
0160    bool HasUpperLimit() const { return fUpLimValid; }
0161    double LowerLimit() const { return fLoLimit; }
0162    double UpperLimit() const { return fUpLimit; }
0163 
0164 private:
0165    unsigned int fNum;
0166    double fValue;
0167    double fError;
0168    bool fConst;
0169    bool fFix;
0170    double fLoLimit;
0171    double fUpLimit;
0172    bool fLoLimValid;
0173    bool fUpLimValid;
0174    std::string fName;
0175 
0176 private:
0177    //    void SetName(const std::string & name) {
0178    //       int l = std::min(int(strlen(name)), 11);
0179    //       memset(fName, 0, 11*sizeof(char));
0180    //       memcpy(fName, name, l*sizeof(char));
0181    //       fName[10] = '\0';
0182    //    }
0183 };
0184 
0185 } // namespace Minuit2
0186 
0187 } // namespace ROOT
0188 
0189 #endif // ROOT_Minuit2_MinuitParameter