Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestIdentical_3D.hh
Go to the documentation of this file.
1 #ifndef __JTESTIDENTICAL_3D__
2 #define __JTESTIDENTICAL_3D__
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 3D 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<TH3*>(o1) == NULL) && !(dynamic_cast<TH3*>(o2) == NULL)) {
71 
72  TH3D* h1 = dynamic_cast<TH3D*>(o1);
73  TH3D* h2 = dynamic_cast<TH3D*>(o2);
74 
75  if(h1 -> GetNbinsX() != h2 -> GetNbinsX())
76  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
77 
78  JTestResult r = JIdenticalTest<TH3D>(h1, h2, tolerance, name, parameter);
79 
80  results.push_back(r);
81  }
82  };
83 
84  /**
85  * Writes the test result to root file
86  * \param f A ROOT file
87  * \param path Path in root file.
88  * \param onlyFailures If true, write only failures.
89  */
90  virtual void save(TFile* f , std::string path, bool onlyFailures = false) override{
91 
92  using namespace std;
93 
94  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
95 
96  if (onlyFailures){
97  if (!r->passed){
98  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
99  f->cd(path.c_str());
100  r->obj->Write();
101  }
102  }else{
103  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
104  f->cd(path.c_str());
105  r->obj->Write();
106  }
107  }
108  }
109 
110  /**
111  * Clear results
112  */
113  void clear() override{
114  results.clear();
115  }
116 
117  /**
118  * Get test name.
119  */
120  std::string getName() override{
121  return name;
122  }
123 
124  /**
125  * Get parameter name.
126  */
127  std::string getParameter() override{
128  return parameter;
129  }
130 
131 
132 private:
133  double tolerance; //!< tolerance value to accept the difference as acceptable.
134  const std::string name = "Identical_3D"; //!< test name.
135  const std::string parameter = "Difference"; //!< parameter name.
136 };
137 
138 #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.
void test(TObject *o1, TObject *o2) override
Applies test for two ROOT TH1 histograms.
const std::string parameter
parameter name.
std::vector< JTestResult > results
Definition: JTest_t.hh:251
Definition: JRoot.hh:19
std::string getName() override
Get test name.
do set_array DAQHEADER JPrintDAQHeader f
Definition: JTuneHV.sh:79
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
data_type r[M+1]
Definition: JPolint.hh:742
Structure containing the result of the test.
Definition: JTest_t.hh:164
do cat driver txt<< EOFevent ev_configure{RC_EVT%< ev_configure.txt > RC_DWRT path
void clear() override
Clear results.
double tolerance
tolerance value to accept the difference as acceptable.
std::istream & read(std::istream &in) override
Read test parameters from input.
#define ERROR(A)
Definition: JMessage.hh:66
std::string getParameter() override
Get parameter name.
const std::string name
test name.
Interface to read input and write output for TObject tests.
Definition: JTest_t.hh:246
std::ostream & write(std::ostream &out, std::string delimiter=" ", bool onlyFailures=false) const override
Write test result to output.
Implementation of the a test to check if two 3D histograms are the same.
JTestIdentical_3D()
Default constructor.
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