Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Public Attributes | Private Attributes | List of all members
JTestIdentical_2D Class Reference

Implementation of the a test to check if two 2D histograms are the same. More...

#include <JTestIdentical_2D.hh>

Inheritance diagram for JTestIdentical_2D:
JTest_t JTestIdentical_t

Public Member Functions

 JTestIdentical_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
 Tests compatibility between two TObjects. 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 JIdenticalTest (T *h1, T *h2, double tolerance, std::string testName, std::string parameterName)
 Bin-by-Bin test of two histograms, that verifies whether the histograms are the same. More...
 

Public Attributes

std::vector< JTestResultresults
 

Private Attributes

double tolerance
 tolerance value to accept the difference as acceptable. More...
 
const std::string name = "Identical_2D"
 test name. More...
 
const std::string parameter = "Difference"
 parameter name. More...
 

Detailed Description

Implementation of the a test to check if two 2D histograms are the same.

Author
rgruiz
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.
The input parameter tolerance(), is used to evaluate whether the test is passed or failed.
The test is run by the method JIdenticalTest().

Definition at line 19 of file JTestIdentical_2D.hh.

Constructor & Destructor Documentation

JTestIdentical_2D::JTestIdentical_2D ( )
inline

Default constructor.

Definition at line 28 of file JTestIdentical_2D.hh.

28 {}

Member Function Documentation

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

Read test parameters from input.

Parameters
ininput stream
Returns
input stream

Implements JTest_t.

Definition at line 36 of file JTestIdentical_2D.hh.

36  {
37  return in >> tolerance;
38  };
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
double tolerance
tolerance value to accept the difference as acceptable.
std::ostream& JTestIdentical_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 48 of file JTestIdentical_2D.hh.

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

Tests compatibility between two TObjects.

Parameters
o1First object
o2Second object

Implements JTest_t.

Definition at line 66 of file JTestIdentical_2D.hh.

66  {
67 
68  using namespace std;
69 
70  if (!(dynamic_cast<TH2*>(o1) == NULL) && !(dynamic_cast<TH2*>(o2) == NULL)) {
71 
72  TH2D* h1 = dynamic_cast<TH2D*>(o1);
73  TH2D* h2 = dynamic_cast<TH2D*>(o2);
74 
75  if(h1 -> GetNbinsX() != h2 -> GetNbinsX() || h1 -> GetNbinsY() != h2 -> GetNbinsY())
76  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
77 
78  JTestResult r = JIdenticalTest<TH2D>(h1, h2, tolerance, name, parameter);
79 
80  results.push_back(r);
81  }
82  };
std::vector< JTestResult > results
Definition: JTest_t.hh:251
const std::string parameter
parameter name.
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
#define ERROR(A)
Definition: JMessage.hh:66
const std::string name
test name.
double tolerance
tolerance value to accept the difference as acceptable.
virtual void JTestIdentical_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 90 of file JTestIdentical_2D.hh.

90  {
91 
92  using namespace std;
93 
94  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
95 
96  if (onlyFailures){
97  if (!r->passed){
98  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
99  f->cd(path.c_str());
100  r->obj->Write();
101  }
102  }else{
103  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
104  f->cd(path.c_str());
105  r->obj->Write();
106  }
107  }
108  }
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 JTestIdentical_2D::clear ( )
inlineoverridevirtual

Clear results.

Implements JTest_t.

Definition at line 113 of file JTestIdentical_2D.hh.

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

Get test name.

Implements JTest_t.

Definition at line 120 of file JTestIdentical_2D.hh.

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

Get parameter name.

Implements JTest_t.

Definition at line 127 of file JTestIdentical_2D.hh.

127  {
128  return parameter;
129  }
const std::string parameter
parameter name.
template<class T >
JTestResult JTestIdentical_t::JIdenticalTest ( T h1,
T h2,
double  tolerance,
std::string  testName,
std::string  parameterName 
)
inlineinherited

Bin-by-Bin test of two histograms, that verifies whether the histograms are the same.


For each bin, the test calculates the difference, and compares it with a tolerance passed as an argument.
The test is passed if the difference is smaller than the tolerance for every bin.
The template parameter can be TH1X, TH2X or TH3X.

Parameters
h1First object
h2Second object
tolerancetolerance value for the bin-by-bin differences
parameterNameName of the parameter used to test the histograms
testNameName of the test used to compare the histograms
Returns
Test result.

Definition at line 39 of file JTestIdentical_t.hh.

39  {
40 
41  using namespace std;
42  using namespace JPP;
43 
44  if(h1 -> GetNbinsX() != h2 -> GetNbinsX() || h1 -> GetNbinsY() != h2 -> GetNbinsY() || h1 -> GetNbinsZ() != h2 -> GetNbinsZ())
45  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
46 
47  T* h3 = (T*)h1->Clone(h1->GetName()==h2->GetName() ?
48  MAKE_CSTRING(to_string(h1->GetName())) :
49  MAKE_CSTRING(to_string(h1->GetName()) + "_VS_" + to_string(h2->GetName())));
50 
51  h3->Add(h2,-1);
52 
53  bool passed;
54 
55  double maxDifference = 0.0;
56 
57  for (int i=0 ; i < h1->GetNbinsX() ; ++i){
58  for (int j=0 ; j< h1->GetNbinsY() ; ++j){
59  for (int k=0 ; k< h1->GetNbinsY() ; ++k){
60 
61  double d = h1->GetBinContent(i+1,j+1,k+1) - h2->GetBinContent(i+1,j+1,k+1);
62 
63  if (fabs(d) > maxDifference)
64  maxDifference = fabs(d);
65  if (fabs(d) > tolerance)
66  passed = false;
67  }
68  }
69  }
70 
71  JResultTitle title(testName, parameterName, passed , maxDifference);
72 
73  h3->SetTitle(title.getTitle().c_str());
74 
75  JTestResult r (testName,
76  string (h1->GetDirectory()->GetPath()).append(h1->GetName()),
77  string (h2->GetDirectory()->GetPath()).append(h2->GetName()),
78  h1->GetDirectory()->GetFile()->GetName(),
79  h2->GetDirectory()->GetFile()->GetName(),
80  parameterName, maxDifference, tolerance, h3, passed);
81 
82  return r;
83  };
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
then JMuonMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
Definition: JMuonPath.sh:45
std::string to_string(const T &value)
Convert value to string.
int j
Definition: JPolint.hh:666

Member Data Documentation

double JTestIdentical_2D::tolerance
private

tolerance value to accept the difference as acceptable.

Definition at line 133 of file JTestIdentical_2D.hh.

const std::string JTestIdentical_2D::name = "Identical_2D"
private

test name.

Definition at line 134 of file JTestIdentical_2D.hh.

const std::string JTestIdentical_2D::parameter = "Difference"
private

parameter name.

Definition at line 135 of file JTestIdentical_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: