Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestChi2_1D.hh
Go to the documentation of this file.
1 #ifndef __JTESTCHI2_1D__
2 #define __JTESTCHI2_1D__
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  * Implementation of the Chi2 test for 1D histograms.
16  */
17 class JTestChi2_1D:
18  public JTest_t ,
19  public JTestChi2_t
20 {
21 public:
22 
23  /*
24  * Default constructor.
25  */
27 
28  /*
29  * Read test parameters from input.
30  *
31  * \param in input stream
32  * \return input stream
33  */
34  std::istream& read(std::istream& in) {
35  return in >> threshold;
36  };
37 
38  /*
39  * Write test result to output.
40  *
41  * \param out output stream
42  * \return output stream
43  */
44  std::ostream& write(std::ostream& out) {
45  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r) {
46  out << scientific << setprecision(2) << (r->passed ? GREEN : RED) << r->message << endl;
47  }
48  return out;
49  };
50 
51  /*
52  * Applies Chi2 test for two ROOT TH1 histograms.
53  *
54  * \param o1 First histogram
55  * \param o2 Second histogram
56  */
57  void test(TObject* o1, TObject* o2) {
58 
59  if (!(dynamic_cast<TH2*>(o1) == NULL) || !(dynamic_cast<TH2*>(o2) == NULL)) {
60  ERROR("For 2D histograms call JTestChi2_2D: " << o1->GetName() << endl);
61 
62  } else if (!(dynamic_cast<TH1*>(o1) == NULL) && !(dynamic_cast<TH1*>(o2) == NULL)) {
63 
64  TH1D* h1 = dynamic_cast<TH1D*>(o1);
65  TH1D* h2 = dynamic_cast<TH1D*>(o2);
66 
67  if(h1 -> GetNbinsX() != h2 -> GetNbinsX())
68  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
69 
70  JTestResult r = JChi2Test(h1, h2, threshold);
71 
72  results.push_back(r);
73  }
74  };
75 
76  /*
77  * Writes the test result to root file
78  * \param f A ROOT file
79  * \param path Path in root file.
80  */
81  virtual void save(TFile* f , string path){
82 
83  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
84 
85  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
86  f->cd(path.c_str());
87  r->obj->Write();
88  }
89  }
90 
91  /*
92  * Clear results
93  */
94  void clear(){
95  results.clear();
96  }
97 
98 private:
99  double threshold; //!< threshold p-value to decide if test is passed.
100 };
101 
102 #endif
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
Definition: JRoot.hh:19
double threshold
threshold p-value to decide if test is passed.
Definition: JTestChi2_1D.hh:99
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
data_type r[M+1]
Definition: JPolint.hh:709
then JPizza f
Definition: JPizza.sh:46
do cat driver txt<< EOFevent ev_configure{RC_EVT%< ev_configure.txt > RC_DWRT path
#define ERROR(A)
Definition: JMessage.hh:66
std::ostream & write(std::ostream &out)
Definition: JTestChi2_1D.hh:44
std::istream & read(std::istream &in)
Definition: JTestChi2_1D.hh:34
virtual void save(TFile *f, string path)
Definition: JTestChi2_1D.hh:81
void test(TObject *o1, TObject *o2)
Definition: JTestChi2_1D.hh:57