Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestRuns_2D.hh
Go to the documentation of this file.
1 #ifndef __JTESTRUNS_2D__
2 #define __JTESTRUNS_2D__
3 
4 #include <istream>
5 #include <ostream>
8 
9 /**
10  * \author rgruiz
11  */
12 
13 /**
14  * Implementation of the Chi2 test for 2D 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  * The parameter slice() can have the values x, X, y or Y. The histograms are sliced along the corresponding axis, and the JRunsTest() test is applied to each slice.\n
17  * This test uses the input parameter threshold() to evaluate whether the test is passed or failed for each slice.\n
18  * The evaluation is done by comparing the threshold value with the result of the JRunsTest() test.\n
19  * The results for each slice are stored in the results buffer (see JTest_t().)
20  */
21 class JTestRuns_2D:
22  public JTestRuns_t,
23  public JTest_t
24 {
25 public:
26 
28 
29  /**
30  * Read test parameters from input.
31  *
32  * \param in input stream
33  * \return input stream
34  */
35  std::istream& read(std::istream& in) override{
36  return in >> threshold >> slice;
37  };
38 
39  /**
40  * Write test result to output.
41  *
42  * \param out output stream
43  * \param delimiter field delimiter
44  * \param onlyFailures If true, write only failures.
45  * \return output stream
46  */
47  std::ostream& write(std::ostream& out, std::string delimiter = " ", bool onlyFailures = false) const override{
48  for (std::vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r) {
49  if (onlyFailures){
50  if (!r->passed)
51  out << std::scientific << std::setprecision(2) << (r->passed ? JPP::GREEN : JPP::RED) << r->print(delimiter) << std::endl;
52  }else{
53  out << std::scientific << std::setprecision(2) << (r->passed ? JPP::GREEN : JPP::RED) << r->print(delimiter) << std::endl;
54  }
55  }
56  return out;
57  };
58 
59  /**
60  * Tests the statistical compatibility of two ROOT TObjects
61  *
62  * \param o1 First object
63  * \param o2 Second object
64  */
65  void test(TObject* o1, TObject* o2) override{
66 
67  using namespace std;
68  using namespace JPP;
69 
70  if (!(dynamic_cast<TH2*>(o1) == NULL) && !(dynamic_cast<TH2*>(o2) == NULL)) {
71 
72  TH2D* h1 = dynamic_cast<TH2D*>(o1);
73  TH2D* h2 = dynamic_cast<TH2D*>(o2);
74 
75  if(slice == 'x' || slice == 'X' || slice == 'y' || slice == 'Y'){
76 
78 
79  results.push_back(r);
80 
81  } else {
82  ERROR ("Slice option should be: x, X, y or Y, and not " + slice);
83  }
84 
85  } else if (!(dynamic_cast<TH1*>(o1) == NULL) && !(dynamic_cast<TH1*>(o2) == NULL)) {
86  ERROR("For 1D histograms call JChi2_1D: " << o1->GetName() << endl);
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  * Clear results
118  */
119  void clear() override{
120  results.clear();
121  }
122 
123  /**
124  * Get test name.
125  */
126  std::string getName() override{
127  return name;
128  }
129 
130  /**
131  * Get parameter name.
132  */
133  std::string getParameter() override{
134  return parameter;
135  }
136 
137 private:
138  double threshold; //!< threshold value to decide if test is passed.
139  double failuresThreshold; //!< threshold value to decide if test is passed.
140  char slice; //!< Axis to slice. x or X for x-axis, y or Y for y-axis, n or N for None.
141  const std::string name = "Runs_2D"; //!< test name.
142  const std::string parameter = "#sigma"; //!< parameter name.
143 };
144 
145 #endif
std::string getName() override
Get test name.
std::vector< JTestResult > results
Definition: JTest_t.hh:251
Definition: JRoot.hh:19
JTestResult JRunsTestSlice(TH2 *h1, TH2 *h2, double threshold, double failuresThreshold, std::string testName, std::string parameterName, char slice)
Runs test for sliced 2D histograms.
Definition: JTestRuns_t.hh:112
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
void test(TObject *o1, TObject *o2) override
Tests the statistical compatibility of two ROOT TObjects.
Definition: JTestRuns_2D.hh:65
do cat driver txt<< EOFevent ev_configure{RC_EVT%< ev_configure.txt > RC_DWRT path
void clear() override
Clear results.
#define ERROR(A)
Definition: JMessage.hh:66
const std::string name
test name.
Implementation of the Chi2 test for 2D histograms.
Definition: JTestRuns_2D.hh:21
virtual void save(TFile *f, std::string path, bool onlyFailures=false) override
Writes the test result to root file.
Definition: JTestRuns_2D.hh:96
double failuresThreshold
threshold value to decide if test is passed.
Implementation of the different Runs-related tests.
Definition: JTestRuns_t.hh:14
char slice
Axis to slice. x or X for x-axis, y or Y for y-axis, n or N for None.
const std::string parameter
parameter name.
Interface to read input and write output for TObject tests.
Definition: JTest_t.hh:246
double threshold
threshold value to decide if test is passed.
std::ostream & write(std::ostream &out, std::string delimiter=" ", bool onlyFailures=false) const override
Write test result to output.
Definition: JTestRuns_2D.hh:47
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
std::string getParameter() override
Get parameter name.
std::istream & read(std::istream &in) override
Read test parameters from input.
Definition: JTestRuns_2D.hh:35