Jpp  16.0.3
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Public Attributes | Protected Attributes | Private Attributes | List of all members
JCOMPAREHISTOGRAMS::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 JCOMPAREHISTOGRAMS::JTestZero:
JCOMPAREHISTOGRAMS::JTest_t JCOMPAREHISTOGRAMS::JTestZero_t

Public Member Functions

 JTestZero ()
 Default constructor. More...
 
std::istream & read (std::istream &in) override
 Read test parameters from input. 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...
 
std::ostream & write (std::ostream &out, const char delimiter= ' ', const bool onlyFailures=false) const
 Write test result to output. More...
 
virtual void save (TFile *f, const std::string &path, const bool onlyFailures=false)
 Writes the test result to root file. More...
 
virtual void clear ()
 Clear results. More...
 
const std::string & getTestName ()
 Get test name. More...
 
const std::string & getResultType ()
 Get result type. 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
 Buffer to store results of multiple tests.*/. More...
 

Protected Attributes

const std::string testName
 test name More...
 
const std::string resultType
 result type More...
 

Private Attributes

double outliersThreshold
 Fraction of bins allowed to fail. More...
 
double threshold
 threshold p-value to decide if test is passed. More...
 

Detailed Description

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


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 29 of file JTestZero.hh.

Constructor & Destructor Documentation

JCOMPAREHISTOGRAMS::JTestZero::JTestZero ( )
inline

Default constructor.

Definition at line 38 of file JTestZero.hh.

38  :
39  JTest_t("Zero", "failure_fraction"),
40  JTestZero_t()
41  {}
JTestZero_t()
Default constructor.
Definition: JTestZero_t.hh:35
JTest_t(const std::string &name, const std::string &type)
Constructor.
Definition: JTest_t.hh:57

Member Function Documentation

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

Read test parameters from input.

Parameters
ininput stream
Returns
input stream

Implements JCOMPAREHISTOGRAMS::JTest_t.

Definition at line 49 of file JTestZero.hh.

49  {
50  return in >> outliersThreshold >> threshold;
51  };
double outliersThreshold
Fraction of bins allowed to fail.
Definition: JTestZero.hh:71
double threshold
threshold p-value to decide if test is passed.
Definition: JTestZero.hh:75
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:42
void JCOMPAREHISTOGRAMS::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 JCOMPAREHISTOGRAMS::JTest_t.

Definition at line 59 of file JTestZero.hh.

59  {
60 
61  using namespace std;
62 
63  if (!(dynamic_cast<TH2*>(o1) == NULL) && !(dynamic_cast<TH2*>(o2) == NULL)) {
64 
65  TH2D* h1 = dynamic_cast<TH2D*>(o1);
66  TH2D* h2 = dynamic_cast<TH2D*>(o2);
67 
68  JTestResult r = JTestZero_2D(h1, h2, outliersThreshold, threshold, testName, resultType);
69  results.push_back(r);
70  }
71  };
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
data_type r[M+1]
Definition: JPolint.hh:758
std::vector< JTestResult > results
Buffer to store results of multiple tests.*/.
Definition: JTest_t.hh:162
double outliersThreshold
Fraction of bins allowed to fail.
Definition: JTestZero.hh:71
double threshold
threshold p-value to decide if test is passed.
Definition: JTestZero.hh:75
const std::string resultType
result type
Definition: JTest_t.hh:167
const std::string testName
test name
Definition: JTest_t.hh:166
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:54
std::ostream& JCOMPAREHISTOGRAMS::JTest_t::write ( std::ostream &  out,
const char  delimiter = ' ',
const bool  onlyFailures = false 
) const
inlineinherited

Write test result to output.

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

Definition at line 81 of file JTest_t.hh.

83  {
84 
85  for (std::vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r) {
86 
87  if (onlyFailures && r->passed) {
88  continue;
89  }
90 
91  print(out, *r, delimiter, true);
92  }
93 
94  return out;
95  }
std::ostream & print(std::ostream &out, const JTestSummary &summary, const char delimiter= ' ', const bool useColors=true)
Print test summary.
data_type r[M+1]
Definition: JPolint.hh:758
std::vector< JTestResult > results
Buffer to store results of multiple tests.*/.
Definition: JTest_t.hh:162
virtual void JCOMPAREHISTOGRAMS::JTest_t::save ( TFile *  f,
const std::string &  path,
const bool  onlyFailures = false 
)
inlinevirtualinherited

Writes the test result to root file.

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

Definition at line 113 of file JTest_t.hh.

