#ifndef __JCOMPAREHISTOGRAMS__JTESTZERO_T__ #define __JCOMPAREHISTOGRAMS__JTESTZERO_T__ #include #include #include "TMath.h" #include "Math/Math.h" #include "Math/Error.h" #include "Math/ProbFuncMathCore.h" #include "Math/SpecFuncMathCore.h" #include "JCompareHistograms/JTest_t.hh" #include "JCompareHistograms/JResultTitle.hh" /** * \author rgruiz */ namespace JCOMPAREHISTOGRAMS { using JGIZMO::JRootObjectID; /** * Implementation of the Zeros test for histograms with expected low bin contents. */ class JTestZero_t { public: /** * Default constructor. */ JTestZero_t(){} /** * Bin-by-Bin test for 2D histograms where a very low number of entries is expected.\n * The test loops over all the bins of both histograms and performs the following operations.\n * -Calculates the probability that the observed bin content for histogram A is obtained from a Poisson of parameter 1.\n * -Compares the previous result with the threshold value given as an input parameter. The result is true if the probability is higher than the threshold.\n * -Calculates the probability that the observed bin content for histogram B is obtained from a Poisson of parameter 1.\n * -Compares the previous result with the threshold value given as an input parameter. The result is true if the probability is higher than the threshold.\n * -Compares the results from both bins: If both are true, or both are false, the test is passed. If one is true and the other is false, the test is failed.\n * At the end of the loop, a failure fraction is computed and compared to the outliersThreshold parameter. If the failure fraction is above the threshold, the test is failed.\n * * \param h1 First object * \param h2 Second object * \param outliersThreshold Fraction of incompatible bins allowed. * \param threshold Poisson p-value * \param parameterName Name of the parameter used to test the histograms * \param testName Name of the test used to compare the histograms */ JTestResult JTestZero_2D(TH2* h1, TH2* h2, double outliersThreshold, double threshold, std::string testName, std::string parameterName) { using namespace std; using namespace JPP; int nx1 = h1->GetNbinsX(); int nx2 = h2->GetNbinsX(); int ny1 = h1->GetNbinsY(); int ny2 = h2->GetNbinsY(); if(nx1 != nx2 || ny1 != ny2) ERROR("Histograms with different binning. The objects: " << h1->GetName() << " can not be compared." << endl); TH2D* h3 = (TH2D*)h1->Clone(h1->GetName()==h2->GetName() ? MAKE_CSTRING(to_string(h1->GetName())) : MAKE_CSTRING(to_string(h1->GetName()) + "_VS_" + to_string(h2->GetName()))); h3->Reset(); double failures = 0; for (int i=1 ; i GetBinContent(i,j); double n = h2 -> GetBinContent(i,j); double p1 = 1 - ROOT::Math::poisson_cdf(m,1); double p2 = 1 - ROOT::Math::poisson_cdf(n,1); if ((p1 > threshold && p2 < threshold) || (p1 < threshold && p2 > threshold)){ h3->Fill(i,j); failures+=1./(nx1*ny1); } } } bool passed; (failures > outliersThreshold ? passed = false : passed = true); JResultTitle title(testName, parameterName, passed , failures); h3->SetTitle(title.getTitle().c_str()); JTestResult r (testName, JRootObjectID(MAKE_STRING(h1->GetDirectory()->GetPath() << h1->GetName())), JRootObjectID(MAKE_STRING(h2->GetDirectory()->GetPath() << h1->GetName())), parameterName, failures, threshold, h3, passed); return r; }; }; } #endif