#ifndef __JCOMPAREHISTOGRAMS__JTESTRUNS_2D__ #define __JCOMPAREHISTOGRAMS__JTESTRUNS_2D__ #include #include #include "JLang/JException.hh" #include "JCompareHistograms/JTest_t.hh" #include "JCompareHistograms/JTestRuns_t.hh" /** * \author rgruiz */ namespace JCOMPAREHISTOGRAMS { /** * Implementation of the Chi2 test for 2D histograms.\n * This class is derived from the abstract class JTest_t(). For a general description of the implementation of this and other tests derived from JTest_t(), see its documentation.\n * The parameter slice() can have the values x, X, y or Y. The histograms are sliced along the corresponding axis, and the JRunsTest() test is applied to each slice.\n * This test uses the input parameter threshold() to evaluate whether the test is passed or failed for each slice.\n * The evaluation is done by comparing the threshold value with the result of the JRunsTest() test.\n * The results for each slice are stored in the results buffer (see JTest_t().) */ class JTestRuns_2D: public JTest_t, public JTestRuns_t { public: JTestRuns_2D() : JTest_t("Runs_2D", "#sigma"), JTestRuns_t() {} /** * Read test parameters from input. * * \param in input stream * \return input stream */ std::istream& read(std::istream& in) override{ in >> threshold >> slice; if (!(slice == 'x' || slice == 'X' || slice == 'y' || slice == 'Y')) { THROW(JLANG::JValueOutOfRange, "JTestRuns_2D::read(): Invalid slice option \'" << slice << "\'"); } return in; }; /** * Tests the statistical compatibility of two ROOT TObjects * * \param o1 First object * \param o2 Second object */ void test(TObject* o1, TObject* o2) override{ using namespace std; using namespace JPP; if (!(slice == 'x' || slice == 'X' || slice == 'y' || slice == 'Y')) { THROW(JLANG::JValueOutOfRange, "JTestRuns_2D::test(): Invalid slice option \'" << slice << "\'"); } if (!(dynamic_cast(o1) == NULL) && !(dynamic_cast(o2) == NULL)) { TH2D* h1 = dynamic_cast(o1); TH2D* h2 = dynamic_cast(o2); JTestResult r = JRunsTestSlice(h1, h2, threshold, failuresThreshold, testName, resultType, slice); results.push_back(r); } else if (!(dynamic_cast(o1) == NULL) && !(dynamic_cast(o2) == NULL)) { THROW(JLANG::JValueOutOfRange, "JTestRuns_2D::test(): For 1D histograms call JChi2_1D: " << o1->GetName() << endl); } }; private: double threshold; //!< threshold value to decide if test is passed. 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. }; } #endif