13 #ifndef ROOT_Fit_FitResult 
   14 #define ROOT_Fit_FitResult 
   52    typedef  ROOT::Math::IParamMultiFunction IModelFunction;
 
   63    FitResult (
const FitConfig & fconfig);
 
   69    FitResult(
const FitResult & rhs);
 
   74    FitResult & operator = (
const FitResult & rhs);
 
   79    virtual ~FitResult ();
 
   88    void FillResult(
const std::shared_ptr<ROOT::Math::Minimizer> & min, 
const FitConfig & fconfig,  
const std::shared_ptr<IModelFunction> & f,
 
   89               bool isValid, 
unsigned int sizeOfData = 0, 
bool binFit = 
true, 
const ROOT::Math::IMultiGenFunction * chi2func = 0, 
unsigned int ncalls = 0);
 
   98    bool Update(
const std::shared_ptr<ROOT::Math::Minimizer> & min, 
const ROOT::Fit::FitConfig & fconfig, 
bool isValid, 
unsigned int ncalls = 0);
 
  103    const std::string & MinimizerType()
 const { 
return fMinimType; }
 
  115    bool IsValid()
 const { 
return fValid; }
 
  118    bool IsEmpty()
 const { 
return (fParams.size() == 0);  }
 
  121    double MinFcnValue()
 const { 
return fVal; }
 
  124    unsigned int NCalls()
 const { 
return fNCalls; }
 
  127    double Edm()
 const { 
return fEdm; }
 
  130    unsigned int NTotalParameters()
 const { 
return fParams.size(); }
 
  132    unsigned int NPar()
 const { 
return NTotalParameters(); }
 
  135    unsigned int NFreeParameters()
 const { 
return fNFree; }
 
  138    int Status()
 const { 
return fStatus; }
 
  143    int CovMatrixStatus()
 const { 
return fCovStatus; }
 
  149    const IModelFunction * FittedFunction()
 const {
 
  150       return fFitFunc.get();
 
  156    const BinData * FittedBinData() 
const;
 
  161    double Chi2()
 const { 
return fChi2; }
 
  164    unsigned int Ndf()
 const { 
return fNdf; }
 
  170    const std::vector<double> & Errors()
 const { 
return fErrors; }
 
  172    const double * GetErrors()
 const { 
return (fErrors.empty()) ? 0 : &fErrors.front(); }
 
  175    const std::vector<double> & Parameters()
 const { 
return fParams; }
 
  177    const double * GetParams()
 const { 
return &fParams.front(); }
 
  180    double Value(
unsigned int i)
 const { 
return fParams[i]; }
 
  182    double Parameter(
unsigned int i)
 const { 
return fParams[i]; }
 
  187    double Error(
unsigned int i)
 const {
 
  188       return (i < fErrors.size() ) ? fErrors[i] : 0;
 
  191    double ParError(
unsigned int i)
 const {
 
  192       return (i < fErrors.size() ) ? fErrors[i] : 0;
 
  196    std::string ParName(
unsigned int i) 
const;
 
  199    void SetMinosError(
unsigned int i, 
double elow, 
double eup);
 
  202    bool HasMinosError(
unsigned int i) 
const;
 
  205    double LowerError(
unsigned int i) 
const;
 
  208    double UpperError(
unsigned int i) 
const;
 
  211    double GlobalCC(
unsigned int i)
 const {
 
  212       return (i < fGlobalCC.size() ) ? fGlobalCC[i] : -1;
 
  217    double CovMatrix (
unsigned int i, 
unsigned int j)
 const {
 
  218       if ( i >= fErrors.size() || j >= fErrors.size() ) 
return 0;
 
  219       if (fCovMatrix.size() == 0) 
return 0; 
 
  221          return fCovMatrix[j + i* (i+1) / 2];
 
  223          return fCovMatrix[i + j* (j+1) / 2];
 
  227    double Correlation(
unsigned int i, 
unsigned int j )
 const {
 
  228       if ( i >= fErrors.size() || j >= fErrors.size() ) 
return 0;
 
  229       if (fCovMatrix.size() == 0) 
return 0; 
 
  230       double tmp = CovMatrix(i,i)*CovMatrix(j,j);
 
  231       return ( tmp > 0) ? CovMatrix(i,j)/ std::sqrt(tmp) : 0;
 
  236    template<
class Matrix>
 
  237    void GetCovarianceMatrix(Matrix & mat)
 const {
 
  238       unsigned int npar = fErrors.size();
 
  239       if (fCovMatrix.size() != npar*(npar+1)/2 ) 
return; 
 
  240       for (
unsigned int i = 0; i< npar; ++i) {
 
  241          for (
unsigned int j = 0; j<=i; ++j) {
 
  242             mat(i,j) = fCovMatrix[j + i*(i+1)/2 ];
 
  243             if (i != j) mat(j,i) = mat(i,j);
 
  250    template<
class Matrix>
 
  251    void GetCorrelationMatrix(Matrix & mat)
 const {
 
  252       unsigned int npar = fErrors.size();
 
  253       if (fCovMatrix.size() != npar*(npar+1)/2) 
return; 
 
  254       for (
unsigned int i = 0; i< npar; ++i) {
 
  255          for (
unsigned int j = 0; j<=i; ++j) {
 
  256             double tmp = fCovMatrix[i * (i +3)/2 ] * fCovMatrix[ j * (j+3)/2 ];
 
  257             mat(i,j) = (tmp > 0) ? fCovMatrix[j + i*(i+1)/2 ] / std::sqrt(tmp) : 0;
 
  258             if (i != j) mat(j,i) = mat(i,j);
 
  276    void GetConfidenceIntervals(
unsigned int n, 
unsigned int stride1, 
unsigned int stride2, 
const double * x,  
double * ci, 
double cl=0.95, 
bool norm = 
false ) 
const;
 
  284    void GetConfidenceIntervals(
const BinData & data, 
double * ci, 
double cl=0.95, 
bool norm = 
false ) 
const;
 
  290    std::vector<double> GetConfidenceIntervals(
double cl=0.95, 
bool norm = 
false ) 
const;
 
  295    bool Scan(
unsigned int ipar, 
unsigned int &npoints, 
double *pntsx, 
double *pntsy, 
double xmin = 0, 
double xmax = 0);
 
  301    bool Contour(
unsigned int ipar, 
unsigned int jpar, 
unsigned int &npoints, 
double *pntsx, 
double *pntsy, 
double confLevel = 0.683);
 
  304    int Index(
const std::string & name) 
const;
 
  307    void NormalizeErrors();
 
  310    bool NormalizedErrors()
 const { 
return fNormalized; }
 
  313    void Print(std::ostream & os, 
bool covmat = 
false) 
const;
 
  316    void PrintCovMatrix(std::ostream & os) 
const;
 
  319    bool IsParameterBound(
unsigned int ipar) 
const;
 
  322    bool IsParameterFixed(
unsigned int ipar) 
const;
 
  325    bool ParameterBounds(
unsigned int ipar, 
double &lower, 
double &upper) 
const;
 
  329    std::string GetParameterName(
unsigned int ipar)
 const {
 
  330       return ParName(ipar);
 
  339    std::shared_ptr<IModelFunction> ModelFunction()  { 
return fFitFunc; }
 
  340    void SetModelFunction(
const std::shared_ptr<IModelFunction> & func) { fFitFunc = func; }
 
  349    unsigned int fNCalls;    
 
  355    std::shared_ptr<ROOT::Math::Minimizer> fMinimizer; 
 
  356    std::shared_ptr<ROOT::Math::IMultiGenFunction> fObjFunc; 
 
  357    std::shared_ptr<IModelFunction> fFitFunc; 
 
  358    std::shared_ptr<FitData>    fFitData; 
 
  359    std::map<unsigned int, bool>           fFixedParams; 
 
  360    std::map<unsigned int, unsigned int>   fBoundParams; 
 
  361    std::vector<std::pair<double,double> >  fParamBounds; 
 
  362    std::vector<double>         fParams;  
 
  363    std::vector<double>         fErrors;  
 
  364    std::vector<double>         fCovMatrix;  
 
  365    std::vector<double>         fGlobalCC;   
 
  366    std::map<unsigned int, std::pair<double,double> > fMinosErrors;   
 
  367    std::string fMinimType;              
 
  368    std::vector<std::string> fParNames;