ROOT logo
AliRoot » STAT » AliTMinuitToolkit

class AliTMinuitToolkit: public TNamed


 The AliTMinuitToolkit serves as an easy to use interface for the TMinuit
 package:

 - It allows to fit a curve to one and two dimensional histograms
   (TH2F::Fit() only allows to fit a hyperplane).
 - Or n points can be specified directly via a n x 2 matrix.
 - An option for robust fitting with non-linear functions is implemented.

 A small example illustrating the usage of AliTMinuitToolkit is given in the function
 "AliTMinuitToolkit::Test()".


 1. Setting the formula:

  The formula is simply set via "void SetFitFunction(TFormula * formula)".


 2. Adding the data points

  - In order to fit a histogram, use "void FitHistogram(TH1F * his)" or
    "void FitHistogram(TH2F * his)". The fitter is started automatically
  - Alternatively, the direct specification of the points is possible via
    "void SetPoints(TMatrixD * points)". Note, that the each point
    corresponds to one row in the matrix. The fitter is then started with
    the command "void Fit()". The weight of each point can be specified
    with an n-dimensional vector using "void SetWeights(TVectorD * weights)".


 3. Accessing the fit results

  The N parameters of the formula are stored in a N-dimensional vector which
  is returned by "TVectorD * GetParameters()". In a similar way the covariance
  matrix of the fit is returned via "TMatrixD * GetCovarianceMatrix()" which
  is of the type N x N.


 4. Non-linear robust fitting:

  Even a few outliers can lead to wrong results of a least-squares fitting
  procedure. In this case the use of robust(resistant) methods can be
  helpful, but a stronger dependence on starting values or convergence to
  local minima can occur.

  The robust option becomes active if EnableRobust(true, sigma) is called. It is
  very much recommended that a normalization value (scale variable) corresponding
  to an expected deviation (sigma) is specified via
  "EnableRobust(Bool_t b, Double_t sigma)".

  Performing the fit without knowledge of sigma is also possible if only
  "EnableRobust(true)" is activated, but this is NOT RECOMMENDED.

  The method is based on another estimator instead of chi^2. For small deviations
  the function behaves like x^2 and for larger deviations like |x| - the so
  called Huber estimator:

   h(x) = x^2                              , for x < 2.5*sigma
   h(x) = 2*(2.5*sigma)*x - (2.5*sigma)^2  , for x > 2.5*sigma

  If a weighting function is specified in addition, a second run with the ordinary
  metric is started, but before entering the iteration every point is weighted
  according to its distance to the outcoming function of the first run. The weighting
  function w(x) must be defined on the intervall x in [0,1]. w(0) then
  corresponds to the weight of the closest point and w(1) to the point with the
  largest distance.

  Some standard weighting functions are predefined in
  "SetWeightFunction(Char_t * name, Float_t param1, Float_t param2 = 0)":
   - "BOX" equals to 1 if x < param1 and to 0 if x > param1.
   - "EXPONENTIAL" corresponds to "Math::Exp(-TMath::Log(param1)*x)"
   - "ERRORFUNCTION" corresponds to "TMath::Erfc((x-param1)/param2)"


  REFERENCE for non-linear robust fitting:
  Ekblom H. and Madsen K. (1988), Alogrithms for non-linear Huber estimation,
  BIT Numerical Mathematics 29 (1989) 60-76.
  internet: http://www.springerlink.com/content/m277218542988344


 5. examples:

  A small example illustrating the working principles of AliTMinuitToolkit is given
  in the function "AliTMinuitToolkit::Test()".



 Comments and questions are always welcome: A.Kalweit@gsi.de

Function Members (Methods)

