Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestKolmogorov_2D.hh
Go to the documentation of this file.
1 #ifndef __JTESTKOLMOGOROV_2D__
2 #define __JTESTKOLMOGOROV_2D__
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  * Kolmogorov test.
13  */
15  public JTestKolmogorov_t,
16  public JTest_t
17 {
18 public:
19  /*
20  * Default constructor.
21  */
23 
24  /*
25  * Read test parameters from input.
26  *
27  * \param in input stream
28  * \return input stream
29  */
30  std::istream& read(std::istream& in) {
31  return in >> threshold >> slice;
32  };
33 
34  /*
35  * Write test result to output.
36  *
37  * \param out output stream
38  * \return output stream
39  */
40  std::ostream& write(std::ostream& out) {
41  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r) {
42  out << scientific << setprecision(2) << (r->passed ? GREEN : RED) << r->message << endl;
43  }
44  return out;
45  };
46 
47  /*
48  * Applies Kolmogorov test for two ROOT TH2 histograms.
49  *
50  * \param o1 First histogram
51  * \param o2 Second histogram
52  */
53  void test(TObject* o1, TObject* o2) {
54 
55  if (!(dynamic_cast<TH2*>(o1) == NULL) && !(dynamic_cast<TH2*>(o2) == NULL)) {
56 
57  TH2D* h1 = dynamic_cast<TH2D*>(o1);
58  TH2D* h2 = dynamic_cast<TH2D*>(o2);
59 
60  if(slice == 'x' || slice == 'X'){
61 
62  int nSlices1 = h1->GetNbinsX();
63  int nSlices2 = h2->GetNbinsX();
64 
65  if(nSlices1 != nSlices2)
66  ERROR("Histograms with different binning. The objects: " << o1->GetName() << " can not be compared." << endl);
67 
68  for (int i=1 ; i<=nSlices1 ; ++i){
69 
70  string name = MAKE_STRING(o1->GetName() + to_string("_") + to_string(i));
71 
72  TH1D* s1 = h1->ProjectionY (name.c_str(),i,i);
73  TH1D* s2 = h2->ProjectionY (name.c_str(),i,i);
74 
75  JTestResult r = JKolmogorovTest(s1, s2, threshold);
76  results.push_back(r);
77  }
78  }else if (slice == 'y' || slice == 'Y'){
79 
80  int nSlices1 = h1->GetNbinsY();
81  int nSlices2 = h2->GetNbinsY();
82 
83  if(nSlices1 != nSlices2)
84  ERROR("Histograms with different binning. The objects: " << o1->GetName() << " can not be compared." << endl);
85 
86  for (int i=1 ; i<=nSlices1 ; ++i){
87 
88  string name = MAKE_STRING(o1->GetName() + to_string("_") + to_string(i));
89 
90  TH1D* s1 = h1->ProjectionX (name.c_str(),i,i);
91  TH1D* s2 = h2->ProjectionX (name.c_str(),i,i);
92 
93  JTestResult r = JKolmogorovTest(s1, s2, threshold);
94  results.push_back(r);
95  }
96  }else if (slice == 'n' || slice == 'N'){
97 
98  JTestResult r = JKolmogorovTest2D(h1,h2,threshold);
99  }
100 
101  }else if (!(dynamic_cast<TH1*>(o1) == NULL) && !(dynamic_cast<TH1*>(o2) == NULL)) {
102  ERROR("For 1D histograms call JTestKolmogorov_1D: " << o1->GetName() << endl);
103  }
104  };
105 
106  /*
107  * Writes the result to root file
108  * \param f The file
109  * \param path Path in root file.
110  */
111  virtual void save(TFile* f , string path){
112 
113  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
114 
115  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
116  f->cd(path.c_str());
117  r->obj->Write();
118  }
119  }
120 
121  /*
122  * Clear results
123  */
124  void clear(){
125  results.clear();
126  }
127 
128 private:
129  double threshold; //!< threshold p-value to decide if test is passed.
130  char slice; //!< Axis to slice.
131 };
132 
133 #endif
double threshold
threshold p-value to decide if test is passed.
virtual void save(TFile *f, string path)
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
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:699
then JPizza f
Definition: JPizza.sh:46
do cat driver txt<< EOFevent ev_configure{RC_EVT%< ev_configure.txt > RC_DWRT path
void test(TObject *o1, TObject *o2)
char slice
Axis to slice.
#define ERROR(A)
Definition: JMessage.hh:66
then echo n User name
Definition: JCookie.sh:45
std::ostream & write(std::ostream &out)
std::string to_string(const T &value)
Convert value to string.
std::istream & read(std::istream &in)