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 n, double *x, int32_t verbosity=-1)
 
int32_t fit (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.

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

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

◆ ~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  n,
double *  x,
int32_t  verbosity = -1 
)
inline

Definition at line 42 of file UnbinnedLikelihoodFit.h.

42  {
43  setData(n, x);
44  return fit(verbosity);
45  }

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

Referenced by trackingPlots.Iteration::modules().

◆ fit() [2/2]

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

Definition at line 56 of file UnbinnedLikelihoodFit.cc.

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 }

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

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

◆ getFunction()

TF1* UnbinnedLikelihoodFit::getFunction ( ) const
inline

Definition at line 48 of file UnbinnedLikelihoodFit.h.

48 { return function_; }

References function_.

◆ getParameterError()

double UnbinnedLikelihoodFit::getParameterError ( uint32_t  i)
inline

Definition at line 50 of file UnbinnedLikelihoodFit.h.

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

References function_, and mps_fire::i.

◆ getParameterErrors()

const double* UnbinnedLikelihoodFit::getParameterErrors ( )
inline

Definition at line 52 of file UnbinnedLikelihoodFit.h.

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

References function_.

◆ getParameterValue()

double UnbinnedLikelihoodFit::getParameterValue ( uint32_t  i)
inline

Definition at line 49 of file UnbinnedLikelihoodFit.h.

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

References function_, and mps_fire::i.

◆ getParameterValues()

double* UnbinnedLikelihoodFit::getParameterValues ( )
inline

Definition at line 51 of file UnbinnedLikelihoodFit.h.

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

References function_.

◆ logL()

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

Definition at line 90 of file UnbinnedLikelihoodFit.cc.

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 }

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

◆ setData()

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

Definition at line 44 of file UnbinnedLikelihoodFit.cc.

44  {
45  datasize_ = n;
46  x_ = x;
47 }

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

Referenced by fit().

◆ setFunction()

void UnbinnedLikelihoodFit::setFunction ( TF1 *  f)

Definition at line 50 of file UnbinnedLikelihoodFit.cc.

50  {
51  function_ = f;
52  nparameters_ = function_ ? function_->GetNpar() : 0;
53 }

References f, function_, and nparameters_.

Referenced by UnbinnedFitDeDxEstimator::UnbinnedFitDeDxEstimator().

◆ setMaxIterations()

void UnbinnedLikelihoodFit::setMaxIterations ( uint32_t  n)
inline

Definition at line 38 of file UnbinnedLikelihoodFit.h.

38 { maxIterations_ = n; }

References maxIterations_, and dqmiodumpmetadata::n.

◆ setTolerance()

void UnbinnedLikelihoodFit::setTolerance ( double  tol)
inline

Definition at line 37 of file UnbinnedLikelihoodFit.h.

37 { tolerance_ = tol; }

References tolerance_.

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.

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 }

Referenced by fit().

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

UnbinnedLikelihoodFit::datasize_
uint32_t datasize_
Definition: UnbinnedLikelihoodFit.h:56
HIPAlignmentAlgorithm_cfi.verbosity
verbosity
Definition: HIPAlignmentAlgorithm_cfi.py:7
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:30
mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
mps_update.status
status
Definition: mps_update.py:69
HLTSiStripMonitoring_cff.Fitter
Fitter
Definition: HLTSiStripMonitoring_cff.py:207
UnbinnedLikelihoodFit::logL
double logL(const double *x) const
Definition: UnbinnedLikelihoodFit.cc:90
UnbinnedLikelihoodFit::arglist_
double arglist_[10]
Definition: UnbinnedLikelihoodFit.h:62
DDAxes::x
UnbinnedLikelihoodFit::nparameters_
uint32_t nparameters_
Definition: UnbinnedLikelihoodFit.h:60
UnbinnedLikelihoodFit::min
TVirtualFitter * min
Definition: UnbinnedLikelihoodFit.h:66
UnbinnedLikelihoodFit::fit
int32_t fit(int32_t verbosity=-1)
Definition: UnbinnedLikelihoodFit.cc:56
UnbinnedLikelihoodFit::x_
double * x_
Definition: UnbinnedLikelihoodFit.h:57
heppy_batch.val
val
Definition: heppy_batch.py:351
UnbinnedLikelihoodFit::setData
void setData(uint32_t n, double *x)
Definition: UnbinnedLikelihoodFit.cc:44
UnbinnedLikelihoodFit::UnbinnedLL
friend void UnbinnedLL(Int_t &npar, Double_t *gin, Double_t &val, Double_t *par, Int_t iflag)
Definition: UnbinnedLikelihoodFit.cc:22
UnbinnedLikelihoodFit::maxIterations_
uint32_t maxIterations_
Definition: UnbinnedLikelihoodFit.h:63
UnbinnedLikelihoodFit::function_
TF1 * function_
Definition: UnbinnedLikelihoodFit.h:59
UnbinnedLikelihoodFit::tolerance_
double tolerance_
Definition: UnbinnedLikelihoodFit.h:64