#ifndef __JCOMPAREHISTOGRAMS__JTESTCHI2_1D__ #define __JCOMPAREHISTOGRAMS__JTESTCHI2_1D__ #include #include #include "JCompareHistograms/JTest_t.hh" #include "JCompareHistograms/JTestChi2_t.hh" /** * \author rgruiz */ namespace JCOMPAREHISTOGRAMS { /** * Implementation of the Chi2 test for 1D 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 input parameter threshold(), is used to evaluate whether the test is passed or failed.\n * The evaluation is done by comparing the threshold() value with the result produced by JChi2Test(). The output of a Chi2 test is a p-value.\n * The parameter threshold() should therefore be a real value between 0 and 1. */ class JTestChi2_1D: public JTest_t , public JTestChi2_t { public: /** * Default constructor. */ JTestChi2_1D() : JTest_t("Chi2_1D", "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 >> options; }; /** * Applies Chi2 test for two ROOT TH1 histograms. * * \param o1 First histogram * \param o2 Second histogram */ void test(TObject* o1, TObject* o2) override{ using namespace std; if (!(dynamic_cast(o1) == NULL) || !(dynamic_cast(o2) == NULL)) { ERROR("For 2D histograms call JTestChi2_2D: " << o1->GetName() << endl); } else if (!(dynamic_cast(o1) == NULL) && !(dynamic_cast(o2) == NULL)) { TH1D* h1 = dynamic_cast(o1); TH1D* h2 = dynamic_cast(o2); if (h1 -> GetNbinsX() != h2 -> GetNbinsX()) { ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl); } JTestResult r = JChi2Test(h1, h2, threshold, testName, resultType, options); results.push_back(r); } }; private: double threshold; //!< threshold p-value to decide if test is passed. std::string options; //!< options for the ROOT chi2 test. }; } #endif