Jpp  16.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestSignificance_t.hh
Go to the documentation of this file.
1 #ifndef __JCOMPAREHISTOGRAMS__JTESTSIGNIFICANCE_T__
2 #define __JCOMPAREHISTOGRAMS__JTESTSIGNIFICANCE_T__
3 
4 #include <istream>
5 #include <ostream>
6 
9 
10 #include "TMath.h"
11 
12 
13 /**
14  * \author bofearraigh
15  * \author rgruiz
16  */
17 namespace JCOMPAREHISTOGRAMS {
18 
20 
21  /*
22  *
23  * Compares two histograms \f$ H_a \f$ and \f$ H_b \f$ by calculating the average bin significance \n
24  *
25  * \f[
26  * 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)}}
27  * \f]
28  *
29  * where:
30  * - \f$ N \f$ is the number of bins in \f$ H_a \f$ and \f$ H_b \f$.
31  * - \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$.
32  * - \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$
33  * - \f$ \sigma \f$ is calculated assuming that the bin contents follow Poisson distributions.
34  *
35  * A threshold value for \f$ S \f$ is used to tag the test as passed or failed.
36  */
38  {
39  public:
40 
41  /**
42  * Default constructor.
43  */
45 
46  /**
47  * Significance test for histograms.\n
48  *
49  * \param h1 First object
50  * \param h2 Second object
51  * \param threshold Significance threshold
52  * \param K Normalisation parameter
53  * \param parameterName Name of the parameter used to test the histograms
54  * \param testName Name of the test used to compare the histograms
55  *
56  * \return Test result.
57  */
58  template<class T>
59  JTestResult JSignificanceTest(T* h1, T* h2, double threshold, double K, std::string testName, std::string parameterName) {
60 
61  using namespace std;
62  using namespace JPP;
63 
64  if(h1 -> GetNbinsX() != h2 -> GetNbinsX())
65  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
66 
67 
68  T* h3 = (T*)h1->Clone(h1->GetName()==h2->GetName() ?
69  MAKE_CSTRING(to_string(h1->GetName())) :
70  MAKE_CSTRING(to_string(h1->GetName()) + "_VS_" + to_string(h2->GetName())));
71 
72  h3->Add(h2,-1*K);
73 
74  double S = 0;
75 
76  for (int i=0 ; i < h1->GetNbinsX() ; ++i){
77  for (int j=0 ; j< h1->GetNbinsY() ; ++j){
78  for (int k=0 ; k< h1->GetNbinsZ() ; ++k){
79 
80  double a = h1->GetBinContent(i+1,j+1,k+1);
81  double b = h2->GetBinContent(i+1,j+1,k+1);
82 
83  if(a!=0 || b!=0){
84  S += fabs((a - K*b)/sqrt(a + K*K*b));
85  }
86  }
87  }
88  }
89 
90  S /= (h1->GetNbinsX()*h1->GetNbinsY()*h1->GetNbinsZ());
91 
92  bool passed;
93 
94  (S < threshold ? passed = false : passed = true);
95 
96  JResultTitle title(testName, parameterName, passed, S);
97 
98  h3->SetTitle(title.getTitle().c_str());
99 
100  JTestResult r (testName,
101  JRootObjectID(MAKE_STRING(h1->GetDirectory()->GetPath() << h1->GetName())),
102  JRootObjectID(MAKE_STRING(h2->GetDirectory()->GetPath() << h1->GetName())),
103  parameterName, S , threshold, h3, passed);
104 
105  return r;
106  };
107  };
108 }
109 
110 #endif
then fatal No hydrophone data file $HYDROPHONE_TXT fi sort gr k
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: JResultTitle.hh:22
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
Auxiliary class to handle file name, ROOT directory and object name.
data_type r[M+1]
Definition: JPolint.hh:758
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:142
do set_variable OUTPUT_DIRECTORY $WORKDIR T
#define ERROR(A)
Definition: JMessage.hh:66
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:58
then JCalibrateToT a
Definition: JTuneHV.sh:116
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:682
JTestResult JSignificanceTest(T *h1, T *h2, double threshold, double K, std::string testName, std::string parameterName)
Significance test for histograms.
std::string getTitle()
Returns a standard string to be used as title of a graphical root object.
Definition: JResultTitle.hh:64