Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestSignificance_1D.hh
Go to the documentation of this file.
1 #ifndef __JTESTSIGNIFICANCE_1D__
2 #define __JTESTSIGNIFICANCE_1D__
3 
4 #include <istream>
5 #include <ostream>
8 
9 // using namespace std;
10 
11 /**
12  * \author bofearraigh
13  * \author rgruiz
14  */
15 
16 /**
17  * Significance test applied to 1D histograms
18  */
20  public JTest_t ,
21  public JTestSignificance_t
22 {
23 public:
24 
25  /**
26  * Default constructor.
27  */
29 
30  /**
31  * Read test parameters from input.
32  *
33  * \param in input stream
34  * \return input stream
35  */
36  std::istream& read(std::istream& in) override{
37  return in >> threshold >> K;
38  };
39 
40  /**
41  * Write test result to output.
42  *
43  * \param out output stream
44  * \param delimiter field delimiter
45  * \param onlyFailures If true, write only failures.
46  * \return output stream
47  */
48  std::ostream& write(std::ostream& out, std::string delimiter = " ", bool onlyFailures = false) const override{
49  for (std::vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r) {
50  if (onlyFailures){
51  if (!r->passed)
52  out << std::scientific << std::setprecision(2) << (r->passed ? JPP::GREEN : JPP::RED) << r->print(delimiter) << std::endl;
53  }else{
54  out << std::scientific << std::setprecision(2) << (r->passed ? JPP::GREEN : JPP::RED) << r->print(delimiter) << std::endl;
55  }
56  }
57  return out;
58  };
59 
60  /**
61  * Applies Significance test for two ROOT TH1 histograms.
62  *
63  * \param o1 First histogram
64  * \param o2 Second histogram
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  ERROR("For 2D histograms call JTestSignificance_2D: " << o1->GetName() << endl);
72 
73  } else if (!(dynamic_cast<TH1*>(o1) == NULL) && !(dynamic_cast<TH1*>(o2) == NULL)) {
74 
75  TH1D* h1 = dynamic_cast<TH1D*>(o1);
76  TH1D* h2 = dynamic_cast<TH1D*>(o2);
77 
78  if (h1 -> GetNbinsX() != h2 -> GetNbinsX())
79  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
80 
81  if (K<0)
82  K = h2->GetEntries()/h1->GetEntries();
83 
84  JTestResult r = JSignificanceTest<TH1D>(h1, h2, threshold, K, name, parameter);
85 
86  results.push_back(r);
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 p-value to decide if test is passed.
139  double K; //!< normalization factor between histograms.
140  const std::string name = "Significance_1D"; //!< test name.
141  const std::string parameter = "Significance"; //!< test name.
142 };
143 #endif
virtual void save(TFile *f, std::string path, bool onlyFailures=false) override
Writes the test result to root file.
const std::string parameter
test name.
Significance test applied to 1D histograms.
double threshold
threshold p-value to decide if test is passed.
std::string getName() override
Get test name.
const std::string name
test name.
std::vector< JTestResult > results
Definition: JTest_t.hh:251
Definition: JRoot.hh:19
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
void test(TObject *o1, TObject *o2) override
Applies Significance test for two ROOT TH1 histograms.
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
std::ostream & write(std::ostream &out, std::string delimiter=" ", bool onlyFailures=false) const override
Write test result to output.
std::istream & read(std::istream &in) override
Read test parameters from input.
std::string getParameter() override
Get parameter name.
void clear() override
Clear results.
#define ERROR(A)
Definition: JMessage.hh:66
double K
normalization factor between histograms.
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:38
JTestSignificance_1D()
Default constructor.