Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Public Attributes | Private Attributes | List of all members
JTestSignificance_2D Class Reference

Significance test applied to 2D histograms. More...

#include <JTestSignificance_2D.hh>

Inheritance diagram for JTestSignificance_2D:
JTest_t JTestSignificance_t

Public Member Functions

 JTestSignificance_2D ()
 Default constructor. More...
 
std::istream & read (std::istream &in) override
 Read test parameters from input. More...
 
std::ostream & write (std::ostream &out, std::string delimiter=" ", bool onlyFailures=false) const override
 Write test result to output. More...
 
void test (TObject *o1, TObject *o2) override
 Applies Significance test for two ROOT TH1 histograms. More...
 
virtual void save (TFile *f, std::string path, bool onlyFailures=false) override
 Writes the test result to root file. More...
 
void clear () override
 Clear results. More...
 
std::string getName () override
 Get test name. More...
 
std::string getParameter () override
 Get parameter name. More...
 
template<class T >
JTestResult JSignificanceTest (T *h1, T *h2, double threshold, double K, std::string testName, std::string parameterName)
 Significance test for histograms. More...
 

Public Attributes

std::vector< JTestResultresults
 

Private Attributes

double threshold
 threshold p-value to decide if test is passed. More...
 
double K
 normalization factor between histograms. More...
 
const std::string name = "Significance_2D"
 test name. More...
 
const std::string parameter = "Significance"
 test name. More...
 

Detailed Description

Significance test applied to 2D histograms.

Author
bofearraigh
rgruiz

Definition at line 17 of file JTestSignificance_2D.hh.

Constructor & Destructor Documentation

JTestSignificance_2D::JTestSignificance_2D ( )
inline

Default constructor.

Definition at line 26 of file JTestSignificance_2D.hh.

26 {}

Member Function Documentation

std::istream& JTestSignificance_2D::read ( std::istream &  in)
inlineoverridevirtual

Read test parameters from input.

Parameters
ininput stream
Returns
input stream

Implements JTest_t.

Definition at line 34 of file JTestSignificance_2D.hh.

34  {
35  return in >> threshold >> K;
36  };
double threshold
threshold p-value to decide if test is passed.
double K
normalization factor between histograms.
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
std::ostream& JTestSignificance_2D::write ( std::ostream &  out,
std::string  delimiter = " ",
bool  onlyFailures = false 
) const
inlineoverridevirtual

Write test result to output.

Parameters
outoutput stream
delimiterfield delimiter
onlyFailuresIf true, write only failures.
Returns
output stream

Implements JTest_t.

Definition at line 46 of file JTestSignificance_2D.hh.

46  {
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  };
std::vector< JTestResult > results
Definition: JTest_t.hh:251
data_type r[M+1]
Definition: JPolint.hh:742
void JTestSignificance_2D::test ( TObject o1,
TObject o2 
)
inlineoverridevirtual

Applies Significance test for two ROOT TH1 histograms.

Parameters
o1First histogram
o2Second histogram

Implements JTest_t.

Definition at line 64 of file JTestSignificance_2D.hh.

64  {
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  };
double threshold
threshold p-value to decide if test is passed.
double K
normalization factor between histograms.
std::vector< JTestResult > results
Definition: JTest_t.hh:251
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
data_type r[M+1]
Definition: JPolint.hh:742
const std::string name
test name.
Structure containing the result of the test.
Definition: JTest_t.hh:164
#define ERROR(A)
Definition: JMessage.hh:66
const std::string parameter
test name.
virtual void JTestSignificance_2D::save ( TFile *  f,
std::string  path,
bool  onlyFailures = false 
)
inlineoverridevirtual

Writes the test result to root file.

Parameters
fA ROOT file
pathPath in root file.
onlyFailuresIf true, write only failures.

Implements JTest_t.

Definition at line 91 of file JTestSignificance_2D.hh.

