Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestIdentical_t.hh
Go to the documentation of this file.
1 #ifndef __JTESTIDENTICAL_T__
2 #define __JTESTIDENTICAL_T__
3 
4 #include <istream>
5 #include <ostream>
7 
8 /**
9  * \author rgruiz
10  */
11 
12 /**
13  * Implementation test that verify if two histograms are the same.
14  */
16 {
17 public:
18 
19  /**
20  * Default constructor.
21  */
23 
24  /**
25  * Bin-by-Bin test of two histograms, that verifies whether the histograms are the same.\n
26  * For each bin, the test calculates the difference, and compares it with a tolerance passed as an argument.\n
27  * The test is passed if the difference is smaller than the tolerance for every bin.\n
28  * The template parameter can be TH1X, TH2X or TH3X.
29  *
30  * \param h1 First object
31  * \param h2 Second object
32  * \param tolerance tolerance value for the bin-by-bin differences
33  * \param parameterName Name of the parameter used to test the histograms
34  * \param testName Name of the test used to compare the histograms
35  *
36  * \return Test result.
37  */
38  template<class T>
39  JTestResult JIdenticalTest(T* h1, T* h2, double tolerance, std::string testName, std::string parameterName) {
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  };
84 };
85 
86 #endif
JTestIdentical_t()
Default constructor.
Implementation test that verify if two histograms are the same.
then fatal No hydrophone data file $HYDROPHONE_TXT fi sort gr k
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
Definition: JTest_t.hh:22
#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
std::string getTitle()
Returns a standard string to be used as title of a graphical root object.
Definition: JTest_t.hh:67
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
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.