20 #include "TMultiGraph.h" 28 extern void F2Fit(Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag);
29 extern void F3Fit(Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag);
42 SetName(
"MinuitFitter");
60 Error(
"Chisquare",
"This function is deprecated - use ROOT::Fit::Chisquare class");
115 TF1 *f = (TF1*)fUserFunc;
116 Int_t npar = f->GetNumberFreeParameters();
117 Int_t npar_real = f->GetNpar();
118 Double_t *grad =
new Double_t[npar_real];
119 Double_t *sum_vector =
new Double_t[npar];
122 if (npar_real != npar){
123 fixed =
new Bool_t[npar_real];
124 memset(fixed,0,npar_real*
sizeof(Bool_t));
126 for (Int_t ipar=0; ipar<npar_real; ipar++){
128 f->GetParLimits(ipar,al,bl);
129 if (al*bl != 0 && al >= bl) {
140 delete [] sum_vector;
147 Double_t chidf =
TMath::Sqrt(f->GetChisquare()/f->GetNDF());
148 Int_t igrad, ifree=0;
149 for (Int_t ipoint=0; ipoint<n; ipoint++){
151 f->GradientPar(x+ndim*ipoint, grad);
153 for (Int_t irow=0; irow<npar; irow++){
156 for (Int_t icol=0; icol<npar; icol++){
161 while (ifree<icol+1){
162 if (fixed[igrad]==0) ifree++;
170 sum_vector[irow]+=matr[irow*npar_real+icol]*grad[igrad];
174 for (Int_t i=0; i<npar; i++){
179 if (fixed[igrad]==0) ifree++;
186 c+=grad[igrad]*sum_vector[i];
190 ci[ipoint]=c*t*chidf;
194 delete [] sum_vector;
223 if (obj->InheritsFrom(TGraph::Class())) {
224 TGraph *gr = (TGraph*)obj;
226 Error(
"GetConfidenceIntervals",
"A TGraphErrors should be passed instead of a graph");
229 if (fObjectFit->InheritsFrom(TGraph2D::Class())){
230 Error(
"GetConfidenceIntervals",
"A TGraph2DErrors should be passed instead of a graph");
233 if (fObjectFit->InheritsFrom(TH1::Class())){
234 if (((TH1*)(fObjectFit))->GetDimension()>1){
235 Error(
"GetConfidenceIntervals",
"A TGraph2DErrors or a TH23 should be passed instead of a graph");
240 for (Int_t i=0; i<gr->GetN(); i++)
241 gr->SetPoint(i, gr->GetX()[i], ((TF1*)(fUserFunc))->
Eval(gr->GetX()[i]));
245 else if (obj->InheritsFrom(TGraph2D::Class())) {
246 TGraph2D *gr2 = (TGraph2D*)obj;
248 Error(
"GetConfidenceIntervals",
"A TGraph2DErrors should be passed instead of a TGraph2D");
251 if (fObjectFit->InheritsFrom(TGraph::Class())){
252 Error(
"GetConfidenceIntervals",
"A TGraphErrors should be passed instead of a TGraph2D");
255 if (fObjectFit->InheritsFrom(TH1::Class())){
256 if (((TH1*)(fObjectFit))->GetDimension()==1){
257 Error(
"GetConfidenceIntervals",
"A TGraphErrors or a TH1 should be passed instead of a graph");
261 TF2 *f=(TF2*)fUserFunc;
263 Int_t np = gr2->GetN();
264 Int_t npar = f->GetNpar();
265 Double_t *grad =
new Double_t[npar];
266 Double_t *sum_vector =
new Double_t[npar];
267 Double_t *
x = gr2->GetX();
268 Double_t *
y = gr2->GetY();
270 Double_t chidf =
TMath::Sqrt(f->GetChisquare()/f->GetNDF());
273 for (Int_t ipoint=0; ipoint<np; ipoint++){
276 f->GradientPar(xy, grad);
277 for (Int_t irow=0; irow<f->GetNpar(); irow++){
279 for (Int_t icol=0; icol<npar; icol++)
280 sum_vector[irow]+=matr[irow*npar+icol]*grad[icol];
283 for (Int_t i=0; i<npar; i++)
284 c+=grad[i]*sum_vector[i];
286 gr2->SetPoint(ipoint, xy[0], xy[1], f->EvalPar(xy));
287 gr2->GetEZ()[ipoint]=c*t*chidf;
291 delete [] sum_vector;
295 else if (obj->InheritsFrom(TH1::Class())) {
296 if (fObjectFit->InheritsFrom(TGraph::Class())){
297 if (((TH1*)obj)->GetDimension()>1){
298 Error(
"GetConfidenceIntervals",
"Fitted graph and passed histogram have different number of dimensions");
302 if (fObjectFit->InheritsFrom(TGraph2D::Class())){
303 if (((TH1*)obj)->GetDimension()!=2){
304 Error(
"GetConfidenceIntervals",
"Fitted graph and passed histogram have different number of dimensions");
308 if (fObjectFit->InheritsFrom(TH1::Class())){
309 if (((TH1*)(fObjectFit))->GetDimension()!=((TH1*)(obj))->GetDimension()){
310 Error(
"GetConfidenceIntervals",
"Fitted and passed histograms have different number of dimensions");
316 TH1 *hfit = (TH1*)obj;
317 TF1 *f = (TF1*)GetUserFunc();
318 Int_t npar = f->GetNpar();
319 Double_t *grad =
new Double_t[npar];
320 Double_t *sum_vector =
new Double_t[npar];
323 Int_t hxfirst = hfit->GetXaxis()->GetFirst();
324 Int_t hxlast = hfit->GetXaxis()->GetLast();
325 Int_t hyfirst = hfit->GetYaxis()->GetFirst();
326 Int_t hylast = hfit->GetYaxis()->GetLast();
327 Int_t hzfirst = hfit->GetZaxis()->GetFirst();
328 Int_t hzlast = hfit->GetZaxis()->GetLast();
330 TAxis *xaxis = hfit->GetXaxis();
331 TAxis *yaxis = hfit->GetYaxis();
332 TAxis *zaxis = hfit->GetZaxis();
334 Double_t chidf =
TMath::Sqrt(f->GetChisquare()/f->GetNDF());
337 for (Int_t binz=hzfirst; binz<=hzlast; binz++){
338 x[2]=zaxis->GetBinCenter(binz);
339 for (Int_t biny=hyfirst; biny<=hylast; biny++) {
340 x[1]=yaxis->GetBinCenter(biny);
341 for (Int_t binx=hxfirst; binx<=hxlast; binx++) {
342 x[0]=xaxis->GetBinCenter(binx);
343 f->GradientPar(x, grad);
344 for (Int_t irow=0; irow<npar; irow++){
346 for (Int_t icol=0; icol<npar; icol++)
347 sum_vector[irow]+=matr[irow*npar+icol]*grad[icol];
350 for (Int_t i=0; i<npar; i++)
351 c+=grad[i]*sum_vector[i];
353 hfit->SetBinContent(binx, biny, binz, f->EvalPar(x));
354 hfit->SetBinError(binx, biny, binz, c*t*chidf);
359 delete [] sum_vector;
362 Error(
"GetConfidenceIntervals",
"This object type is not supported");
375 ((
TFitter*)
this)->fCovar =
new Double_t[npars*npars];
387 if (i < 0 || i >= npars || j < 0 || j >= npars) {
388 Error(
"GetCovarianceMatrixElement",
"Illegal arguments i=%d, j=%d",i,j);
402 Int_t
TFitter::GetErrors(Int_t ipar,Double_t &eplus, Double_t &eminus, Double_t &eparab, Double_t &globcc)
const 435 Double_t value,verr,vlow,vhigh;
449 Double_t value,verr,vlow,vhigh;
465 Int_t
TFitter::GetParameter(Int_t ipar,
char *parname,Double_t &value,Double_t &verr,Double_t &vlow, Double_t &vhigh)
const 470 strcpy(parname,pname.Data());
491 Int_t
TFitter::GetStats(Double_t &amin, Double_t &edm, Double_t &errdef, Int_t &nvpar, Int_t &nparx)
const 510 for (Int_t j=0;j<=
fNlog;j++) {
550 void TFitter::SetFCN(
void (*fcn)(Int_t &, Double_t *, Double_t &f, Double_t *, Int_t))
553 TVirtualFitter::SetFCN(fcn);
581 Int_t
TFitter::SetParameter(Int_t ipar,
const char *parname,Double_t value,Double_t verr,Double_t vlow, Double_t vhigh)
593 void F2Fit(Int_t &, Double_t * , Double_t &f,Double_t *u, Int_t )
595 TVirtualFitter *fitter = TVirtualFitter::GetFitter();
596 TF2 *f2 = (TF2*)fitter->GetObjectFit();
597 f2->InitArgs(u, f2->GetParameters() );
603 void F3Fit(Int_t &, Double_t * , Double_t &f,Double_t *u, Int_t )
605 TVirtualFitter *fitter = TVirtualFitter::GetFitter();
606 TF3 *f3 = (TF3*)fitter->GetObjectFit();
607 f3->InitArgs(u, f3->GetParameters() );
virtual Bool_t IsFixed(Int_t ipar) const
return kTRUE if parameter ipar is fixed, kFALSE othersise)
virtual void mnstat(Double_t &fmin, Double_t &fedm, Double_t &errdef, Int_t &npari, Int_t &nparx, Int_t &istat)
Returns concerning the current status of the minimization.
virtual void mnprin(Int_t inkode, Double_t fval)
Prints the values of the parameters at the time of the call.
virtual void PrintResults(Int_t level, Double_t amin) const
Print fit results.
Implementation in C++ of the Minuit package written by Fred James.
virtual Double_t GetCovarianceMatrixElement(Int_t i, Int_t j) const
return element i,j from the covariance matrix
virtual void mnemat(Double_t *emat, Int_t ndim)
Calculates the external error matrix from the internal matrix.
virtual Double_t * GetCovarianceMatrix() const
return a pointer to the covariance matrix
Double_t QuietNaN()
Returns a quiet NaN as defined by IEEE 754
Double_t StudentQuantile(Double_t p, Double_t ndf, Bool_t lower_tail=kTRUE)
Computes quantiles of the Student's t-distribution 1st argument is the probability, at which the quantile is computed 2nd argument - the number of degrees of freedom of the Student distribution When the 3rd argument lower_tail is kTRUE (default)- the algorithm returns such x0, that.
virtual Int_t GetErrors(Int_t ipar, Double_t &eplus, Double_t &eminus, Double_t &eparab, Double_t &globcc) const
return current errors for a parameter ipar : parameter number eplus : upper error eminus : lower erro...
virtual Int_t ExecuteCommand(const char *command, Double_t *args, Int_t nargs)
Execute a fitter command; command : command string args : list of nargs command arguments.
you should not use this method at all Int_t y
virtual const char * GetParName(Int_t ipar) const
return name of parameter ipar
virtual Int_t FixParameter(Int_t parNo)
fix a parameter
virtual ~TFitter()
Default destructor.
virtual void ReleaseParameter(Int_t ipar)
Release parameter ipar.
virtual void mnrn15(Double_t &val, Int_t &inseed)
This is a super-portable random number generator.
virtual Int_t GetNumberFreeParameters() const
return the number of free parameters
virtual void SetFCN(void(*fcn)(Int_t &, Double_t *, Double_t &f, Double_t *, Int_t))
Specify the address of the fitting algorithm.
virtual void mnpout(Int_t iuext, TString &chnam, Double_t &val, Double_t &err, Double_t &xlolim, Double_t &xuplim, Int_t &iuint) const
Provides the user with information concerning the current status.
virtual Double_t GetParameter(Int_t ipar) const
return current value of parameter ipar
TString * fCpnam
Character to be plotted at the X,Y contour positions.
virtual void mncler()
Resets the parameter list to UNDEFINED.
virtual void mnparm(Int_t k, TString cnamj, Double_t uk, Double_t wk, Double_t a, Double_t b, Int_t &ierflg)
Implements one parameter definition.
virtual void mnerrs(Int_t number, Double_t &eplus, Double_t &eminus, Double_t &eparab, Double_t &gcc)
Utility routine to get MINOS errors.
virtual Double_t Chisquare(Int_t npar, Double_t *params) const
* x
Deprecated and error prone model selection interface.
virtual void SetFitMethod(const char *name)
ret fit method (chisquare or loglikelihood)
virtual Double_t GetSumLog(Int_t i)
return Sum(log(i) i=0,n used by log likelihood fits
void F2Fit(Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag)
virtual Double_t GetParError(Int_t ipar) const
return error of parameter ipar
virtual Int_t Release(Int_t parNo)
release a parameter
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 Parameters: n - number of points...
virtual void mnexcm(const char *comand, Double_t *plist, Int_t llist, Int_t &ierflg)
Interprets a command and takes appropriate action.
virtual void FixParameter(Int_t ipar)
Fix parameter ipar.
double Eval(double x, const double *c)
virtual void Clear(Option_t *option="")
reset the fitter environment
virtual void SetFCN(void(*fcn)(Int_t &, Double_t *, Double_t &f, Double_t *, Int_t))
To set the address of the minimization function.
Double_t Sqrt(Double_t x)
void F3Fit(Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag)
virtual Int_t GetNumPars() const
returns the total number of parameters that have been defined as fixed or free.
virtual Int_t GetNumberTotalParameters() const
return the total number of parameters (free + fixed)
virtual Int_t GetStats(Double_t &amin, Double_t &edm, Double_t &errdef, Int_t &nvpar, Int_t &nparx) const
return global fit parameters amin : chisquare edm : estimated distance to minimum errdef nvpar : numb...
virtual Int_t SetParameter(Int_t ipar, const char *parname, Double_t value, Double_t verr, Double_t vlow, Double_t vhigh)
set initial values for a parameter ipar : parameter number parname : parameter name value : initial p...