Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestKolmogorov_1D.hh
Go to the documentation of this file.
1 #ifndef __JTESTKOLMOGOROV_1D__
2 #define __JTESTKOLMOGOROV_1D__
3 
4 #include <istream>
5 #include <ostream>
6 #include "TMath.h"
9 
10 /**
11  * \author rgruiz
12  */
13 
14 /**
15  *
16  * Implementation of the Kolmogorov test for 1D histograms.\n
17  * 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
18  * This test uses the input parameter threshold() to evaluate whether the test is passed or failed.\n
19  * The evaluation is done by comparing the threshold value with the result of the JKolmogorovTest() test. This is a p-value.\n
20  * The parameter threshold should therefore be a real value between 0 and 1.
21  */
23  public JTestKolmogorov_t,
24  public JTest_t
25 {
26 public:
27 
28  /**
29  * Default constructor.
30  */
32 
33  /**
34  * Read test parameters from input.
35  *
36  * \param in input stream
37  * \return input stream
38  */
39  std::istream& read(std::istream& in) override{
40  return in >> threshold;
41  };
42 
43 
44  /**
45  * Write test result to output.
46  *
47  * \param out output stream
48  * \param delimiter field delimiter
49  * \param onlyFailures If true, write only failures.
50  * \return output stream
51  */
52  std::ostream& write(std::ostream& out, std::string delimiter = " ", bool onlyFailures = false) const override{
53  for (std::vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r) {
54  if (onlyFailures){
55  if (!r->passed)
56  out << std::scientific << std::setprecision(2) << (r->passed ? JPP::GREEN : JPP::RED) << r->print(delimiter) << std::endl;
57  }else{
58  out << std::scientific << std::setprecision(2) << (r->passed ? JPP::GREEN : JPP::RED) << r->print(delimiter) << std::endl;
59  }
60  }
61  return out;
62  };
63 
64 
65  /**
66  * Applies Kolmogorov test for two ROOT TH1 histograms.
67  *
68  * \param o1 First histogram
69  * \param o2 Second histogram
70  */
71  void test(TObject* o1, TObject* o2) override{
72 
73  using namespace std;
74 
75  if (!(dynamic_cast<TH2*>(o1) == NULL) || !(dynamic_cast<TH2*>(o2) == NULL)) {
76  ERROR("For 2D histograms call JTestKolmogorov_2D: " << o1->GetName() << endl);
77 
78  } else if (!(dynamic_cast<TH1*>(o1) == NULL) && !(dynamic_cast<TH1*>(o2) == NULL)) {
79 
80  TH1D* h1 = dynamic_cast<TH1D*>(o1);
81  TH1D* h2 = dynamic_cast<TH1D*>(o2);
82 
84 
85  results.push_back(r);
86  }
87  };
88 
89 
90  /**
91  * Writes the test result to root file
92  * \param f A ROOT file
93  * \param path Path in root file.
94  * \param onlyFailures If true, write only failures.
95  */
96  virtual void save(TFile* f , std::string path, bool onlyFailures = false) override{
97 
98  using namespace std;
99 
100  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
101 
102  if (onlyFailures){
103  if (!r->passed){
104  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
105  f->cd(path.c_str());
106  r->obj->Write();
107  }
108  }else{
109  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
110  f->cd(path.c_str());
111  r->obj->Write();
112  }
113  }
114  }
115 
116 
117  /**
118  * Clear results
119  */
120  void clear() override{
121  results.clear();
122  }
123 
124  /**
125  * Get test name.
126  */
127  std::string getName() override{
128  return name;
129  }
130 
131  /**
132  * Get parameter name.
133  */
134  std::string getParameter() override{
135  return parameter;
136  }
137 
138 private:
139  double threshold; //!< threshold p-value to decide if test is passed.
140  const std::string name = "KS_1D"; //!< test name.
141  const std::string parameter = "p-Value(KS)"; //!< parameter name.
142 };
143 
144 #endif
virtual void save(TFile *f, std::string path, bool onlyFailures=false) override
Writes the test result to root file.
Implementation of the different Kolmogorov-related tests.
std::vector< JTestResult > results
Definition: JTest_t.hh:251
Definition: JRoot.hh:19
do set_array DAQHEADER JPrintDAQHeader f
Definition: JTuneHV.sh:74
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
data_type r[M+1]
Definition: JPolint.hh:742
std::istream & read(std::istream &in) override
Read test parameters from input.
void test(TObject *o1, TObject *o2) override
Applies Kolmogorov test for two ROOT TH1 histograms.
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
#define ERROR(A)
Definition: JMessage.hh:66
std::ostream & write(std::ostream &out, std::string delimiter=" ", bool onlyFailures=false) const override
Write test result to output.
JTestResult JKolmogorovTest(TH1 *h1, TH1 *h2, double threshold, std::string testName, std::string parameterName)
Kolmogorov test for 1D histograms.
void clear() override
Clear results.
JTestKolmogorov_1D()
Default constructor.
std::string getParameter() override
Get parameter name.
double threshold
threshold p-value to decide if test is passed.
std::string getName() override
Get test name.
const std::string name
test name.
const std::string parameter
parameter name.
Interface to read input and write output for TObject tests.
Definition: JTest_t.hh:246
Implementation of the Kolmogorov test for 1D histograms.
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 typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36