Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestChi2_Bin.hh
Go to the documentation of this file.
1 #ifndef __JTESTCHI2_BIN__
2 #define __JTESTCHI2_BIN__
3 
4 #include <iostream>
5 #include "JTest_t.hh"
6 #include "JTestChi2_t.hh"
7 
8 using namespace std;
9 
10 /*
11  * \author rgruiz
12  */
13 
14 /*
15  * Bin-by-Bin chi2 test.
16  */
18  public JTest_t,
19  public JTestChi2_t
20 {
21 public:
22  /*
23  * Default constructor.
24  */
26 
27  /*
28  * Read test parameters from input.
29  *
30  * \param in input stream
31  * \return input stream
32  */
33  std::istream& read(std::istream& in) {
34  return in >> outliersThreshold >> chi2Threshold;
35  };
36 
37  /*
38  * Write test result to output.
39  *
40  * \param out output stream
41  * \return output stream
42  */
43  std::ostream& write(std::ostream& out) {
44  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r) {
45  out << scientific << setprecision(2) << (r->passed ? GREEN : RED) << r->message << endl;
46  }
47  return out;
48  };
49 
50  /*
51  * Tests the statistical compatibility of two ROOT 2D histograms
52  *
53  * \param o1 First histogram
54  * \param o2 Second histogram
55  *
56  * \return Test result
57  */
58  void test(TObject* o1, TObject* o2) {
59 
60  if (!(dynamic_cast<TH2*>(o1) == NULL) && !(dynamic_cast<TH2*>(o2) == NULL)) {
61 
62  TH2D* h1 = dynamic_cast<TH2D*>(o1);
63  TH2D* h2 = dynamic_cast<TH2D*>(o2);
64 
65  JTestResult r = JChi2TestBin_2D(h1, h2, outliersThreshold, chi2Threshold);
66  results.push_back(r);
67  }
68  };
69 
70  /*
71  * Writes the result to root file
72  * \param f The file
73  * \param path Path in root file.
74  */
75  virtual void save(TFile* f , string path){
76 
77  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
78 
79  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
80  f->cd(path.c_str());
81  r->obj->Write();
82  }
83  }
84 
85  /*
86  * Clear results
87  */
88  void clear(){
89  results.clear();
90  }
91 
92 private:
93  double chi2Threshold; //!< threshold p-value to decide if test is passed for a bin.
94  double outliersThreshold; //!< number of bins allowed to fail the test.
95 };
96 
97 #endif
void test(TObject *o1, TObject *o2)
std::ostream & write(std::ostream &out)
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
Definition: JRoot.hh:19
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
data_type r[M+1]
Definition: JPolint.hh:709
std::istream & read(std::istream &in)
then JPizza f
Definition: JPizza.sh:46
do cat driver txt<< EOFevent ev_configure{RC_EVT%< ev_configure.txt > RC_DWRT path
double outliersThreshold
number of bins allowed to fail the test.
virtual void save(TFile *f, string path)
double chi2Threshold
threshold p-value to decide if test is passed for a bin.