91  {
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  }
std::vector< JTestResult > results
Definition: JTest_t.hh:251
do set_array DAQHEADER JPrintDAQHeader f
Definition: JTuneHV.sh:79
data_type r[M+1]
Definition: JPolint.hh:742
do cat driver txt<< EOFevent ev_configure{RC_EVT%< ev_configure.txt > RC_DWRT path
void JTestSignificance_2D::clear ( )
inlineoverridevirtual

Clear results.

Implements JTest_t.

Definition at line 114 of file JTestSignificance_2D.hh.

114  {
115  results.clear();
116  }
std::vector< JTestResult > results
Definition: JTest_t.hh:251
std::string JTestSignificance_2D::getName ( )
inlineoverridevirtual

Get test name.

Implements JTest_t.

Definition at line 121 of file JTestSignificance_2D.hh.

121  {
122  return name;
123  }
const std::string name
test name.
std::string JTestSignificance_2D::getParameter ( )
inlineoverridevirtual

Get parameter name.

Implements JTest_t.

Definition at line 128 of file JTestSignificance_2D.hh.

128  {
129  return parameter;
130  }
const std::string parameter
test name.
template<class T >
JTestResult JTestSignificance_t::JSignificanceTest ( T h1,
T h2,
double  threshold,
double  K,
std::string  testName,
std::string  parameterName 
)
inlineinherited

Significance test for histograms.


Parameters
h1First object
h2Second object
threshold
KNormalisation parameter
parameterNameName of the parameter used to test the histograms
testNameName of the test used to compare the histograms
Returns
Test result.

Definition at line 51 of file JTestSignificance_t.hh.

51  {
52 
53  using namespace std;
54  using namespace JPP;
55 
56  if(h1 -> GetNbinsX() != h2 -> GetNbinsX())
57  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
58 
59 
60  T* h3 = (T*)h1->Clone(h1->GetName()==h2->GetName() ?
61  MAKE_CSTRING(to_string(h1->GetName())) :
62  MAKE_CSTRING(to_string(h1->GetName()) + "_VS_" + to_string(h2->GetName())));
63 
64  h3->Add(h2,-1*K);
65 
66  double S = 0;
67 
68  for (int i=0 ; i < h1->GetNbinsX() ; ++i){
69  for (int j=0 ; j< h1->GetNbinsY() ; ++j){
70  for (int k=0 ; k< h1->GetNbinsY() ; ++k){
71 
72  double a = h1->GetBinContent(i+1,j+1,k+1);
73  double b = h2->GetBinContent(i+1,j+1,k+1);
74 
75  if(a!=0 || b!=0){
76  S += fabs((a - K*b)/sqrt(a + K*K*b));
77  }
78  }
79  }
80  }
81 
82  S /= (h1->GetNbinsX()*h1->GetNbinsY()*h1->GetNbinsZ());
83 
84  bool passed;
85 
86  (S < threshold ? passed = false : passed = true);
87 
88  JResultTitle title(testName, parameterName, passed, S);
89 
90  h3->SetTitle(title.getTitle().c_str());
91 
92  JTestResult r (testName,
93  string (h1->GetDirectory()->GetPath()).append(h1->GetName()),
94  string (h2->GetDirectory()->GetPath()).append(h2->GetName()),
95  h1->GetDirectory()->GetFile()->GetName(),
96  h2->GetDirectory()->GetFile()->GetName(),
97  parameterName, S , threshold, h3, passed);
98 
99  return r;
100  };
static const uint32_t K[64]
Definition: crypt.cc:77
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
Definition: JTest_t.hh:22
then fatal No sound hydrophone file $HYDROPHONE_TXT fi JGraph f $HYDROPHONE_TXT o $HYDROPHONE_ROOT sort gr k
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
data_type r[M+1]
Definition: JPolint.hh:742
Structure containing the result of the test.
Definition: JTest_t.hh:164
do set_variable OUTPUT_DIRECTORY $WORKDIR T
#define ERROR(A)
Definition: JMessage.hh:66
do set_variable SIGMA_NS set_variable OUTLIERS set_variable OUTPUT_FILE matrix[${ALPHA_DEG}\deg\] root $JPP JMatrixNZ a $DETECTOR f $INPUT_FILE o $OUTPUT_FILE S
Definition: JMatrixNZ.sh:56
then JCalibrateToT a
Definition: JTuneHV.sh:108
std::string to_string(const T &value)
Convert value to string.
int j
Definition: JPolint.hh:666

Member Data Documentation

double JTestSignificance_2D::threshold
private

threshold p-value to decide if test is passed.

Definition at line 134 of file JTestSignificance_2D.hh.

double JTestSignificance_2D::K
private

normalization factor between histograms.

Definition at line 135 of file JTestSignificance_2D.hh.

const std::string JTestSignificance_2D::name = "Significance_2D"
private

test name.

Definition at line 136 of file JTestSignificance_2D.hh.

const std::string JTestSignificance_2D::parameter = "Significance"
private

test name.

Definition at line 137 of file JTestSignificance_2D.hh.

std::vector<JTestResult> JTest_t::results
inherited

Buffer to store results of multiple tests.

Definition at line 251 of file JTest_t.hh.


The documentation for this class was generated from the following file: