1 #ifndef __JCOMPAREHISTOGRAMS__JTESTRUNS_2D__
2 #define __JCOMPAREHISTOGRAMS__JTESTRUNS_2D__
15 namespace JCOMPAREHISTOGRAMS {}
16 namespace JPP {
using namespace JCOMPAREHISTOGRAMS; }
18 namespace JCOMPAREHISTOGRAMS {
52 const TH2* h1 =
dynamic_cast<const TH2*
>(o1);
53 const TH2* h2 =
dynamic_cast<const TH2*
>(o2);
55 if (h1 == NULL || h2 == NULL) {
56 THROW(JValueOutOfRange,
"JTestKolmogorov_Slice2D::test(): Could not cast given TObjects to TH2.");
61 const char*
const h3name = (h1->GetName() == h2->GetName() ?
70 const int nSlices1 = h1->GetNbinsX();
71 const int nSlices2 = h2->GetNbinsX();
73 if (nSlices1 != nSlices2) {
74 THROW(JValueOutOfRange,
"JTestRuns_Slice2D::test(): Histograms with different binning. The objects: " << h1->GetName() <<
" and " << h2->GetName() <<
" can not be compared." << endl);
79 h3 = h1->ProjectionX(h3name);
81 for (
int i=1 ;
i<=nSlices1 ; ++
i){
85 const TH1* s1 = h1->ProjectionY (sliceName.c_str(),
i,
i);
86 const TH1* s2 = h2->ProjectionY (sliceName.c_str(),
i,
i);
88 if (!(s1->GetSumOfWeights() > 0 && s2->GetSumOfWeights() > 0)) {
continue; }
90 const double R = s1->Integral();
91 const double T = s2->Integral();
93 bool a = ((T/
R)*s1->GetBinContent(1) - s2->GetBinContent(1)) < 0;
96 double p = (a ? 1 : 0);
97 double q = (a ? 0 : 1);
99 for (
int i = 2 ;
i<s1->GetNbinsX() ; ++
i){
101 const bool b = ((T/
R)*s1->GetBinContent(
i) - s2->GetBinContent(
i)) < 0;
111 const double N = 1 + 2*p*q/(p+q) ;
112 const double s = sqrt( 2*p*q*(2*p*q-p-q)/(p+q)/(p+q)/(p+q-1) );
113 const double d = (n-
N)/s;
117 h3->SetBinContent(
i,fabs(d));
122 const int nSlices1 = h1->GetNbinsX();
123 const int nSlices2 = h2->GetNbinsX();
125 if (nSlices1 != nSlices2) {
126 THROW(JValueOutOfRange,
"JTestRuns_Slice2D::test(): Histograms with different binning. The objects: " << h1->GetName() <<
" and " << h2->GetName() <<
" can not be compared." << endl);
131 h3 = h1->ProjectionY(h3name);
133 for (
int i=1 ;
i<=nSlices1 ; ++
i){
137 const TH1* s1 = h1->ProjectionX (sliceName.c_str(),
i,
i);
138 const TH1* s2 = h2->ProjectionX (sliceName.c_str(),
i,
i);
140 if (!(s1->GetSumOfWeights() > 0 && s2->GetSumOfWeights() > 0)) {
continue; }
142 const double R = s1->Integral();
143 const double T = s2->Integral();
145 bool a = ((T/
R)*s1->GetBinContent(1) - s2->GetBinContent(1)) < 0;
148 double p = (a ? 1 : 0);
149 double q = (a ? 0 : 1);
151 for (
int i = 2 ;
i<s1->GetNbinsX() ; ++
i){
153 const bool b = ((T/
R)*s1->GetBinContent(
i) - s2->GetBinContent(
i)) < 0;
163 const double N = 1 + 2*p*q/(p+q) ;
164 const double s = sqrt( 2*p*q*(2*p*q-p-q)/(p+q)/(p+q)/(p+q-1) );
165 const double d = (n-
N)/s;
169 h3->SetBinContent(
i,fabs(d));
177 h3->SetTitle(title.
getTitle().c_str());
195 std::istream&
read(std::istream&
in)
override
202 THROW(JValueOutOfRange,
"JTestRuns_Slice2D::read(): Invalid failuresThreshold value " <<
failuresThreshold);
205 if (failuresThreshold < 0.0 || failuresThreshold > 1.0) {
206 THROW(JValueOutOfRange,
"JTestRuns_Slice2D::read(): Invalid failuresThreshold value " <<
failuresThreshold);
210 THROW(JValueOutOfRange,
"JTestRuns_Slice2D::read(): Invalid slice option \'" <<
slice <<
"\'");
Interface to read input and write output for TObject tests.
std::string getTitle() const
Returns a standard string to be used as title of a graphical root object.
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
#define MAKE_CSTRING(A)
Make C-string.
Auxiliary class to handle file name, ROOT directory and object name.
#define MAKE_STRING(A)
Make string.
std::istream & read(std::istream &in) override
Read test parameters from input.
double failuresThreshold
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.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
const std::string resultType
test result type
const std::string testName
test name
then JCookie sh JDataQuality D $DETECTOR_ID R
double threshold
threshold value to decide if test is passed.
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
then JMuonMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
void test(const TObject *o1, const TObject *o2) override
Tests the statistical compatibility of two ROOT TObjects.
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 JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Implementation of the Chi2 test for 2D histograms.
std::string to_string(const T &value)
Convert value to string.
Structure containing the result of the test.
JTestRuns_Slice2D()
Default constructor.