Jpp  17.3.1
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 __JCOMPAREHISTOGRAMS__JTESTIDENTICAL_T__
2 #define __JCOMPAREHISTOGRAMS__JTESTIDENTICAL_T__
3 
4 #include <istream>
5 #include <ostream>
6 
9 
10 
11 /**
12  * \author rgruiz
13  */
14 namespace JCOMPAREHISTOGRAMS {
15 
17 
18  /**
19  * Implementation test that verify if two histograms are the same.
20  */
22  {
23  public:
24 
25  /**
26  * Default constructor.
27  */
29 
30  /**
31  * Bin-by-Bin test of two histograms, that verifies whether the histograms are the same.\n
32  * For each bin, the test calculates the difference, and compares it with a tolerance passed as an argument.\n
33  * The test is passed if the difference is smaller than the tolerance for every bin.\n
34  * The template parameter can be TH1X, TH2X or TH3X.
35  *
36  * \param h1 First object
37  * \param h2 Second object
38  * \param tolerance tolerance value for the bin-by-bin differences
39  * \param parameterName Name of the parameter used to test the histograms
40  * \param testName Name of the test used to compare the histograms
41  *
42  * \return Test result.
43  */
44  template<class T>
45  JTestResult JIdenticalTest(T* h1, T* h2, double tolerance, std::string testName, std::string parameterName) {
46 
47  using namespace std;
48  using namespace JPP;
49 
50  if(h1 -> GetNbinsX() != h2 -> GetNbinsX() || h1 -> GetNbinsY() != h2 -> GetNbinsY() || h1 -> GetNbinsZ() != h2 -> GetNbinsZ())
51  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
52 
53  T* h3 = (T*)h1->Clone(h1->GetName()==h2->GetName() ?
54  MAKE_CSTRING(to_string(h1->GetName())) :
55  MAKE_CSTRING(to_string(h1->GetName()) + "_VS_" + to_string(h2->GetName())));
56 
57  h3->Add(h2,-1);
58 
59  bool passed;
60 
61  double maxDifference = 0.0;
62 
63  for (int i=0 ; i < h1->GetNbinsX() ; ++i){
64  for (int j=0 ; j< h1->GetNbinsY() ; ++j){
65  for (int k=0 ; k< h1->GetNbinsZ() ; ++k){
66 
67  double d = h1->GetBinContent(i+1,j+1,k+1) - h2->GetBinContent(i+1,j+1,k+1);
68 
69  if (fabs(d) > maxDifference)
70  maxDifference = fabs(d);
71  if (fabs(d) > tolerance)
72  passed = false;
73  }
74  }
75  }
76 
77  JResultTitle title(testName, parameterName, passed , maxDifference);
78 
79  h3->SetTitle(title.getTitle().c_str());
80 
81  JTestResult r (testName,
82  JRootObjectID(MAKE_STRING(h1->GetDirectory()->GetPath() << h1->GetName())),
83  JRootObjectID(MAKE_STRING(h2->GetDirectory()->GetPath() << h1->GetName())),
84  parameterName, maxDifference, tolerance, h3, passed);
85 
86  return r;
87  };
88  };
89 }
90 
91 #endif
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: JResultTitle.hh:22
JTestIdentical_t()
Default constructor.
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
Auxiliary class to handle file name, ROOT directory and object name.
data_type r[M+1]
Definition: JPolint.hh:779
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:127
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.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
#define ERROR(A)
Definition: JMessage.hh:66
then awk string
then JMuonMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
Definition: JMuonPath.sh:47
std::string to_string(const T &value)
Convert value to string.
Structure containing the result of the test.
Definition: JTestResult.hh:27
int j
Definition: JPolint.hh:703
std::string getTitle()
Returns a standard string to be used as title of a graphical root object.
Definition: JResultTitle.hh:64