PhysicsTools
Utilities
interface
HistoPoissonLikelihoodRatio.h
Go to the documentation of this file.
1
#ifndef PhysicsTools_Utilities_HistoPoissonLikelihoodRatio_h
2
#define PhysicsTools_Utilities_HistoPoissonLikelihoodRatio_h
3
#include "
PhysicsTools/Utilities/interface/RootMinuitResultPrinter.h
"
4
#include <vector>
5
#include <cmath>
6
#include "TH1.h"
7
#include "TMath.h"
8
9
namespace
fit
{
10
template
<
typename
T>
11
class
HistoPoissonLikelihoodRatio
{
12
public
:
13
HistoPoissonLikelihoodRatio
() {}
14
HistoPoissonLikelihoodRatio
(
T
&
t
, TH1 *
histo
,
double
rangeMin,
double
rangeMax)
15
:
t_
(&
t
),
rangeMin_
(rangeMin),
rangeMax_
(rangeMax) {
16
nBins_
=
histo
->GetNbinsX();
17
xMin_
=
histo
->GetXaxis()->GetXmin();
18
xMax_
=
histo
->GetXaxis()->GetXmax();
19
deltaX_
= (
xMax_
-
xMin_
) /
nBins_
;
20
for
(
size_t
i
= 0;
i
<
nBins_
; ++
i
) {
21
cont_
.push_back(
histo
->GetBinContent(
i
+ 1));
22
}
23
}
24
double
operator()
()
const
{
25
double
chi2lambda = 0;
26
for
(
size_t
i
= 0;
i
<
nBins_
; ++
i
) {
27
double
x =
xMin_
+ (
i
+ .5) *
deltaX_
;
28
if
((x >
rangeMin_
) && (x <
rangeMax_
)) {
29
double
nu = (*t_)(x);
30
if
(nu > 0 &&
cont_
[
i
] > 0)
31
chi2lambda += nu -
cont_
[
i
] +
cont_
[
i
] *
log
(
cont_
[
i
] / nu);
32
}
33
}
34
chi2lambda *= 2;
35
return
chi2lambda;
36
}
37
void
setHistos
(TH1 *
histo
) {
38
nBins_
=
histo
->GetNbinsX();
39
xMin_
=
histo
->GetXaxis()->GetXmin();
40
xMax_
=
histo
->GetXaxis()->GetXmax();
41
deltaX_
= (
xMax_
-
xMin_
) /
nBins_
;
42
}
43
size_t
numberOfBins
()
const
{
44
size_t
fullBins = 0;
45
for
(
size_t
i
= 0;
i
<
nBins_
; ++
i
) {
46
double
x =
xMin_
+ (
i
+ .5) *
deltaX_
;
47
if
((x >
rangeMin_
) && (x <
rangeMax_
))
48
fullBins++;
49
}
50
return
fullBins;
51
}
52
T
&
function
() {
return
*
t_
; }
53
const
T
&
function
()
const
{
return
*
t_
; }
54
55
private
:
56
T
*
t_
;
57
double
rangeMin_
,
rangeMax_
;
58
size_t
nBins_
;
59
double
xMin_
,
xMax_
,
deltaX_
;
60
std::vector<double>
cont_
;
61
};
62
63
template
<
typename
T>
64
struct
RootMinuitResultPrinter
<
HistoPoissonLikelihoodRatio
<
T
> > {
65
static
void
print
(
double
amin,
unsigned
int
numberOfFreeParameters,
const
HistoPoissonLikelihoodRatio<T>
&
f
) {
66
unsigned
int
ndof
=
f
.numberOfBins() - numberOfFreeParameters;
67
std::cout
<<
"chi-squared/n.d.o.f. = "
<< amin <<
"/"
<<
ndof
<<
" = "
<< amin /
ndof
68
<<
"; prob: "
<< TMath::Prob(amin,
ndof
) << std::endl;
69
}
70
};
71
}
// namespace fit
72
73
#endif
mps_fire.i
i
Definition:
mps_fire.py:428
fit::HistoPoissonLikelihoodRatio::HistoPoissonLikelihoodRatio
HistoPoissonLikelihoodRatio(T &t, TH1 *histo, double rangeMin, double rangeMax)
Definition:
HistoPoissonLikelihoodRatio.h:14
f
double f[11][100]
Definition:
MuScleFitUtils.cc:78
gather_cfg.cout
cout
Definition:
gather_cfg.py:144
timingPdfMaker.histo
histo
Definition:
timingPdfMaker.py:278
fit::HistoPoissonLikelihoodRatio::rangeMin_
double rangeMin_
Definition:
HistoPoissonLikelihoodRatio.h:57
ndof
Definition:
HIMultiTrackSelector.h:49
fit::HistoPoissonLikelihoodRatio::nBins_
size_t nBins_
Definition:
HistoPoissonLikelihoodRatio.h:58
fit::HistoPoissonLikelihoodRatio::deltaX_
double deltaX_
Definition:
HistoPoissonLikelihoodRatio.h:59
fit::HistoPoissonLikelihoodRatio
Definition:
HistoPoissonLikelihoodRatio.h:11
fit::HistoPoissonLikelihoodRatio::operator()
double operator()() const
Definition:
HistoPoissonLikelihoodRatio.h:24
fit::RootMinuitResultPrinter< HistoPoissonLikelihoodRatio< T > >::print
static void print(double amin, unsigned int numberOfFreeParameters, const HistoPoissonLikelihoodRatio< T > &f)
Definition:
HistoPoissonLikelihoodRatio.h:65
fit::HistoPoissonLikelihoodRatio::cont_
std::vector< double > cont_
Definition:
HistoPoissonLikelihoodRatio.h:60
fit::HistoPoissonLikelihoodRatio::rangeMax_
double rangeMax_
Definition:
HistoPoissonLikelihoodRatio.h:57
fit::HistoPoissonLikelihoodRatio::t_
T * t_
Definition:
HistoPoissonLikelihoodRatio.h:56
fit::HistoPoissonLikelihoodRatio::numberOfBins
size_t numberOfBins() const
Definition:
HistoPoissonLikelihoodRatio.h:43
RootMinuitResultPrinter.h
T
long double T
Definition:
Basic3DVectorLD.h:48
fit::HistoPoissonLikelihoodRatio::HistoPoissonLikelihoodRatio
HistoPoissonLikelihoodRatio()
Definition:
HistoPoissonLikelihoodRatio.h:13
fit::HistoPoissonLikelihoodRatio::setHistos
void setHistos(TH1 *histo)
Definition:
HistoPoissonLikelihoodRatio.h:37
dqm-mbProfile.log
log
Definition:
dqm-mbProfile.py:17
fit::HistoPoissonLikelihoodRatio::xMin_
double xMin_
Definition:
HistoPoissonLikelihoodRatio.h:59
fit::RootMinuitResultPrinter
Definition:
RootMinuitResultPrinter.h:8
submitPVValidationJobs.t
string t
Definition:
submitPVValidationJobs.py:644
fit
Definition:
CombinedChiSquaredLikelihood.h:6
fit::HistoPoissonLikelihoodRatio::xMax_
double xMax_
Definition:
HistoPoissonLikelihoodRatio.h:59
Generated for CMSSW Reference Manual by
1.8.16