CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes | Friends

UnbinnedLikelihoodFit Class Reference

#include <UnbinnedLikelihoodFit.h>

List of all members.

Public Member Functions

int32_t fit (int32_t verbosity=-1)
int32_t fit (int32_t n, double *x, int32_t verbosity=-1)
TF1 * getFunction () const
double getParameterError (uint32_t i)
double * getParameterErrors ()
double getParameterValue (uint32_t i)
double * getParameterValues ()
void setData (uint32_t n, double *x)
void setFunction (TF1 *f)
void setMaxIterations (uint32_t n)
void setTolerance (double tol)
 UnbinnedLikelihoodFit ()
 ~UnbinnedLikelihoodFit ()

Private Member Functions

double logL (const double *x) const

Private Attributes

double arglist_ [10]
uint32_t datasize_
TF1 * function_
uint32_t maxIterations_
TVirtualFitter * min
uint32_t nparameters_
double tolerance_
double * x_

Friends

void UnbinnedLL (Int_t &npar, Double_t *gin, Double_t &val, Double_t *par, Int_t iflag)

Detailed Description

Definition at line 24 of file UnbinnedLikelihoodFit.h.


Constructor & Destructor Documentation

UnbinnedLikelihoodFit::UnbinnedLikelihoodFit ( )

Definition at line 30 of file UnbinnedLikelihoodFit.cc.

References datasize_, maxIterations_, min, nparameters_, NULL, tolerance_, and x_.

                                             {
  nparameters_ = 0;
  datasize_ = 0;
  x_ = NULL;
  min = NULL;
  tolerance_ = 0.01;
  maxIterations_ = 1000;
}
UnbinnedLikelihoodFit::~UnbinnedLikelihoodFit ( )

Definition at line 40 of file UnbinnedLikelihoodFit.cc.

                                              {
}

Member Function Documentation

int32_t UnbinnedLikelihoodFit::fit ( int32_t  verbosity = -1)

Definition at line 57 of file UnbinnedLikelihoodFit.cc.

References arglist_, ExpressReco_HICollisions_FallBack::Fitter, function_, i, maxIterations_, min, nparameters_, ntuplemaker::status, tolerance_, UnbinnedLL, and verbosity.

Referenced by UnbinnedFitDeDxEstimator::dedx().

                                                    {
  // creates a fitter 
  min = TVirtualFitter::Fitter(this,nparameters_);
  min->SetFCN(UnbinnedLL);
  
  // set print level: no output
  arglist_[0] = 0;
  min->ExecuteCommand("SET NOWarnings",arglist_,1);
  arglist_[0] = verbosity;
  min->ExecuteCommand("SET PRINT",arglist_,1);
  
  // initial values, error, range
  double parmin,parmax;
  for(uint32_t i=0;i<nparameters_;++i) {
    function_->GetParLimits(i, parmin, parmax);
    min->SetParameter(i,
                      function_->GetParName(i),
                      function_->GetParameter(i),
                      tolerance_,
                      parmin, parmax);
  }

  // run MIGRAD
  arglist_[0] = maxIterations_; // number of function calls
  arglist_[1] = tolerance_;     // tolerance
  int32_t status = min->ExecuteCommand("MIGRAD",arglist_,2);

  // get fit parameters and errors
  for(uint32_t i=0;i<nparameters_;++i) {
    function_->SetParameter(i, min->GetParameter(i));
    function_->SetParError( i, min->GetParError(i) );
  }

  // returns the status
  return status;
}
int32_t UnbinnedLikelihoodFit::fit ( int32_t  n,
double *  x,
int32_t  verbosity = -1 
) [inline]

Definition at line 43 of file UnbinnedLikelihoodFit.h.

References fit(), setData(), and verbosity.

Referenced by fit().

{ setData(n,x); return fit(verbosity); }
TF1* UnbinnedLikelihoodFit::getFunction ( ) const [inline]

Definition at line 46 of file UnbinnedLikelihoodFit.h.

References function_.

{ return function_; }
double UnbinnedLikelihoodFit::getParameterError ( uint32_t  i) [inline]

Definition at line 48 of file UnbinnedLikelihoodFit.h.

References function_.

