Jpp  18.0.0-rc.1
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 __JCOMPAREHISTOGRAMS__JTESTZERO_T__
2 #define __JCOMPAREHISTOGRAMS__JTESTZERO_T__
3 
4 #include <istream>
5 #include <ostream>
6 
7 #include "TMath.h"
8 
9 #include "Math/Math.h"
10 #include "Math/Error.h"
11 #include "Math/ProbFuncMathCore.h"
12 #include "Math/SpecFuncMathCore.h"
13 
16 
17 
18 /**
19  * \author rgruiz
20  */
21 namespace JCOMPAREHISTOGRAMS {
22 
24 
25  /**
26  * Implementation of the Zeros test for histograms with expected low bin contents.
27  */
29  {
30  public:
31 
32  /**
33  * Default constructor.
34  */
36 
37  /**
38  * Bin-by-Bin test for 2D histograms where a very low number of entries is expected.\n
39  * The test loops over all the bins of both histograms and performs the following operations.\n
40  * -Calculates the probability that the observed bin content for histogram A is obtained from a Poisson of parameter 1.\n
41  * -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
42  * -Calculates the probability that the observed bin content for histogram B is obtained from a Poisson of parameter 1.\n
43  * -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
44  * -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
45  * 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
46  *
47  * \param h1 First object
48  * \param h2 Second object
49  * \param outliersThreshold Fraction of incompatible bins allowed.
50  * \param threshold Poisson p-value
51  * \param parameterName Name of the parameter used to test the histograms
52  * \param testName Name of the test used to compare the histograms
53  */
54  JTestResult JTestZero_2D(TH2* h1, TH2* h2, double outliersThreshold, double threshold, std::string testName, std::string parameterName) {
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  };
106  };
107 }
108 
109 #endif
then usage $script< detector file > minrun maxrun report nIn case of failures
TPaveText * p1
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
Definition: JResultTitle.hh:22
JTestZero_t()
Default constructor.
Definition: JTestZero_t.hh:35
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
Auxiliary class to handle file name, ROOT directory and object name.
data_type r[M+1]
Definition: JPolint.hh:779
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:127
Implementation of the Zeros test for histograms with expected low bin contents.
Definition: JTestZero_t.hh:28
const int n
Definition: JPolint.hh:697
#define ERROR(A)
Definition: JMessage.hh:66
then awk string
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
p2
Definition: module-Z:fit.sh:74
std::string to_string(const T &value)
Convert value to string.
Structure containing the result of the test.
Definition: JTestResult.hh:27
int j
Definition: JPolint.hh:703
std::string getTitle()
Returns a standard string to be used as title of a graphical root object.
Definition: JResultTitle.hh:64