Jpp  pmt_effective_area_update_2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestZero.hh
Go to the documentation of this file.
1 #ifndef __JTESTZERO__
2 #define __JTESTZERO__
3 
4 #include <istream>
5 #include <ostream>
6 
7 #include <TROOT.h>
8 #include <TObject.h>
9 #include "TGraph.h"
10 #include "TCanvas.h"
11 #include "TLine.h"
12 #include "TMath.h"
15 #include "JTools/JQuantile.hh"
16 #include "JTools/JRange.hh"
17 
18 /**
19  * \author rgruiz
20  */
21 
22 /**
23  * Implementation of a bin-by-bin compatibility test for 2D histograms with low bin contents.\n
24  * 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
25  * The test is run by the method JTestZero_2D().
26  */
27 class JTestZero:
28  public JTest_t,
29  public JTestZero_t
30 {
31 public:
32 
33  /**
34  * Default constructor.
35  */
37 
38  /**
39  * Read test parameters from input.
40  *
41  * \param in input stream
42  * \return input stream
43  */
44  std::istream& read(std::istream& in) override{
45  return in >> outliersThreshold >> threshold;
46  };
47 
48  /**
49  * Write test result to output.
50  *
51  * \param out output stream
52  * \param delimiter field delimiter
53  * \param onlyFailures If true, write only failures.
54  * \return output stream
55  */
56  std::ostream& write(std::ostream& out, std::string delimiter = " ", bool onlyFailures = false) const override{
57  for (std::vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r) {
58  if (onlyFailures){
59  if (!r->passed)
60  out << std::scientific << std::setprecision(2) << (r->passed ? JPP::GREEN : JPP::RED) << r->print(delimiter) << std::endl;
61  }else{
62  out << std::scientific << std::setprecision(2) << (r->passed ? JPP::GREEN : JPP::RED) << r->print(delimiter) << std::endl;
63  }
64  }
65  return out;
66  };
67 
68  /**
69  * Bin-by-bin comparison for ROOT TH2 histograms, of compatibility with a Poisson pdf of parameter 1.
70  *
71  * \param o1 First histogram
72  * \param o2 Second histogram
73  */
74  void test(TObject* o1, TObject* o2) override{
75 
76  using namespace std;
77 
78  if (!(dynamic_cast<TH2*>(o1) == NULL) && !(dynamic_cast<TH2*>(o2) == NULL)) {
79 
80  TH2D* h1 = dynamic_cast<TH2D*>(o1);
81  TH2D* h2 = dynamic_cast<TH2D*>(o2);
82 
84  results.push_back(r);
85  }
86  };
87 
88  /**
89  * Writes the test result to root file
90  * \param f A ROOT file
91  * \param path Path in root file.
92  * \param onlyFailures If true, write only failures.
93  */
94  virtual void save(TFile* f , std::string path, bool onlyFailures = false) override{
95 
96  using namespace std;
97 
98  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
99 
100  if (onlyFailures){
101  if (!r->passed){
102  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
103  f->cd(path.c_str());
104  r->obj->Write();
105  }
106  }else{
107  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
108  f->cd(path.c_str());
109  r->obj->Write();
110  }
111  }
112  }
113 
114  /**
115  * Clear results
116  */
117  void clear() override{
118  results.clear();
119  }
120 
121  /**
122  * Get test name.
123  */
124  std::string getName() override{
125  return name;
126  }
127 
128  /**
129  * Get parameter name.
130  */
131  std::string getParameter() override{
132  return parameter;
133  }
134 
135 private:
136  double outliersThreshold; //!< Fraction of bins allowed to fail.
137  double threshold; //!< threshold p-value to decide if test is passed.
138  const std::string name = "Zero" ; //!< test name.
139  const std::string parameter = "failure_fraction" ; //!< parameter name.
140 };
141 
142 #endif
void clear() override
Clear results.
Definition: JTestZero.hh:117
JTestResult JTestZero_2D(TH2 *h1, TH2 *h2, double outliersThreshold, double threshold, std::string testName, std::string parameterName)
Bin-by-Bin test for 2D histograms where a very low number of entries is expected. ...
Definition: JTestZero_t.hh:46
JTestZero()
Default constructor.
Definition: JTestZero.hh:36
const std::string parameter
parameter name.
Definition: JTestZero.hh:139
const std::string name
test name.
Definition: JTestZero.hh:138
std::istream & read(std::istream &in) override
Read test parameters from input.
Definition: JTestZero.hh:44
void test(TObject *o1, TObject *o2) override
Bin-by-bin comparison for ROOT TH2 histograms, of compatibility with a Poisson pdf of parameter 1...
Definition: JTestZero.hh:74
double outliersThreshold
Fraction of bins allowed to fail.
Definition: JTestZero.hh:136
std::vector< JTestResult > results
Definition: JTest_t.hh:251
Definition: JRoot.hh:19
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
Implementation of a bin-by-bin compatibility test for 2D histograms with low bin contents.
Definition: JTestZero.hh:27
data_type r[M+1]
Definition: JPolint.hh:742
double threshold
threshold p-value to decide if test is passed.
Definition: JTestZero.hh:137
Structure containing the result of the test.
Definition: JTest_t.hh:164
virtual void save(TFile *f, std::string path, bool onlyFailures=false) override
Writes the test result to root file.
Definition: JTestZero.hh:94
then JPizza f
Definition: JPizza.sh:46
Implementation of the Zeros test for histograms with expected low bin contents.
Definition: JTestZero_t.hh:20
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: JTestZero.hh:56
std::string getName() override
Get test name.
Definition: JTestZero.hh:124
std::string getParameter() override
Get parameter name.
Definition: JTestZero.hh:131
Auxiliary class to define a range between two values.
Interface to read input and write output for TObject tests.
Definition: JTest_t.hh:246
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:40