#ifndef __JCOMPAREHISTOGRAMS__JTESTCHI2_2D__ #define __JCOMPAREHISTOGRAMS__JTESTCHI2_2D__ #include #include #include "JCompareHistograms/JTest_t.hh" #include "JCompareHistograms/JTestChi2_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 JChi2Test() test is applied to each slice.\n * The input parameter threshold(), is used 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 produced by JChi2Test(). The output of JChi2Test() is a p-value.\n * The parameter threshold() should therefore be a real value between 0 and 1. */ class JTestChi2_2D: public JTest_t, public JTestChi2_t { public: /** * Default constructor. */ JTestChi2_2D() : JTest_t("Chi2_2D", "p-Value(chi2)"), JTestChi2_t() {} /** * Read test parameters from input. * * \param in input stream * \return input stream */ std::istream& read(std::istream& in) override{ return in >> threshold >> failuresThreshold >> slice >> options; }; /** * Applies Chi2 test for two ROOT TH2 histograms. * * \param o1 First histogram * \param o2 Second histogram */ void test(TObject* o1, TObject* o2) override{ using namespace std; using namespace JPP; if (!(dynamic_cast(o1) == NULL) && !(dynamic_cast(o2) == NULL)) { TH2D* h1 = dynamic_cast(o1); TH2D* h2 = dynamic_cast(o2); if(slice == 'x' || slice == 'X' || slice == 'y' || slice == 'Y'){ JTestResult r = JChi2TestSlice(h1, h2, threshold, failuresThreshold, testName, resultType, options, slice); results.push_back(r); } else { ERROR ("Slice option should be: x, X, y or Y, and not " + slice); } } else if (!(dynamic_cast(o1) == NULL) && !(dynamic_cast(o2) == NULL)) { ERROR("For 1D histograms call JChi2_1D: " << o1->GetName() << endl); } }; private: double threshold; //!< threshold p-value to decide if test is passed. double failuresThreshold; //!< threshold p-value to decide if test is passed. char slice; //!< axis to slice. std::string options; //!< options for the ROOT chi2 test. }; } #endif