Jpp - the software that should make you happy
 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 <istream>
5 #include <ostream>
8 
9 /**
10  * \author rgruiz
11  */
12 
13 /**
14  * Implementation of the Runs test for 1D histograms.\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  * This test uses the input parameter threshold() to evaluate whether the test is passed or failed.\n
17  * The evaluation is done by comparing the threshold value with the result of the JRunsTest() test.
18  */
19 class JTestRuns_1D:
20  public JTest_t,
21  public JTestRuns_t
22 {
23 public:
24 
26 
27  /**
28  * Read test parameters from input.
29  *
30  * \param in input stream
31  * \return input stream
32  */
33  std::istream& read(std::istream& in) override{
34  return in >> threshold;
35  };
36 
37  /**
38  * Write test result to output.
39  *
40  * \param out output stream
41  * \param delimiter field delimiter
42  * \param onlyFailures If true, write only failures.
43  * \return output stream
44  */
45  std::ostream& write(std::ostream& out, std::string delimiter = " ", bool onlyFailures = false) const override{
46  for (std::vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r) {
47  if (onlyFailures){
48  if (!r->passed)
49  out << std::scientific << std::setprecision(2) << (r->passed ? JPP::GREEN : JPP::RED) << r->print(delimiter) << std::endl;
50  }else{
51  out << std::scientific << std::setprecision(2) << (r->passed ? JPP::GREEN : JPP::RED) << r->print(delimiter) << std::endl;
52  }
53  }
54  return out;
55  };
56 
57  /**
58  * Tests the statistical compatibility of two ROOT TObjects
59  *
60  * \param o1 First object
61  * \param o2 Second object
62  */
63  void test(TObject* o1, TObject* o2) override{
64 
65  using namespace std;
66 
67  if (!(dynamic_cast<TH2*>(o1) == NULL) || !(dynamic_cast<TH2*>(o2) == NULL)) {
68  ERROR("For 2D histograms call JTestRuns_2D: " << o1->GetName() << endl);
69 
70  } else if (!(dynamic_cast<TH1*>(o1) == NULL) && !(dynamic_cast<TH1*>(o2) == NULL)) {
71 
72  TH1D* h1 = dynamic_cast<TH1D*>(o1);
73  TH1D* h2 = dynamic_cast<TH1D*>(o2);
74 
75  if(h1 -> GetNbinsX() != h2 -> GetNbinsX())
76  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
77 
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 private:
132  double threshold; //!< threshold value to decide if test is passed.
133  const std::string name = "Runs_1D"; //!< test name.
134  const std::string parameter = "#sigma"; //!< parameter name.
135 };
136 
137 #endif
double threshold
threshold value to decide if test is passed.
std::vector< JTestResult > results
Definition: JTest_t.hh:251
Definition: JRoot.hh:19
do set_array DAQHEADER JPrintDAQHeader f
Definition: JTuneHV.sh:79
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
std::istream & read(std::istream &in) override
Read test parameters from input.
Definition: JTestRuns_1D.hh:33
data_type r[M+1]
Definition: JPolint.hh:742
Implementation of the Runs test for 1D histograms.
Definition: JTestRuns_1D.hh:19
Structure containing the result of the test.
Definition: JTest_t.hh:164
std::string getName() override
Get test name.
do cat driver txt<< EOFevent ev_configure{RC_EVT%< ev_configure.txt > RC_DWRT path
std::ostream & write(std::ostream &out, std::string delimiter=" ", bool onlyFailures=false) const override
Write test result to output.
Definition: JTestRuns_1D.hh:45
std::string getParameter() override
Get parameter name.
void clear() override
Clear results.
#define ERROR(A)
Definition: JMessage.hh:66
const std::string parameter
parameter name.
Implementation of the different Runs-related tests.
Definition: JTestRuns_t.hh:14
Interface to read input and write output for TObject tests.
Definition: JTest_t.hh:246
const std::string name
test name.
void test(TObject *o1, TObject *o2) override
Tests the statistical compatibility of two ROOT TObjects.
Definition: JTestRuns_1D.hh:63
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
virtual void save(TFile *f, std::string path, bool onlyFailures=false) override
Writes the test result to root file.
Definition: JTestRuns_1D.hh:90
JTestResult JRunsTest(TH1 *h1, TH1 *h2, double threshold, std::string testName, std::string parameterName)
Implements the Wald-Wolfowitx runs test: https://en.wikipedia.org/wiki/Wald%E2%80%93Wolfowitz_runs_te...
Definition: JTestRuns_t.hh:34