1 #ifndef __JTESTCHI2_T__
2 #define __JTESTCHI2_T__
44 if(h1 -> GetNbinsX() != h2 -> GetNbinsX())
45 ERROR(
"Histograms with different bining. The objects: " << h1 -> GetName() <<
" can not be compared." << endl);
47 double chi2 = h1 -> Chi2Test (h2 , options.c_str());
49 double M = h1->Integral();
50 double N = h2->Integral();
52 TH2D* h3 = (TH2D*)h1->Clone(h1->GetName()==h2->GetName() ?
58 for (
int i=1 ; i < h1->GetNbinsX() ; ++i){
60 double m = h1->GetBinContent(i);
61 double n = h2->GetBinContent(i);
64 double c = (
M*n -
N*m)/sqrt((n+m)*(
N*
M));
65 h3->SetBinContent(i,c);
71 if (options.find(
"CHI2") != std::string::npos) {
72 (chi2 > threshold ? passed =
false : passed =
true);
74 (chi2 < threshold ? passed =
false : passed =
true);
77 JResultTitle title(testName, parameterName, passed , chi2);
79 h3->SetTitle(title.
getTitle().c_str());
82 string (h1->GetDirectory()->GetPath()).append(h1->GetName()),
83 string (h2->GetDirectory()->GetPath()).append(h2->GetName()),
84 h1->GetDirectory()->GetFile()->GetName(),
85 h2->GetDirectory()->GetFile()->GetName(),
86 parameterName, chi2, threshold, h3, passed);
120 if(slice ==
'x' || slice ==
'X'){
122 int nSlices1 = h1->GetNbinsX();
123 int nSlices2 = h2->GetNbinsX();
125 TH1* h3 = h1->ProjectionX(h1->GetName()==h2->GetName() ?
129 if(nSlices1 != nSlices2)
130 ERROR(
"Histograms with different binning. The objects: " << h1->GetName() <<
" and " << h2->GetName() <<
" can not be compared." << endl);
132 for (
int i=1 ; i<=nSlices1 ; ++i){
136 TH1D* s1 = h1->ProjectionY (sliceName.c_str(),i,i);
137 TH1D* s2 = h2->ProjectionY (sliceName.c_str(),i,i);
139 double chi2 = s1 -> Chi2Test (s2 , options.c_str());
143 if (options.find(
"CHI2") != std::string::npos) {
144 (chi2 > threshold ? passed =
false : passed =
true);
146 (chi2 < threshold ? passed =
false : passed =
true);
149 if (!passed) nFailures++;
151 h3->SetBinContent(i,chi2);
157 (nFailures/nSlices1 > failuresThreshold ? passed =
false : passed =
true);
159 JResultTitle title(testName, parameterName, passed , nFailures);
161 h3->SetTitle(title.
getTitle().c_str());
164 string (h1->GetDirectory()->GetPath()).append(h1->GetName()),
165 string (h2->GetDirectory()->GetPath()).append(h2->GetName()),
166 h1->GetDirectory()->GetFile()->GetName(),
167 h2->GetDirectory()->GetFile()->GetName(),
168 parameterName, nFailures, failuresThreshold, h3, passed);
170 }
else if (slice ==
'y' || slice ==
'Y'){
172 int nSlices1 = h1->GetNbinsY();
173 int nSlices2 = h2->GetNbinsY();
175 TH1* h3 = h1->ProjectionY(h1->GetName()==h2->GetName() ?
179 if(nSlices1 != nSlices2)
180 ERROR(
"Histograms with different binning. The objects: " << h1->GetName() <<
" can not be compared." << endl);
182 for (
int i=1 ; i<=nSlices1 ; ++i){
186 TH1D* s1 = h1->ProjectionX (sliceName.c_str(),i,i);
187 TH1D* s2 = h2->ProjectionX (sliceName.c_str(),i,i);
189 double chi2 = s1 -> Chi2Test (s2 , options.c_str());
193 if (options.find(
"CHI2") != std::string::npos) {
194 (chi2 > threshold ? passed =
false : passed =
true);
196 (chi2 < threshold ? passed =
false : passed =
true);
199 if (!passed) nFailures++;
201 h3->SetBinContent(i,chi2);
206 (nFailures/nSlices1 > failuresThreshold ? passed =
false : passed =
true);
208 JResultTitle title(testName, parameterName, passed , nFailures);
210 h3->SetTitle(title.
getTitle().c_str());
213 string (h1->GetDirectory()->GetPath()).append(h1->GetName()),
214 string (h2->GetDirectory()->GetPath()).append(h2->GetName()),
215 h1->GetDirectory()->GetFile()->GetName(),
216 h2->GetDirectory()->GetFile()->GetName(),
217 parameterName, nFailures, failuresThreshold, h3, passed);
245 int nx1 = h1->GetNbinsX();
246 int nx2 = h2->GetNbinsX();
247 int ny1 = h1->GetNbinsY();
248 int ny2 = h2->GetNbinsY();
250 double M = h1->Integral();
251 double N = h2->Integral();
253 if(nx1 != nx2 || ny1 != ny2 ||
M == 0 ||
N == 0)
254 ERROR(
"Histograms with different binning. The objects: " << h1->GetName() <<
" can not be compared." << endl);
256 TH2D* h3 = (TH2D*)h1->Clone(h1->GetName()==h2->GetName() ?
264 for (
int i=1 ; i<nx1 ; ++i){
265 for (
int j=1 ;
j<ny1 ; ++
j){
267 double m = h1 -> GetBinContent(i,
j);
268 double n = h2 -> GetBinContent(i,
j);
269 double chi2 = (n-m*
N/
M)/sqrt(m*
N/
M);
270 (fabs(chi2) > chi2Threshold ? outliers+=1./(nx1*ny1) : outliers+=0 );
271 h3->SetBinContent(i,
j,chi2);
277 (outliers > outliersThreshold ? passed =
false : passed =
true);
279 JResultTitle title(testName, parameterName , passed , 100*outliers);
281 h3->SetTitle(title.
getTitle().c_str());
284 string (h1->GetDirectory()->GetPath()).append(h1->GetName()),
285 string (h2->GetDirectory()->GetPath()).append(h2->GetName()),
286 h1->GetDirectory()->GetFile()->GetName(),
287 h2->GetDirectory()->GetFile()->GetName(),
288 parameterName, 100*outliers, 100*outliersThreshold, h3, passed);
JTestChi2_t()
Default constructor.
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
#define MAKE_CSTRING(A)
Make C-string.
then for HISTOGRAM in h0 h1
Structure containing the result of the test.
#define MAKE_STRING(A)
Make string.
then print u2 $script< option > print u2 Possible options
std::string getTitle()
Returns a standard string to be used as title of a graphical root object.
JTestResult JChi2TestBin_2D(TH2 *h1, TH2 *h2, double outliersThreshold, double chi2Threshold, std::string testName, std::string parameterName)
Bin-by-Bin Chi2 comparison of 2D histograms.
alias put_queue eval echo n
std::string to_string(const T &value)
Convert value to string.
Implementation of the different Chi2-related tests.
JTestResult JChi2TestSlice(TH2 *h1, TH2 *h2, double threshold, double failuresThreshold, std::string testName, std::string parameterName, std::string options, char slice)
Chi2 test for sliced 2D histograms.
then usage $script[input file[working directory[option]]] nWhere option can be N
JTestResult JChi2Test(TH1 *h1, TH1 *h2, double threshold, std::string testName, std::string parameterName, std::string options)
Chi2 test for 1D histograms.