113 const std::vector<double> & minpar =
fFitter->Result().Parameters();
114 assert (npar == (
int) minpar.size() );
117 for (
int i =0; i < npar; ++i) {
118 diff += std::abs( params[i] - minpar[i] );
122 if (diff > s * 1.E-12 )
Warning(
"Chisquare",
"given parameter values are not at minimum - chi2 at minimum is returned");
123 return fFitter->Result().Chi2();
138 std::cout<<
"Execute command= "<<command<<std::endl;
150 Error(
"ExecuteCommand",
"FCN must set before executing this command");
156 return (ret) ? 0 : -1;
164 Error(
"ExecuteCommand",
"FCN must set before executing this command");
168 return (ret) ? 0 : -1;
174 Error(
"ExecuteCommand",
"FCN must set before executing this command");
180 return (ret) ? 0 : -1;
186 Error(
"ExecuteCommand",
"FCN must set before executing this command");
192 return (ret) ? 0 : -1;
195 else if (scommand.
Contains(
"MINO")) {
197 if (
fFitter->Config().MinosErrors() )
return 0;
200 Error(
"ExecuteCommand",
"FCN must set before executing this command");
204 fFitter->Config().SetMinosErrors(
true);
209 return (ret) ? 0 : -1;
213 else if (scommand.
Contains(
"HES")) {
215 if (
fFitter->Config().ParabErrors() )
return 0;
218 Error(
"ExecuteCommand",
"FCN must set before executing this command");
223 fFitter->Config().SetParabErrors(
true);
226 return (ret) ? 0 : -1;
230 else if (scommand.
Contains(
"FIX")) {
231 for(
int i = 0; i < nargs; i++) {
237 else if (scommand.
Contains(
"SET LIM")) {
239 Error(
"ExecuteCommand",
"Invalid parameters given in SET LIMIT");
242 int ipar =
int(args[0]);
244 double low = args[1];
246 fFitter->Config().ParSettings(ipar).SetLimits(low,up);
250 else if (scommand.
Contains(
"SET PRIN")) {
251 if (nargs < 1)
return -1;
252 fFitter->Config().MinimizerOptions().SetPrintLevel(
int(args[0]) );
256 else if (scommand.
Contains(
"SET ERR")) {
257 if (nargs < 1)
return -1;
258 fFitter->Config().MinimizerOptions().SetPrintLevel(
int( args[0]) );
262 else if (scommand.
Contains(
"SET STR")) {
263 if (nargs < 1)
return -1;
264 fFitter->Config().MinimizerOptions().SetStrategy(
int(args[0]) );
268 else if (scommand.
Contains(
"SET GRA")) {
274 else if (scommand.
Contains(
"SET NOW")) {
280 else if (scommand.
Contains(
"CALL FCN")) {
283 if (nargs < 1 ||
fFCN ==
nullptr )
return -1;
286 std::vector<double> params(npar);
287 for (
int i = 0; i < npar; ++i)
291 (*fFCN)(npar,
nullptr, fval, ¶ms[0],
int(args[0]) ) ;
296 Error(
"ExecuteCommand",
"Invalid or not supported command given %s",command);
305 int nps =
fFitter->Config().ParamsSettings().size();
306 if (ipar < 0 || ipar >= nps ) {
308 Error(
"ValidParameterIndex",
"%s",msg.c_str());
319 fFitter->Config().ParSettings(ipar).Fix();
335 if (!
fFitter->Result().IsValid()) {
336 Error(
"GetConfidenceIntervals",
"Cannot compute confidence intervals with an invalide fit result");
340 fFitter->Result().GetConfidenceIntervals(
n,ndim,1,
x,ci,cl,
false);
370 if (!
fFitter->Result().IsValid() ) {
371 Error(
"GetConfidenceIntervals",
"Cannot compute confidence intervals with an invalide fit result");
379 Error(
"GetConfidenceIntervals",
"Cannot compute confidence intervals without a fitting object");
385 TH1 *
h1 =
dynamic_cast<TH1*
>(fitobj);
386 assert(
h1 !=
nullptr);
392 Error(
"GetConfidenceIntervals",
"Invalid object passed for storing confidence level data, must be a TGraphErrors or a TH1");
398 Error(
"GetConfidenceIntervals",
"Invalid object passed for storing confidence level data, must be a TGraph2DErrors or a TH2");
404 Error(
"GetConfidenceIntervals",
"Invalid object passed for storing confidence level data, must be a TH3");
411 data.Opt().fUseEmpty =
true;
423 unsigned int n =
data.Size();
425 std::vector<double> ci(
n );
427 fFitter->Result().GetConfidenceIntervals(
data,&ci[0],cl,
false);
430 assert(func !=
nullptr);
433 for (
unsigned int i = 0; i <
n; ++i) {
434 const double *
x =
data.Coords(i);
435 double y = (*func)(
x );
439 assert(
gr !=
nullptr);
445 assert(
gr !=
nullptr);
450 TH1 *
h1 =
dynamic_cast<TH1 *
> (obj);
451 assert(
h1 !=
nullptr);
471 if (
fCovar.size() != nfreepar*nfreepar )
472 fCovar.resize(nfreepar*nfreepar);
474 if (!
fFitter->Result().IsValid() ) {
475 Warning(
"GetCovarianceMatrix",
"Invalid fit result");
480 for (
unsigned int i = 0; i < ntotpar; ++i) {
481 if (
fFitter->Config().ParSettings(i).IsFixed() )
continue;
483 for (
unsigned int j = 0; j < ntotpar; ++j) {
484 if (
fFitter->Config().ParSettings(j).IsFixed() )
continue;
485 unsigned int index = nfreepar*
l +
m;
499 unsigned int np2 =
fCovar.size();
501 if ( np2 == 0 || np2 != npar *npar ) {
503 if (
c ==
nullptr)
return 0;
505 return fCovar[i*npar + j];
516 Warning(
"GetErrors",
"Invalid fit result");
520 eparab =
result.Error(ipar);
521 eplus =
result.UpperError(ipar);
522 eminus =
result.LowerError(ipar);
523 globcc =
result.GlobalCC(ipar);
531 return fFitter->Result().NTotalParameters();
535 return fFitter->Result().NFreeParameters();
542 if (
fFitter->Result().IsEmpty() ) {
546 return fFitter->Result().Error(ipar);
553 if (
fFitter->Result().IsEmpty() ) {
557 return fFitter->Result().Value(ipar);
567 const std::string & pname =
fFitter->Config().ParSettings(ipar).Name();
568 const char *
c = pname.c_str();
569 std::copy(
c,
c + pname.size(),
name);
571 if (
fFitter->Result().IsEmpty() ) {
573 verr =
fFitter->Config().ParSettings(ipar).Value();
574 vlow =
fFitter->Config().ParSettings(ipar).LowerLimit();
575 vhigh =
fFitter->Config().ParSettings(ipar).UpperLimit();
580 verr =
fFitter->Result().Error(ipar);
581 vlow =
fFitter->Result().LowerError(ipar);
582 vhigh =
fFitter->Result().UpperError(ipar);
594 return fFitter->Config().ParSettings(ipar).Name().c_str();
602 amin =
result.MinFcnValue();
604 errdef =
fFitter->Config().MinimizerOptions().ErrorDef();
605 nvpar =
result.NFreeParameters();
606 nparx =
result.NTotalParameters();
614 Warning(
"GetSumLog",
"Dummy method - returned 0");
625 return fFitter->Config().ParSettings(ipar).IsFixed();
633 if (
fFitter->GetMinimizer() &&
fFitter->Config().MinimizerType() ==
"Minuit")
634 fFitter->GetMinimizer()->PrintResults();
636 if (level > 0)
fFitter->Result().Print(std::cout);
637 if (level > 1)
fFitter->Result().PrintCovMatrix(std::cout);
647 fFitter->Config().ParSettings(ipar).Release();
655 Info(
"SetFitMethod",
"non supported method");
664 std::vector<ROOT::Fit::ParameterSettings> & parlist =
fFitter->Config().ParamsSettings();
665 if ( ipar >= (
int) parlist.size() ) parlist.resize(ipar+1);
667 if (verr == 0) ps.
Fix();
668 if (vlow < vhigh) ps.
SetLimits(vlow, vhigh);
692 if (
fFitter->Result().FittedFunction() !=
nullptr) {
716 Error(
"SetMinimizerFunction",
"cannot create minimizer %s",
fFitter->Config().MinimizerType().c_str() );
720 Error(
"SetMinimizerFunction",
"Object Function pointer is NULL");
757 assert(fobj !=
nullptr);
758 int ndim =
fFitter->Config().ParamsSettings().size();
781 return fFitter->GetMinimizer();
788 if (!
fFitter.get() )
return nullptr;
800 if (!
gr)
return false;
803 Error(
"Scan",
"Minimizer is not available - cannot scan before fitting");
807 unsigned int npoints =
gr->
GetN();
813 if ((
int) npoints < gr->GetN() )
gr->
Set(npoints);
853 if (!
gr)
return false;
856 Error(
"Scan",
"Minimizer is not available - cannot scan before fitting");
861 double upScale =
fFitter->Config().MinimizerOptions().ErrorDef();
868 unsigned int npoints =
gr->
GetN();
874 if ((
int) npoints < gr->GetN() )
gr->
Set(npoints);
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
Chi2FCN class for binned fits using the least square methods.
void SetDimension(int dim)
class containing the result of the fit and all the related information (fitted parameter values,...
LogLikelihoodFCN class for likelihood fits.
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
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 The c...
void Fix()
fix the parameter
class evaluating the log likelihood for binned Poisson likelihood fits it is template to distinguish ...
Class describing the un-binned data sets (just x coordinates values) of any dimensions.
Documentation for the abstract class IBaseFunctionMultiDim.
virtual IBaseFunctionMultiDimTempl< T > * Clone() const =0
Clone a function.
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2,...
void SetErrorDef(double up)
set scale for calculating the errors
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)=0
set the function to minimize
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 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...
Backward compatible implementation of TVirtualFitter.
const char * GetParName(Int_t ipar) const override
Return name of parameter ipar.
void GetConfidenceIntervals(Int_t n, Int_t ndim, const Double_t *x, Double_t *ci, Double_t cl=0.95) override
Computes point-by-point confidence intervals for the fitted function.
void ReleaseParameter(Int_t ipar) override
Release a fit parameter.
Double_t GetParError(Int_t ipar) const override
Parameter error.
ROOT::Math::Minimizer * fMinimizer
void DoSetDimension()
Private method to set dimension in objective function.
void SetFCN(void(*fcn)(Int_t &, Double_t *, Double_t &f, Double_t *, Int_t)) override
Override setFCN to use the Adapter to Minuit2 FCN interface To set the address of the minimization fu...
ROOT::Math::Minimizer * GetMinimizer() const
Return a pointer to the minimizer.
void Clear(Option_t *option="") override
Clear resources for consecutive fits.
void PrintResults(Int_t level, Double_t amin) const override
Print the fit result.
Int_t GetStats(Double_t &amin, Double_t &edm, Double_t &errdef, Int_t &nvpar, Int_t &nparx) const override
Get fit statistical information.
Int_t GetNumberFreeParameters() const override
TBackCompFitter()
Constructor needed by TVirtualFitter interface.
void FixParameter(Int_t ipar) override
Fix the parameter.
void SetFitMethod(const char *name) override
Set fit method (chi2 or likelihood).
Double_t GetCovarianceMatrixElement(Int_t i, Int_t j) const override
Get error matrix element (return all zero if matrix is not available)
Bool_t IsFixed(Int_t ipar) const override
Query if parameter ipar is fixed.
std::shared_ptr< ROOT::Fit::FitData > fFitData
! Data of the fit
ROOT::Math::IParamMultiFunction * fModelFunc
Int_t GetNumberTotalParameters() const override
Number of total parameters.
Int_t ExecuteCommand(const char *command, Double_t *args, Int_t nargs) override
Execute the command (Fortran Minuit compatible interface)
TFitResult * GetTFitResult() const
Get a copy of the Fit result returning directly a new TFitResult.
void ReCreateMinimizer()
Recreate a minimizer instance using the function and data set objective function in minimizers functi...
std::shared_ptr< ROOT::Fit::Fitter > fFitter
! Pointer to fitter object
Int_t GetErrors(Int_t ipar, Double_t &eplus, Double_t &eminus, Double_t &eparab, Double_t &globcc) const override
Get fit errors.
std::vector< double > fCovar
Cached covariance matrix (NxN)
bool ValidParameterIndex(int ipar) const
Check if ipar is a valid parameter index.
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...
Double_t GetSumLog(Int_t i) override
Sum of log (un-needed)
~TBackCompFitter() override
Destructor - delete the managed objects.
Double_t Chisquare(Int_t npar, Double_t *params) const override
Do chisquare calculations in case of likelihood fits Do evaluation a the minimum only.
ROOT::Math::IMultiGenFunction * GetObjFunction() const
Return a pointer to the objective function (FCN) If fitting directly using TBackCompFitter the pointe...
virtual void SetObjFunction(ROOT::Math::IMultiGenFunction *f)
Set the objective function for fitting Needed if fitting directly using TBackCompFitter class The cla...
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...
ROOT::Math::IMultiGenFunction * fObjFunc
Double_t GetParameter(Int_t ipar) const override
Parameter value.
Int_t SetParameter(Int_t ipar, const char *parname, Double_t value, Double_t verr, Double_t vlow, Double_t vhigh) override
Set (add) a new fit parameter passing initial value, step size (verr) and parameter limits if vlow > ...
Double_t * GetCovarianceMatrix() const override
Get the error matrix in a pointer to a NxN array.
Extends the ROOT::Fit::Result class with a TNamed inheritance providing easy possibility for I/O.
Graph 2D class with errors.
Graphics object made of three arrays X, Y and Z with the same number of points each.
A TGraphErrors is a TGraph with error bars.
virtual void SetPointError(Double_t ex, Double_t ey)
Set ex and ey values for point pointed by the mouse.
A TGraph is an object made of two arrays X and Y with npoints each.
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
virtual void Set(Int_t n)
Set number of points in the graph Existing coordinates are preserved New coordinates above fNpoints a...
TH1 is the base class of all histogram classes in ROOT.
virtual Int_t GetDimension() const
virtual void SetBinError(Int_t bin, Double_t error)
Set the bin Error Note that this resets the bin eror option to be of Normal Type and for the non-empt...
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 Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0)
Return Global bin number corresponding to x,y,z.
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
virtual void SetName(const char *name)
Set the name of the TNamed.
Mother of all ROOT objects.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
void ToUpper()
Change string to upper case.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual TObject * GetObjectFit() const
virtual Foption_t GetFitOption() const
static const char * GetDefaultFitter()
static: return the name of the default fitter
void(* fFCN)(Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag)
void FillData(BinData &dv, const TH1 *hist, TF1 *func=nullptr)
fill the data vector from a TH1.
std::string ToString(const T &val)
Utility function for conversion to strings.
Double_t ChisquareQuantile(Double_t p, Double_t ndf)
Evaluate the quantiles of the chi-squared probability distribution function.