#ifndef __JTRIGGER__JHIT__ #define __JTRIGGER__JHIT__ #include "JTrigger/JGetRiseTime.hh" /** * \file * * Basic data structure for time and time over threshold information of hit. * \author mdejong */ namespace JTRIGGER {} namespace JPP { using namespace JTRIGGER; } namespace JTRIGGER { /** * %Hit data structure. */ class JHit { public: /** * Default constructor. */ JHit() : t(0.0), tot(0.0) {} /** * Constructor. * * \param t_ns calibrated time of hit [ns] */ JHit(const double t_ns) : t(t_ns), tot(0.0) {} /** * Constructor. * * \param t_ns calibrated time of hit [ns] * \param tot_ns time over threshold of hit [ns] */ JHit(const double t_ns, const double tot_ns) : t(t_ns), tot(tot_ns) {} /** * Get combined hit. * * Note that: * - leading edge of this hit is set to the earliest leading edge of the all hits; * - trailing edge of this hit is set to the latest trailing edge of the all hits; * * It is assumed that the template class has the following methods: *
     *      %getT();
     *      %getToT();
     * 
* which should return the time and time over threshold, respectively. * * \param __begin begin of hits * \param __end end of hits */ template JHit(T __begin, T __end) : t(0.0), tot(0.0) { if (__begin != __end) { double t1 = __begin->getT1(); double t2 = __begin->getT2(); for (T i = __begin; ++i != __end; ) { if (t1 > i->getT1()) { t1 = i->getT1(); } if (t2 < i->getT2()) { t2 = i->getT2(); } } this->t = t1; this->tot = t2 - t1; } } /** * Get hit. * * \return hit */ const JHit& getHit() const { return static_cast(*this); } /** * Get slewing option. * * \return slewing option */ static bool getSlewing() { return get_slewing(); } /** * Set slewing option. * * \param slewing slewing option */ static void setSlewing(const bool slewing) { get_slewing() = slewing; } /** * Type conversion. * * \return time [ns] */ inline operator double() const { return t; } /** * Get calibrated time of hit. * * \return time [ns] */ inline double getT() const { if (!getSlewing()) return t; else return t - getRiseTime(tot); } /** * Get calibrated time over threshold of hit. * * \return time over threshold [ns] */ inline double getToT() const { return tot; } /** * Get leading edge of hit. * * Note that no slewing correction is applied. * * \return time [ns] */ inline double getT1() const { return t; } /** * Get trailing edge of hit. * * Note that no slewing correction is applied. * * \return time [ns] */ inline double getT2() const { return t + tot; } /** * Join hit. * * Note that: * - leading edge of this hit is maintained; * - time over threshold of this hit is set to the difference between the trailing edge of given hit and leading edge of this hit; * * \param hit hit */ void join(const JHit& hit) { this->tot = hit.getT2() - this->getT1(); } protected: double t; //!< time of leading edge [ns] double tot; //!< time-over-threshold [ns] /** * Get reference to slewing parameter. * * \return reference to slewing parameter */ static bool& get_slewing() { static bool slewing = true; return slewing; } }; /** * Less than operator for hits. * * The less than operator is applied to the time of the hits. * * \param first first hit * \param second second hit * \result true if first hit earlier; else false */ inline bool operator<(const JHit& first, const JHit& second) { return first.getT() < second.getT(); } /** * Less than operator for hits. * * The less than operator is applied to the time of the hits. * * \param hit hit * \param t1 time [ns] * \result true if hit earlier than t; else false */ inline bool operator<(const JHit& hit, const double t1) { return hit.getT() < t1; } /** * Equal operator for hits. * * The equal operator is applied to the time of the hits. * * \param first hit * \param second hit * \result true if first hit time equal to second hit time; else false */ inline bool operator==(const JHit& first, const JHit& second) { return first.getT() == second.getT(); } /** * Get hit count. * * The hit refers to a data structure which should have the following member method: * - int %getN(); * * \param hit hit * \return count */ template inline int getCount(const T& hit) { return hit.getN(); } /** * Get hit count. * * The hit iterator refers to a data structure which should have the following member method: * - int %getN(); * * \param __begin begin of data * \param __end end of data * \return count */ template inline int getCount(T __begin, T __end) { int count = 0; for (T hit = __begin; hit !=__end; ++hit) { count += getCount(*hit); } return count; } } #endif