Jpp  pmt_effective_area_update
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Public Attributes | Private Attributes | List of all members
JTestZero Class Reference

Implementation of a bin-by-bin compatibility test for 2D histograms with low bin contents. More...

#include <JTestZero.hh>

Inheritance diagram for JTestZero:
JTest_t JTestZero_t

Public Member Functions

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

Public Attributes

std::vector< JTestResultresults
 

Private Attributes

double outliersThreshold
 Fraction of bins allowed to fail. More...
 
double threshold
 threshold p-value to decide if test is passed. More...
 
const std::string name = "Zero"
 test name. More...
 
const std::string parameter = "failure_fraction"
 parameter name. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

JTestZero::JTestZero ( )
inline

Default constructor.

Definition at line 36 of file JTestZero.hh.

36 {}

Member Function Documentation

std::istream& JTestZero::read ( std::istream &  in)
inlineoverridevirtual

Read test parameters from input.

Parameters
ininput stream
Returns
input stream

Implements JTest_t.

Definition at line 44 of file JTestZero.hh.

44  {
45  return in >> outliersThreshold >> threshold;
46  };
double outliersThreshold
Fraction of bins allowed to fail.
Definition: JTestZero.hh:136
double threshold
threshold p-value to decide if test is passed.
Definition: JTestZero.hh:137
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
Definition: JCanberra.sh:40
std::ostream& JTestZero::write ( std::ostream &  out,
std::string  delimiter = " ",
bool  onlyFailures = false 
) const
inlineoverridevirtual

Write test result to output.

Parameters
outoutput stream
delimiterfield delimiter
onlyFailuresIf true, write only failures.
Returns
output stream

Implements JTest_t.

Definition at line 56 of file JTestZero.hh.

56  {
57  for (std::vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r) {
58  if (onlyFailures){
59  if (!r->passed)
60  out << std::scientific << std::setprecision(2) << (r->passed ? JPP::GREEN : JPP::RED) << r->print(delimiter) << std::endl;
61  }else{
62  out << std::scientific << std::setprecision(2) << (r->passed ? JPP::GREEN : JPP::RED) << r->print(delimiter) << std::endl;
63  }
64  }
65  return out;
66  };
std::vector< JTestResult > results
Definition: JTest_t.hh:251
data_type r[M+1]
Definition: JPolint.hh:742
void JTestZero::test ( TObject o1,
TObject o2 
)
inlineoverridevirtual

Bin-by-bin comparison for ROOT TH2 histograms, of compatibility with a Poisson pdf of parameter 1.

Parameters
o1First histogram
o2Second histogram

Implements JTest_t.

Definition at line 74 of file JTestZero.hh.

74  {
75 
76  using namespace std;
77 
78  if (!(dynamic_cast<TH2*>(o1) == NULL) && !(dynamic_cast<TH2*>(o2) == NULL)) {
79 
80  TH2D* h1 = dynamic_cast<TH2D*>(o1);
81  TH2D* h2 = dynamic_cast<TH2D*>(o2);
82 
84  results.push_back(r);
85  }
86  };
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. ...
Definition: JTestZero_t.hh:46
const std::string parameter
parameter name.
Definition: JTestZero.hh:139
const std::string name
test name.
Definition: JTestZero.hh:138
double outliersThreshold
Fraction of bins allowed to fail.
Definition: JTestZero.hh:136
std::vector< JTestResult > results
Definition: JTest_t.hh:251
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
data_type r[M+1]
Definition: JPolint.hh:742
double threshold
threshold p-value to decide if test is passed.
Definition: JTestZero.hh:137
Structure containing the result of the test.
Definition: JTest_t.hh:164
virtual void JTestZero::save ( TFile *  f,
std::string  path,
bool  onlyFailures = false 
)
inlineoverridevirtual

Writes the test result to root file.

Parameters
fA ROOT file
pathPath in root file.
onlyFailuresIf true, write only failures.

Implements JTest_t.

Definition at line 94 of file JTestZero.hh.