public:
AliTMinuitToolkit()
virtual~AliTMinuitToolkit()
voidTObject::AbstractMethod(const char* method) const
virtual voidTObject::AppendPad(Option_t* option = "")
virtual voidTObject::Browse(TBrowser* b)
static TClass*Class()
virtual const char*TObject::ClassName() const
virtual voidTNamed::Clear(Option_t* option = "")
virtual TObject*TNamed::Clone(const char* newname = "") const
virtual Int_tTNamed::Compare(const TObject* obj) const
virtual voidTNamed::Copy(TObject& named) const
virtual voidTObject::Delete(Option_t* option = "")MENU
virtual Int_tTObject::DistancetoPrimitive(Int_t px, Int_t py)
virtual voidTObject::Draw(Option_t* option = "")
virtual voidTObject::DrawClass() constMENU
virtual TObject*TObject::DrawClone(Option_t* option = "") constMENU
virtual voidTObject::Dump() constMENU
voidEnableRobust(Bool_t b)
voidEnableRobust(Bool_t b, Double_t sigma)
virtual voidTObject::Error(const char* method, const char* msgfmt) const
virtual voidTObject::Execute(const char* method, const char* params, Int_t* error = 0)
virtual voidTObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0)
virtual voidTObject::ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual voidTObject::Fatal(const char* method, const char* msgfmt) const
virtual voidTNamed::FillBuffer(char*& buffer)
virtual TObject*TObject::FindObject(const char* name) const
virtual TObject*TObject::FindObject(const TObject* obj) const
voidFit()
voidFitHistogram(TH1F *const his)
voidFitHistogram(TH2F *const his)
static voidFitterFCN(int& npar, double* dummy, double& fchisq, double* gin, int iflag)
TMatrixD*GetCovarianceMatrix() const
virtual Option_t*TObject::GetDrawOption() const
static Long_tTObject::GetDtorOnly()
Double_tGetExpectedSigma() const
TFormula*GetFormula() const
virtual const char*TObject::GetIconName() const
virtual const char*TNamed::GetName() const
virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const
static Bool_tTObject::GetObjectStat()
virtual Option_t*TObject::GetOption() const
TVectorD*GetParameters() const
TMatrixD*GetPoints() const
Bool_tGetStatus() const
virtual const char*TNamed::GetTitle() const
virtual UInt_tTObject::GetUniqueID() const
TFormula*GetWeightFunction() const
TVectorD*GetWeights() const
virtual Bool_tTObject::HandleTimer(TTimer* timer)
virtual ULong_tTNamed::Hash() const
virtual voidTObject::Info(const char* method, const char* msgfmt) const
virtual Bool_tTObject::InheritsFrom(const char* classname) const
virtual Bool_tTObject::InheritsFrom(const TClass* cl) const
virtual voidTObject::Inspect() constMENU
voidTObject::InvertBit(UInt_t f)
virtual TClass*IsA() const
virtual Bool_tTObject::IsEqual(const TObject* obj) const
virtual Bool_tTObject::IsFolder() const
Bool_tTObject::IsOnHeap() const
virtual Bool_tTNamed::IsSortable() const
Bool_tTObject::IsZombie() const
virtual voidTNamed::ls(Option_t* option = "") const
voidTObject::MayNotUse(const char* method) const
virtual Bool_tTObject::Notify()
voidTObject::Obsolete(const char* method, const char* asOfVers, const char* removedFromVers) const
static voidTObject::operator delete(void* ptr)
static voidTObject::operator delete(void* ptr, void* vp)
static voidTObject::operator delete[](void* ptr)
static voidTObject::operator delete[](void* ptr, void* vp)
void*TObject::operator new(size_t sz)
void*TObject::operator new(size_t sz, void* vp)
void*TObject::operator new[](size_t sz)
void*TObject::operator new[](size_t sz, void* vp)
virtual voidTObject::Paint(Option_t* option = "")
virtual voidTObject::Pop()
virtual voidTNamed::Print(Option_t* option = "") const
virtual Int_tTObject::Read(const char* name)
virtual voidTObject::RecursiveRemove(TObject* obj)
voidTObject::ResetBit(UInt_t f)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
virtual voidTObject::SavePrimitive(basic_ostream<char,char_traits<char> >& out, Option_t* option = "")
voidTObject::SetBit(UInt_t f)
voidTObject::SetBit(UInt_t f, Bool_t set)
virtual voidTObject::SetDrawOption(Option_t* option = "")MENU
static voidTObject::SetDtorOnly(void* obj)
voidSetFitAlgorithm(Char_t *const name)
voidSetFitFunction(TFormula *const formula)
voidSetInitialParam(TVectorD *const param)
voidSetMaxCalls(Int_t calls)
virtual voidTNamed::SetName(const char* name)MENU
virtual voidTNamed::SetNameTitle(const char* name, const char* title)
static voidTObject::SetObjectStat(Bool_t stat)
voidSetParamLimits(TMatrixD *const paramLimits)
voidSetPoints(TMatrixD *const points)
virtual voidTNamed::SetTitle(const char* title = "")MENU
voidSetTolerance(Double_t tol)
virtual voidTObject::SetUniqueID(UInt_t uid)
voidSetWeightFunction(TFormula *const weightFunction)
voidSetWeightFunction(const Char_t* name, Float_t param1, Float_t param2 = 0.1)
voidSetWeights(TVectorD *const weights)
virtual voidShowMembers(TMemberInspector&)
virtual Int_tTNamed::Sizeof() const
virtual voidStreamer(TBuffer&)
voidStreamerNVirtual(TBuffer& ClassDef_StreamerNVirtual_b)
virtual voidTObject::SysError(const char* method, const char* msgfmt) const
static voidTest()
Bool_tTObject::TestBit(UInt_t f) const
Int_tTObject::TestBits(UInt_t f) const
virtual voidTObject::UseCurrentStyle()
virtual voidTObject::Warning(const char* method, const char* msgfmt) const
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0)
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const
protected:
virtual voidTObject::DoError(int level, const char* location, const char* fmt, va_list va) const
voidTObject::MakeZombie()

Data Members

protected:
TStringTNamed::fNameobject identifier
TStringTNamed::fTitleobject title
private:
Double_t*fChi2chi-square
TMatrixD*fCovarcovariance matrix
Double_tfExpectedSigmaexpected sigma to normalize robust fitting
TStringfFitAlgorithmfit algorithm for TMinuit: migrad, simplex, ...
TFormula*fFormulaformula of the fitted function
Int_tfMaxCallsmaximum number of calls, default value depends on fit algorithm
TVectorD*fParamparameter values
TMatrixD*fParamLimitslimits of the parameters (up, down)
TMatrixD*fPointsfitted points
Double_tfPrecisionnormalized tolerance, default value depends on fit algorithm
Bool_tfUseRobustswitch on/off robust option, default: kFalse
TFormula*fWeightFunctionweight function, must be defined between 0 and 1
TVectorD*fWeightsweights of the points

Class Charts

Inheritance Chart:
TNamed
AliTMinuitToolkit

Function documentation

AliTMinuitToolkit()
 standard constructor

AliTMinuitToolkit(const AliTMinuitToolkit& )
AliTMinuitToolkit& operator=(const AliTMinuitToolkit& )
~AliTMinuitToolkit()
 destructor

void FitHistogram(TH1F *const his)
 Fit a one dimensional histogram

void FitHistogram(TH2F *const his)
 Fit a curve to a two dimensional histogram

void SetWeightFunction(const Char_t* name, Float_t param1, Float_t param2 = 0.1)
 Set the weight function which must be defined on the interval [0,1].

void FitterFCN(int& npar, double* dummy, double& fchisq, double* gin, int iflag)
 internal function which gives the specified function to the TMinuit function

void Fit()
 internal function that calls the fitter

void Test()
 This test function shows the basic working principles of this class
 and illustrates how a robust fit can improve the results

void SetInitialParam(TVectorD *const param)
{ fParam=param;}
void SetParamLimits(TMatrixD *const paramLimits)
{ fParamLimits=paramLimits;}
void SetFitFunction(TFormula *const formula)
{fFormula=formula;}
void SetWeightFunction(TFormula *const weightFunction)
{fWeightFunction=weightFunction;}
void SetFitAlgorithm(Char_t *const name)
void SetMaxCalls(Int_t calls)
{fMaxCalls = calls;}
void SetTolerance(Double_t tol)
{fPrecision = tol;}
void SetPoints(TMatrixD *const points)
{fPoints = points;}
void SetWeights(TVectorD *const weights)
{fWeights = weights;}
void EnableRobust(Bool_t b)
{fUseRobust = b;}
void EnableRobust(Bool_t b, Double_t sigma)
{fUseRobust = b; fExpectedSigma = sigma;}
TMatrixD * GetPoints() const
{return fPoints;}
TVectorD * GetWeights() const
{return fWeights;}
TFormula * GetFormula() const
{return fFormula;}
TVectorD * GetParameters() const
{return fParam;}
TFormula * GetWeightFunction() const
{return fWeightFunction;}
TMatrixD * GetCovarianceMatrix() const
{return fCovar;}
Bool_t GetStatus() const
{return fUseRobust;}
Double_t GetExpectedSigma() const
{return fExpectedSigma;}