diff --git a/hist/hist/src/TF1.cxx b/hist/hist/src/TF1.cxx index 6964209abdacc..c09426a879d50 100644 --- a/hist/hist/src/TF1.cxx +++ b/hist/hist/src/TF1.cxx @@ -2690,7 +2690,7 @@ void TF1::Print(Option_t *option) const if (fFunctor) printf("Compiled based function: %s based on a functor object. Ndim = %d, Npar = %d\n", GetName(), GetNpar(), GetNdim()); else { - printf("Function based on a list of points from a compiled based function: %s. Ndim = %d, Npar = %d, Npx = %d\n", GetName(), GetNpar(), GetNdim(), fSave.size()); + printf("Function based on a list of points from a compiled based function: %s. Ndim = %d, Npar = %d, Npx = %zu\n", GetName(), GetNpar(), GetNdim(), fSave.size()); if (fSave.empty()) Warning("Print", "Function %s is based on a list of points but list is empty", GetName()); } diff --git a/math/mathcore/inc/Fit/FitConfig.h b/math/mathcore/inc/Fit/FitConfig.h index 6ae6d766d46af..698d81cfb43f1 100644 --- a/math/mathcore/inc/Fit/FitConfig.h +++ b/math/mathcore/inc/Fit/FitConfig.h @@ -103,10 +103,34 @@ class FitConfig { set the parameter settings from a model function. Create always new parameter setting list from a given model function */ - void CreateParamsSettings(const ROOT::Math::IParamMultiFunction & func); -#ifdef R__HAS_VECCORE - void CreateParamsSettings(const ROOT::Math::IParamMultiFunctionTempl & func); + template + void CreateParamsSettings(const ROOT::Math::IParamMultiFunctionTempl &func) { + // initialize from model function + // set the parameters values from the function + unsigned int npar = func.NPar(); + const double *begin = func.Parameters(); + if (begin == 0) { + fSettings = std::vector(npar); + return; + } + + fSettings.clear(); + fSettings.reserve(npar); + const double *end = begin + npar; + unsigned int i = 0; + for (const double *ipar = begin; ipar != end; ++ipar) { + double val = *ipar; + double step = 0.3 * std::fabs(val); // step size is 30% of par value + // double step = 2.0*std::fabs(val); // step size is 30% of par value + if (val == 0) step = 0.3; + + fSettings.push_back(ParameterSettings(func.ParameterName(i), val, step)); +#ifdef DEBUG + std::cout << "FitConfig: add parameter " << func.ParameterName(i) << " val = " << val << std::endl; #endif + i++; + } + } /** set the parameter settings from number of parameters and a vector of values and optionally step values. If there are not existing or number of parameters does not match existing one, create a new parameter setting list. diff --git a/math/mathcore/inc/Fit/FitUtil.h b/math/mathcore/inc/Fit/FitUtil.h index c6f208e1d91a5..5c72a66c01a38 100644 --- a/math/mathcore/inc/Fit/FitUtil.h +++ b/math/mathcore/inc/Fit/FitUtil.h @@ -223,7 +223,7 @@ namespace FitUtil { vecCore::Load(xx, x); const double *p0 = p; auto res = (*f)( &xx, (const double *)p0); - return res[0]; + return vecCore::Get(res, 0); } #endif @@ -274,8 +274,10 @@ namespace FitUtil { return also nPoints as the effective number of used points in the LogL evaluation */ void EvaluateLogLGradient(const IModelFunction & func, const UnBinData & data, const double * x, double * grad, unsigned int & nPoints); + #ifdef R__HAS_VECCORE - void EvaluateLogLGradient(const IModelFunctionTempl &, const UnBinData &, const double *, double *, unsigned int & ) ; + template ::value)>> + void EvaluateLogLGradient(const IModelFunctionTempl &, const UnBinData &, const double *, double *, unsigned int & ) {} #endif /** @@ -283,7 +285,8 @@ namespace FitUtil { return also nPoints as the effective number of used points in the LogL evaluation By default is extended, pass extedend to false if want to be not extended (MultiNomial) */ - double EvaluatePoissonLogL(const IModelFunction & func, const BinData & data, const double * x, int iWeight, bool extended, unsigned int & nPoints, const unsigned int &executionPolicy, unsigned nChunks = 0); + double EvaluatePoissonLogL(const IModelFunction &func, const BinData &data, const double *x, int iWeight, bool extended, + unsigned int &nPoints, const unsigned int &executionPolicy, unsigned nChunks = 0); /** evaluate the Poisson LogL given a model function and the data at the point x. @@ -308,9 +311,20 @@ namespace FitUtil { is used */ double EvaluatePdf(const IModelFunction & func, const UnBinData & data, const double * x, unsigned int ipoint, double * g = 0); + #ifdef R__HAS_VECCORE - double EvaluatePdf(const IModelFunctionTempl & func, const UnBinData & data, const double * p, unsigned int i, double *); + template ::value)>> + double EvaluatePdf(const IModelFunctionTempl &func, const UnBinData &data, const double *p, unsigned int i, double *) { + // evaluate the pdf contribution to the generic logl function in case of bin data + // return actually the log of the pdf and its derivatives + // func.SetParameters(p); + const auto x = vecCore::FromPtr(data.GetCoordComponent(i, 0)); + auto fval = func(&x, p); + auto logPdf = ROOT::Math::Util::EvalLog(fval); + return vecCore::Get(logPdf, 0); + } #endif + /** evaluate the pdf contribution to the Poisson LogL given a model function and the BinPoint data. If the pointer g is not null evaluate also the gradient of the Poisson pdf. @@ -362,7 +376,7 @@ namespace FitUtil { auto invErrorptr = (invError != nullptr) ? invError : &ones.front(); vecCore::Load(invErrorVec, invErrorptr); - const T * x; + const T *x; if(data.NDim() > 1) { std::vector xc; xc.resize(data.NDim()); @@ -480,19 +494,20 @@ namespace FitUtil { if(data.NDim() > 1) { std::vector x(data.NDim()); for (unsigned int j = 0; j < data.NDim(); ++j) - x[j] = *data.GetCoordComponent(i, j); + vecCore::Load(x[j], data.GetCoordComponent(i, j)); #ifdef USE_PARAMCACHE - fval = func ( x.data() ); + fval = func(x.data()); #else - fval = func ( x.data(), p ); + fval = func(x.data(), p); #endif - // one -dim case + // one -dim case } else { - const auto x = data.GetCoordComponent(i, 0); + T x; + vecCore::Load(x, data.GetCoordComponent(i, 0)); #ifdef USE_PARAMCACHE - fval = func ( x ); + fval = func(&x); #else - fval = func ( x, p ); + fval = func(&x, p); #endif } @@ -618,14 +633,14 @@ namespace FitUtil { // reset the number of fitting data points // nPoints = n; - // std::cout<<", n: "< &func, const BinData & data, const double * p, int iWeight, - bool extended, unsigned int &nPoints, const unsigned int &executionPolicy, unsigned nChunks = 0) + static double EvalPoissonLogL(const IModelFunctionTempl &func, const BinData &data, const double *p, int iWeight, bool extended, + unsigned int &nPoints, const unsigned int &executionPolicy, unsigned nChunks = 0) { // evaluate the Poisson Log Likelihood // for binned likelihood fits @@ -651,7 +666,8 @@ namespace FitUtil { // get fit option and check case of using integral of bins const DataOptions &fitOpt = data.Opt(); if (fitOpt.fExpErrors || fitOpt.fIntegral) - Error("FitUtil::EvaluateChi2", "The vectorized implementation doesn't support Integrals or BinVolume\n. Aborting operation."); + Error("FitUtil::EvaluateChi2", + "The vectorized implementation doesn't support Integrals or BinVolume\n. Aborting operation."); bool useW2 = (iWeight == 2); auto mapFunction = [&](unsigned int i) { @@ -659,22 +675,23 @@ namespace FitUtil { vecCore::Load(y, data.ValuePtr(i * vecSize)); T fval{}; - if(data.NDim() > 1) { + if (data.NDim() > 1) { std::vector x(data.NDim()); for (unsigned int j = 0; j < data.NDim(); ++j) - x[j] = *data.GetCoordComponent(i, j); + vecCore::Load(x[j], data.GetCoordComponent(i, j)); #ifdef USE_PARAMCACHE - fval = func ( x.data() ); + fval = func(x.data()); #else - fval = func ( x.data(), p ); + fval = func(x.data(), p); #endif - // one -dim case + // one -dim case } else { - const auto x = data.GetCoordComponent(i, 0); + T x; + vecCore::Load(x, data.GetCoordComponent(i, 0)); #ifdef USE_PARAMCACHE - fval = func ( x ); + fval = func(&x); #else - fval = func ( x, p ); + fval = func(&x, p); #endif } @@ -683,7 +700,7 @@ namespace FitUtil { auto m = vecCore::Mask_v(fval < 0.0); vecCore::MaskedAssign(fval, m, 0.0); - T nloglike{}; // negative loglikelihood + T nloglike{}; // negative loglikelihood if (useW2) { // apply weight correction . Effective weight is error^2/ y @@ -717,18 +734,16 @@ namespace FitUtil { // this is needed for Poisson likelihood (which are extened and not for multinomial) // the formula below include constant term due to likelihood of saturated model (f(x) = y) // (same formula as in Baker-Cousins paper, page 439 except a factor of 2 - if (extended) nloglike = fval - y ; + if (extended) nloglike = fval - y; - vecCore::MaskedAssign(nloglike, y > 0, nloglike + y * (ROOT::Math::Util::EvalLog(y) - - ROOT::Math::Util::EvalLog(fval))); + vecCore::MaskedAssign( + nloglike, y > 0, nloglike + y * (ROOT::Math::Util::EvalLog(y) - ROOT::Math::Util::EvalLog(fval))); } return nloglike; }; - auto redFunction = [](const std::vector &objs) { - return std::accumulate(objs.begin(), objs.end(), T{}); - }; + auto redFunction = [](const std::vector &objs) { return std::accumulate(objs.begin(), objs.end(), T{}); }; T res{}; if (executionPolicy == ROOT::Fit::kSerial) { @@ -745,7 +760,9 @@ namespace FitUtil { // ROOT::TProcessExecutor pool; // res = pool.MapReduce(mapFunction, ROOT::TSeq(0, data.Size()/vecSize), redFunction); } else { - Error("FitUtil::Evaluate::EvalPoissonLogL", "Execution policy unknown. Avalaible choices:\n 0: Serial (default)\n 1: MultiThread (requires IMT)\n"); + Error( + "FitUtil::Evaluate::EvalPoissonLogL", + "Execution policy unknown. Avalaible choices:\n 0: Serial (default)\n 1: MultiThread (requires IMT)\n"); } return vecCore::Reduce(res); @@ -779,14 +796,16 @@ namespace FitUtil { // optionally the integral of function in the bin is used return FitUtil::EvaluateChi2(func, data, p, nPoints, executionPolicy, nChunks); } + static double EvalLogL(const IModelFunctionTempl &func, const UnBinData & data, const double * p, int iWeight, bool extended, unsigned int &nPoints, const unsigned int &executionPolicy, unsigned nChunks = 0) { return FitUtil::EvaluateLogL(func, data, p, iWeight, extended, nPoints, executionPolicy, nChunks); } - static double EvalPoissonLogL(const IModelFunctionTempl & func, const BinData & data, const double * p, int iWeight, bool extended, - unsigned int & nPoints, const unsigned int &executionPolicy, unsigned nChunks = 0 ) { + static double EvalPoissonLogL(const IModelFunctionTempl &func, const BinData &data, const double *p, int iWeight, bool extended, unsigned int &nPoints, + const unsigned int &executionPolicy, unsigned nChunks = 0) + { return FitUtil::EvaluatePoissonLogL(func, data, p, iWeight, extended, nPoints, executionPolicy, nChunks); } diff --git a/math/mathcore/inc/Fit/Fitter.h b/math/mathcore/inc/Fit/Fitter.h index ce5a6e3a8feb5..fdf3209d2ba83 100644 --- a/math/mathcore/inc/Fit/Fitter.h +++ b/math/mathcore/inc/Fit/Fitter.h @@ -27,7 +27,7 @@ Classes used for fitting (regression analysis) and estimation of parameter value #include "Fit/FitConfig.h" #include "Fit/FitExecutionPolicy.h" #include "Fit/FitResult.h" -#include "Math/IParamFunctionfwd.h" +#include "Math/IParamFunction.h" #include namespace ROOT { @@ -164,11 +164,14 @@ class Fitter { /** Binned Likelihood fit. Default is extended */ - bool LikelihoodFit(const BinData & data, bool extended = true, ROOT::Fit::ExecutionPolicy executionPolicy = ROOT::Fit::kSerial) { + bool LikelihoodFit(const BinData &data, bool extended = true, + ROOT::Fit::ExecutionPolicy executionPolicy = ROOT::Fit::kSerial) { SetData(data); return DoBinnedLikelihoodFit(extended, executionPolicy); } - bool LikelihoodFit(const std::shared_ptr & data, bool extended = true, ROOT::Fit::ExecutionPolicy executionPolicy = ROOT::Fit::kSerial) { + + bool LikelihoodFit(const std::shared_ptr &data, bool extended = true, + ROOT::Fit::ExecutionPolicy executionPolicy = ROOT::Fit::kSerial) { SetData(data); return DoBinnedLikelihoodFit(extended, executionPolicy); } @@ -324,7 +327,8 @@ class Fitter { Set the fitted function (model function) from a vectorized parametric function interface */ #ifdef R__HAS_VECCORE - void SetFunction(const IModelFunction_v & func); + template ::value)>> + void SetFunction(const IModelFunction_v &func); #endif /** Set the fitted function from a parametric 1D function interface @@ -425,7 +429,7 @@ class Fitter { /// least square fit bool DoLeastSquareFit(ROOT::Fit::ExecutionPolicy executionPolicy = ROOT::Fit::kSerial); /// binned likelihood fit - bool DoBinnedLikelihoodFit( bool extended = true, ROOT::Fit::ExecutionPolicy executionPolicy = ROOT::Fit::kSerial); + bool DoBinnedLikelihoodFit(bool extended = true, ROOT::Fit::ExecutionPolicy executionPolicy = ROOT::Fit::kSerial); /// un-binned likelihood fit bool DoUnbinnedLikelihoodFit( bool extended = false, ROOT::Fit::ExecutionPolicy executionPolicy = ROOT::Fit::kSerial); /// linear least square fit @@ -516,6 +520,21 @@ bool Fitter::GetDataFromFCN() { } } +#ifdef R__HAS_VECCORE +template +void Fitter::SetFunction(const IModelFunction_v &func) +{ + // set the fit model function (clone the given one and keep a copy ) + // std::cout << "set a non-grad function" << std::endl; + fUseGradient = false; + fFunc_v = std::shared_ptr(dynamic_cast(func.Clone())); + assert(fFunc_v); + + // creates the parameter settings + fConfig.CreateParamsSettings(*fFunc_v); + fFunc.reset(); +} +#endif } // end namespace Fit diff --git a/math/mathcore/inc/Fit/LogLikelihoodFCN.h b/math/mathcore/inc/Fit/LogLikelihoodFCN.h index 5e462ddb9c078..e14015e7b984f 100644 --- a/math/mathcore/inc/Fit/LogLikelihoodFCN.h +++ b/math/mathcore/inc/Fit/LogLikelihoodFCN.h @@ -178,8 +178,7 @@ class LogLikelihoodFCN : public BasicFCN { mutable std::vector fGrad; // for derivatives - ROOT::Fit::ExecutionPolicy fExecutionPolicy; //Execution policy - + ROOT::Fit::ExecutionPolicy fExecutionPolicy; // Execution policy }; // define useful typedef's // using LogLikelihoodFunction_v = LogLikelihoodFCN>; diff --git a/math/mathcore/inc/Fit/PoissonLikelihoodFCN.h b/math/mathcore/inc/Fit/PoissonLikelihoodFCN.h index 49ac1bd6a8848..e67665d9bb207 100644 --- a/math/mathcore/inc/Fit/PoissonLikelihoodFCN.h +++ b/math/mathcore/inc/Fit/PoissonLikelihoodFCN.h @@ -162,9 +162,11 @@ class PoissonLikelihoodFCN : public BasicFCN virtual double DoEval (const double * x) const { this->UpdateNCalls(); #ifdef R__HAS_VECCORE - return FitUtil::Evaluate::EvalPoissonLogL(BaseFCN::ModelFunction(), BaseFCN::Data(), x, fWeight, fIsExtended, fNEffPoints, fExecutionPolicy); + return FitUtil::Evaluate::EvalPoissonLogL(BaseFCN::ModelFunction(), BaseFCN::Data(), x, fWeight, fIsExtended, + fNEffPoints, fExecutionPolicy); #else - return FitUtil::EvaluatePoissonLogL(BaseFCN::ModelFunction(), BaseFCN::Data(), x, fWeight, fIsExtended, fNEffPoints, fExecutionPolicy); + return FitUtil::EvaluatePoissonLogL(BaseFCN::ModelFunction(), BaseFCN::Data(), x, fWeight, fIsExtended, + fNEffPoints, fExecutionPolicy); #endif } @@ -184,7 +186,7 @@ class PoissonLikelihoodFCN : public BasicFCN mutable std::vector fGrad; // for derivatives - ROOT::Fit::ExecutionPolicy fExecutionPolicy; //Execution policy + ROOT::Fit::ExecutionPolicy fExecutionPolicy; // Execution policy }; // define useful typedef's diff --git a/math/mathcore/src/FitConfig.cxx b/math/mathcore/src/FitConfig.cxx index a6e89cb394415..84b2cc592cee6 100644 --- a/math/mathcore/src/FitConfig.cxx +++ b/math/mathcore/src/FitConfig.cxx @@ -171,67 +171,6 @@ void FitConfig::SetParamsSettings(unsigned int npar, const double *params, const } } -void FitConfig::CreateParamsSettings(const ROOT::Math::IParamMultiFunction & func) { - // initialize from model function - // set the parameters values from the function - unsigned int npar = func.NPar(); - const double * begin = func.Parameters(); - if (begin == 0) { - fSettings = std::vector(npar); - return; - } - - fSettings.clear(); - fSettings.reserve(npar); - const double * end = begin+npar; - unsigned int i = 0; - for (const double * ipar = begin; ipar != end; ++ipar) { - double val = *ipar; - double step = 0.3*std::fabs(val); // step size is 30% of par value - //double step = 2.0*std::fabs(val); // step size is 30% of par value - if (val == 0) step = 0.3; - - fSettings.push_back( ParameterSettings(func.ParameterName(i), val, step ) ); -#ifdef DEBUG - std::cout << "FitConfig: add parameter " << func.ParameterName(i) << " val = " << val << std::endl; -#endif - i++; - } - -} - -#ifdef R__HAS_VECCORE -void FitConfig::CreateParamsSettings(const ROOT::Math::IParamMultiFunctionTempl & func){ - - // initialize from model function - // set the parameters values from the function - unsigned int npar = func.NPar(); - const double * begin = func.Parameters(); - if (begin == 0) { - fSettings = std::vector(npar); - return; - } - - fSettings.clear(); - fSettings.reserve(npar); - const double * end = begin+npar; - unsigned int i = 0; - for (const double * ipar = begin; ipar != end; ++ipar) { - double val = *ipar; - double step = 0.3*std::fabs(val); // step size is 30% of par value - //double step = 2.0*std::fabs(val); // step size is 30% of par value - if (val == 0) step = 0.3; - - fSettings.push_back( ParameterSettings(func.ParameterName(i), val, step ) ); -#ifdef DEBUG - std::cout << "FitConfig: add parameter " << func.ParameterName(i) << " val = " << val << std::endl; -#endif - i++; - } - -} -#endif - ROOT::Math::Minimizer * FitConfig::CreateMinimizer() { // create minimizer according to the chosen configuration using the // plug-in manager diff --git a/math/mathcore/src/FitUtil.cxx b/math/mathcore/src/FitUtil.cxx index 1db2d8ea1f048..d7ffe9e0c368d 100644 --- a/math/mathcore/src/FitUtil.cxx +++ b/math/mathcore/src/FitUtil.cxx @@ -754,21 +754,6 @@ void FitUtil::EvaluateChi2Gradient(const IModelFunction & f, const BinData & dat // utility function used by the likelihoods // for LogLikelihood functions -#ifdef R__HAS_VECCORE -double FitUtil::EvaluatePdf(const IModelFunctionTempl & func, const UnBinData & data, const double * p, unsigned int i, double *) { - // evaluate the pdf contribution to the generic logl function in case of bin data - // return actually the log of the pdf and its derivatives - - - //func.SetParameters(p); - - - const auto x = vecCore::FromPtr(data.GetCoordComponent(i,0)); - auto fval = func (&x, p); - auto logPdf = ROOT::Math::Util::EvalLog(fval); - return logPdf[0]; -} -#endif double FitUtil::EvaluatePdf(const IModelFunction & func, const UnBinData & data, const double * p, unsigned int i, double * g) { // evaluate the pdf contribution to the generic logl function in case of bin data @@ -1000,11 +985,6 @@ nPoints = 0; return -logl; } -#ifdef R__HAS_VECCORE -void FitUtil::EvaluateLogLGradient(const IModelFunctionTempl &, const UnBinData &, const double * , double *, unsigned int & ) { -} -#endif - void FitUtil::EvaluateLogLGradient(const IModelFunction & f, const UnBinData & data, const double * p, double * grad, unsigned int & ) { // evaluate the gradient of the log likelihood function @@ -1151,8 +1131,7 @@ double FitUtil::EvaluatePoissonBinPdf(const IModelFunction & func, const BinData } double FitUtil::EvaluatePoissonLogL(const IModelFunction &func, const BinData &data, const double *p, int iWeight, bool extended, - unsigned int &nPoints, const unsigned int &executionPolicy, unsigned nChunks) -{ + unsigned int &nPoints, const unsigned int &executionPolicy, unsigned nChunks) { // evaluate the Poisson Log Likelihood // for binned likelihood fits // this is Sum ( f(x_i) - y_i * log( f (x_i) ) ) @@ -1248,7 +1227,7 @@ double FitUtil::EvaluatePoissonLogL(const IModelFunction &func, const BinData &d } else { // calculate integral (normalized by bin volume) // need to set function and parameters here in case loop is parallelized - fval = igEval(x, data.BinUpEdge(i)) ; + fval = igEval(x, data.BinUpEdge(i)); } if (useBinVolume) fval *= binVolume; @@ -1274,7 +1253,7 @@ double FitUtil::EvaluatePoissonLogL(const IModelFunction &func, const BinData &d // negative values of fval fval = std::max(fval, 0.0); - double nloglike = 0; // negative loglikelihood + double nloglike = 0; // negative loglikelihood if (useW2) { // apply weight correction . Effective weight is error^2/ y // and expected events in bins is fval/weight @@ -1303,10 +1282,10 @@ double FitUtil::EvaluatePoissonLogL(const IModelFunction &func, const BinData &d // this is needed for Poisson likelihood (which are extened and not for multinomial) // the formula below include constant term due to likelihood of saturated model (f(x) = y) // (same formula as in Baker-Cousins paper, page 439 except a factor of 2 - if (extended) nloglike = fval - y ; + if (extended) nloglike = fval - y; if (y > 0) { - nloglike += y * (ROOT::Math::Util::EvalLog(y) - ROOT::Math::Util::EvalLog(fval)); + nloglike += y * (ROOT::Math::Util::EvalLog(y) - ROOT::Math::Util::EvalLog(fval)); nPoints++; } } @@ -1344,11 +1323,12 @@ double FitUtil::EvaluatePoissonLogL(const IModelFunction &func, const BinData &d ROOT::TThreadExecutor pool; res = pool.MapReduce(mapFunction, ROOT::TSeq(0, n), redFunction, chunks); #endif -// } else if(executionPolicy == ROOT::Fit::kMultitProcess){ + // } else if(executionPolicy == ROOT::Fit::kMultitProcess){ // ROOT::TProcessExecutor pool; // res = pool.MapReduce(mapFunction, ROOT::TSeq(0, n), redFunction); } else { - Error("FitUtil::EvaluatePoissonLogL", "Execution policy unknown. Avalaible choices:\n 0: Serial (default)\n 1: MultiThread (requires IMT)\n"); + Error("FitUtil::EvaluatePoissonLogL", + "Execution policy unknown. Avalaible choices:\n 0: Serial (default)\n 1: MultiThread (requires IMT)\n"); } #ifdef DEBUG diff --git a/math/mathcore/src/Fitter.cxx b/math/mathcore/src/Fitter.cxx index bd64581c5cea6..1d2bd47611f33 100644 --- a/math/mathcore/src/Fitter.cxx +++ b/math/mathcore/src/Fitter.cxx @@ -128,21 +128,6 @@ void Fitter::SetFunction(const IModelFunction & func, bool useGradient) fFunc_v.reset(); } -#ifdef R__HAS_VECCORE -void Fitter::SetFunction(const IModelFunction_v & func) -{ - // set the fit model function (clone the given one and keep a copy ) - //std::cout << "set a non-grad function" << std::endl; - fUseGradient = false; - fFunc_v = std::shared_ptr(dynamic_cast(func.Clone() ) ); - assert(fFunc_v); - - // creates the parameter settings - fConfig.CreateParamsSettings(*fFunc_v); - fFunc.reset(); -} -#endif - void Fitter::SetFunction(const IModel1DFunction & func, bool useGradient) { fUseGradient = useGradient; @@ -426,7 +411,7 @@ bool Fitter::DoBinnedLikelihoodFit(bool extended, ROOT::Fit::ExecutionPolicy exe if (!fUseGradient) { // do minimization without using the gradient - PoissonLikelihoodFCN logl(data,fFunc, useWeight, extended, executionPolicy); + PoissonLikelihoodFCN logl(data, fFunc, useWeight, extended, executionPolicy); fFitType = logl.Type(); // do minimization if (!DoMinimization (logl, &chi2) ) return false; @@ -449,7 +434,7 @@ bool Fitter::DoBinnedLikelihoodFit(bool extended, ROOT::Fit::ExecutionPolicy exe if (!extended) { MATH_WARN_MSG("Fitter::DoBinnedLikelihoodFit","Not-extended binned fit with gradient not yet supported - do an extended fit"); } - PoissonLikelihoodFCN logl(data,gradFun, useWeight, true, executionPolicy); + PoissonLikelihoodFCN logl(data, gradFun, useWeight, true, executionPolicy); fFitType = logl.Type(); // do minimization if (!DoMinimization (logl, &chi2) ) return false; diff --git a/math/mathcore/test/fit/testBinnedFitExecPolicy.cxx b/math/mathcore/test/fit/testBinnedFitExecPolicy.cxx index 3cd976e69b5dd..daa068d0671a8 100644 --- a/math/mathcore/test/fit/testBinnedFitExecPolicy.cxx +++ b/math/mathcore/test/fit/testBinnedFitExecPolicy.cxx @@ -15,37 +15,36 @@ int compareResult(double v1, double v2, std::string s = "", double tol = 0.01) return -1; } -template +template T func(const T *data, const double *params) { return params[0] * exp(-(*data + (-130.)) * (*data + (-130.)) / 2) + - params[1] * exp(-(params[2] * (*data * (0.01)) - - params[3] * ((*data) * (0.01)) * ((*data) * (0.01)))); + params[1] * exp(-(params[2] * (*data * (0.01)) - params[3] * ((*data) * (0.01)) * ((*data) * (0.01)))); } int main() { TF1 *f = new TF1("fvCore", func, 100, 200, 4); f->SetParameters(1, 1000, 7.5, 1.5); - TH1D h1f("h1f", "Test random numbers", 128000 , 100, 200); + TH1D h1f("h1f", "Test random numbers", 128000, 100, 200); gRandom->SetSeed(1); h1f.FillRandom("fvCore", 1000000); auto r1 = h1f.Fit(f, "S"); - if ((Int_t) r1 != 0) { + if ((Int_t)r1 != 0) { Error("testChi2ExecPolicy", "Sequential Chi2 Fit failed!"); return -1; } auto rL1 = h1f.Fit(f, "S L"); - if ((Int_t) r1 != 0) { + if ((Int_t)r1 != 0) { Error("testChi2ExecPolicy", "Sequential Binned Likelihood Fit failed!"); return -1; } #ifdef R__USE_IMT auto r2 = h1f.Fit(f, "MULTITHREAD S"); - if ((Int_t) r2 != 0) { + if ((Int_t)r2 != 0) { Error("testChi2ExecPolicy", "Multithreaded Chi2 Fit failed!"); return -1; } else { @@ -53,7 +52,7 @@ int main() } auto rL2 = h1f.Fit(f, "MULTITHREAD S L"); - if ((Int_t) rL2 != 0) { + if ((Int_t)rL2 != 0) { Error("testChi2ExecPolicy", "Multithreaded Binned Likelihood Fit failed!"); return -1; } else { @@ -65,7 +64,7 @@ int main() TF1 *fvecCore = new TF1("fvCore", func, 100, 200, 4); fvecCore->SetParameters(1, 1000, 7.5, 1.5); auto r3 = h1f.Fit(fvecCore, "S"); - if ((Int_t) r3 != 0) { + if ((Int_t)r3 != 0) { Error("testChi2ExecPolicy", "Vectorized Chi2 Fit failed!"); return -1; } else { @@ -73,7 +72,7 @@ int main() } auto rL3 = h1f.Fit(fvecCore, "S L"); - if ((Int_t) rL3 != 0) { + if ((Int_t)rL3 != 0) { Error("testChi2ExecPolicy", "Vectorized Binned Likelihood Fit failed!"); return -1; } else { @@ -82,7 +81,7 @@ int main() #ifdef R__USE_IMT auto r4 = h1f.Fit(fvecCore, "MULTITHREAD S"); - if ((Int_t) r4 != 0) { + if ((Int_t)r4 != 0) { Error("testChi2ExecPolicy", "Multithreaded vectorized Fit failed!"); return -1; } else { @@ -90,7 +89,7 @@ int main() } auto rL4 = h1f.Fit(fvecCore, "MULTITHREAD S L"); - if ((Int_t) rL4 != 0) { + if ((Int_t)rL4 != 0) { Error("testChi2ExecPolicy", "Multithreaded Binned Likelihood vectorized Fit failed!"); return -1; } else {