94  {
95 
96  using namespace std;
97 
98  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
99 
100  if (onlyFailures){
101  if (!r->passed){
102  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
103  f->cd(path.c_str());
104  r->obj->Write();
105  }
106  }else{
107  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
108  f->cd(path.c_str());
109  r->obj->Write();
110  }
111  }
112  }
std::vector< JTestResult > results
Definition: JTest_t.hh:251
data_type r[M+1]
Definition: JPolint.hh:742
then JPizza f
Definition: JPizza.sh:46
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.

117  {
118  results.clear();
119  }
std::vector< JTestResult > results
Definition: JTest_t.hh:251
std::string JTestZero::getName ( )
inlineoverridevirtual

Get test name.

Implements JTest_t.

Definition at line 124 of file JTestZero.hh.

124  {
125  return name;
126  }
const std::string name
test name.
Definition: JTestZero.hh:138
std::string JTestZero::getParameter ( )
inlineoverridevirtual

Get parameter name.

Implements JTest_t.

Definition at line 131 of file JTestZero.hh.

131  {
132  return parameter;
133  }
const std::string parameter
parameter name.
Definition: JTestZero.hh:139
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
h1First object
h2Second object
outliersThresholdFraction of incompatible bins allowed.
thresholdPoisson p-value
parameterNameName of the parameter used to test the histograms
testNameName of the test used to compare the histograms

Definition at line 46 of file JTestZero_t.hh.

46  {
47 
48  using namespace std;
49  using namespace JPP;
50 
51  int nx1 = h1->GetNbinsX();
52  int nx2 = h2->GetNbinsX();
53  int ny1 = h1->GetNbinsY();
54  int ny2 = h2->GetNbinsY();
55 
56  if(nx1 != nx2 || ny1 != ny2)
57  ERROR("Histograms with different binning. The objects: " << h1->GetName() << " can not be compared." << endl);
58 
59  TH2D* h3 = (TH2D*)h1->Clone(h1->GetName()==h2->GetName() ?
60  MAKE_CSTRING(to_string(h1->GetName())) :
61  MAKE_CSTRING(to_string(h1->GetName()) + "_VS_" + to_string(h2->GetName())));
62  h3->Reset();
63 
64  double failures = 0;
65 
66  for (int i=1 ; i<nx1+1 ; ++i){
67  for (int j=1 ; j<ny1+1 ; ++j){
68 
69  double m = h1 -> GetBinContent(i,j);
70  double n = h2 -> GetBinContent(i,j);
71 
72  double p1 = 1 - ROOT::Math::poisson_cdf(m,1);
73  double p2 = 1 - ROOT::Math::poisson_cdf(n,1);
74 
75  if ((p1 > threshold && p2 < threshold) ||
76  (p1 < threshold && p2 > threshold)){
77  h3->Fill(i,j);
78  failures+=1./(nx1*ny1);
79  }
80  }
81  }
82 
83  bool passed;
84 
85  (failures > outliersThreshold ? passed = false : passed = true);
86 
87  JResultTitle title(testName, parameterName, passed , failures);
88 
89  h3->SetTitle(title.getTitle().c_str());
90 
91  JTestResult r (testName,
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);
97 
98  return r;
99  };
TPaveText * p1
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
Definition: JTest_t.hh:22
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
data_type r[M+1]
Definition: JPolint.hh:742
Structure containing the result of the test.
Definition: JTest_t.hh:164
#define ERROR(A)
Definition: JMessage.hh:66
p2
Definition: module-Z:fit.sh:73
alias put_queue eval echo n
Definition: qlib.csh:19
std::string to_string(const T &value)
Convert value to string.
int j
Definition: JPolint.hh:666

Member Data Documentation

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

test name.

Definition at line 138 of file JTestZero.hh.

const std::string JTestZero::parameter = "failure_fraction"
private

parameter name.

Definition at line 139 of file JTestZero.hh.

std::vector<JTestResult> JTest_t::results
inherited

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: