Tests the statistical compatibility of two ROOT TObjects.
52 {
55
56 const TH2* h1 = dynamic_cast<const TH2*>(o1);
57 const TH2* h2 = dynamic_cast<const TH2*>(o2);
58
59 if (h1 == NULL || h2 == NULL) {
61 }
62
63 TH1* h3 = NULL;
64
65 const char* const h3name = (h1->GetName() == h2->GetName() ?
68
69 int nFailures = 0;
70 int nSlices = 0;
71
73
74 const int nSlices1 = h1->GetNbinsX();
75 const int nSlices2 = h2->GetNbinsX();
76
77 if (nSlices1 != nSlices2) {
78 THROW(
JValueOutOfRange,
"JTestRuns_Slice2D::test(): Histograms with different binning. The objects: " << h1->GetName() <<
" and " << h2->GetName() <<
" can not be compared." << endl);
79 }
80
81 nSlices = nSlices1;
82
83 h3 = h1->ProjectionX(h3name);
84
85 for (int i=1 ; i<=nSlices1 ; ++i){
86
88
89 const TH1* s1 = h1->ProjectionY (sliceName.c_str(),i,i);
90 const TH1* s2 = h2->ProjectionY (sliceName.c_str(),i,i);
91
92 if (!(s1->GetSumOfWeights() > 0 && s2->GetSumOfWeights() > 0)) { continue; }
93
94 const double R = s1->Integral();
95 const double T = s2->Integral();
96
97 bool a = ((T/R)*s1->GetBinContent(1) - s2->GetBinContent(1)) < 0;
98
100 double p = (
a ? 1 : 0);
101 double q = (
a ? 0 : 1);
102
103 for (int i = 2 ; i<s1->GetNbinsX() ; ++i){
104
105 const bool b = ((T/R)*s1->GetBinContent(i) - s2->GetBinContent(i)) < 0;
106
107 (b ? ++p : ++q);
108
109 if (b != a){
112 }
113 }
114
115 const double N = 1 + 2*p*q/(p+q) ;
116 const double s = sqrt( 2*p*q*(2*p*q-p-q)/(p+q)/(p+q)/(p+q-1) );
117 const double d = (
n-N)/s;
118
120
121 h3->SetBinContent(i,fabs(d));
122 }
123
125
126 const int nSlices1 = h1->GetNbinsX();
127 const int nSlices2 = h2->GetNbinsX();
128
129 if (nSlices1 != nSlices2) {
130 THROW(
JValueOutOfRange,
"JTestRuns_Slice2D::test(): Histograms with different binning. The objects: " << h1->GetName() <<
" and " << h2->GetName() <<
" can not be compared." << endl);
131 }
132
133 nSlices = nSlices1;
134
135 h3 = h1->ProjectionY(h3name);
136
137 for (int i=1 ; i<=nSlices1 ; ++i){
138
140
141 const TH1* s1 = h1->ProjectionX (sliceName.c_str(),i,i);
142 const TH1* s2 = h2->ProjectionX (sliceName.c_str(),i,i);
143
144 if (!(s1->GetSumOfWeights() > 0 && s2->GetSumOfWeights() > 0)) { continue; }
145
146 const double R = s1->Integral();
147 const double T = s2->Integral();
148
149 bool a = ((T/R)*s1->GetBinContent(1) - s2->GetBinContent(1)) < 0;
150
152 double p = (
a ? 1 : 0);
153 double q = (
a ? 0 : 1);
154
155 for (int i = 2 ; i<s1->GetNbinsX() ; ++i){
156
157 const bool b = ((T/R)*s1->GetBinContent(i) - s2->GetBinContent(i)) < 0;
158
159 (b ? ++p : ++q);
160
161 if (b != a){
164 }
165 }
166
167 const double N = 1 + 2*p*q/(p+q) ;
168 const double s = sqrt( 2*p*q*(2*p*q-p-q)/(p+q)/(p+q)/(p+q-1) );
169 const double d = (
n-N)/s;
170
172
173 h3->SetBinContent(i,fabs(d));
174 }
175 }
176
178
180
181 h3->SetTitle(title.getTitle().c_str());
183
188
189 this->push_back(r);
190 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
#define MAKE_CSTRING(A)
Make C-string.
#define MAKE_STRING(A)
Make string.
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
double failuresThreshold
threshold value to decide if test is passed.
double threshold
threshold value to decide if test is passed.
char slice
Axis to slice. x or X for x-axis, y or Y for y-axis, n or N for None.
const std::string resultType
test result type
const std::string testName
test name
Auxiliary class to handle file name, ROOT directory and object name.
Exception for accessing a value in a collection that is outside of its range.
std::string to_string(const T &value)
Convert value to string.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Structure containing the result of the test.