Applies a log-likelihood ratio test to the two given histograms.
95 {
98
99 const TH1* h1 = dynamic_cast<const TH1*>(o1);
100 const TH1* h2 = dynamic_cast<const TH1*>(o2);
101
102 if (h1 == NULL || h2 == NULL) {
103 THROW(
JValueOutOfRange,
"JTestEffectiveLogLikelihood::test(): Could not cast given TObjects to TH1.");
104 }
105
106 if(h1->GetNbinsX() != h2->GetNbinsX() ||
107 h1->GetNbinsY() != h2->GetNbinsY() ||
108 h1->GetNbinsZ() != h2->GetNbinsZ()) {
109 THROW(
JValueOutOfRange,
"JTestEffectiveLogLikelihood::test(): Histograms with different binning. The objects: " <<
110 h1->GetName() << " and " << h2->GetName() << " can not be compared." << endl);
111 }
112
113 TH1* h3 = (TH1*) h1->Clone(h1->GetName() == h2->GetName() ?
116
117 h3->Reset();
118
119 double LnLratio = 0.0;
120
121 for (int i=1 ; i <= h1->GetNbinsX() ; ++i) {
122 for (
int j=1 ;
j <= h1->GetNbinsY() ; ++
j) {
123 for (int k=1 ; k <= h1->GetNbinsZ() ; ++k) {
124
125 const double n1 = h1->GetBinContent(i,j,k);
126 const double n2 = h2->GetBinContent(i,j,k);
127
128 const double e1 = h1->GetBinError(i,j,k);
129 const double e2 = h2->GetBinError(i,j,k);
130
131 double contribution = 0.0;
132
133 if (n1 > 0.0) {
134 contribution = (
getNLL(n1, n2, e2) -
136 } else if (n2 > 0.0) {
137 contribution =
getNLL(n1, n2, e2);
138 }
139
140 h3->SetBinContent(i,j,k, contribution);
141
142 LnLratio += contribution;
143 }
144 }
145 }
146
147 const bool passed = (LnLratio <
threshold);
148
150
151 h3->SetTitle(title.getTitle().c_str());
153
158
159 this->push_back(r);
160 }
#define MAKE_CSTRING(A)
Make C-string.
#define MAKE_STRING(A)
Make string.
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
static double getNLL(const double k, const double n, const double ne)
Get negative log-likelihood (i.e.
const std::string resultType
test result type
const std::string testName
test name
Auxiliary class to handle file name, ROOT directory and object name.
Structure containing the result of the test.