115  {
116 
117  using namespace std;
118 
119  if (f -> GetDirectory(path.c_str())==0) {
120  f->mkdir(path.c_str());
121  }
122 
123  f->cd(path.c_str());
124 
125  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
126 
127  if (!onlyFailures || !r->passed){
128  r->obj->Write();
129  }
130  }
131  }
o $QUALITY_ROOT d $DEBUG!JPlot1D f
Definition: JDataQuality.sh:66
data_type r[M+1]
Definition: JPolint.hh:758
std::vector< JTestResult > results
Buffer to store results of multiple tests.*/.
Definition: JTest_t.hh:162
$WORKDIR driver txt done cat $WORKDIR driver txt<< EOFprocess ${DATAFILTER}$FILTER_HOST csh-c '(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&(JDataFilter-H\$SERVER\$-M\$LOGGER\$-d $DEBUG-u ${DATAFILTER}-P $PORT</dev/null > &/dev/null &))';process ${DATAWRITER}$WRITER_HOST csh-c '(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&(JDataWriter-H\$SERVER\$-M\$LOGGER\$-d $DEBUG-u ${DATAWRITER}</dev/null > &/dev/null &))';print enterevent ev_init{RC_CMD}event ev_reset{RC_CMD}event ev_init{RC_CMD}event ev_configure{RC_DFLTR%<$WORKDIR/ev_configure_datafilter.txt > RC_DOM<$WORKDIR/ev_configure_domsimulator.txt > RC_DWRT path
virtual void JCOMPAREHISTOGRAMS::JTest_t::clear ( )
inlinevirtualinherited

Clear results.

Definition at line 137 of file JTest_t.hh.

137  {
138  results.clear();
139  }
std::vector< JTestResult > results
Buffer to store results of multiple tests.*/.
Definition: JTest_t.hh:162
const std::string& JCOMPAREHISTOGRAMS::JTest_t::getTestName ( )
inlineinherited

Get test name.

Returns
test name

Definition at line 147 of file JTest_t.hh.

147  {
148  return testName;
149  }
const std::string testName
test name
Definition: JTest_t.hh:166
const std::string& JCOMPAREHISTOGRAMS::JTest_t::getResultType ( )
inlineinherited

Get result type.

Returns
result type

Definition at line 157 of file JTest_t.hh.

157  {
158  return resultType;
159  }
const std::string resultType
result type
Definition: JTest_t.hh:167
JTestResult JCOMPAREHISTOGRAMS::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 54 of file JTestZero_t.hh.

54  {
55 
56  using namespace std;
57  using namespace JPP;
58 
59  int nx1 = h1->GetNbinsX();
60  int nx2 = h2->GetNbinsX();
61  int ny1 = h1->GetNbinsY();
62  int ny2 = h2->GetNbinsY();
63 
64  if(nx1 != nx2 || ny1 != ny2)
65  ERROR("Histograms with different binning. The objects: " << h1->GetName() << " can not be compared." << endl);
66 
67  TH2D* h3 = (TH2D*)h1->Clone(h1->GetName()==h2->GetName() ?
68  MAKE_CSTRING(to_string(h1->GetName())) :
69  MAKE_CSTRING(to_string(h1->GetName()) + "_VS_" + to_string(h2->GetName())));
70  h3->Reset();
71 
72  double failures = 0;
73 
74  for (int i=1 ; i<nx1+1 ; ++i){
75  for (int j=1 ; j<ny1+1 ; ++j){
76 
77  double m = h1 -> GetBinContent(i,j);
78  double n = h2 -> GetBinContent(i,j);
79 
80  double p1 = 1 - ROOT::Math::poisson_cdf(m,1);
81  double p2 = 1 - ROOT::Math::poisson_cdf(n,1);
82 
83  if ((p1 > threshold && p2 < threshold) ||
84  (p1 < threshold && p2 > threshold)){
85  h3->Fill(i,j);
86  failures+=1./(nx1*ny1);
87  }
88  }
89  }
90 
91  bool passed;
92 
93  (failures > outliersThreshold ? passed = false : passed = true);
94 
95  JResultTitle title(testName, parameterName, passed , failures);
96 
97  h3->SetTitle(title.getTitle().c_str());
98 
99  JTestResult r (testName,
100  JRootObjectID(MAKE_STRING(h1->GetDirectory()->GetPath() << h1->GetName())),
101  JRootObjectID(MAKE_STRING(h2->GetDirectory()->GetPath() << h1->GetName())),
102  parameterName, failures, threshold, h3, passed);
103 
104  return r;
105  };
TPaveText * p1
#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:758
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:142
const int n
Definition: JPolint.hh:676
#define ERROR(A)
Definition: JMessage.hh:66
p2
Definition: module-Z:fit.sh:74
std::string to_string(const T &value)
Convert value to string.
int j
Definition: JPolint.hh:682

Member Data Documentation

double JCOMPAREHISTOGRAMS::JTestZero::outliersThreshold
private

Fraction of bins allowed to fail.

Definition at line 71 of file JTestZero.hh.

double JCOMPAREHISTOGRAMS::JTestZero::threshold
private

threshold p-value to decide if test is passed.

Definition at line 75 of file JTestZero.hh.

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

Buffer to store results of multiple tests.*/.

Definition at line 162 of file JTest_t.hh.

const std::string JCOMPAREHISTOGRAMS::JTest_t::testName
protectedinherited

test name

Definition at line 166 of file JTest_t.hh.

const std::string JCOMPAREHISTOGRAMS::JTest_t::resultType
protectedinherited

result type

Definition at line 167 of file JTest_t.hh.


The documentation for this class was generated from the following file: