Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestKolmogorov_1D.hh
Go to the documentation of this file.
1 #ifndef __JTESTKOLMOGOROV_1D__
2 #define __JTESTKOLMOGOROV_1D__
3 
4 #include <iostream>
5 #include "TMath.h"
6 #include "JTest_t.hh"
7 #include "JTestKolmogorov_t.hh"
8 
9 using namespace std;
10 
11 /*
12  * \author rgruiz
13  */
14 
15 /*
16  * Implementation of the Kolmogorov test for 1D histograms.
17  */
19  public JTestKolmogorov_t,
20  public JTest_t
21 {
22 public:
23 
24  /*
25  * Default constructor.
26  */
28 
29  /*
30  * Read test parameters from input.
31  *
32  * \param in input stream
33  * \return input stream
34  */
35  std::istream& read(std::istream& in) {
36  return in >> threshold;
37  };
38 
39  /*
40  * Write test result to output.
41  *
42  * \param out output stream
43  * \return output stream
44  */
45  std::ostream& write(std::ostream& out) {
46  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r) {
47  out << scientific << setprecision(2) << (r->passed ? GREEN : RED) << r->message << endl;
48  }
49  return out;
50  };
51 
52  /*
53  * Applies Kolmogorov test for two ROOT TH1 histograms.
54  *
55  * \param o1 First histogram
56  * \param o2 Second histogram
57  */
58  void test(TObject* o1, TObject* o2) {
59 
60  if (!(dynamic_cast<TH2*>(o1) == NULL) || !(dynamic_cast<TH2*>(o2) == NULL)) {
61  ERROR("For 2D histograms call JTestKolmogorov_2D: " << o1->GetName() << endl);
62 
63  } else if (!(dynamic_cast<TH1*>(o1) == NULL) && !(dynamic_cast<TH1*>(o2) == NULL)) {
64 
65  TH1D* h1 = dynamic_cast<TH1D*>(o1);
66  TH1D* h2 = dynamic_cast<TH1D*>(o2);
67 
68  JTestResult r = JKolmogorovTest(h1, h2, threshold);
69 
70  results.push_back(r);
71  }
72  };
73 
74  /*
75  * Writes the result to root file
76  * \param f The file
77  * \param path Path in root file.
78  */
79  virtual void save(TFile* f , string path){
80 
81  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
82 
83  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
84  f->cd(path.c_str());
85  r->obj->Write();
86  }
87  }
88 
89  /*
90  * Clear results
91  */
92  void clear(){
93  results.clear();
94  }
95 
96 private:
97  double threshold; //!< threshold p-value to decide if test is passed.
98 };
99 
100 #endif
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
std::istream & read(std::istream &in)
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)
double threshold
threshold p-value to decide if test is passed.
void test(TObject *o1, TObject *o2)
virtual void save(TFile *f, string path)