Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestSignificance_t.hh
Go to the documentation of this file.
1 #ifndef __JTESTSIGNIFICANCE_T__
2 #define __JTESTSIGNIFICANCE_T__
3 
4 #include <istream>
5 #include <ostream>
7 #include "TMath.h"
8 
9 
10 /**
11  *
12  * \author bofearraigh
13  * \author rgruiz
14  *
15  * Compares two histograms \f$ H_a \f$ and \f$ H_b \f$ by calculating the average bin significance \n
16  *
17  * \f[
18  * S = \frac{1}{N} \cdot \sum_{i=0}^{N} \frac{|a_i - K \cdot b_i|}{\sqrt{\sigma ^2(a_i) + K^2 \cdot \sigma ^2(b_i)}}
19  * \f]
20  *
21  * where:
22  * - \f$ N \f$ is the number of bins in \f$ H_a \f$ and \f$ H_b \f$.
23  * - \f$ a_i \f$ and \f$ b_i \f$ are the contents of bin \f$ i \f$ in \f$ H_a \f$ and \f$ H_b \f$.
24  * - \f$ K \f$ is a normalisation parameter. It should be interpreted as the integral of \f$ H_a \f$ divided by the integral of \f$ H_b \f$
25  * - \f$ \sigma \f$ is calculated assuming that the bin contents follow Poisson distributions.
26  *
27  * A threshold value for \f$ S \f$ is used to tag the test as passed or failed.
28  */
30 {
31 public:
32 
33  /**
34  * Default constructor.
35  */
37 
38  /**
39  * Significance test for histograms.\n
40  *
41  * \param h1 First object
42  * \param h2 Second object
43  * \param threshold
44  * \param K Normalisation parameter
45  * \param parameterName Name of the parameter used to test the histograms
46  * \param testName Name of the test used to compare the histograms
47  *
48  * \return Test result.
49  */
50  template<class T>
51  JTestResult JSignificanceTest(T* h1, T* h2, double threshold, double K, std::string testName, std::string parameterName) {
52 
53  using namespace std;
54  using namespace JPP;
55 
56  if(h1 -> GetNbinsX() != h2 -> GetNbinsX())
57  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
58 
59 
60  T* h3 = (T*)h1->Clone(h1->GetName()==h2->GetName() ?
61  MAKE_CSTRING(to_string(h1->GetName())) :
62  MAKE_CSTRING(to_string(h1->GetName()) + "_VS_" + to_string(h2->GetName())));
63 
64  h3->Add(h2,-1*K);
65 
66  double S = 0;
67 
68  for (int i=0 ; i < h1->GetNbinsX() ; ++i){
69  for (int j=0 ; j< h1->GetNbinsY() ; ++j){
70  for (int k=0 ; k< h1->GetNbinsY() ; ++k){
71 
72  double a = h1->GetBinContent(i+1,j+1,k+1);
73  double b = h2->GetBinContent(i+1,j+1,k+1);
74 
75  if(a!=0 || b!=0){
76  S += fabs((a - K*b)/sqrt(a + K*K*b));
77  }
78  }
79  }
80  }
81 
82  S /= (h1->GetNbinsX()*h1->GetNbinsY()*h1->GetNbinsZ());
83 
84  bool passed;
85 
86  (S < threshold ? passed = false : passed = true);
87 
88  JResultTitle title(testName, parameterName, passed, S);
89 
90  h3->SetTitle(title.getTitle().c_str());
91 
92  JTestResult r (testName,
93  string (h1->GetDirectory()->GetPath()).append(h1->GetName()),
94  string (h2->GetDirectory()->GetPath()).append(h2->GetName()),
95  h1->GetDirectory()->GetFile()->GetName(),
96  h2->GetDirectory()->GetFile()->GetName(),
97  parameterName, S , threshold, h3, passed);
98 
99  return r;
100  };
101 
102 };
103 
104 #endif
static const uint32_t K[64]
Definition: crypt.cc:77
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
Definition: JTest_t.hh:22
JTestResult JSignificanceTest(T *h1, T *h2, double threshold, double K, std::string testName, std::string parameterName)
Significance test for histograms.
then fatal No sound hydrophone file $HYDROPHONE_TXT fi JGraph f $HYDROPHONE_TXT o $HYDROPHONE_ROOT sort gr k
JTestSignificance_t()
Default constructor.
#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
do set_variable OUTPUT_DIRECTORY $WORKDIR T
#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
do set_variable SIGMA_NS set_variable OUTLIERS set_variable OUTPUT_FILE matrix[${ALPHA_DEG}\deg\] root $JPP JMatrixNZ a $DETECTOR f $INPUT_FILE o $OUTPUT_FILE S
Definition: JMatrixNZ.sh:56
then $JPP_DIR software JCalibrate JCalibrateToT a
Definition: JTuneHV.sh:108
std::string to_string(const T &value)
Convert value to string.
int j
Definition: JPolint.hh:666