112 const std::vector<double> &
minpar =
fFitter->Result().Parameters();
116 for (
int i =0; i <
npar; ++i) {
121 if (
diff > s * 1.E-12 )
Warning(
"Chisquare",
"given parameter values are not at minimum - chi2 at minimum is returned");
122 return fFitter->Result().Chi2();
137 std::cout<<
"Execute command= "<<
command<<std::endl;
149 Error(
"ExecuteCommand",
"FCN must set before executing this command");
155 return (
ret) ? 0 : -1;
163 Error(
"ExecuteCommand",
"FCN must set before executing this command");
167 return (
ret) ? 0 : -1;
173 Error(
"ExecuteCommand",
"FCN must set before executing this command");
179 return (
ret) ? 0 : -1;
185 Error(
"ExecuteCommand",
"FCN must set before executing this command");
191 return (
ret) ? 0 : -1;
194 else if (
scommand.Contains(
"MINO")) {
196 if (
fFitter->Config().MinosErrors() )
return 0;
199 Error(
"ExecuteCommand",
"FCN must set before executing this command");
203 fFitter->Config().SetMinosErrors(
true);
208 return (
ret) ? 0 : -1;
212 else if (
scommand.Contains(
"HES")) {
214 if (
fFitter->Config().ParabErrors() )
return 0;
217 Error(
"ExecuteCommand",
"FCN must set before executing this command");
222 fFitter->Config().SetParabErrors(
true);
225 return (
ret) ? 0 : -1;
229 else if (
scommand.Contains(
"FIX")) {
230 for(
int i = 0; i <
nargs; i++) {
236 else if (
scommand.Contains(
"SET LIM")) {
238 Error(
"ExecuteCommand",
"Invalid parameters given in SET LIMIT");
241 int ipar =
int(args[0]);
243 double low = args[1];
245 fFitter->Config().ParSettings(ipar).SetLimits(low,
up);
249 else if (
scommand.Contains(
"SET PRIN")) {
250 if (
nargs < 1)
return -1;
251 fFitter->Config().MinimizerOptions().SetPrintLevel(
int(args[0]) );
255 else if (
scommand.Contains(
"SET ERR")) {
256 if (
nargs < 1)
return -1;
257 fFitter->Config().MinimizerOptions().SetPrintLevel(
int( args[0]) );
261 else if (
scommand.Contains(
"SET STR")) {
262 if (
nargs < 1)
return -1;
263 fFitter->Config().MinimizerOptions().SetStrategy(
int(args[0]) );
267 else if (
scommand.Contains(
"SET GRA")) {
273 else if (
scommand.Contains(
"SET NOW")) {
279 else if (
scommand.Contains(
"CALL FCN")) {
282 if (
nargs < 1 ||
fFCN ==
nullptr )
return -1;
285 std::vector<double> params(
npar);
286 for (
int i = 0; i <
npar; ++i)
290 (*fFCN)(
npar,
nullptr,
fval, ¶ms[0],
int(args[0]) ) ;
295 Error(
"ExecuteCommand",
"Invalid or not supported command given %s",
command);
304 int nps =
fFitter->Config().ParamsSettings().size();
307 Error(
"ValidParameterIndex",
"%s",
msg.c_str());
318 fFitter->Config().ParSettings(ipar).Fix();
334 if (!
fFitter->Result().IsValid()) {
335 Error(
"GetConfidenceIntervals",
"Cannot compute confidence intervals with an invalide fit result");
339 fFitter->Result().GetConfidenceIntervals(
n,ndim,1,
x,
ci,cl,
false);
369 if (!
fFitter->Result().IsValid() ) {
370 Error(
"GetConfidenceIntervals",
"Cannot compute confidence intervals with an invalide fit result");
378 Error(
"GetConfidenceIntervals",
"Cannot compute confidence intervals without a fitting object");
391 Error(
"GetConfidenceIntervals",
"Invalid object passed for storing confidence level data, must be a TGraphErrors or a TH1");
397 Error(
"GetConfidenceIntervals",
"Invalid object passed for storing confidence level data, must be a TGraph2DErrors or a TH2");
403 Error(
"GetConfidenceIntervals",
"Invalid object passed for storing confidence level data, must be a TH3");
410 data.Opt().fUseEmpty =
true;
422 unsigned int n =
data.Size();
424 std::vector<double>
ci(
n );
426 fFitter->Result().GetConfidenceIntervals(
data,&
ci[0],cl,
false);
432 for (
unsigned int i = 0; i <
n; ++i) {
433 const double *
x =
data.Coords(i);
434 double y = (*func)(
x );
449 TH1 *
h1 =
dynamic_cast<TH1 *
> (obj);
473 if (!
fFitter->Result().IsValid() ) {
474 Warning(
"GetCovarianceMatrix",
"Invalid fit result");
479 for (
unsigned int i = 0; i <
ntotpar; ++i) {
480 if (
fFitter->Config().ParSettings(i).IsFixed() )
continue;
483 if (
fFitter->Config().ParSettings(
j).IsFixed() )
continue;
502 if (
c ==
nullptr)
return 0;
515 Warning(
"GetErrors",
"Invalid fit result");
520 eplus =
result.UpperError(ipar);
530 return fFitter->Result().NTotalParameters();
534 return fFitter->Result().NFreeParameters();
541 if (
fFitter->Result().IsEmpty() ) {
545 return fFitter->Result().Error(ipar);
552 if (
fFitter->Result().IsEmpty() ) {
556 return fFitter->Result().Value(ipar);
566 const std::string &
pname =
fFitter->Config().ParSettings(ipar).Name();
567 const char *
c =
pname.c_str();
570 if (
fFitter->Result().IsEmpty() ) {
572 verr =
fFitter->Config().ParSettings(ipar).Value();
573 vlow =
fFitter->Config().ParSettings(ipar).LowerLimit();
574 vhigh =
fFitter->Config().ParSettings(ipar).UpperLimit();
593 return fFitter->Config().ParSettings(ipar).Name().c_str();
613 Warning(
"GetSumLog",
"Dummy method - returned 0");
624 return fFitter->Config().ParSettings(ipar).IsFixed();
632 if (
fFitter->GetMinimizer() &&
fFitter->Config().MinimizerType() ==
"Minuit")
633 fFitter->GetMinimizer()->PrintResults();
635 if (level > 0)
fFitter->Result().Print(std::cout);
636 if (level > 1)
fFitter->Result().PrintCovMatrix(std::cout);
646 fFitter->Config().ParSettings(ipar).Release();
654 Info(
"SetFitMethod",
"non supported method");
663 std::vector<ROOT::Fit::ParameterSettings> &
parlist =
fFitter->Config().ParamsSettings();
691 if (
fFitter->Result().FittedFunction() !=
nullptr) {
715 Error(
"SetMinimizerFunction",
"cannot create minimizer %s",
fFitter->Config().MinimizerType().c_str() );
719 Error(
"SetMinimizerFunction",
"Object Function pointer is NULL");
757 int ndim =
fFitter->Config().ParamsSettings().size();
758 if (ndim != 0)
fobj->SetDimension(ndim);
780 return fFitter->GetMinimizer();
787 if (!
fFitter.get() )
return nullptr;
799 if (!
gr)
return false;
802 Error(
"Scan",
"Minimizer is not available - cannot scan before fitting");
852 if (!
gr)
return false;
855 Error(
"Scan",
"Minimizer is not available - cannot scan before fitting");
const char Option_t
Option string (const char)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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.
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 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.
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.
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.