Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TMultiDimFit.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/hist:$Id$
0002 // Author: Christian Holm Christensen 07/11/2000
0003 
0004 #ifndef ROOT_TMultiDimFit
0005 #define ROOT_TMultiDimFit
0006 
0007 #include "TNamed.h"
0008 #include "TVectorD.h"
0009 #include "TMatrixD.h"
0010 #include "TVirtualFitter.h"
0011 
0012 class TBrowser;
0013 class TList;
0014 
0015 class TMultiDimFit : public TNamed {
0016 
0017 public:
0018    enum EMDFPolyType {
0019       kMonomials,
0020       kChebyshev,
0021       kLegendre
0022    };
0023 
0024 private:
0025    static TMultiDimFit* fgInstance; // Static instance
0026 protected:
0027 
0028    TVectorD     fQuantity;             ///< Training sample, dependent quantity
0029    TVectorD     fSqError;              ///< Training sample, error in quantity
0030    Double_t     fMeanQuantity;         ///< Mean of dependent quantity
0031    Double_t     fMaxQuantity;          ///< Max value of dependent quantity
0032    Double_t     fMinQuantity;          ///< Min value of dependent quantity
0033    Double_t     fSumSqQuantity;        ///< SumSquare of dependent quantity
0034    Double_t     fSumSqAvgQuantity;     ///< Sum of squares away from mean
0035 
0036    TVectorD     fVariables;            ///< Training sample, independent variables
0037    Int_t        fNVariables;           ///< Number of independent variables
0038    TVectorD     fMeanVariables;        ///< mean value of independent variables
0039    TVectorD     fMaxVariables;         ///< max value of independent variables
0040    TVectorD     fMinVariables;         ///< min value of independent variables
0041 
0042    Int_t        fSampleSize;           ///< Size of training sample
0043 
0044    TVectorD     fTestQuantity;         ///< Test sample, dependent quantity
0045    TVectorD     fTestSqError;          ///< Test sample, Error in quantity
0046    TVectorD     fTestVariables;        ///< Test sample, independent variables
0047 
0048    Int_t        fTestSampleSize;       ///< Size of test sample
0049 
0050    Double_t     fMinAngle;             ///< Min angle for accepting new function
0051    Double_t     fMaxAngle;             ///< Max angle for accepting new function
0052    Int_t        fMaxTerms;             ///< Max terms expected in final expr.
0053    Double_t     fMinRelativeError;     ///< Min relative error accepted
0054    Int_t       *fMaxPowers;            ///<[fNVariables] maximum powers
0055    Double_t     fPowerLimit;           ///< Control parameter
0056 
0057 
0058    TMatrixD     fFunctions;            ///< Functions evaluated over sample
0059    Int_t        fMaxFunctions;         ///< max number of functions
0060    Int_t       *fFunctionCodes;        ///<[fMaxFunctions] acceptance code
0061    Int_t        fMaxStudy;             ///< max functions to study
0062    Int_t        fMaxFuncNV;            ///< fMaxFunctions*fNVariables
0063 
0064    TMatrixD     fOrthFunctions;        ///< As above, but orthogonalised
0065    TVectorD     fOrthFunctionNorms;    ///< Norm of the evaluated functions
0066 
0067 
0068    Int_t       *fMaxPowersFinal;       ///<[fNVariables] maximum powers from fit;
0069    Int_t       *fPowers;               ///<[fMaxFuncNV] where fMaxFuncNV = fMaxFunctions*fNVariables
0070    Int_t       *fPowerIndex;           ///<[fMaxTerms] Index of accepted powers
0071 
0072    TVectorD     fResiduals;            ///< Vector of the final residuals
0073    Double_t     fMaxResidual;          ///< Max residual value
0074    Double_t     fMinResidual;          ///< Min residual value
0075    Int_t        fMaxResidualRow;       ///< Row giving max residual
0076    Int_t        fMinResidualRow;       ///< Row giving min residual
0077    Double_t     fSumSqResidual;        ///< Sum of Square residuals
0078 
0079    Int_t        fNCoefficients;        ///< Dimension of model coefficients
0080    TVectorD     fOrthCoefficients;     ///< The model coefficients
0081    TMatrixD     fOrthCurvatureMatrix;  ///< Model matrix
0082    TVectorD     fCoefficients;         ///< Vector of the final coefficients
0083    TVectorD     fCoefficientsRMS;      ///< Vector of RMS of coefficients
0084    Double_t     fRMS;                  ///< Root mean square of fit
0085    Double_t     fChi2;                 ///< Chi square of fit
0086    Int_t        fParameterisationCode; ///< Exit code of parameterisation
0087 
0088    Double_t     fError;                ///< Error from parametrization
0089    Double_t     fTestError;            ///< Error from test
0090    Double_t     fPrecision;            ///< Relative precision of param
0091    Double_t     fTestPrecision;        ///< Relative precision of test
0092    Double_t     fCorrelationCoeff;     ///< Multi Correlation coefficient
0093    TMatrixD     fCorrelationMatrix;    ///< Correlation matrix
0094    Double_t     fTestCorrelationCoeff; ///< Multi Correlation coefficient
0095 
0096    TList*       fHistograms;           ///< List of histograms
0097    Byte_t       fHistogramMask;        ///< Bit pattern of histograms used
0098    Int_t        fBinVarX;              ///< Number of bin in independent variables
0099    Int_t        fBinVarY;              ///< Number of bin in dependent variables
0100 
0101    TVirtualFitter* fFitter;            //! Fit object (MINUIT)
0102 
0103    EMDFPolyType fPolyType;             ///< Type of polynomials to use
0104    Bool_t       fShowCorrelation;      ///< print correlation matrix
0105    Bool_t       fIsUserFunction;       ///< Flag for user defined function
0106    Bool_t       fIsVerbose;            ///
0107 
0108    virtual Double_t EvalFactor(Int_t p, Double_t x) const;
0109    virtual Double_t EvalControl(const Int_t *powers) const;
0110    virtual void     MakeCoefficientErrors();
0111    virtual void     MakeCorrelation();
0112    virtual Double_t MakeGramSchmidt(Int_t function);
0113    virtual void     MakeCoefficients();
0114    virtual void     MakeCandidates();
0115    virtual void     MakeNormalized();
0116    virtual void     MakeParameterization();
0117    virtual void     MakeRealCode(const char *filename,
0118                                  const char *classname,
0119                                  Option_t   *option="");
0120    virtual Bool_t   Select(const Int_t *iv);
0121    virtual Bool_t   TestFunction(Double_t squareResidual,
0122                                  Double_t dResidur);
0123 public:
0124    TMultiDimFit();
0125    TMultiDimFit(Int_t dimension,
0126                 EMDFPolyType type=kMonomials,
0127                 Option_t *option="");
0128    ~TMultiDimFit() override;
0129 
0130    virtual void     AddRow(const Double_t *x, Double_t D, Double_t E=0);
0131    virtual void     AddTestRow(const Double_t *x, Double_t D, Double_t E=0);
0132    void     Browse(TBrowser* b) override;
0133    void     Clear(Option_t *option="") override; // *MENU*
0134    void     Draw(Option_t * ="d") override { }
0135    virtual Double_t Eval(const Double_t *x, const Double_t *coeff = nullptr) const;
0136    virtual Double_t EvalError(const Double_t *x, const Double_t *coeff = nullptr) const;
0137    virtual void     FindParameterization(Option_t* option=""); // *MENU*
0138    virtual void     Fit(Option_t *option=""); // *MENU*
0139 
0140    Double_t         GetChi2()              const { return fChi2; }
0141    const TMatrixD*  GetCorrelationMatrix() const { return &fCorrelationMatrix; }
0142    const TVectorD*  GetCoefficients()      const { return &fCoefficients; }
0143    const TVectorD*  GetCoefficientsRMS()   const { return &fCoefficientsRMS; }
0144    Double_t         GetError()             const { return fError; }
0145    Int_t*           GetFunctionCodes()     const { return fFunctionCodes; }
0146    const TMatrixD*  GetFunctions()         const { return &fFunctions; }
0147    virtual TList*   GetHistograms()        const { return fHistograms; }
0148    Double_t         GetMaxAngle()          const { return fMaxAngle; }
0149    Int_t            GetMaxFunctions()      const { return fMaxFunctions; }
0150    Int_t*           GetMaxPowers()         const { return fMaxPowers; }
0151    Double_t         GetMaxQuantity()       const { return fMaxQuantity; }
0152    Int_t            GetMaxStudy()          const { return fMaxStudy; }
0153    Int_t            GetMaxTerms()          const { return fMaxTerms; }
0154    const TVectorD*  GetMaxVariables()      const { return &fMaxVariables; }
0155    Double_t         GetMeanQuantity()      const { return fMeanQuantity; }
0156    const TVectorD*  GetMeanVariables()     const { return &fMeanVariables; }
0157    Double_t         GetMinAngle()          const { return fMinAngle; }
0158    Double_t         GetMinQuantity()       const { return fMinQuantity; }
0159    Double_t         GetMinRelativeError()  const { return fMinRelativeError; }
0160    const TVectorD*  GetMinVariables()      const { return &fMinVariables; }
0161    Int_t            GetNVariables()        const { return fNVariables; }
0162    Int_t            GetNCoefficients()     const { return fNCoefficients; }
0163    Int_t            GetPolyType()          const { return fPolyType; }
0164    Int_t*           GetPowerIndex()        const { return fPowerIndex; }
0165    Double_t         GetPowerLimit()        const { return fPowerLimit; }
0166    const Int_t*     GetPowers()            const { return fPowers; }
0167    Double_t         GetPrecision()         const { return fPrecision; }
0168    const TVectorD*  GetQuantity()          const { return &fQuantity; }
0169    Double_t         GetResidualMax()       const { return fMaxResidual; }
0170    Double_t         GetResidualMin()       const { return fMinResidual; }
0171    Int_t            GetResidualMaxRow()    const { return fMaxResidualRow; }
0172    Int_t            GetResidualMinRow()    const { return fMinResidualRow; }
0173    Double_t         GetResidualSumSq()     const { return fSumSqResidual; }
0174    Double_t         GetRMS()               const { return fRMS; }
0175    Int_t            GetSampleSize()        const { return fSampleSize; }
0176    const TVectorD*  GetSqError()           const { return &fSqError; }
0177    Double_t         GetSumSqAvgQuantity()  const { return fSumSqAvgQuantity; }
0178    Double_t         GetSumSqQuantity()     const { return fSumSqQuantity; }
0179    Double_t         GetTestError()         const { return fTestError; }
0180    Double_t         GetTestPrecision()     const { return fTestPrecision; }
0181    const TVectorD*  GetTestQuantity()      const { return &fTestQuantity; }
0182    Int_t            GetTestSampleSize()    const { return fTestSampleSize; }
0183    const TVectorD*  GetTestSqError()       const { return &fTestSqError; }
0184    const TVectorD*  GetTestVariables()     const { return &fTestVariables; }
0185    const TVectorD*  GetVariables()         const { return &fVariables; }
0186 
0187    static TMultiDimFit* Instance();
0188    Bool_t   IsFolder()             const override { return kTRUE; }
0189    virtual Double_t MakeChi2(const Double_t* coeff = nullptr);
0190    virtual void     MakeCode(const char *functionName="MDF", Option_t *option=""); // *MENU*
0191    virtual void     MakeHistograms(Option_t* option="A"); // *MENU*
0192    virtual void     MakeMethod(const Char_t* className="MDF", Option_t* option=""); // *MENU*
0193    void     Print(Option_t *option="ps") const override; // *MENU*
0194 
0195    void             SetBinVarX(Int_t nbbinvarx) {fBinVarX = nbbinvarx;}
0196    void             SetBinVarY(Int_t nbbinvary) {fBinVarY = nbbinvary;}
0197    void             SetMaxAngle(Double_t angle=0);
0198    void             SetMaxFunctions(Int_t n) { fMaxFunctions = n; }
0199    void             SetMaxPowers(const Int_t *powers);
0200    void             SetMaxStudy(Int_t n) { fMaxStudy  = n; }
0201    void             SetMaxTerms(Int_t terms) { fMaxTerms = terms; }
0202    void             SetMinRelativeError(Double_t error);
0203    void             SetMinAngle(Double_t angle=1);
0204    void             SetPowerLimit(Double_t limit=1e-3);
0205    virtual void     SetPowers(const Int_t *powers, Int_t terms);
0206 
0207    ClassDefOverride(TMultiDimFit,2) // Multi dimensional fit class
0208 }
0209 ;
0210 #endif