Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestIdentical_1D.hh
Go to the documentation of this file.
1 #ifndef __JTESTIDENTICAL_1D__
2 #define __JTESTIDENTICAL_1D__
3 
4 #include <istream>
5 #include <ostream>
8 
9 /**
10  * \author rgruiz
11  */
12 
13 /**
14  * Implementation of the a test to check if two 1D histograms are the same.\n
15  * This class is derived from the abstract class JTest_t(). For a general description of the implementation of this and other tests derived from JTest_t(), see its documentation.\n
16  * The input parameter tolerance(), is used to evaluate whether the test is passed or failed.\n
17  * The test is run by the method JIdenticalTest().
18  */
20  public JTest_t ,
21  public JTestIdentical_t
22 {
23 public:
24 
25  /**
26  * Default constructor.
27  */
29 
30  /**
31  * Read test parameters from input.
32  *
33  * \param in input stream
34  * \return input stream
35  */
36  std::istream& read(std::istream& in) override{
37  return in >> tolerance;
38  };
39 
40  /**
41  * Write test result to output.
42  *
43  * \param out output stream
44  * \param delimiter field delimiter
45  * \param onlyFailures If true, write only failures.
46  * \return output stream
47  */
48  std::ostream& write(std::ostream& out, std::string delimiter = " ", bool onlyFailures = false) const override{
49  for (std::vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r) {
50  if (onlyFailures){
51  if (!r->passed)
52  out << std::scientific << std::setprecision(2) << (r->passed ? JPP::GREEN : JPP::RED) << r->print(delimiter) << std::endl;
53  }else{
54  out << std::scientific << std::setprecision(2) << (r->passed ? JPP::GREEN : JPP::RED) << r->print(delimiter) << std::endl;
55  }
56  }
57  return out;
58  };
59 
60  /**
61  * Applies test for two ROOT TH1 histograms.
62  *
63  * \param o1 First histogram
64  * \param o2 Second histogram
65  */
66  void test(TObject* o1, TObject* o2) override{
67 
68  using namespace std;
69 
70  if (!(dynamic_cast<TH2*>(o1) == NULL) || !(dynamic_cast<TH2*>(o2) == NULL)) {
71  ERROR("For 2D histograms call JTestIdentical_2D: " << o1->GetName() << endl);
72 
73  } else if (!(dynamic_cast<TH1*>(o1) == NULL) && !(dynamic_cast<TH1*>(o2) == NULL)) {
74 
75  TH1D* h1 = dynamic_cast<TH1D*>(o1);
76  TH1D* h2 = dynamic_cast<TH1D*>(o2);
77 
78  if(h1 -> GetNbinsX() != h2 -> GetNbinsX())
79  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
80 
81  JTestResult r = JIdenticalTest<TH1D>(h1, h2, tolerance, name, parameter);
82 
83  results.push_back(r);
84  }
85  };
86 
87  /**
88  * Writes the test result to root file
89  * \param f A ROOT file
90  * \param path Path in root file.
91  * \param onlyFailures If true, write only failures.
92  */
93  virtual void save(TFile* f , std::string path, bool onlyFailures = false) override{
94 
95  using namespace std;
96 
97  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
98 
99  if (onlyFailures){
100  if (!r->passed){
101  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
102  f->cd(path.c_str());
103  r->obj->Write();
104  }
105  }else{
106  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
107  f->cd(path.c_str());
108  r->obj->Write();
109  }
110  }
111  }
112 
113  /**
114  * Clear results
115  */
116  void clear() override{
117  results.clear();
118  }
119 
120  /**
121  * Get test name.
122  */
123  std::string getName() override{
124  return name;
125  }
126 
127  /**
128  * Get parameter name.
129  */
130  std::string getParameter() override{
131  return parameter;
132  }
133 
134 
135 private:
136  double tolerance; //!< tolerance value to accept the difference as acceptable.
137  const std::string name = "Identical_1D"; //!< test name.
138  const std::string parameter = "Difference"; //!< parameter name.
139 };
140 
141 #endif
Implementation test that verify if two histograms are the same.
virtual void save(TFile *f, std::string path, bool onlyFailures=false) override
Writes the test result to root file.
std::vector< JTestResult > results
Definition: JTest_t.hh:251
const std::string name
test name.
JTestIdentical_1D()
Default constructor.
Definition: JRoot.hh:19
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
data_type r[M+1]
Definition: JPolint.hh:742
double tolerance
tolerance value to accept the difference as acceptable.
Structure containing the result of the test.
Definition: JTest_t.hh:164
then JPizza f
Definition: JPizza.sh:46
do cat driver txt<< EOFevent ev_configure{RC_EVT%< ev_configure.txt > RC_DWRT path
std::string getParameter() override
Get parameter name.
void test(TObject *o1, TObject *o2) override
Applies test for two ROOT TH1 histograms.
const std::string parameter
parameter name.
std::istream & read(std::istream &in) override
Read test parameters from input.
#define ERROR(A)
Definition: JMessage.hh:66
std::string getName() override
Get test name.
Implementation of the a test to check if two 1D histograms are the same.
std::ostream & write(std::ostream &out, std::string delimiter=" ", bool onlyFailures=false) const override
Write test result to output.
Interface to read input and write output for TObject tests.
Definition: JTest_t.hh:246
void clear() override
Clear results.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:38