Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestRuns_1D.hh
Go to the documentation of this file.
1 #ifndef __JTESTRUNS_1D__
2 #define __JTESTRUNS_1D__
3 
4 #include <iostream>
5 #include "JTest_t.hh"
6 #include "JTestRuns_t.hh"
7 
8 using namespace std;
9 
10 /*
11  * Interface to read input and write output for TObject tests.
12  */
13 class JTestRuns_1D:
14  public JTest_t,
15  public JTestRuns_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;
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  ERROR("For 2D histograms call JTestRuns_2D: " << o1->GetName() << endl);
54 
55  } else if (!(dynamic_cast<TH1*>(o1) == NULL) && !(dynamic_cast<TH1*>(o2) == NULL)) {
56 
57  TH1D* h1 = dynamic_cast<TH1D*>(o1);
58  TH1D* h2 = dynamic_cast<TH1D*>(o2);
59 
60  if(h1 -> GetNbinsX() != h2 -> GetNbinsX())
61  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
62 
63  JTestResult r = JRunsTest(h1, h2, threshold, logX, logY);
64 
65  results.push_back(r);
66  }
67  };
68 
69  /*
70  * Writes the result to root file
71  * \param f The file
72  * \param path Path in root file.
73  */
74  virtual void save(TFile* f , string path){
75 
76  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
77 
78  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
79  f->cd(path.c_str());
80  r->obj->Write();
81  }
82  }
83 
84  /*
85  * Clear results
86  */
87  void clear(){
88  results.clear();
89  }
90 
91 private:
92  double threshold;
93  bool logX;
94  bool logY;
95 };
96 
97 #endif
double threshold
Definition: JTestRuns_1D.hh:92
std::istream & read(std::istream &in)
Definition: JTestRuns_1D.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
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)
Definition: JTestRuns_1D.hh:50
#define ERROR(A)
Definition: JMessage.hh:66
std::ostream & write(std::ostream &out)
Definition: JTestRuns_1D.hh:37
virtual void save(TFile *f, string path)
Definition: JTestRuns_1D.hh:74