Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestSignificance_2D.hh
Go to the documentation of this file.
1 #ifndef __JTESTSIGNIFICANCE_2D__
2 #define __JTESTSIGNIFICANCE_2D__
3 
4 #include <istream>
5 #include <ostream>
8 
9 /**
10  * \author bofearraigh
11  * \author rgruiz
12  */
13 
14 /**
15  * Significance test applied to 2D histograms
16  */
18  public JTest_t ,
19  public JTestSignificance_t
20 {
21 public:
22 
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 >> threshold >> K;
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  * Applies Significance test for two ROOT TH1 histograms.
60  *
61  * \param o1 First histogram
62  * \param o2 Second histogram
63  */
64  void test(TObject* o1, TObject* o2) override{
65 
66  using namespace std;
67 
68  if (!(dynamic_cast<TH2*>(o1) == NULL) && !(dynamic_cast<TH2*>(o2) == NULL)) {
69 
70  TH2D* h1 = dynamic_cast<TH2D*>(o1);
71  TH2D* h2 = dynamic_cast<TH2D*>(o2);
72 
73  if (h1 -> GetNbinsX() != h2 -> GetNbinsX() || h1 -> GetNbinsY() != h2 -> GetNbinsY())
74  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
75 
76  if (K<0)
77  K = h2->GetEntries()/h1->GetEntries();
78 
79  JTestResult r = JSignificanceTest<TH2D>(h1, h2, threshold, K, name, parameter);
80 
81  results.push_back(r);
82  }
83  };
84 
85  /**
86  * Writes the test result to root file
87  * \param f A ROOT file
88  * \param path Path in root file.
89  * \param onlyFailures If true, write only failures.
90  */
91  virtual void save(TFile* f , std::string path, bool onlyFailures = false) override{
92 
93  using namespace std;
94 
95  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
96 
97  if (onlyFailures){
98  if (!r->passed){
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  }else{
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  }
109  }
110 
111  /**
112  * Clear results
113  */
114  void clear() override{
115  results.clear();
116  }
117 
118  /**
119  * Get test name.
120  */
121  std::string getName() override{
122  return name;
123  }
124 
125  /**
126  * Get parameter name.
127  */
128  std::string getParameter() override{
129  return parameter;
130  }
131 
132 
133 private:
134  double threshold; //!< threshold p-value to decide if test is passed.
135  double K; //!< normalization factor between histograms.
136  const std::string name = "Significance_2D"; //!< test name.
137  const std::string parameter = "Significance"; //!< test name.
138 };
139 #endif
std::string getName() override
Get test name.
JTestSignificance_2D()
Default constructor.
std::istream & read(std::istream &in) override
Read test parameters from input.
double threshold
threshold p-value to decide if test is passed.
double K
normalization factor between histograms.
void clear() override
Clear results.
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
void test(TObject *o1, TObject *o2) override
Applies Significance test for two ROOT TH1 histograms.
data_type r[M+1]
Definition: JPolint.hh:742
const std::string name
test name.
std::string getParameter() override
Get parameter name.
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
Significance test applied to 2D histograms.
virtual void save(TFile *f, std::string path, bool onlyFailures=false) override
Writes the test result to root file.
#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.
const std::string parameter
test name.
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 typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36