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