Jpp  15.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestChi2_1D.hh
Go to the documentation of this file.
1 #ifndef __JCOMPAREHISTOGRAMS__JTESTCHI2_1D__
2 #define __JCOMPAREHISTOGRAMS__JTESTCHI2_1D__
3 
4 #include <istream>
5 #include <ostream>
8 
9 
10 /**
11  * \author rgruiz
12  */
13 namespace JCOMPAREHISTOGRAMS {
14  /**
15  * Implementation of the Chi2 test for 1D histograms.\n
16  * 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.\n
17  * The input parameter threshold(), is used to evaluate whether the test is passed or failed.\n
18  * The evaluation is done by comparing the threshold() value with the result produced by JChi2Test(). The output of a Chi2 test is a p-value.\n
19  * The parameter threshold() should therefore be a real value between 0 and 1.
20  */
21  class JTestChi2_1D:
22  public JTest_t ,
23  public JTestChi2_t
24  {
25  public:
26 
27  /**
28  * Default constructor.
29  */
31  JTest_t("Chi2_1D", "p-Value(chi2)"),
32  JTestChi2_t()
33  {}
34 
35  /**
36  * Read test parameters from input.
37  *
38  * \param in input stream
39  * \return input stream
40  */
41  std::istream& read(std::istream& in) override{
42  return in >> threshold >> options;
43  };
44 
45  /**
46  * Applies Chi2 test for two ROOT TH1 histograms.
47  *
48  * \param o1 First histogram
49  * \param o2 Second histogram
50  */
51  void test(TObject* o1, TObject* o2) override{
52 
53  using namespace std;
54 
55  if (!(dynamic_cast<TH2*>(o1) == NULL) || !(dynamic_cast<TH2*>(o2) == NULL)) {
56 
57  ERROR("For 2D histograms call JTestChi2_2D: " << o1->GetName() << endl);
58 
59  } else if (!(dynamic_cast<TH1*>(o1) == NULL) && !(dynamic_cast<TH1*>(o2) == NULL)) {
60 
61  TH1D* h1 = dynamic_cast<TH1D*>(o1);
62  TH1D* h2 = dynamic_cast<TH1D*>(o2);
63 
64  if (h1 -> GetNbinsX() != h2 -> GetNbinsX()) {
65  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
66  }
67 
69 
70  results.push_back(r);
71  }
72  };
73 
74  private:
75 
76  double threshold; //!< threshold p-value to decide if test is passed.
77  std::string options; //!< options for the ROOT chi2 test.
78  };
79 }
80 
81 #endif
Interface to read input and write output for TObject tests.
Definition: JTest_t.hh:46
JTestResult JChi2Test(TH1 *h1, TH1 *h2, double threshold, std::string testName, std::string parameterName, std::string options)
Chi2 test for 1D histograms.
Definition: JTestChi2_t.hh:45
Definition: JRoot.hh:19
void test(TObject *o1, TObject *o2) override
Applies Chi2 test for two ROOT TH1 histograms.
Definition: JTestChi2_1D.hh:51
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
data_type r[M+1]
Definition: JPolint.hh:742
JTestChi2_1D()
Default constructor.
Definition: JTestChi2_1D.hh:30
std::vector< JTestResult > results
Buffer to store results of multiple tests.*/.
Definition: JTest_t.hh:162
std::istream & read(std::istream &in) override
Read test parameters from input.
Definition: JTestChi2_1D.hh:41
#define ERROR(A)
Definition: JMessage.hh:66
const std::string resultType
result type
Definition: JTest_t.hh:167
const std::string testName
test name
Definition: JTest_t.hh:166
Implementation of the Chi2 test for 1D histograms.
Definition: JTestChi2_1D.hh:21
Structure containing the result of the test.
Definition: JTestResult.hh:27
double threshold
threshold p-value to decide if test is passed.
Definition: JTestChi2_1D.hh:72
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:41
std::string options
options for the ROOT chi2 test.
Definition: JTestChi2_1D.hh:77
Implementation of the different Chi2-related tests.
Definition: JTestChi2_t.hh:21