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