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

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::UnbinnedLikelihoodFit ( )

Definition at line 30 of file UnbinnedLikelihoodFit.cc.

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

30  {
31  nparameters_ = 0;
32  datasize_ = 0;
33  x_ = nullptr;
34  min = nullptr;
35  tolerance_ = 0.01;
36  maxIterations_ = 1000;
37 }

◆ ~UnbinnedLikelihoodFit()

UnbinnedLikelihoodFit::~UnbinnedLikelihoodFit ( )
override

Definition at line 40 of file UnbinnedLikelihoodFit.cc.

40 {}

Member Function Documentation

◆ fit() [1/2]

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

Definition at line 56 of file UnbinnedLikelihoodFit.cc.

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

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

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

◆ fit() [2/2]

int32_t UnbinnedLikelihoodFit::fit ( int32_t  n,
double *  x,
int32_t  verbosity = -1 
)
inline

Definition at line 42 of file UnbinnedLikelihoodFit.h.

References fit(), create_idmaps::n, setData(), verbosity, and x.

Referenced by trackingPlots.Iteration::modules().

42  {
43  setData(n, x);
44  return fit(verbosity);
45  }
void setData(uint32_t n, double *x)
const int verbosity
int32_t fit(int32_t verbosity=-1)

◆ getFunction()

TF1* UnbinnedLikelihoodFit::getFunction ( ) const
inline

Definition at line 48 of file UnbinnedLikelihoodFit.h.

References function_.

48 { return function_; }

◆ getParameterError()

double UnbinnedLikelihoodFit::getParameterError ( uint32_t  i)
inline

Definition at line 50 of file UnbinnedLikelihoodFit.h.

References function_, and mps_fire::i.

50 { return function_ ? function_->GetParError(i) : 0; }

◆ getParameterErrors()

const double* UnbinnedLikelihoodFit::getParameterErrors ( )
inline

Definition at line 52 of file UnbinnedLikelihoodFit.h.

References function_.

52 { return function_ ? function_->GetParErrors() : nullptr; }

◆ getParameterValue()

double UnbinnedLikelihoodFit::getParameterValue ( uint32_t  i)
inline

Definition at line 49 of file UnbinnedLikelihoodFit.h.

References function_, and mps_fire::i.

49 { return function_ ? function_->GetParameter(i) : 0; }

◆ getParameterValues()

double* UnbinnedLikelihoodFit::getParameterValues ( )
inline

Definition at line 51 of file UnbinnedLikelihoodFit.h.

References function_.

51 { return function_ ? function_->GetParameters() : nullptr; }

◆ logL()

double UnbinnedLikelihoodFit::logL ( const double *  x) const
private

Definition at line 90 of file UnbinnedLikelihoodFit.cc.

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

90  {
91  double val = 0;
92  if (!function_)
93  return val;
94  for (uint32_t i = 0; i < datasize_; ++i) {
95  val += TMath::Log(function_->EvalPar(&(x_[i]), parameters));
96  }
97  return val;
98 }

◆ setData()

void UnbinnedLikelihoodFit::setData ( uint32_t  n,
double *  x 
)

Definition at line 44 of file UnbinnedLikelihoodFit.cc.

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

Referenced by fit().

◆ setFunction()

void UnbinnedLikelihoodFit::setFunction ( TF1 *  f)

Definition at line 50 of file UnbinnedLikelihoodFit.cc.

References f, function_, and nparameters_.

Referenced by UnbinnedFitDeDxEstimator::UnbinnedFitDeDxEstimator().

50  {
51  function_ = f;
52  nparameters_ = function_ ? function_->GetNpar() : 0;
53 }
double f[11][100]

◆ setMaxIterations()

void UnbinnedLikelihoodFit::setMaxIterations ( uint32_t  n)
inline

Definition at line 38 of file UnbinnedLikelihoodFit.h.

References maxIterations_, and create_idmaps::n.

◆ setTolerance()

void UnbinnedLikelihoodFit::setTolerance ( double  tol)
inline

Definition at line 37 of file UnbinnedLikelihoodFit.h.

References tolerance_.

37 { tolerance_ = tol; }

Friends And Related Function Documentation

◆ UnbinnedLL

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

◆ arglist_

double UnbinnedLikelihoodFit::arglist_[10]
private

Definition at line 62 of file UnbinnedLikelihoodFit.h.

Referenced by fit().

◆ datasize_

uint32_t UnbinnedLikelihoodFit::datasize_
private

Definition at line 56 of file UnbinnedLikelihoodFit.h.

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

◆ function_

TF1* UnbinnedLikelihoodFit::function_
private

◆ maxIterations_

uint32_t UnbinnedLikelihoodFit::maxIterations_
private

Definition at line 63 of file UnbinnedLikelihoodFit.h.

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

◆ min

TVirtualFitter* UnbinnedLikelihoodFit::min
private

Definition at line 66 of file UnbinnedLikelihoodFit.h.

Referenced by fit(), and UnbinnedLikelihoodFit().

◆ nparameters_

uint32_t UnbinnedLikelihoodFit::nparameters_
private

Definition at line 60 of file UnbinnedLikelihoodFit.h.

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

◆ tolerance_

double UnbinnedLikelihoodFit::tolerance_
private

Definition at line 64 of file UnbinnedLikelihoodFit.h.

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

◆ x_

double* UnbinnedLikelihoodFit::x_
private

Definition at line 57 of file UnbinnedLikelihoodFit.h.

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