CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes | Friends
UnbinnedLikelihoodFit Class Reference

#include <UnbinnedLikelihoodFit.h>

Inheritance diagram for UnbinnedLikelihoodFit:

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)
 
const 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_.

30  {
31  nparameters_ = 0;
32  datasize_ = 0;
33  x_ = NULL;
34  min = NULL;
35  tolerance_ = 0.01;
36  maxIterations_ = 1000;
37 }
#define NULL
Definition: scimark2.h:8
UnbinnedLikelihoodFit::~UnbinnedLikelihoodFit ( )

Definition at line 40 of file UnbinnedLikelihoodFit.cc.

40  {
41 }

Member Function Documentation

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

Definition at line 57 of file UnbinnedLikelihoodFit.cc.

References arglist_, egammaCTFFinalFitWithMaterial_cff::Fitter, function_, mps_fire::i, maxIterations_, min, nparameters_, mps_update::status, tolerance_, UnbinnedLL, and HIPAlignmentAlgorithm_cfi::verbosity.

Referenced by UnbinnedFitDeDxEstimator::dedx(), trackingPlots.Iteration::modules(), and setMaxIterations().

57  {
58  // creates a fitter
60  min->SetFCN(UnbinnedLL);
61 
62  // set print level: no output
63  arglist_[0] = 0;
64  min->ExecuteCommand("SET NOWarnings",arglist_,1);
65  arglist_[0] = verbosity;
66  min->ExecuteCommand("SET PRINT",arglist_,1);
67 
68  // initial values, error, range
69  double parmin,parmax;
70  for(uint32_t i=0;i<nparameters_;++i) {
71  function_->GetParLimits(i, parmin, parmax);
72  min->SetParameter(i,
73  function_->GetParName(i),
74  function_->GetParameter(i),
75  tolerance_,
76  parmin, parmax);
77  }
78 
79  // run MIGRAD
80  arglist_[0] = maxIterations_; // number of function calls
81  arglist_[1] = tolerance_; // tolerance
82  int32_t status = min->ExecuteCommand("MIGRAD",arglist_,2);
83 
84  // get fit parameters and errors
85  for(uint32_t i=0;i<nparameters_;++i) {
86  function_->SetParameter(i, min->GetParameter(i));
87  function_->SetParError( i, min->GetParError(i) );
88  }
89 
90  // returns the status
91  return status;
92 }
friend void UnbinnedLL(Int_t &npar, Double_t *gin, Double_t &val, Double_t *par, Int_t iflag)
int32_t UnbinnedLikelihoodFit::fit ( int32_t  n,
double *  x,
int32_t  verbosity = -1 
)
inline
TF1* UnbinnedLikelihoodFit::getFunction ( ) const
inline

Definition at line 46 of file UnbinnedLikelihoodFit.h.

References function_.

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

Definition at line 48 of file UnbinnedLikelihoodFit.h.

References function_.

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

Definition at line 50 of file UnbinnedLikelihoodFit.h.

References function_, and NULL.

50 { return function_ ? function_->GetParErrors() : NULL; }
#define NULL
Definition: scimark2.h:8
double UnbinnedLikelihoodFit::getParameterValue ( uint32_t  i)
inline

Definition at line 47 of file UnbinnedLikelihoodFit.h.

References function_.

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

Definition at line 49 of file UnbinnedLikelihoodFit.h.

References function_, and NULL.

49 { return function_ ? function_->GetParameters() : NULL; }
#define NULL
Definition: scimark2.h:8
double UnbinnedLikelihoodFit::logL ( const double *  x) const
private

Definition at line 95 of file UnbinnedLikelihoodFit.cc.

References datasize_, function_, mps_fire::i, heppy_batch::val, and x_.

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

Definition at line 45 of file UnbinnedLikelihoodFit.cc.

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

Referenced by fit().

void UnbinnedLikelihoodFit::setFunction ( TF1 *  f)

Definition at line 51 of file UnbinnedLikelihoodFit.cc.

References f, function_, and nparameters_.

Referenced by UnbinnedFitDeDxEstimator::UnbinnedFitDeDxEstimator().

51  {
52  function_ = f;
53  nparameters_ = function_ ? function_->GetNpar() : 0;
54 }
double f[11][100]
void UnbinnedLikelihoodFit::setMaxIterations ( uint32_t  n)
inline
void UnbinnedLikelihoodFit::setTolerance ( double  tol)
inline

Definition at line 38 of file UnbinnedLikelihoodFit.h.

References tolerance_.

38 { 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().

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

Member Data Documentation

double UnbinnedLikelihoodFit::arglist_[10]
private

Definition at line 60 of file UnbinnedLikelihoodFit.h.

Referenced by fit().

uint32_t UnbinnedLikelihoodFit::datasize_
private

Definition at line 54 of file UnbinnedLikelihoodFit.h.

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

TF1* UnbinnedLikelihoodFit::function_
private
uint32_t UnbinnedLikelihoodFit::maxIterations_
private

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().

uint32_t UnbinnedLikelihoodFit::nparameters_
private

Definition at line 58 of file UnbinnedLikelihoodFit.h.

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

double UnbinnedLikelihoodFit::tolerance_
private

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().