00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef ROOT_Fit_FitResult
00014 #define ROOT_Fit_FitResult
00015
00016 #ifndef ROOT_Fit_IFunctionfwd
00017 #include "Math/IFunctionfwd.h"
00018 #endif
00019 #ifndef ROOT_Fit_IParamFunctionfwd
00020 #include "Math/IParamFunctionfwd.h"
00021 #endif
00022
00023 #include <vector>
00024 #include <map>
00025 #include <string>
00026 #include <cmath>
00027 #include <cassert>
00028
00029 namespace ROOT {
00030
00031 namespace Math {
00032 class Minimizer;
00033 }
00034
00035
00036 namespace Fit {
00037
00038 class FitConfig;
00039 class BinData;
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 class FitResult {
00051
00052 public:
00053
00054 typedef ROOT::Math::IParamMultiFunction IModelFunction;
00055
00056
00057
00058
00059 FitResult ();
00060
00061
00062
00063
00064
00065 FitResult(ROOT::Math::Minimizer & min, const FitConfig & fconfig, const IModelFunction * f, bool isValid, unsigned int sizeOfData = 0, bool binFit = true, const ROOT::Math::IMultiGenFunction * chi2func = 0, unsigned int ncalls = 0);
00066
00067
00068
00069
00070 FitResult(const FitResult &);
00071
00072
00073
00074
00075 FitResult & operator = (const FitResult & rhs);
00076
00077
00078
00079
00080 ~FitResult ();
00081
00082
00083 public:
00084
00085
00086
00087
00088
00089
00090
00091 bool Update(const ROOT::Math::Minimizer & min, bool isValid, unsigned int ncalls = 0 );
00092
00093
00094
00095
00096 const std::string & MinimizerType() const { return fMinimType; }
00097
00098
00099 bool IsValid() const { return fValid; }
00100
00101
00102 bool IsEmpty() const { return (fParams.size() == 0); }
00103
00104
00105 double MinFcnValue() const { return fVal; }
00106
00107
00108 unsigned int NCalls() const { return fNCalls; }
00109
00110
00111 double Edm() const { return fEdm; }
00112
00113
00114 unsigned int NTotalParameters() const { return fParams.size(); }
00115
00116 unsigned int NPar() const { return NTotalParameters(); }
00117
00118
00119 unsigned int NFreeParameters() const { return fNFree; }
00120
00121
00122 int Status() const { return fStatus; }
00123
00124
00125
00126
00127 int CovMatrixStatus() const { return fCovStatus; }
00128
00129
00130
00131
00132 const IModelFunction * FittedFunction() const { return fFitFunc; }
00133
00134
00135
00136 double Chi2() const { return fChi2; }
00137
00138
00139 unsigned int Ndf() const { return fNdf; }
00140
00141
00142 double Prob() const;
00143
00144
00145 const std::vector<double> & Errors() const { return fErrors; }
00146
00147 const double * GetErrors() const { return (fErrors.empty()) ? 0 : &fErrors.front(); }
00148
00149
00150 const std::vector<double> & Parameters() const { return fParams; }
00151
00152 const double * GetParams() const { return &fParams.front(); }
00153
00154
00155 double Value(unsigned int i) const { return fParams[i]; }
00156
00157 double Parameter(unsigned int i) const { return fParams[i]; }
00158
00159
00160
00161
00162 double Error(unsigned int i) const {
00163 return (i < fErrors.size() ) ? fErrors[i] : 0;
00164 }
00165
00166 double ParError(unsigned int i) const {
00167 return (i < fErrors.size() ) ? fErrors[i] : 0;
00168 }
00169
00170
00171 std::string ParName(unsigned int i) const;
00172
00173
00174 void SetMinosError(unsigned int i, double elow, double eup);
00175
00176
00177 double LowerError(unsigned int i) const;
00178
00179
00180 double UpperError(unsigned int i) const;
00181
00182
00183 double GlobalCC(unsigned int i) const {
00184 return (i < fGlobalCC.size() ) ? fGlobalCC[i] : -1;
00185 }
00186
00187
00188
00189 double CovMatrix (unsigned int i, unsigned int j) const {
00190 if ( i >= fErrors.size() || j >= fErrors.size() ) return 0;
00191 if (fCovMatrix.size() == 0) return 0;
00192 if ( j < i )
00193 return fCovMatrix[j + i* (i+1) / 2];
00194 else
00195 return fCovMatrix[i + j* (j+1) / 2];
00196 }
00197
00198
00199 double Correlation(unsigned int i, unsigned int j ) const {
00200 if ( i >= fErrors.size() || j >= fErrors.size() ) return 0;
00201 if (fCovMatrix.size() == 0) return 0;
00202 double tmp = CovMatrix(i,i)*CovMatrix(j,j);
00203 return ( tmp > 0) ? CovMatrix(i,j)/ std::sqrt(tmp) : 0;
00204 }
00205
00206
00207
00208 template<class Matrix>
00209 void GetCovarianceMatrix(Matrix & mat) const {
00210 unsigned int npar = fErrors.size();
00211 if (fCovMatrix.size() != npar*(npar+1)/2 ) return;
00212 for (unsigned int i = 0; i< npar; ++i) {
00213 for (unsigned int j = 0; j<=i; ++j) {
00214 mat(i,j) = fCovMatrix[j + i*(i+1)/2 ];
00215 if (i != j) mat(j,i) = mat(i,j);
00216 }
00217 }
00218 }
00219
00220
00221
00222 template<class Matrix>
00223 void GetCorrelationMatrix(Matrix & mat) const {
00224 unsigned int npar = fErrors.size();
00225 if (fCovMatrix.size() != npar*(npar+1)/2) return;
00226 for (unsigned int i = 0; i< npar; ++i) {
00227 for (unsigned int j = 0; j<=i; ++j) {
00228 double tmp = fCovMatrix[i * (i +3)/2 ] * fCovMatrix[ j * (j+3)/2 ];
00229 mat(i,j) = (tmp > 0) ? fCovMatrix[j + i*(i+1)/2 ] / std::sqrt(tmp) : 0;
00230 if (i != j) mat(j,i) = mat(i,j);
00231 }
00232 }
00233 }
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 void GetConfidenceIntervals(unsigned int n, unsigned int stride1, unsigned int stride2, const double * x, double * ci, double cl=0.95, bool norm = true ) const;
00248
00249
00250
00251
00252
00253
00254 void GetConfidenceIntervals(const BinData & data, double * ci, double cl=0.95, bool norm = true ) const;
00255
00256
00257
00258 int Index(const std::string & name) const;
00259
00260
00261
00262 void NormalizeErrors();
00263
00264
00265 bool NormalizedErrors() { return fNormalized; }
00266
00267
00268 void Print(std::ostream & os, bool covmat = false) const;
00269
00270
00271 void PrintCovMatrix(std::ostream & os) const;
00272
00273
00274 bool IsParameterBound(unsigned int ipar) const;
00275
00276
00277 bool IsParameterFixed(unsigned int ipar) const;
00278
00279
00280 std::string GetParameterName(unsigned int ipar) const {
00281 return ParName(ipar);
00282 }
00283
00284
00285 protected:
00286
00287
00288
00289
00290 IModelFunction * ModelFunction() { return fFitFunc; }
00291 void SetModelFunction(IModelFunction * func) { fFitFunc = func; }
00292
00293 friend class Fitter;
00294
00295
00296 bool fValid;
00297 bool fNormalized;
00298 unsigned int fNFree;
00299 unsigned int fNdf;
00300 unsigned int fNCalls;
00301 int fStatus;
00302 int fCovStatus;
00303 double fVal;
00304 double fEdm;
00305 double fChi2;
00306 IModelFunction * fFitFunc;
00307 std::vector<unsigned int> fFixedParams;
00308 std::vector<unsigned int> fBoundParams;
00309 std::vector<double> fParams;
00310 std::vector<double> fErrors;
00311 std::vector<double> fCovMatrix;
00312 std::vector<double> fGlobalCC;
00313 std::map<unsigned int, std::pair<double,double> > fMinosErrors;
00314 std::string fMinimType;
00315 std::vector<std::string> fParNames;
00316
00317 };
00318
00319 }
00320
00321 }
00322
00323
00324 #endif