#ifndef __JCOMPAREHISTOGRAMS__JTESTZERO__
#define __JCOMPAREHISTOGRAMS__JTESTZERO__

#include <istream>
#include <ostream>

#include <TROOT.h>
#include <TObject.h>
#include "TGraph.h"
#include "TCanvas.h"
#include "TLine.h"
#include "TMath.h"
#include "JCompareHistograms/JTest_t.hh"
#include "JCompareHistograms/JTestZero_t.hh"
#include "JTools/JQuantile.hh"
#include "JTools/JRange.hh"


/**
 * \author rgruiz
 */
namespace JCOMPAREHISTOGRAMS {

  /**
   * Implementation of a bin-by-bin compatibility test for 2D histograms with low bin contents.\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 test is run by the method JTestZero_2D(). 
   */
  class JTestZero: 
    public JTest_t,
    public JTestZero_t
  { 
  public:  

    /**
     * Default constructor.
     */
    JTestZero() :
      JTest_t("Zero", "failure_fraction"),
      JTestZero_t()
    {}
  
    /**
     * Read test parameters from input.
     *
     * \param  in            input stream
     * \return               input stream
     */
    std::istream& read(std::istream& in) override{ 
      return in >> outliersThreshold >> threshold;
    };
    
    /**
     * Bin-by-bin comparison for ROOT TH2 histograms, of compatibility with a Poisson pdf of parameter 1.
     * 
     * \param o1 First histogram
     * \param o2 Second histogram
     */
    void test(TObject* o1, TObject* o2) override{    

      using namespace std;
    
      if (!(dynamic_cast<TH2*>(o1) == NULL) && !(dynamic_cast<TH2*>(o2) == NULL)) {
	 	  
	TH2D* h1 = dynamic_cast<TH2D*>(o1);
	TH2D* h2 = dynamic_cast<TH2D*>(o2);
      
	JTestResult r = JTestZero_2D(h1, h2, outliersThreshold, threshold, testName, resultType);
	results.push_back(r);
      }
    };
      
  private:
    double outliersThreshold;                          //!< Fraction of bins allowed to fail.
    double threshold;                                  //!< threshold p-value to decide if test is passed.
  };
}
  
#endif