From 36fd827b2753b1c8670cb73e769bb477533ef8b0 Mon Sep 17 00:00:00 2001 From: Lorenzo Moneta <Lorenzo.Moneta@cern.ch> Date: Wed, 26 Mar 2008 15:50:27 +0000 Subject: [PATCH] - update the documentation, add tag for making visible via THtml git-svn-id: http://root.cern.ch/svn/root/trunk@22850 27541ba8-7e3a-0410-8455-c3a389f83636 --- fit/inc/Fit/BinData.h | 111 +++++++++++++++++++---------- fit/inc/Fit/Chi2FCN.h | 1 + fit/inc/Fit/DataOptions.h | 15 ++-- fit/inc/Fit/DataRange.h | 4 +- fit/inc/Fit/FitConfig.h | 69 +++++++++++++----- fit/inc/Fit/FitResult.h | 33 +++------ fit/inc/Fit/Fitter.h | 34 ++++----- fit/inc/Fit/LogLikelihoodFCN.h | 1 + fit/inc/Fit/ParameterSettings.h | 17 ++--- fit/inc/Fit/PoissonLikelihoodFCN.h | 1 + fit/inc/Fit/UnBinData.h | 41 ++++++++--- fit/inc/LinkDef.h | 4 +- fit/src/FitResult.cxx | 7 ++ mathcore/test/binarySearchTime.cxx | 11 ++- 14 files changed, 219 insertions(+), 130 deletions(-) diff --git a/fit/inc/Fit/BinData.h b/fit/inc/Fit/BinData.h index 8c3b77d7b00..758fb391342 100644 --- a/fit/inc/Fit/BinData.h +++ b/fit/inc/Fit/BinData.h @@ -33,6 +33,7 @@ namespace ROOT { +//___________________________________________________________________________________ /** BinData : class describing the binned data : vectors of x coordinates, y values and optionally error on y values and error on coordinates @@ -114,14 +115,20 @@ public : */ BinData(unsigned int n, const double * dataX, const double * dataY, const double * dataZ, const double * val, const double * ex , const double * ey , const double * ez , const double * eval ); - /// copy constructor + /** + copy constructor + */ BinData(const BinData &); - /// assignment operator (private) + /** + assignment operator + */ BinData & operator= (const BinData &); - /// destructor + /** + destructor + */ ~BinData(); /** @@ -130,28 +137,35 @@ public : */ void Initialize(unsigned int maxpoints, unsigned int dim = 1, ErrorType err = kValueError ); -// /** -// re-initialize adding some additional set of points keeping the previous ones -// */ -// void ReInitialize(unsigned int nexpoints) { -// if (!fDataVector) return; -// (fDataVector->Data()).resize( fDataVector->Size() + nexpoints * fPointSize ); -// } - + + /** + return the size of a fit point (is the coordinate dimension + 1 for the value and eventually + the number of all errors + */ unsigned int PointSize() const { return fPointSize; } + /** + return the size of internal data (number of fit points) + if data are not copied in but used externally the size is 0 + */ unsigned int DataSize() const { if (fDataVector) return fDataVector->Size(); return 0; } + /** + flag to control if data provides error on the coordinates + */ bool HaveCoordErrors() const { if (fPointSize > fDim +2) return true; return false; } + /** + flag to control if data provides asymmetric errors on the value + */ bool HaveAsymErrors() const { if (fPointSize > 2 * fDim +2) return true; return false; @@ -164,38 +178,41 @@ public : void Add(double x, double y ); /** - add one dim data with no error in x - in this case store the inverse of the error in y + add one dim data with no error in the coordinate (x) + in this case store the inverse of the error in the value (y) */ void Add(double x, double y, double ey); /** - add one dim data with error in x - in this case store the y error and not the inverse + add one dim data with error in the coordinate (x) + in this case store the value (y) error and not the inverse */ void Add(double x, double y, double ex, double ey); /** - add one dim data with error in x and asymmetric errors in y + add one dim data with error in the coordinate (x) and asymmetric errors in the value (y) in this case store the y errors and not the inverse */ void Add(double x, double y, double ex, double eyl , double eyh); /** - add multi dim data with only value (no errors) + add multi-dim coordinate data with only value (no errors) */ void Add(const double *x, double val); /** - add multi dim data with only error in value + add multi-dim coordinate data with only error in value */ void Add(const double *x, double val, double eval); /** - add multi dim data with error in coordinates and value + add multi-dim coordinate data with both error in coordinates and value */ void Add(const double *x, double val, const double * ex, double eval); + /** + return a pointer to the coordinates data for the given fit point + */ const double * Coords(unsigned int ipoint) const { if (fDataVector) return &((fDataVector->Data())[ ipoint*fPointSize ] ); @@ -203,6 +220,9 @@ public : return fDataWrapper->Coords(ipoint); } + /** + return the value for the given fit point + */ double Value(unsigned int ipoint) const { if (fDataVector) return (fDataVector->Data())[ ipoint*fPointSize + fDim ]; @@ -210,10 +230,10 @@ public : return fDataWrapper->Value(ipoint); } -//#ifdef LATER + /** - return error on the value - safe (but slower) method returning correctly the error on the value + return error on the value for the given fit point + Safe (but slower) method returning correctly the error on the value in case of asymm errors return the average 0.5(eu + el) */ double Error(unsigned int ipoint) const { @@ -235,7 +255,7 @@ public : } /** - return the inverse of error on the value + Return the inverse of error on the value for the given fit point useful when error in the coordinates are not stored and then this is used directly this as the weight in the least square function */ @@ -253,10 +273,10 @@ public : double eval = fDataWrapper->Error(ipoint); return eval != 0 ? 1.0/eval : 0; } -//#endif + /** - return a pointer to the errors in the coordinates + Return a pointer to the errors in the coordinates for the given fit point */ const double * CoordErrors(unsigned int ipoint) const { if (fDataVector) { @@ -267,7 +287,10 @@ public : return fDataWrapper->CoordErrors(ipoint); } - + /** + retrieve at the same time a pointer to the coordinate data and the fit value + More efficient than calling Coords(i) and Value(i) + */ const double * GetPoint(unsigned int ipoint, double & value) const { if (fDataVector) { unsigned int j = ipoint*fPointSize; @@ -280,7 +303,11 @@ public : return fDataWrapper->Coords(ipoint); } - // get coordinate value and error. To be used only when type is kValueError otherwise inverse error is returned + /** + retrieve in a single call a pointer to the coordinate data, value and inverse error for + the given fit point. + To be used only when type is kValueError otherwise the error is returned and not the inverse + */ const double * GetPoint(unsigned int ipoint, double & value, double & invError) const { if (fDataVector) { assert(fPointSize == fDim +2); // value error @@ -297,9 +324,12 @@ public : return fDataWrapper->Coords(ipoint); } - /// Get errors on the point (coordinate and value) + /** + Retrieve the errors on the point (coordinate and value) for the given fit point + It must be called only when the coordinate errors are stored otherwise it will produce an + assert. + */ const double * GetPointError(unsigned int ipoint, double & errvalue) const { -// to be called only when coord errors are stored if (fDataVector) { assert(fPointSize > fDim + 2); unsigned int j = ipoint*fPointSize; @@ -312,9 +342,13 @@ public : return fDataWrapper->CoordErrors(ipoint); } - /// Get errors on the point (coordinates and value with the asymmetric errors) + /** + Get errors on the point (coordinate errors and asymmetric value errors) for the + given fit point. + It must be called only when the coordinate errors and asymmetric errors are stored + otherwise it will produce an assert. + */ const double * GetPointError(unsigned int ipoint, double & errlow, double & errhigh) const { -// to be called only when coord errors are stored // external data is not supported for asymmetric errors assert(fDataVector); @@ -387,17 +421,22 @@ public : (fDataVector->Data()).resize(PointSize() *npoints); } - + /** + return number of fit points + */ unsigned int NPoints() const { return fNPoints; } /** - return number of contained points - in case of integral option size is npoints -1 + return number of fit points + In case of integral option size is npoints -1 */ unsigned int Size() const { return (Opt().fIntegral) ? fNPoints-1 : fNPoints; } + /** + return coordinate data dimension + */ unsigned int NDim() const { return fDim; } /** @@ -420,8 +459,8 @@ private: unsigned int fPointSize; // total point size including value and errors (= fDim + 2 for error in only Y ) unsigned int fNPoints; // number of contained points in the data set (can be different than size of vector) - DataVector * fDataVector; - DataWrapper * fDataWrapper; + DataVector * fDataVector; // pointer to the copied in data vector + DataWrapper * fDataWrapper; // pointer to the external data wrapper structure #ifdef USE_BINPOINT_CLASS mutable BinPoint fPoint; diff --git a/fit/inc/Fit/Chi2FCN.h b/fit/inc/Fit/Chi2FCN.h index 7be8514ae41..3492b42a0a2 100644 --- a/fit/inc/Fit/Chi2FCN.h +++ b/fit/inc/Fit/Chi2FCN.h @@ -61,6 +61,7 @@ struct ModelFunctionTrait<ROOT::Math::IMultiGradFunction> { +//___________________________________________________________________________________ /** Chi2FCN class for binnned fits using the least square methods diff --git a/fit/inc/Fit/DataOptions.h b/fit/inc/Fit/DataOptions.h index 45615a26c3e..fdab47536eb 100644 --- a/fit/inc/Fit/DataOptions.h +++ b/fit/inc/Fit/DataOptions.h @@ -19,6 +19,7 @@ namespace ROOT { namespace Fit { +//___________________________________________________________________________________ /** DataOptions : simple structure holding the options on how the data are filled */ @@ -26,7 +27,7 @@ struct DataOptions { /** - Default constructor: have default options + Default constructor: use the default options */ DataOptions () : fIntegral(false), @@ -38,12 +39,12 @@ struct DataOptions { {} - bool fIntegral; - bool fUseEmpty; - bool fUseRange; - bool fErrors1; // use all errors equal to 1 (fit without errors) - bool fCoordErrors; // use errors on the coordinates when available - bool fAsymErrors; // use asymmetric errors in the value when available (depending on sign of residual) + bool fIntegral; // use integral of bin content instead of bin center (default is false) + bool fUseEmpty; // use empty bins (default is false) with a fixed error of 1 + bool fUseRange; // use the function range when creating the fit data (default is false) + bool fErrors1; // use all errors equal to 1, i.e. fit without errors (default is false) + bool fCoordErrors; // use errors on the coordinates when available (default is false) + bool fAsymErrors; // use asymmetric errors in the value when available, selecting them according to the on sign of residual (default is false) }; diff --git a/fit/inc/Fit/DataRange.h b/fit/inc/Fit/DataRange.h index 9f8665e44da..cf90bb7f06e 100644 --- a/fit/inc/Fit/DataRange.h +++ b/fit/inc/Fit/DataRange.h @@ -20,6 +20,7 @@ namespace ROOT { namespace Fit { +//___________________________________________________________________________________ /** class describing the range in the coordinates it supports multiple range in a coordinate. @@ -105,7 +106,6 @@ public: ~DataRange () {} - // use default copy-ctrs /** add a range [xmin,xmax] for the new coordinate icoord @@ -132,7 +132,7 @@ protected: private: - RangeIntervals fRanges; + RangeIntervals fRanges; // list of all ranges }; diff --git a/fit/inc/Fit/FitConfig.h b/fit/inc/Fit/FitConfig.h index 27e70ab4555..2239509187d 100644 --- a/fit/inc/Fit/FitConfig.h +++ b/fit/inc/Fit/FitConfig.h @@ -38,7 +38,7 @@ namespace ROOT { namespace Fit { - +//___________________________________________________________________________________ /** FitConfig class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::ParameterSettings class @@ -57,56 +57,87 @@ public: */ ~FitConfig (); - /// get the parameter settings for the i-th parameter (const method) + /** + get the parameter settings for the i-th parameter (const method) + */ const ParameterSettings & ParSettings(unsigned int i) const { return fSettings[i]; } - /// get the parameter settings for the i-th parameter (non-const method) + /** + get the parameter settings for the i-th parameter (non-const method) + */ ParameterSettings & ParSettings(unsigned int i) { return fSettings[i]; } - /// get the vector of parameter settings (const method) + /** + get the vector of parameter settings (const method) + */ const std::vector<ROOT::Fit::ParameterSettings> & ParamsSettings() const { return fSettings; } - /// get the vector of parameter settings (non-const method) + /** + get the vector of parameter settings (non-const method) + */ std::vector<ROOT::Fit::ParameterSettings> & ParamsSettings() { return fSettings; } - /// set the parameter settings from number of params and optionally a vector of values (otherwise are set to zero) + /** + set the parameter settings from number of params and optionally a vector of values (otherwise are set to zero) + */ void SetParamsSettings(unsigned int npar, const double * params = 0); - /// set the parameter settings from a function + /** + set the parameter settings from a function + */ void SetParamsSettings(const ROOT::Math::IParamMultiFunction & func); - /// create a new minimizer according to chosen configuration + /** + create a new minimizer according to chosen configuration + */ ROOT::Math::Minimizer * CreateMinimizer(); - /// access to the minimizer control parameter (const method) + /** + access to the minimizer control parameter (const method) + */ const MinimizerControlParams & MinimizerOptions() const { return fMinimizerOpts; } - /// access to the minimizer control parameter (non const method) + /** + access to the minimizer control parameter (non const method) + */ MinimizerControlParams & MinimizerOptions() { return fMinimizerOpts; } - /// set minimizer type + /** + set minimizer type + */ void SetMinimizer(const std::string & type, std::string algo = "") { fMinimizerType = type; fMinimAlgoType = algo; } - /// return type of minimizer package + /** + return type of minimizer package + */ const std::string & MinimizerType() const { return fMinimizerType; } - /// return type of minimizer algorithms + /** + return type of minimizer algorithms + */ const std::string & MinimizerAlgoType() const { return fMinimAlgoType; } - /// flag to check if errors needs to be normalized according to chi2/ndf + + /** + flag to check if resulting errors are be normalized according to chi2/ndf + */ bool NormalizeErrors(){ return fNormErrors; } + /** + set the option to normalize the error on the result according to chi2/ndf + */ void SetNormErrors(bool on) { fNormErrors= on; } - // static function to cnotrol default parameters - + /** + static function to control default minimizer type and algorithm + */ static void SetDefaultMinimizer(const std::string & type, const std::string & algo = ""); @@ -115,13 +146,13 @@ protected: private: - bool fNormErrors; + bool fNormErrors; // flag for error normalization - std::vector<ROOT::Fit::ParameterSettings> fSettings; + std::vector<ROOT::Fit::ParameterSettings> fSettings; // vector with the parameter settings std::string fMinimizerType; // minimizer type (MINUIT, MINUIT2, etc..) std::string fMinimAlgoType; // algorithm type (MIGRAD, SIMPLEX, etc..) - MinimizerControlParams fMinimizerOpts; + MinimizerControlParams fMinimizerOpts; //minimizer control parameters }; diff --git a/fit/inc/Fit/FitResult.h b/fit/inc/Fit/FitResult.h index 3b6b0f189a7..96c3491c96b 100644 --- a/fit/inc/Fit/FitResult.h +++ b/fit/inc/Fit/FitResult.h @@ -34,6 +34,7 @@ namespace ROOT { class FitConfig; +//___________________________________________________________________________________ /** FitResult class containg the result of the fit. Contains a reference to the fitted function. @@ -55,44 +56,30 @@ public: */ FitResult(ROOT::Math::Minimizer & min, const FitConfig & fconfig, const IModelFunction & f, bool isValid, unsigned int sizeOfData = 0, const ROOT::Math::IMultiGenFunction * chi2func = 0, bool minosErr = false, unsigned int ncalls = 0); + // use default copy constructor and assignment operator + /** Destructor (no operations) */ ~FitResult () {} -// leave to default ?? -// private: -// // usually copying is non trivial, so we make this unaccessible - -// /** -// Copy constructor -// */ -// FitResult(const FitResult &) {} - -// /** -// Assignment operator -// */ -// FitResult & operator = (const FitResult & rhs) { -// if (this == &rhs) return *this; // time saving self-test -// return *this; -// } public: ///normalize errors using chi2/ndf for chi2 fits void NormalizeErrors(); - /// flag tp chek if errors are normalized + /// flag to chek if errors are normalized bool NormalizedErrors() { return fNormalized; } /// True if fit successful, otherwise false. bool IsValid() const { return fValid; } - /// Function with fitted parameter values. - ///IModelFunction &FittedFunction() const; + /// Return pointer to model (fit) function with fitted parameter values. + const IModelFunction * FittedFunction() const { return fFitFunc; } - /// value of the objective function (chi2 or likelihood) used in the fit + /// Return value of the objective function (chi2 or likelihood) used in the fit double MinFcnValue() const { return fVal; } /// Chi2 fit value @@ -102,10 +89,10 @@ public: /// Number of degree of freedom unsigned int Ndf() const { return fNdf; } - /// p value of the fit chi2 - double Prob() const { return 0; } // to be done + /// p value of the fit (chi2 probability) + double Prob() const; - /// covariance matrix + /// retrieve covariance matrix element double CovMatrix (unsigned int i, unsigned int j) const { if ( i >= fErrors.size() || j >= fErrors.size() ) return 0; if (fCovMatrix.size() == 0) return 0; // nomatrix available in case of non-valid fits diff --git a/fit/inc/Fit/Fitter.h b/fit/inc/Fit/Fitter.h index 6be76342e85..ef1bc504e55 100644 --- a/fit/inc/Fit/Fitter.h +++ b/fit/inc/Fit/Fitter.h @@ -47,6 +47,7 @@ namespace ROOT { namespace Fit { +//___________________________________________________________________________________ /** Fitter class. Fits are performed using the generic ROOT::Fit::Fitter::Fit method. @@ -67,8 +68,6 @@ public: typedef ROOT::Math::IParamFunction IModel1DFunction; typedef ROOT::Math::IParamGradFunction IGradModel1DFunction; -// typedef IModelFunction::BaseFunc BaseFunc; -// typedef IGradModelFunction::BaseGradFunc BaseGradFunc; typedef ROOT::Math::IMultiGenFunction BaseFunc; typedef ROOT::Math::IMultiGradFunction BaseGradFunc; @@ -176,18 +175,20 @@ public: */ void SetFunction(const IGradModel1DFunction & func); -// /** -// Set the fitted function from a generic callable object -// */ -// void SetFunction(const BinData * data); - /// get fit result + /** + get fit result + */ const FitResult & Result() const { return fResult; } - /// access to the configuration (const method) + /** + access to the fit configuration (const method) + */ const FitConfig & Config() const { return fConfig; } - /// access to the configuration (non const method) + /** + access to the configuration (non const method) + */ FitConfig & Config() { return fConfig; } @@ -209,20 +210,13 @@ protected: private: - ///flag to indicate if using gradient or not - bool fUseGradient; + bool fUseGradient; // flag to indicate if using gradient or not - /// copy of the fitted function which will contain on output the fit result - IModelFunction * fFunc; + IModelFunction * fFunc; // copy of the fitted function containing on output the fit result - /// object containing the result of the fit - FitResult fResult; + FitResult fResult; // object containing the result of the fit - - /// fitter configuration (options and parameter settings - FitConfig fConfig; - - + FitConfig fConfig; // fitter configuration (options and parameter settings) }; diff --git a/fit/inc/Fit/LogLikelihoodFCN.h b/fit/inc/Fit/LogLikelihoodFCN.h index 324fbf08525..ad16d2c7764 100644 --- a/fit/inc/Fit/LogLikelihoodFCN.h +++ b/fit/inc/Fit/LogLikelihoodFCN.h @@ -40,6 +40,7 @@ namespace ROOT { namespace Fit { +//___________________________________________________________________________________ /** LogLikelihoodFCN class for likelihood fits diff --git a/fit/inc/Fit/ParameterSettings.h b/fit/inc/Fit/ParameterSettings.h index b670d7d19a3..21df5c9c7fb 100644 --- a/fit/inc/Fit/ParameterSettings.h +++ b/fit/inc/Fit/ParameterSettings.h @@ -20,6 +20,7 @@ namespace ROOT { namespace Fit { +//___________________________________________________________________________________ /** ParameterSettings class, describing value, limits and step size of the parameters Provides functionality also to set/retrieve values, step sizes, limits and fix the @@ -171,15 +172,15 @@ protected: private: - double fValue; - double fStepSize; - bool fFix; - double fLowerLimit; - double fUpperLimit; - bool fHasLowerLimit; - bool fHasUpperLimit; + double fValue; // parameter value + double fStepSize; // parameter step size (used by minimizer) + bool fFix; // flag to control if parameter is fixed + double fLowerLimit; // lower parameter limit + double fUpperLimit; // upper parameter limit + bool fHasLowerLimit; // flag to control lower parameter limit + bool fHasUpperLimit; // flag to control upper parameter limit - std::string fName; + std::string fName; // parameter name }; diff --git a/fit/inc/Fit/PoissonLikelihoodFCN.h b/fit/inc/Fit/PoissonLikelihoodFCN.h index 7311c1c29d0..d0987e8e6c8 100644 --- a/fit/inc/Fit/PoissonLikelihoodFCN.h +++ b/fit/inc/Fit/PoissonLikelihoodFCN.h @@ -41,6 +41,7 @@ namespace ROOT { namespace Fit { +//___________________________________________________________________________________ /** class evaluating the log likelihood for binned Poisson likelihood fits diff --git a/fit/inc/Fit/UnBinData.h b/fit/inc/Fit/UnBinData.h index 9f1ccd772a1..8e719160ed5 100644 --- a/fit/inc/Fit/UnBinData.h +++ b/fit/inc/Fit/UnBinData.h @@ -25,6 +25,7 @@ namespace ROOT { namespace Fit { +//___________________________________________________________________________________ /** UnBinData : class describing the unbinned data (just x coordinates values) of any dimensions @@ -159,6 +160,9 @@ public: } #endif + /** + destructor, delete pointer to internal data or external data wrapper + */ virtual ~UnBinData() { if (fDataVector) delete fDataVector; if (fDataWrapper) delete fDataWrapper; @@ -176,18 +180,24 @@ public: fDataVector = new DataVector( dim * maxpoints); } - + + /** + return fit point size (for unbin data is equivalent to coordinate dimension) + */ unsigned int PointSize() const { return fDim; } + /** + return size of internal data vector (is 0 for external data) + */ unsigned int DataSize() const { return fDataVector->Size(); } - /** - add one dim data - */ + /** + add one dim coordinate data + */ void Add(double x) { int index = fNPoints*PointSize(); assert(fDataVector != 0); @@ -197,8 +207,10 @@ public: fNPoints++; } - //for multi dim data + /** + add multi-dim coordinate data + */ void Add(double *x) { int index = fNPoints*PointSize(); @@ -213,7 +225,10 @@ public: fNPoints++; } - virtual const double * Coords(unsigned int ipoint) const { + /** + return pointer to coordinate data + */ + const double * Coords(unsigned int ipoint) const { if (fDataVector) return &( (fDataVector->Data()) [ ipoint*PointSize() ] ); else @@ -232,6 +247,9 @@ public: } + /** + return number of contained points + */ unsigned int NPoints() const { return fNPoints; } /** @@ -239,6 +257,9 @@ public: */ unsigned int Size() const { return fNPoints; } + /** + return coordinate data dimension + */ unsigned int NDim() const { return fDim; } protected: @@ -247,11 +268,11 @@ protected: private: - unsigned int fDim; - unsigned int fNPoints; + unsigned int fDim; // coordinate data dimension + unsigned int fNPoints; // numer of fit points - DataVector * fDataVector; - DataWrapper * fDataWrapper; + DataVector * fDataVector; // pointer to internal data vector (null for external data) + DataWrapper * fDataWrapper; // pointer to structure wrapping external data (null when data are copied in) }; diff --git a/fit/inc/LinkDef.h b/fit/inc/LinkDef.h index 4e9af21ed4b..e0d9b018da4 100644 --- a/fit/inc/LinkDef.h +++ b/fit/inc/LinkDef.h @@ -17,10 +17,10 @@ #pragma link C++ namespace ROOT::Fit; -//#pragma link C++ class ROOT::Fit::BinPoint; + #pragma link C++ class ROOT::Fit::DataRange; #pragma link C++ class ROOT::Fit::DataOptions; -//#pragma link C++ class ROOT::Fit::DataVector<ROOT::Fit::BinPoint>; + #pragma link C++ class ROOT::Fit::Fitter; #pragma link C++ class ROOT::Fit::FitConfig+; #pragma link C++ class ROOT::Fit::BinData+; diff --git a/fit/src/FitResult.cxx b/fit/src/FitResult.cxx index 67edc2b70e9..231f0385e60 100644 --- a/fit/src/FitResult.cxx +++ b/fit/src/FitResult.cxx @@ -18,6 +18,8 @@ #include "Math/IParamFunction.h" +#include "Math/DistFunc.h" + #include <cassert> #include <cmath> @@ -100,6 +102,11 @@ void FitResult::NormalizeErrors() { fNormalized = true; } +double FitResult::Prob() const { + // fit probability + return ROOT::Math::chisquared_cdf_c(fChi2, static_cast<double>(fNdf) ); +} + int FitResult::Index(const std::string & name) const { // find index for given parameter name unsigned int npar = fParams.size(); diff --git a/mathcore/test/binarySearchTime.cxx b/mathcore/test/binarySearchTime.cxx index b24d074dc48..a06cd91158a 100644 --- a/mathcore/test/binarySearchTime.cxx +++ b/mathcore/test/binarySearchTime.cxx @@ -37,28 +37,33 @@ template <typename T> void testBinarySearch(const int n, double* tTMath, double* std::sort(k.begin(), k.end()); + int s = 0; t.Start(); for (int j = 0; j < npass; ++j) { for ( T elem = 0; elem < maxint; ++elem ) { - /*Long_t index = */TMath::BinarySearch((Long_t) n, &k[0], elem); + Long_t index = TMath::BinarySearch((Long_t) n, &k[0], elem); + s += index; } } t.Stop(); *tTMath = t.RealTime(); cout << "TMath::BinarySearch time :\t " << t.RealTime() << endl; + cout << "sum " << s << endl; - + s = 0; t.Start(); for (int j = 0; j < npass; ++j) { for ( T elem = 0; elem < maxint; ++elem ) { T* pind; pind = std::lower_bound(&k[0], &k[n], elem); - //Long_t index2 = ((*pind == elem)? (pind - &k[0]): ( pind - &k[0] - 1)); + Long_t index2 = ((*pind == elem)? (pind - &k[0]): ( pind - &k[0] - 1)); + s+= index2; } } t.Stop(); *tStd = t.RealTime(); std::cout << "std::binary_search time:\t " << t.RealTime() << '\n' << std::endl; + cout << "sum " << s << endl; } -- GitLab