00001 // @(#)root/mathcore:$Id: FitUtil.h 24477 2008-06-23 12:58:47Z moneta $ 00002 // Author: L. Moneta Tue Nov 28 10:52:47 2006 00003 00004 /********************************************************************** 00005 * * 00006 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT * 00007 * * 00008 * * 00009 **********************************************************************/ 00010 00011 // Header file for class FitUtil 00012 00013 #ifndef ROOT_Fit_FitUtil 00014 #define ROOT_Fit_FitUtil 00015 00016 #ifndef ROOT_Math_IParamFunctionfwd 00017 #include "Math/IParamFunctionfwd.h" 00018 #endif 00019 00020 #ifndef ROOT_Fit_DataVectorfwd 00021 #include "Fit/DataVectorfwd.h" 00022 #endif 00023 00024 00025 namespace ROOT { 00026 00027 namespace Fit { 00028 00029 00030 00031 00032 /** 00033 namespace defining utility free functions using in Fit for evaluating the various fit method 00034 functions (chi2, likelihood, etc..) given the data and the model function 00035 00036 @ingroup FitMain 00037 */ 00038 namespace FitUtil { 00039 00040 typedef ROOT::Math::IParamMultiFunction IModelFunction; 00041 typedef ROOT::Math::IParamMultiGradFunction IGradModelFunction; 00042 00043 /** Chi2 Functions */ 00044 00045 /** 00046 evaluate the Chi2 given a model function and the data at the point x. 00047 return also nPoints as the effective number of used points in the Chi2 evaluation 00048 */ 00049 double EvaluateChi2(const IModelFunction & func, const BinData & data, const double * x, unsigned int & nPoints); 00050 00051 /** 00052 evaluate the effective Chi2 given a model function and the data at the point x. 00053 The effective chi2 uses the errors on the coordinates : W = 1/(sigma_y**2 + ( sigma_x_i * df/dx_i )**2 ) 00054 return also nPoints as the effective number of used points in the Chi2 evaluation 00055 */ 00056 double EvaluateChi2Effective(const IModelFunction & func, const BinData & data, const double * x, unsigned int & nPoints); 00057 00058 /** 00059 evaluate the Chi2 gradient given a model function and the data at the point x. 00060 return also nPoints as the effective number of used points in the Chi2 evaluation 00061 */ 00062 void EvaluateChi2Gradient(const IModelFunction & func, const BinData & data, const double * x, double * grad, unsigned int & nPoints); 00063 00064 /** 00065 evaluate the LogL given a model function and the data at the point x. 00066 return also nPoints as the effective number of used points in the LogL evaluation 00067 */ 00068 double EvaluateLogL(const IModelFunction & func, const UnBinData & data, const double * x, unsigned int & nPoints); 00069 00070 /** 00071 evaluate the LogL gradient given a model function and the data at the point x. 00072 return also nPoints as the effective number of used points in the LogL evaluation 00073 */ 00074 void EvaluateLogLGradient(const IModelFunction & func, const UnBinData & data, const double * x, double * grad, unsigned int & nPoints); 00075 00076 /** 00077 evaluate the Poisson LogL given a model function and the data at the point x. 00078 return also nPoints as the effective number of used points in the LogL evaluation 00079 */ 00080 double EvaluatePoissonLogL(const IModelFunction & func, const BinData & data, const double * x, unsigned int & nPoints); 00081 00082 /** 00083 evaluate the Poisson LogL given a model function and the data at the point x. 00084 return also nPoints as the effective number of used points in the LogL evaluation 00085 */ 00086 void EvaluatePoissonLogLGradient(const IModelFunction & func, const BinData & data, const double * x, double * grad); 00087 00088 // /** 00089 // Parallel evaluate the Chi2 given a model function and the data at the point x. 00090 // return also nPoints as the effective number of used points in the Chi2 evaluation 00091 // */ 00092 // double ParallelEvalChi2(const IModelFunction & func, const BinData & data, const double * x, unsigned int & nPoints); 00093 00094 // methods required by dedicate minimizer like Fumili 00095 00096 /** 00097 evaluate the residual contribution to the Chi2 given a model function and the BinPoint data 00098 and if the pointer g is not null evaluate also the gradient of the residual. 00099 If the function provides parameter derivatives they are used otherwise a simple derivative calculation 00100 is used 00101 */ 00102 double EvaluateChi2Residual(const IModelFunction & func, const BinData & data, const double * x, unsigned int ipoint, double *g = 0); 00103 00104 /** 00105 evaluate the pdf contribution to the LogL given a model function and the BinPoint data. 00106 If the pointer g is not null evaluate also the gradient of the pdf. 00107 If the function provides parameter derivatives they are used otherwise a simple derivative calculation 00108 is used 00109 */ 00110 double EvaluatePdf(const IModelFunction & func, const UnBinData & data, const double * x, unsigned int ipoint, double * g = 0); 00111 00112 /** 00113 evaluate the pdf contribution to the Poisson LogL given a model function and the BinPoint data. 00114 If the pointer g is not null evaluate also the gradient of the Poisson pdf. 00115 If the function provides parameter derivatives they are used otherwise a simple derivative calculation 00116 is used 00117 */ 00118 double EvaluatePoissonBinPdf(const IModelFunction & func, const BinData & data, const double * x, unsigned int ipoint, double * g = 0); 00119 00120 00121 00122 00123 00124 00125 00126 } // end namespace FitUtil 00127 00128 } // end namespace Fit 00129 00130 } // end namespace ROOT 00131 00132 00133 #endif /* ROOT_Fit_FitUtil */