Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestZero_t.hh
Go to the documentation of this file.
1 #ifndef __JTESTZERO_T__
2 #define __JTESTZERO_T__
3 
4 #include <istream>
5 #include <ostream>
6 #include "TMath.h"
7 #include "Math/Math.h"
8 #include "Math/Error.h"
9 #include "Math/ProbFuncMathCore.h"
10 #include "Math/SpecFuncMathCore.h"
12 
13 /**
14  * \author rgruiz
15  */
16 
17 /**
18  * Implementation of the Zeros test for histograms with expected low bin contents.
19  */
21 {
22 public:
23 
24  /**
25  * Default constructor.
26  */
28 
29  /**
30  * Bin-by-Bin test for 2D histograms where a very low number of entries is expected.\n
31  * The test loops over all the bins of both histograms and performs the following operations.\n
32  * -Calculates the probability that the observed bin content for histogram A is obtained from a Poisson of parameter 1.\n
33  * -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.\n
34  * -Calculates the probability that the observed bin content for histogram B is obtained from a Poisson of parameter 1.\n
35  * -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.\n
36  * -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.\n
37  * 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.\n
38  *
39  * \param h1 First object
40  * \param h2 Second object
41  * \param outliersThreshold Fraction of incompatible bins allowed.
42  * \param threshold Poisson p-value
43  * \param parameterName Name of the parameter used to test the histograms
44  * \param testName Name of the test used to compare the histograms
45  */
46  JTestResult JTestZero_2D(TH2* h1, TH2* h2, double outliersThreshold, double threshold, std::string testName, std::string parameterName) {
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  };
100 };
101 
102 #endif
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
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:69
data_type r[M+1]
Definition: JPolint.hh:742
Structure containing the result of the test.
Definition: JTest_t.hh:164
Implementation of the Zeros test for histograms with expected low bin contents.
Definition: JTestZero_t.hh:20
#define ERROR(A)
Definition: JMessage.hh:66
std::string getTitle()
Returns a standard string to be used as title of a graphical root object.
Definition: JTest_t.hh:67
p2
Definition: module-Z:fit.sh:72
JTestZero_t()
Default constructor.
Definition: JTestZero_t.hh:27
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