Jpp
 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 <iostream>
5 
6 #include <TROOT.h>
7 #include <TObject.h>
8 #include "TGraph.h"
9 #include "TCanvas.h"
10 #include "TLine.h"
11 #include "TMath.h"
12 #include "JTest_t.hh"
13 #include "JTools/JQuantile.hh"
14 #include "JTools/JRange.hh"
15 #include "JTestZero_t.hh"
16 
17 using namespace std;
18 
19 /*
20  * Bin-by-Bin test for low content histograms.
21  */
22 class JTestZero:
23  public JTest_t,
24  public JTestZero_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) {
40  return in >> outliersThreshold >> threshold;
41  };
42 
43  /*
44  * Write test result to output.
45  *
46  * \param out output stream
47  * \return output stream
48  */
49  std::ostream& write(std::ostream& out) {
50  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r) {
51  out << scientific << setprecision(2) << (r->passed ? GREEN : RED) << r->message << endl;
52  }
53  return out;
54  };
55 
56  /*
57  * Bin-by-bin comparison for ROOT TH2 histograms, of compatibility with a Poisson pdf of parameter 1.
58  *
59  * \param o1 First histogram
60  * \param o2 Second histogram
61  */
62  void test(TObject* o1, TObject* o2) {
63 
64  if (!(dynamic_cast<TH2*>(o1) == NULL) && !(dynamic_cast<TH2*>(o2) == NULL)) {
65 
66  TH2D* h1 = dynamic_cast<TH2D*>(o1);
67  TH2D* h2 = dynamic_cast<TH2D*>(o2);
68 
69  JTestResult r = JTestZero_2D(h1, h2, outliersThreshold, threshold);
70  results.push_back(r);
71  }
72  };
73 
74  /*
75  * Writes the result to root file
76  *
77  * \param f The file
78  * \param path Path in root file.
79  */
80  virtual void save(TFile* f , string path){
81 
82  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
83 
84  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
85  f->cd(path.c_str());
86  r->obj->Write();
87  }
88  }
89 
90  /*
91  * Clear results
92  */
93  void clear(){
94  results.clear();
95  }
96 
97 private:
98  double outliersThreshold; //!< Fraction of bins allowed to fail.
99  double threshold; //!< threshold p-value to decide if test is passed.
100 };
101 
102 #endif
double outliersThreshold
Fraction of bins allowed to fail.
Definition: JTestZero.hh:98
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
Definition: JRoot.hh:19
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
data_type r[M+1]
Definition: JPolint.hh:709
virtual void save(TFile *f, string path)
Definition: JTestZero.hh:80
double threshold
threshold p-value to decide if test is passed.
Definition: JTestZero.hh:99
then JPizza f
Definition: JPizza.sh:46
do cat driver txt<< EOFevent ev_configure{RC_EVT%< ev_configure.txt > RC_DWRT path
std::istream & read(std::istream &in)
Definition: JTestZero.hh:39
void clear()
Definition: JTestZero.hh:93
void test(TObject *o1, TObject *o2)
Definition: JTestZero.hh:62
std::ostream & write(std::ostream &out)
Definition: JTestZero.hh:49
Auxiliary class to define a range between two values.