116 const std::vector<double> & minpar =
fFitter->Result().Parameters();
117 assert (npar == (
int) minpar.size() );
120 for (
int i =0; i < npar; ++i) {
121 diff += std::abs( params[i] - minpar[i] );
125 if (diff > s * 1.
E-12 )
Warning(
"Chisquare",
"given parameter values are not at minimum - chi2 at minimum is returned");
126 return fFitter->Result().Chi2();
141 std::cout<<
"Execute command= "<<command<<std::endl;
153 Error(
"ExecuteCommand",
"FCN must set before executing this command");
159 return (ret) ? 0 : -1;
167 Error(
"ExecuteCommand",
"FCN must set before executing this command");
171 return (ret) ? 0 : -1;
177 Error(
"ExecuteCommand",
"FCN must set before executing this command");
183 return (ret) ? 0 : -1;
189 Error(
"ExecuteCommand",
"FCN must set before executing this command");
195 return (ret) ? 0 : -1;
198 else if (scommand.
Contains(
"MINO")) {
200 if (
fFitter->Config().MinosErrors() )
return 0;
203 Error(
"ExecuteCommand",
"FCN must set before executing this command");
207 fFitter->Config().SetMinosErrors(
true);
212 return (ret) ? 0 : -1;
216 else if (scommand.
Contains(
"HES")) {
218 if (
fFitter->Config().ParabErrors() )
return 0;
221 Error(
"ExecuteCommand",
"FCN must set before executing this command");
226 fFitter->Config().SetParabErrors(
true);
229 return (ret) ? 0 : -1;
233 else if (scommand.
Contains(
"FIX")) {
234 for(
int i = 0; i < nargs; i++) {
240 else if (scommand.
Contains(
"SET LIM")) {
242 Error(
"ExecuteCommand",
"Invalid parameters given in SET LIMIT");
245 int ipar = int(args[0]);
247 double low = args[1];
249 fFitter->Config().ParSettings(ipar).SetLimits(low,up);
253 else if (scommand.
Contains(
"SET PRIN")) {
254 if (nargs < 1)
return -1;
255 fFitter->Config().MinimizerOptions().SetPrintLevel(
int(args[0]) );
259 else if (scommand.
Contains(
"SET ERR")) {
260 if (nargs < 1)
return -1;
261 fFitter->Config().MinimizerOptions().SetPrintLevel(
int( args[0]) );
265 else if (scommand.
Contains(
"SET STR")) {
266 if (nargs < 1)
return -1;
267 fFitter->Config().MinimizerOptions().SetStrategy(
int(args[0]) );
271 else if (scommand.
Contains(
"SET GRA")) {
277 else if (scommand.
Contains(
"SET NOW")) {
283 else if (scommand.
Contains(
"CALL FCN")) {
286 if (nargs < 1 ||
fFCN == 0 )
return -1;
289 std::vector<double> params(npar);
290 for (
int i = 0; i < npar; ++i)
294 (*fFCN)(npar, 0, fval, ¶ms[0],int(args[0]) ) ;
299 Error(
"ExecuteCommand",
"Invalid or not supported command given %s",command);
308 int nps =
fFitter->Config().ParamsSettings().size();
309 if (ipar < 0 || ipar >= nps ) {
311 Error(
"ValidParameterIndex",
"%s",msg.c_str());
322 fFitter->Config().ParSettings(ipar).Fix();
338 if (!
fFitter->Result().IsValid()) {
339 Error(
"GetConfidenceIntervals",
"Cannot compute confidence intervals with an invalide fit result");
343 fFitter->Result().GetConfidenceIntervals(n,ndim,1,x,ci,cl);
373 if (!
fFitter->Result().IsValid() ) {
374 Error(
"GetConfidenceIntervals",
"Cannot compute confidence intervals with an invalide fit result");
382 Error(
"GetConfidenceIntervals",
"Cannot compute confidence intervals without a fitting object");
388 TH1 *
h1 =
dynamic_cast<TH1*
>(fitobj);
395 Error(
"GetConfidenceIntervals",
"Invalid object passed for storing confidence level data, must be a TGraphErrors or a TH1");
401 Error(
"GetConfidenceIntervals",
"Invalid object passed for storing confidence level data, must be a TGraph2DErrors or a TH2");
407 Error(
"GetConfidenceIntervals",
"Invalid object passed for storing confidence level data, must be a TH3");
426 unsigned int n = data.
Size();
428 std::vector<double> ci( n );
430 fFitter->Result().GetConfidenceIntervals(data,&ci[0],cl);
436 for (
unsigned int i = 0; i <
n; ++i) {
437 const double *
x = data.
Coords(i);
438 double y = (*func)(
x );
453 TH1 *
h1 =
dynamic_cast<TH1 *
> (obj);
456 if (datadim == 1) ibin = h1->
FindBin(*x);
457 if (datadim == 2) ibin = h1->
FindBin(x[0],x[1]);
458 if (datadim == 3) ibin = h1->
FindBin(x[0],x[1],x[2]);
474 if (
fCovar.size() != nfreepar*nfreepar )
475 fCovar.resize(nfreepar*nfreepar);
477 if (!
fFitter->Result().IsValid() ) {
478 Warning(
"GetCovarianceMatrix",
"Invalid fit result");
483 for (
unsigned int i = 0; i < ntotpar; ++i) {
484 if (
fFitter->Config().ParSettings(i).IsFixed() )
continue;
486 for (
unsigned int j = 0; j < ntotpar; ++j) {
487 if (
fFitter->Config().ParSettings(j).IsFixed() )
continue;
488 unsigned int index = nfreepar*l +
m;
489 assert(index <
fCovar.size() );
502 unsigned int np2 =
fCovar.size();
504 if ( np2 == 0 || np2 != npar *npar ) {
506 if (c == 0)
return 0;
508 return fCovar[i*npar + j];
519 Warning(
"GetErrors",
"Invalid fit result");
523 eparab = result.
Error(ipar);
534 return fFitter->Result().NTotalParameters();
538 return fFitter->Result().NFreeParameters();
545 if (
fFitter->Result().IsEmpty() ) {
549 return fFitter->Result().Error(ipar);
556 if (
fFitter->Result().IsEmpty() ) {
560 return fFitter->Result().Value(ipar);
570 const std::string & pname =
fFitter->Config().ParSettings(ipar).Name();
571 const char *
c = pname.c_str();
572 std::copy(c,c + pname.size(),
name);
574 if (
fFitter->Result().IsEmpty() ) {
575 value =
fFitter->Config().ParSettings(ipar).Value();
576 verr =
fFitter->Config().ParSettings(ipar).Value();
577 vlow =
fFitter->Config().ParSettings(ipar).LowerLimit();
578 vhigh =
fFitter->Config().ParSettings(ipar).UpperLimit();
582 value =
fFitter->Result().Value(ipar);
583 verr =
fFitter->Result().Error(ipar);
584 vlow =
fFitter->Result().LowerError(ipar);
585 vhigh =
fFitter->Result().UpperError(ipar);
597 return fFitter->Config().ParSettings(ipar).Name().c_str();
607 errdef =
fFitter->Config().MinimizerOptions().ErrorDef();
617 Warning(
"GetSumLog",
"Dummy method - returned 0");
628 return fFitter->Config().ParSettings(ipar).IsFixed();
636 if (
fFitter->GetMinimizer() &&
fFitter->Config().MinimizerType() ==
"Minuit")
637 fFitter->GetMinimizer()->PrintResults();
639 if (level > 0)
fFitter->Result().Print(std::cout);
640 if (level > 1)
fFitter->Result().PrintCovMatrix(std::cout);
650 fFitter->Config().ParSettings(ipar).Release();
658 Info(
"SetFitMethod",
"non supported method");
667 std::vector<ROOT::Fit::ParameterSettings> & parlist =
fFitter->Config().ParamsSettings();
668 if ( ipar >= (
int) parlist.size() ) parlist.resize(ipar+1);
670 if (verr == 0) ps.
Fix();
671 if (vlow < vhigh) ps.
SetLimits(vlow, vhigh);
695 if (
fFitter->Result().FittedFunction() != 0) {
718 if (fMinimizer == 0) {
719 Error(
"SetMinimizerFunction",
"cannot create minimizer %s",
fFitter->Config().MinimizerType().c_str() );
723 Error(
"SetMinimizerFunction",
"Object Function pointer is NULL");
771 Error(
"SetFCN",
"Not used anymore.");
799 int ndim =
fFitter->Config().ParamsSettings().size();
822 return fFitter->GetMinimizer();
841 if (!gr)
return false;
844 Error(
"Scan",
"Minimizer is not available - cannot scan before fitting");
848 unsigned int npoints = gr->
GetN();
854 if ((
int) npoints < gr->
GetN() ) gr->
Set(npoints);
894 if (!gr)
return false;
897 Error(
"Scan",
"Minimizer is not available - cannot scan before fitting");
902 double upScale =
fFitter->Config().MinimizerOptions().ErrorDef();
909 unsigned int npoints = gr->
GetN();
914 bool ret = minimizer->
Contour( ipar, jpar, npoints, gr->
GetX(), gr->
GetY());
915 if ((
int) npoints < gr->
GetN() ) gr->
Set(npoints);
unsigned int Size() const
return number of fit points
void DoSetDimension()
Private method to set dimension in objective function.
virtual Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0)
Return Global bin number corresponding to x,y,z.
virtual Double_t * GetCovarianceMatrix() const
Get the error matrix in a pointer to a NxN array.
virtual Double_t GetCovarianceMatrixElement(Int_t i, Int_t j) const
Get error matrix element (return all zero if matrix is not available)
virtual void PrintResults(Int_t level, Double_t amin) const
Print the fit result.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
void SetErrorDef(double up)
set scale for calculating the errors
virtual Int_t GetStats(Double_t &amin, Double_t &edm, Double_t &errdef, Int_t &nvpar, Int_t &nparx) const
Get fit statistical information.
virtual void Clear(Option_t *option="")
Clear resources for consecutive fits.
ROOT::Math::Minimizer * GetMinimizer() const
Return a pointer to the minimizer.
bool Contour(unsigned int ipar, unsigned int jpar, TGraph *gr, double confLevel=0.683)
Create a 2D contour around the minimum for the parameter ipar and jpar if a minimum does not exist or...
ROOT::Math::IMultiGenFunction * GetObjFunction() const
Return a pointer to the objective function (FCN) If fitting directly using TBackCompFitter the pointe...
double Error(unsigned int i) const
parameter error by index
virtual Int_t ExecuteCommand(const char *command, Double_t *args, Int_t nargs)
Execute the command (Fortran Minuit compatible interface)
double Edm() const
Expected distance from minimum.
virtual Int_t GetNumberFreeParameters() const
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
bool Scan(unsigned int ipar, TGraph *gr, double xmin=0, double xmax=0)
Scan parameter ipar between value of xmin and xmax A graph must be given which will be on return fill...
virtual void SetName(const char *name)
Set the name of the TNamed.
ROOT::Math::Minimizer * fMinimizer
pointer to fitter object
void ToUpper()
Change string to upper case.
LogLikelihoodFCN class for likelihood fits.
void ReCreateMinimizer()
Recreate a minimizer instance using the function and data set objective function in minimizers functi...
virtual void SetFCN(void(*fcn)(Int_t &, Double_t *, Double_t &f, Double_t *, Int_t))
Override setFCN to use the Adapter to Minuit2 FCN interface To set the address of the minimization fu...
Class describing the unbinned data sets (just x coordinates values) of any dimensions.
Backward compatible implementation of TVirtualFitter.
TFitResult * GetTFitResult() const
Return a new copy of the TFitResult object which needs to be deleted later by the user...
double MinFcnValue() const
Return value of the objective function (chi2 or likelihood) used in the fit.
unsigned int NTotalParameters() const
get total number of parameters
TMethodCall * GetMethodCall() const
static const char * GetDefaultFitter()
static: return the name of the default fitter
virtual Double_t GetParError(Int_t ipar) const
Parameter error.
void SetParamPtrs(void *paramArr, Int_t nparam=-1)
ParamArr is an array containing the function argument values.
virtual Int_t GetDimension() const
Double_t ChisquareQuantile(Double_t p, Double_t ndf)
Evaluate the quantiles of the chi-squared probability distribution function.
TBackCompFitter()
Constructor needed by TVirtualFitter interface.
Extends the ROOT::Fit::Result class with a TNamed inheritance providing easy possibility for I/O...
class evaluating the log likelihood for binned Poisson likelihood fits it is template to distinguish ...
virtual ~TBackCompFitter()
Destructor - delete the managed objects.
virtual void SetPointError(Int_t i, Double_t ex, Double_t ey, Double_t ez)
Set ex, ey and ez values for point number i.
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2, Minuit, GSL, etc..) Plug-in's exist in ROOT to be able to instantiate the derived classes like ROOT::Math::GSLMinimizer or ROOT::Math::Minuit2Minimizer via the plug-in manager.
virtual Int_t GetNumberTotalParameters() const
Number of total parameters.
virtual bool Contour(unsigned int ivar, unsigned int jvar, unsigned int &npoints, double *xi, double *xj)
find the contour points (xi, xj) of the function for parameter ivar and jvar around the minimum The c...
void Fix()
fix the parameter
double LowerError(unsigned int i) const
lower Minos error. If Minos has not run for parameter i return the parabolic error ...
Method or function calling interface.
virtual void SetBinError(Int_t bin, Double_t error)
See convention for numbering bins in TH1::GetBin.
virtual Bool_t IsFixed(Int_t ipar) const
Query if parameter ipar is fixed.
virtual void FixParameter(Int_t ipar)
Fix the parameter.
static void SetFitter(TVirtualFitter *fitter, Int_t maxpar=25)
Static function to set an alternative fitter.
virtual Int_t GetErrors(Int_t ipar, Double_t &eplus, Double_t &eminus, Double_t &eparab, Double_t &globcc) const
Get fit errors.
virtual void SetObjFunction(ROOT::Math::IMultiGenFunction *f)
Set the objective function for fitting Needed if fitting directly using TBackCompFitter class The cla...
virtual Foption_t GetFitOption() const
void InteractiveFCNm2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag)
Static function called when SetFCN is called in interactive mode.
Chi2FCN class for binnned fits using the least square methods.
ROOT::Math::IMultiGenFunction * fObjFunc
void FillData(BinData &dv, const TH1 *hist, TF1 *func=0)
fill the data vector from a TH1.
unsigned int NFreeParameters() const
get total number of free parameters
IParamFunction interface (abstract class) describing multi-dimensional parameteric functions It is a ...
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
const double * Coords(unsigned int ipoint) const
return a pointer to the coordinates data for the given fit point
static TVirtualFitter * GetFitter()
static: return the current Fitter
const DataOptions & Opt() const
access to options
virtual Double_t GetSumLog(Int_t i)
Sum of log (un-needed)
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
double UpperError(unsigned int i) const
upper Minos error. If Minos has not run for parameter i return the parabolic error ...
virtual Double_t Chisquare(Int_t npar, Double_t *params) const
Do chisquare calculations in case of likelihood fits Do evaluation a the minimum only.
virtual void ReleaseParameter(Int_t ipar)
Release a fit parameter.
class containg the result of the fit and all the related information (fitted parameter values...
std::shared_ptr< ROOT::Fit::FitData > fFitData
virtual void SetPoint(Int_t i, Double_t x, Double_t y, Double_t z)
Set x, y and z values for point number i.
bool IsValid() const
True if fit successful, otherwise false.
double func(double *x, double *p)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Mother of all ROOT objects.
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
std::string ToString(const T &val)
Utility function for conversion to strings.
std::vector< double > fCovar
void Execute(const char *, const char *, int *=0)
Execute method on this object with the given parameter string, e.g.
A Graph is a graphics object made of two arrays X and Y with npoints each.
virtual Int_t SetParameter(Int_t ipar, const char *parname, Double_t value, Double_t verr, Double_t vlow, Double_t vhigh)
Set (add) a new fit parameter passing initial value, step size (verr) and parameter limits if vlow > ...
A TGraphErrors is a TGraph with error bars.
void(* fFCN)(Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag)
std::shared_ptr< ROOT::Fit::Fitter > fFitter
data of the fit
virtual const char * GetParName(Int_t ipar) const
Return name of parameter ipar.
void SetLimits(double low, double up)
set a double side limit, if low == up the parameter is fixed if low > up the limits are removed ...
bool ValidParameterIndex(int ipar) const
Check if ipar is a valid parameter index.
virtual bool Scan(unsigned int ivar, unsigned int &nstep, double *x, double *y, double xmin=0, double xmax=0)
scan function minimum for variable i.
virtual void GetConfidenceIntervals(Int_t n, Int_t ndim, const Double_t *x, Double_t *ci, Double_t cl=0.95)
Computes point-by-point confidence intervals for the fitted function.
void SetDimension(int dim)
virtual void SetPointError(Double_t ex, Double_t ey)
Set ex and ey values for point pointed by the mouse.
Documentation for the abstract class IBaseFunctionMultiDim.
virtual void Set(Int_t n)
Set number of points in the graph Existing coordinates are preserved New coordinates above fNpoints a...
double GlobalCC(unsigned int i) const
parameter global correlation coefficient
virtual TObject * GetObjectFit() const
virtual void SetFitMethod(const char *name)
Set fit method (chi2 or likelihood).
ROOT::Math::IParamMultiFunction * fModelFunc
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual IBaseFunctionMultiDim * Clone() const =0
Clone a function.
Graph 2D class with errors.
virtual Double_t GetParameter(Int_t ipar) const
Parameter value.