Back to home page

EIC code displayed by LXR

 
 

    


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

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() {}
0070 
0071    MinuitParameter(const MinuitParameter &par)
0072       : fNum(par.fNum), fValue(par.fValue), fError(par.fError), fConst(par.fConst), fFix(par.fFix),
0073         fLoLimit(par.fLoLimit), fUpLimit(par.fUpLimit), fLoLimValid(par.fLoLimValid), fUpLimValid(par.fUpLimValid),
0074         fName(par.fName)
0075    {
0076    }
0077 
0078    MinuitParameter &operator=(const MinuitParameter &par)
0079    {
0080       if (this != &par) {
0081          fNum = par.fNum;
0082          fName = par.fName;
0083          fValue = par.fValue;
0084          fError = par.fError;
0085          fConst = par.fConst;
0086          fFix = par.fFix;
0087          fLoLimit = par.fLoLimit;
0088          fUpLimit = par.fUpLimit;
0089          fLoLimValid = par.fLoLimValid;
0090          fUpLimValid = par.fUpLimValid;
0091       }
0092       return *this;
0093    }
0094 
0095    // access methods
0096    unsigned int Number() const { return fNum; }
0097    // new API returning a string
0098    const std::string &GetName() const { return fName; }
0099    // return const char * for maintaining backward compatibility
0100    const char *Name() const { return fName.c_str(); }
0101 
0102    double Value() const { return fValue; }
0103    double Error() const { return fError; }
0104 
0105    // interaction
0106    void SetName(const std::string &name) { fName = name; }
0107 
0108    void SetValue(double val) { fValue = val; }
0109    void SetError(double err) { fError = err; }
0110    void SetLimits(double low, double up)
0111    {
0112       assert(low != up);
0113       fLoLimit = low;
0114       fUpLimit = up;
0115       fLoLimValid = true;
0116       fUpLimValid = true;
0117       if (low > up) {
0118          fLoLimit = up;
0119          fUpLimit = low;
0120       }
0121    }
0122 
0123    void SetUpperLimit(double up)
0124    {
0125       fLoLimit = 0.;
0126       fUpLimit = up;
0127       fLoLimValid = false;
0128       fUpLimValid = true;
0129    }
0130 
0131    void SetLowerLimit(double low)
0132    {
0133       fLoLimit = low;
0134       fUpLimit = 0.;
0135       fLoLimValid = true;
0136       fUpLimValid = false;
0137    }
0138 
0139    void RemoveLimits()
0140    {
0141       fLoLimit = 0.;
0142       fUpLimit = 0.;
0143       fLoLimValid = false;
0144       fUpLimValid = false;
0145    }
0146 
0147    void Fix() { fFix = true; }
0148    void Release() { fFix = false; }
0149 
0150    // state of Parameter (fixed/const/limited)
0151    bool IsConst() const { return fConst; }
0152    bool IsFixed() const { return fFix; }
0153 
0154    bool HasLimits() const { return fLoLimValid || fUpLimValid; }
0155    bool HasLowerLimit() const { return fLoLimValid; }
0156    bool HasUpperLimit() const { return fUpLimValid; }
0157    double LowerLimit() const { return fLoLimit; }
0158    double UpperLimit() const { return fUpLimit; }
0159 
0160 private:
0161    unsigned int fNum;
0162    double fValue;
0163    double fError;
0164    bool fConst;
0165    bool fFix;
0166    double fLoLimit;
0167    double fUpLimit;
0168    bool fLoLimValid;
0169    bool fUpLimValid;
0170    std::string fName;
0171 
0172 private:
0173    //    void SetName(const std::string & name) {
0174    //       int l = std::min(int(strlen(name)), 11);
0175    //       memset(fName, 0, 11*sizeof(char));
0176    //       memcpy(fName, name, l*sizeof(char));
0177    //       fName[10] = '\0';
0178    //    }
0179 };
0180 
0181 } // namespace Minuit2
0182 
0183 } // namespace ROOT
0184 
0185 #endif // ROOT_Minuit2_MinuitParameter