#ifndef __JTRIGGER__JMATCHL0__
#define __JTRIGGER__JMATCHL0__

#include "JTrigger/JMatch.hh"


/**
 * \file
 *
 * Match operator for consecutive hits.
 * \author mdejong
 */
namespace JTRIGGER {}
namespace JPP { using namespace JTRIGGER; }

namespace JTRIGGER {

  /** 
   * L0 match criterion. 
   *
   * The maximal time difference between trailing and leading edge of two consecutive hits
   * can be interpreted as the effective two-hit resolution of a PMT/TDC.
   *
   * Note that the hits should be time ordered.
   */
  template<class JHit_t>
  class JMatchL0 :
    public JClonable< JMatch<JHit_t>, JMatchL0<JHit_t> >
  {
  public:
    /**
     * Constructor.
     *
     * \param  Tmax_ns       maximal time difference between trailing and leading edge [ns]
     */
    JMatchL0(const double Tmax_ns) :
      Tmax_ns(Tmax_ns)
    {}
      
      
    /**
     * Match function.
     *
     * The template should provide for the following member methods:
     * <pre>
     *    double getT1() const;   // time of leading edge
     *    double getT2() const;   // time of traling edge
     * </pre>
     * 
     * \param  first         first  hit
     * \param  second        second hit
     * \return               true if time difference between trailing edge and leading edge less than specified time; else false
     */
    bool operator()(const JHit_t& first, const JHit_t& second) const
    {
      return (second.getT1() > first.getT1() &&
              second.getT1() < first.getT2() + Tmax_ns);
    }
      
    double Tmax_ns;
  };
}

#endif