Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestChi2_Bin.hh
Go to the documentation of this file.
1 #ifndef __JTESTCHI2_BIN__
2 #define __JTESTCHI2_BIN__
3 
4 #include <istream>
5 #include <ostream>
8 
9 /**
10  * \author rgruiz
11  */
12 
13 /**
14  * Implementation of a bin-by-bin 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 test is run by the method JChi2TestBin_2D().
17  */
19  public JTest_t,
20  public JTestChi2_t
21 {
22 public:
23  /**
24  * Default constructor.
25  */
27 
28  /**
29  * Read test parameters from input.
30  *
31  * \param in input stream
32  * \return input stream
33  */
34  std::istream& read(std::istream& in) override{
35  return in >> outliersThreshold >> chi2Threshold;
36  };
37 
38  /**
39  * Write test result to output.
40  *
41  * \param out output stream
42  * \param delimiter field delimiter
43  * \param onlyFailures If true, write only failures.
44  * \return output stream
45  */
46  std::ostream& write(std::ostream& out, std::string delimiter = " ", bool onlyFailures = false) const override{
47  for (std::vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r) {
48  if (onlyFailures){
49  if (!r->passed)
50  out << std::scientific << std::setprecision(2) << (r->passed ? JPP::GREEN : JPP::RED) << r->print(delimiter) << std::endl;
51  }else{
52  out << std::scientific << std::setprecision(2) << (r->passed ? JPP::GREEN : JPP::RED) << r->print(delimiter) << std::endl;
53  }
54  }
55  return out;
56  };
57 
58  /**
59  * Tests the statistical compatibility of two ROOT 2D histograms
60  *
61  * \param o1 First histogram
62  * \param o2 Second histogram
63  *
64  * \return Test result
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 
72  TH2D* h1 = dynamic_cast<TH2D*>(o1);
73  TH2D* h2 = dynamic_cast<TH2D*>(o2);
74 
76  results.push_back(r);
77  }
78  };
79 
80  /**
81  * Writes the test result to root file
82  * \param f A ROOT file
83  * \param path Path in root file.
84  * \param onlyFailures If true, write only failures.
85  */
86  virtual void save(TFile* f , std::string path, bool onlyFailures = false) override{
87 
88  using namespace std;
89 
90  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
91 
92  if (onlyFailures){
93  if (!r->passed){
94  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
95  f->cd(path.c_str());
96  r->obj->Write();
97  }
98  }else{
99  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
100  f->cd(path.c_str());
101  r->obj->Write();
102  }
103  }
104  }
105 
106  /**
107  * Clear results
108  */
109  void clear() override{
110  results.clear();
111  }
112 
113  /**
114  * Get test name.
115  */
116  std::string getName() override{
117  return name;
118  }
119 
120  /**
121  * Get parameter name.
122  */
123  std::string getParameter() override{
124  return parameter;
125  }
126 
127 private:
128  double chi2Threshold; //!< threshold p-value to decide if test is passed for a bin.
129  double outliersThreshold; //!< number of bins allowed to fail the test.
130  const std::string name = "Chi2_Bin"; //!< test name.
131  const std::string parameter = "Outliers[%]"; //!< parameter name.
132 };
133 
134 #endif
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
void test(TObject *o1, TObject *o2) override
Tests the statistical compatibility of two ROOT 2D histograms.
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::string getName() override
Get test name.
data_type r[M+1]
Definition: JPolint.hh:742
Implementation of a bin-by-bin Chi2 test for 2D histograms.
Structure containing the result of the test.
Definition: JTest_t.hh:164
const std::string name
test name.
do cat driver txt<< EOFevent ev_configure{RC_EVT%< ev_configure.txt > RC_DWRT path
double outliersThreshold
number of bins allowed to fail the test.
std::ostream & write(std::ostream &out, std::string delimiter=" ", bool onlyFailures=false) const override
Write test result to output.
const std::string parameter
parameter name.
JTestResult JChi2TestBin_2D(TH2 *h1, TH2 *h2, double outliersThreshold, double chi2Threshold, std::string testName, std::string parameterName)
Bin-by-Bin Chi2 comparison of 2D histograms.
Definition: JTestChi2_t.hh:240
void clear() override
Clear results.
double chi2Threshold
threshold p-value to decide if test is passed for a bin.
Interface to read input and write output for TObject tests.
Definition: JTest_t.hh:246
Implementation of the different Chi2-related tests.
Definition: JTestChi2_t.hh:15
std::istream & read(std::istream &in) override
Read test parameters from input.
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
JTestChi2_Bin()
Default constructor.
std::string getParameter() override
Get parameter name.