Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:31

0001 // @(#)root/hist:$Id$
0002 // Author: L. Moneta    08/2008
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2008 ROOT Foundation,  CERN/PH-SFT                   *
0007  *                                                                    *
0008  **********************************************************************/
0009 
0010 #ifndef ROOT_TBackCompFitter_H_
0011 #define ROOT_TBackCompFitter_H_
0012 
0013 #include "TVirtualFitter.h"
0014 #include "Fit/BasicFCN.h"
0015 #include "Fit/FitResult.h"
0016 #include "Fit/Fitter.h"
0017 #include "Math/IFunctionfwd.h"
0018 #include <vector>
0019 
0020 /*
0021     TVirtualFitter backward compatibility implementation using new ROOT::Fit::Fitter
0022 */
0023 
0024 class TGraph;
0025 class TFitResult;
0026 
0027 namespace ROOT {
0028    namespace Fit {
0029       class FitData;
0030    }
0031    namespace Math {
0032       class Minimizer;
0033    }
0034 }
0035 
0036 
0037 class TBackCompFitter : public TVirtualFitter {
0038 
0039 public:
0040 
0041 
0042 
0043    TBackCompFitter();
0044 
0045    //TBackCompFitter(ROOT::Fit::Fitter & fitter, ROOT::Fit::FitData * );
0046    TBackCompFitter( const std::shared_ptr<ROOT::Fit::Fitter> & fitter, const std::shared_ptr<ROOT::Fit::FitData> & data  );
0047 
0048    ~TBackCompFitter() override;
0049 
0050 public:
0051 
0052    enum EStatusBits {
0053       kCanDeleteLast = BIT(9)  // object can be deleted before creating a new one
0054    };
0055 
0056    // inherited interface
0057    Double_t  Chisquare(Int_t npar, Double_t *params) const override;
0058    void      Clear(Option_t *option="") override;
0059    Int_t     ExecuteCommand(const char *command, Double_t *args, Int_t nargs) override;
0060    void      FixParameter(Int_t ipar) override;
0061 
0062    void      GetConfidenceIntervals(Int_t n, Int_t ndim, const Double_t *x, Double_t *ci, Double_t cl=0.95) override;
0063    void      GetConfidenceIntervals(TObject *obj, Double_t cl=0.95) override;
0064 
0065    Double_t *GetCovarianceMatrix() const override;
0066    Double_t  GetCovarianceMatrixElement(Int_t i, Int_t j) const override;
0067    Int_t     GetErrors(Int_t ipar,Double_t &eplus, Double_t &eminus, Double_t &eparab, Double_t &globcc) const override;
0068    Int_t     GetNumberTotalParameters() const override;
0069    Int_t     GetNumberFreeParameters() const override;
0070 
0071    Double_t  GetParError(Int_t ipar) const override;
0072    Double_t  GetParameter(Int_t ipar) const override;
0073    Int_t     GetParameter(Int_t ipar,char *name,Double_t &value,Double_t &verr,Double_t &vlow, Double_t &vhigh) const override;
0074    const char *GetParName(Int_t ipar) const override;
0075    Int_t     GetStats(Double_t &amin, Double_t &edm, Double_t &errdef, Int_t &nvpar, Int_t &nparx) const override;
0076    Double_t  GetSumLog(Int_t i) override;
0077 
0078    Bool_t    IsFixed(Int_t ipar) const override ;
0079 
0080    void      PrintResults(Int_t level, Double_t amin) const override;
0081    void      ReleaseParameter(Int_t ipar) override;
0082    void      SetFitMethod(const char *name) override;
0083    Int_t     SetParameter(Int_t ipar,const char *parname,Double_t value,Double_t verr,Double_t vlow, Double_t vhigh) override;
0084 
0085    void      SetFCN(void (*fcn)(Int_t &, Double_t *, Double_t &f, Double_t *, Int_t) ) override;
0086 
0087    /// For using interpreted function passed by the user
0088    virtual void SetMethodCall(TMethodCall * m) { fMethodCall = m; }
0089 
0090    /// Get reference to Fit configuration (NOTE: it will be invalid when class is deleted)
0091    ROOT::Fit::FitConfig & GetFitConfig()  { return fFitter->Config(); }
0092 
0093    /// Get reference to Fit Result object (NOTE: it will be invalid when class is deleted)
0094    const ROOT::Fit::FitResult & GetFitResult() const { return fFitter->Result(); }
0095 
0096    /// Get a copy of the Fit result returning directly a new  TFitResult
0097    TFitResult * GetTFitResult() const;
0098 
0099    /// Get reference to Fit Data object (NOTE: it will be invalid when class is deleted)
0100    const ROOT::Fit::FitData & GetFitData() const { return *fFitData; }
0101 
0102    // Return pointer to last used minimizer
0103    ROOT::Math::Minimizer * GetMinimizer() const;
0104 
0105    // Return pointer to last used objective function
0106    ROOT::Math::IMultiGenFunction * GetObjFunction() const;
0107 
0108    // Scan likelihood value of  parameter and fill the given graph.
0109    bool  Scan(unsigned int ipar, TGraph * gr, double xmin = 0, double xmax = 0);
0110 
0111    //    scan likelihood value for two  parameters and fill the given graph.
0112    //    bool  Scan2D(unsigned int ipar, unsigned int jpar, TGraph2D * gr,
0113    //                         double xmin = 0, double xmax = 0, double ymin = 0, double ymax = 0);
0114 
0115    // Create contour of two parameters around the minimum
0116    // pass as option confidence level:  default is a value of 0.683
0117    bool  Contour(unsigned int ipar, unsigned int jpar, TGraph * gr , double confLevel = 0.683);
0118 
0119    // Set FCN using new interface
0120    virtual void SetObjFunction(  ROOT::Math::IMultiGenFunction * f);
0121 
0122    // Recreate minimizer and FCN for TMinuit fits and standard printout
0123    void ReCreateMinimizer();
0124 
0125 
0126 protected:
0127 
0128    bool ValidParameterIndex(int ipar) const;
0129    void DoSetDimension();
0130 
0131 private:
0132 
0133    //ROOT::Fit::FitData * fFitData;
0134    std::shared_ptr<ROOT::Fit::FitData>  fFitData;  ///<! Data of the fit
0135    std::shared_ptr<ROOT::Fit::Fitter>   fFitter;   ///<! Pointer to fitter object
0136    ROOT::Math::Minimizer * fMinimizer;
0137    ROOT::Math::IMultiGenFunction * fObjFunc;
0138    ROOT::Math::IParamMultiFunction * fModelFunc;
0139    mutable std::vector<double> fCovar;             ///< Cached covariance matrix (NxN)
0140 
0141 
0142 
0143    ClassDefOverride(TBackCompFitter,1)  // Class providing backward compatibility for fitting by implementing the TVirtualFitter interface
0144 
0145 };
0146 
0147 
0148 
0149 #endif //ROOT_TBackCompFitter_H_