#ifndef __JCOMPAREHISTOGRAMS__JTESTKOLMOGOROV_SLICE__ #define __JCOMPAREHISTOGRAMS__JTESTKOLMOGOROV_SLICE__ #include #include #include "TMath.h" #include "JCompareHistograms/JTest_t.hh" #include "JCompareHistograms/JTestKolmogorov_t.hh" /** * \author rgruiz */ namespace JCOMPAREHISTOGRAMS { /** * Implementation of the Kolmogorov 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 * This test compares two 2D histograms. If the parameter slice() equals x, X y or Y, the histograms are sliced along the corresponding axis, and the JKolmogorovTest() test is applied to each slice.\n * If slice() equals n or N, the histograms are not sliced, and JKolmogorovTest2D() is applied.\n * The input parameter threshold(), is used to evaluate whether the test is passed or failed for each slice or for the full 2D distribution.\n * The evaluation is done by comparing the threshold() value with the result produced by JKolmogorovTest() or JKolmogorovTest2D(), which is a p-value.\n * The parameter threshold() should therefore be a real value between 0 and 1. */ class JTestKolmogorovSlice: public JTest_t, public JTestKolmogorov_t { public: /** * Default constructor. */ JTestKolmogorovSlice() : JTest_t("KS_Slice", "p-Value(KS)"), JTestKolmogorov_t() {} /** * Read test parameters from input. * * \param in input stream * \return input stream */ std::istream& read(std::istream& in) override{ return in >> threshold >> slice >> failuresThreshold; }; /** * Applies Kolmogorov 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 = JKolmogorovTestSlice(h1, h2, threshold, failuresThreshold, testName, resultType, 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 JTestKolmogorov_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. x or X for x-axis, y or Y for y-axis, n or N for None. }; } #endif