{ return function_ ? function_->GetParError(i)  : 0; }
double* UnbinnedLikelihoodFit::getParameterErrors ( ) [inline]

Definition at line 50 of file UnbinnedLikelihoodFit.h.

References function_, and NULL.

{ return function_ ? function_->GetParErrors()  : NULL; }
double UnbinnedLikelihoodFit::getParameterValue ( uint32_t  i) [inline]

Definition at line 47 of file UnbinnedLikelihoodFit.h.

References function_.

{ return function_ ? function_->GetParameter(i) : 0; }
double* UnbinnedLikelihoodFit::getParameterValues ( ) [inline]

Definition at line 49 of file UnbinnedLikelihoodFit.h.

References function_, and NULL.

{ return function_ ? function_->GetParameters() : NULL; }
double UnbinnedLikelihoodFit::logL ( const double *  x) const [private]

Definition at line 95 of file UnbinnedLikelihoodFit.cc.

References datasize_, function_, i, and x_.

                                                                 {
  double val=0;
  if(!function_) return val;
  for (uint32_t i=0;i<datasize_;++i){
    val += TMath::Log(function_->EvalPar(&(x_[i]),parameters));
  }
  return val; 
} 
void UnbinnedLikelihoodFit::setData ( uint32_t  n,
double *  x 
)

Definition at line 45 of file UnbinnedLikelihoodFit.cc.

References datasize_, n, ExpressReco_HICollisions_FallBack::x, and x_.

Referenced by fit().

                                                         {
  datasize_ = n;
  x_ = x;
}
void UnbinnedLikelihoodFit::setFunction ( TF1 *  f)

Definition at line 51 of file UnbinnedLikelihoodFit.cc.

References f, function_, and nparameters_.

Referenced by UnbinnedFitDeDxEstimator::UnbinnedFitDeDxEstimator().

                                              {
  function_ = f;
  nparameters_ = function_ ? function_->GetNpar() : 0;
}
void UnbinnedLikelihoodFit::setMaxIterations ( uint32_t  n) [inline]

Definition at line 39 of file UnbinnedLikelihoodFit.h.

References maxIterations_, and n.

void UnbinnedLikelihoodFit::setTolerance ( double  tol) [inline]

Definition at line 38 of file UnbinnedLikelihoodFit.h.

References tolerance_.

{ tolerance_ = tol; }

Friends And Related Function Documentation

void UnbinnedLL ( Int_t &  npar,
Double_t *  gin,
Double_t &  val,
Double_t *  par,
Int_t  iflag 
) [friend]

Definition at line 22 of file UnbinnedLikelihoodFit.cc.

Referenced by fit().

                                                                        {
  // retrieve the data object (it's also the fitter)
  // - sign to have a minimum
  // factor 2 to have the right errors (see for example the pdg)
  val = -2*((dynamic_cast<const UnbinnedLikelihoodFit*>((TVirtualFitter::GetFitter())->GetObjectFit()))->logL(par));
}

Member Data Documentation

double UnbinnedLikelihoodFit::arglist_[10] [private]

Definition at line 60 of file UnbinnedLikelihoodFit.h.

Referenced by fit().

Definition at line 54 of file UnbinnedLikelihoodFit.h.

Referenced by logL(), setData(), and UnbinnedLikelihoodFit().

Definition at line 61 of file UnbinnedLikelihoodFit.h.

Referenced by fit(), setMaxIterations(), and UnbinnedLikelihoodFit().

TVirtualFitter* UnbinnedLikelihoodFit::min [private]

Definition at line 64 of file UnbinnedLikelihoodFit.h.

Referenced by fit(), and UnbinnedLikelihoodFit().

Definition at line 58 of file UnbinnedLikelihoodFit.h.

Referenced by fit(), setFunction(), and UnbinnedLikelihoodFit().

Definition at line 62 of file UnbinnedLikelihoodFit.h.

Referenced by fit(), setTolerance(), and UnbinnedLikelihoodFit().

double* UnbinnedLikelihoodFit::x_ [private]

Definition at line 55 of file UnbinnedLikelihoodFit.h.

Referenced by logL(), setData(), and UnbinnedLikelihoodFit().