Implementation of a bin-by-bin compatibility test for 2D histograms with low bin contents.
More...
#include <JTestZero.hh>
|
| JTestZero () |
| Default constructor. More...
|
|
std::istream & | read (std::istream &in) override |
| Read test parameters from input. More...
|
|
std::ostream & | write (std::ostream &out, std::string delimiter=" ", bool onlyFailures=false) const override |
| Write test result to output. More...
|
|
void | test (TObject *o1, TObject *o2) override |
| Bin-by-bin comparison for ROOT TH2 histograms, of compatibility with a Poisson pdf of parameter 1. More...
|
|
virtual void | save (TFile *f, std::string path, bool onlyFailures=false) override |
| Writes the test result to root file. More...
|
|
void | clear () override |
| Clear results. More...
|
|
std::string | getName () override |
| Get test name. More...
|
|
std::string | getParameter () override |
| Get parameter name. More...
|
|
JTestResult | JTestZero_2D (TH2 *h1, TH2 *h2, double outliersThreshold, double threshold, std::string testName, std::string parameterName) |
| Bin-by-Bin test for 2D histograms where a very low number of entries is expected. More...
|
|
Implementation of a bin-by-bin compatibility test for 2D histograms with low bin contents.
- Author
- rgruiz
This class is derived from the abstract class JTest_t(). For a general description of the implementation of this and other tests derived from JTest_t(), see its documentation.
The test is run by the method JTestZero_2D().
Definition at line 27 of file JTestZero.hh.
std::istream& JTestZero::read |
( |
std::istream & |
in | ) |
|
|
inlineoverridevirtual |
Read test parameters from input.
- Parameters
-
- Returns
- input stream
Implements JTest_t.
Definition at line 44 of file JTestZero.hh.
double outliersThreshold
Fraction of bins allowed to fail.
double threshold
threshold p-value to decide if test is passed.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
std::ostream& JTestZero::write |
( |
std::ostream & |
out, |
|
|
std::string |
delimiter = " " , |
|
|
bool |
onlyFailures = false |
|
) |
| const |
|
inlineoverridevirtual |
Write test result to output.
- Parameters
-
out | output stream |
delimiter | field delimiter |
onlyFailures | If true, write only failures. |
- Returns
- output stream
Implements JTest_t.
Definition at line 56 of file JTestZero.hh.
60 out << std::scientific << std::setprecision(2) << (
r->passed ?
JPP::GREEN :
JPP::RED) <<
r->print(delimiter) << std::endl;
62 out << std::scientific << std::setprecision(2) << (
r->passed ?
JPP::GREEN :
JPP::RED) <<
r->print(delimiter) << std::endl;
std::vector< JTestResult > results
Bin-by-bin comparison for ROOT TH2 histograms, of compatibility with a Poisson pdf of parameter 1.
- Parameters
-
o1 | First histogram |
o2 | Second histogram |
Implements JTest_t.
Definition at line 74 of file JTestZero.hh.
78 if (!(dynamic_cast<TH2*>(o1) == NULL) && !(dynamic_cast<TH2*>(o2) == NULL)) {
80 TH2D*
h1 =
dynamic_cast<TH2D*
>(o1);
81 TH2D* h2 =
dynamic_cast<TH2D*
>(o2);
JTestResult JTestZero_2D(TH2 *h1, TH2 *h2, double outliersThreshold, double threshold, std::string testName, std::string parameterName)
Bin-by-Bin test for 2D histograms where a very low number of entries is expected. ...
const std::string parameter
parameter name.
const std::string name
test name.
double outliersThreshold
Fraction of bins allowed to fail.
std::vector< JTestResult > results
then for HISTOGRAM in h0 h1
double threshold
threshold p-value to decide if test is passed.
Structure containing the result of the test.
virtual void JTestZero::save |
( |
TFile * |
f, |
|
|
std::string |
path, |
|
|
bool |
onlyFailures = false |
|
) |
| |
|
inlineoverridevirtual |
Writes the test result to root file.
- Parameters
-
f | A ROOT file |
path | Path in root file. |
onlyFailures | If true, write only failures. |
Implements JTest_t.
Definition at line 94 of file JTestZero.hh.
102 if (
f -> GetDirectory(
path.c_str())==0)
f->mkdir(
path.c_str());
107 if (
f -> GetDirectory(
path.c_str())==0)
f->mkdir(
path.c_str());
std::vector< JTestResult > results
do cat driver txt<< EOFevent ev_configure{RC_EVT%< ev_configure.txt > RC_DWRT path
void JTestZero::clear |
( |
| ) |
|
|
inlineoverridevirtual |
Clear results.
Implements JTest_t.
Definition at line 117 of file JTestZero.hh.
std::vector< JTestResult > results
std::string JTestZero::getName |
( |
| ) |
|
|
inlineoverridevirtual |
Get test name.
Implements JTest_t.
Definition at line 124 of file JTestZero.hh.
const std::string name
test name.
std::string JTestZero::getParameter |
( |
| ) |
|
|
inlineoverridevirtual |
Get parameter name.
Implements JTest_t.
Definition at line 131 of file JTestZero.hh.
const std::string parameter
parameter name.
JTestResult JTestZero_t::JTestZero_2D |
( |
TH2 * |
h1, |
|
|
TH2 * |
h2, |
|
|
double |
outliersThreshold, |
|
|
double |
threshold, |
|
|
std::string |
testName, |
|
|
std::string |
parameterName |
|
) |
| |
|
inlineinherited |
Bin-by-Bin test for 2D histograms where a very low number of entries is expected.
The test loops over all the bins of both histograms and performs the following operations.
-Calculates the probability that the observed bin content for histogram A is obtained from a Poisson of parameter 1.
-Compares the previous result with the threshold value given as an input parameter. The result is true if the probability is higher than the threshold.
-Calculates the probability that the observed bin content for histogram B is obtained from a Poisson of parameter 1.
-Compares the previous result with the threshold value given as an input parameter. The result is true if the probability is higher than the threshold.
-Compares the results from both bins: If both are true, or both are false, the test is passed. If one is true and the other is false, the test is failed.
At the end of the loop, a failure fraction is computed and compared to the outliersThreshold parameter. If the failure fraction is above the threshold, the test is failed.
- Parameters
-
h1 | First object |
h2 | Second object |
outliersThreshold | Fraction of incompatible bins allowed. |
threshold | Poisson p-value |
parameterName | Name of the parameter used to test the histograms |
testName | Name of the test used to compare the histograms |
Definition at line 46 of file JTestZero_t.hh.
51 int nx1 =
h1->GetNbinsX();
52 int nx2 = h2->GetNbinsX();
53 int ny1 =
h1->GetNbinsY();
54 int ny2 = h2->GetNbinsY();
56 if(nx1 != nx2 || ny1 != ny2)
57 ERROR(
"Histograms with different binning. The objects: " <<
h1->GetName() <<
" can not be compared." << endl);
59 TH2D* h3 = (TH2D*)
h1->Clone(
h1->GetName()==h2->GetName() ?
66 for (
int i=1 ; i<nx1+1 ; ++i){
67 for (
int j=1 ;
j<ny1+1 ; ++
j){
69 double m =
h1 -> GetBinContent(i,
j);
70 double n = h2 -> GetBinContent(i,
j);
72 double p1 = 1 - ROOT::Math::poisson_cdf(m,1);
73 double p2 = 1 - ROOT::Math::poisson_cdf(n,1);
75 if ((p1 > threshold && p2 < threshold) ||
76 (p1 < threshold && p2 > threshold)){
78 failures+=1./(nx1*ny1);
85 (failures > outliersThreshold ? passed =
false : passed =
true);
87 JResultTitle title(testName, parameterName, passed , failures);
89 h3->SetTitle(title.getTitle().c_str());
92 string (
h1->GetDirectory()->GetPath()).append(
h1->GetName()),
93 string (h2->GetDirectory()->GetPath()).append(h2->GetName()),
94 h1->GetDirectory()->GetFile()->GetName(),
95 h2->GetDirectory()->GetFile()->GetName(),
96 parameterName, failures, threshold, h3, passed);
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
#define MAKE_CSTRING(A)
Make C-string.
then for HISTOGRAM in h0 h1
Structure containing the result of the test.
alias put_queue eval echo n
std::string to_string(const T &value)
Convert value to string.
double JTestZero::outliersThreshold |
|
private |
Fraction of bins allowed to fail.
Definition at line 136 of file JTestZero.hh.
double JTestZero::threshold |
|
private |
threshold p-value to decide if test is passed.
Definition at line 137 of file JTestZero.hh.
const std::string JTestZero::name = "Zero" |
|
private |
const std::string JTestZero::parameter = "failure_fraction" |
|
private |
Buffer to store results of multiple tests.
Definition at line 251 of file JTest_t.hh.
The documentation for this class was generated from the following file: