#ifndef __JTRIGGER__JHITTOOLKIT__ #define __JTRIGGER__JHITTOOLKIT__ #include #include "JLang/JClass.hh" #include "km3net-dataformat/online/JDAQHit.hh" #include "JTrigger/JHit.hh" #include "JTrigger/JHitR0.hh" #include "JTrigger/JCalibration.hh" /** * \file * * Tools for handling different hit types. * \author mdejong */ namespace JTRIGGER {} namespace JPP { using namespace JTRIGGER; } namespace JTRIGGER { using KM3NETDAQ::JDAQHit; /** * Get calibrated time of DAQ hit. * * \param hit DAQ hit * \param cal calibration * \return time [ns] */ inline double getTime(const JDAQHit& hit, const JCalibration& cal) { return getTime(hit.getT(), cal); } /** * Get calibrated time-over-threshold of DAQ hit. * * \param hit DAQ hit * \param cal calibration * \return time-over-threshold [ns] */ inline double getToT(const JDAQHit& hit, const JCalibration& cal) { return getToT(hit.getToT(), cal); } /** * Template definition of hit toolkit. * * The specialised class should provide implementations for * the methods and operators that are used by the trigger. */ template::is_primitive> struct JHitToolkit; /** * Template specialisation of hit toolkit for JHit class. */ template<> struct JHitToolkit { /** * Get toolkit. * * \return this hit toolkit */ const JHitToolkit& getToolkit() const { return *this; } /** * Get time of hit. * * \param hit hit * \return time of hit [ns] */ static inline double getT(const JHit& hit) { return hit.getT(); } /** * Get time-over-threshold of hit. * * \param hit hit * \return time-over-threshold of hit [ns] */ static inline double getToT(const JHit& hit) { return hit.getToT(); } /** * Construct JHit. * * \param hit hit * \return hit */ static inline JHit getJHit(const JHit& hit) { return hit; } /** * Construct hit. * * \param hit DAQ hit * \param cal calibration * \return hit */ static inline JHit getHit(const JDAQHit& hit, const JCalibration& cal) { return JHit(JTRIGGER::getTime(hit, cal), JTRIGGER::getToT(hit, cal)); } /** * Get end marker. * * \return latest possible hit */ static inline JHit getEndMarker() { return JHit(std::numeric_limits::max()); } /** * Get time difference between two hits. * * \param first first hit * \param second second hit * \return time second hit - time first hit [ns] */ static inline double getTimeDifference(const JHit& first, const JHit& second) { return getT(second) - getT(first); } /** * Compare time of two hits. * * \param first first hit * \param second second hit * \return true if second hit later; else false */ inline bool operator()(const JHit& first, const JHit& second) const { return getT(first) < getT(second); } /** * Join two hits. * * \param first first hit * \param second second hit * \return joined hit */ static inline JHit join(const JHit& first, const JHit& second) { JHit hit(first); hit.join(second); return hit; } }; /** * Template specialisation of hit toolkit for JDAQHit class. */ template<> struct JHitToolkit { /** * Get toolkit. * * \return this hit toolkit */ const JHitToolkit& getToolkit() const { return *this; } /** * Get time of hit. * * \param hit hit * \return time of hit [ns] */ static inline double getT(const JDAQHit& hit) { return hit.getT(); } /** * Get time-over-threshold of hit. * * \param hit hit * \return time-over-threshold of hit [ns] */ static inline double getToT(const JDAQHit& hit) { return hit.getToT(); } /** * Construct JHit. * * \param hit hit * \return hit */ static inline JHit getJHit(const JDAQHit& hit) { return JHit(hit.getT(), hit.getToT()); } /** * Construct hit. * * \param hit DAQ hit * \param cal calibration * \return hit */ static inline JDAQHit getHit(const JDAQHit& hit, const JCalibration& cal) { return hit; } /** * Get end marker. * * \return latest possible hit */ static inline JDAQHit getEndMarker() { return JDAQHit(0, std::numeric_limits::max(), 0); } /** * Get time difference between two hits. * * \param first first hit * \param second second hit * \return time second hit - time first hit [ns] */ static inline double getTimeDifference(const JDAQHit& first, const JDAQHit& second) { return getT(second) - getT(first); } /** * Compare time of two hits. * * \param first first hit * \param second second hit * \return true if second hit later; else false */ inline bool operator()(const JDAQHit& first, const JDAQHit& second) const { return getT(first) < getT(second); } /** * Join two hits. * * \param first first hit * \param second second hit * \return joined hit */ static inline JHit join(const JHit& first, const JHit& second) { JHit hit(first); hit.join(second); return hit; } }; /** * Template specialisation of hit toolkit for JHitR0 class. */ template<> struct JHitToolkit : public JHitToolkit { /** * Get toolkit. * * \return this hit toolkit */ const JHitToolkit& getToolkit() const { return *this; } /** * Construct hit. * * \param hit DAQ hit * \param cal calibration * \return hit */ static inline JHitR0 getHit(const JDAQHit& hit, const JCalibration& cal) { return JHitR0(hit.getPMT(), JHitToolkit::getHit(hit, cal)); } /** * Get end marker. * * \return latest possible hit */ static inline JHitR0 getEndMarker() { return JHitR0(0, JHitToolkit::getEndMarker()); } /** * Join two hits. * * \param first first hit * \param second second hit * \return joined hit */ static inline JHitR0 join(const JHitR0& first, const JHitR0& second) { JHitR0 hit(first); hit.join(second); return hit; } }; /** * Template specialisation of hit toolkit for any primitive data type. */ template struct JHitToolkit { /** * Get toolkit. * * \return this hit toolkit */ const JHitToolkit& getToolkit() const { return *this; } /** * Get time of hit. * * \param hit hit * \return time of hit [ns] */ static inline double getT(const JHit_t hit) { return hit; } /** * Get time-over-threshold of hit. * * \param hit hit * \return 0 */ static inline double getToT(const JHit_t& hit) { return 0.0; } /** * Construct JHit. * * \param hit hit * \return hit */ static inline JHit getJHit(const JHit_t hit) { return JHit(getT(hit), getToT(hit)); } /** * Construct hit. * * \param hit DAQ hit * \param cal calibration * \return hit */ static inline JHit_t getHit(const JDAQHit& hit, const JCalibration& cal) { return getTime(hit, cal); } /** * Get end marker. * * \return latest possible hit */ static inline JHit_t getEndMarker() { return std::numeric_limits::max(); } /** * Get time difference between two hits. * * \param first first hit * \param second second hit * \return time second hit - time first hit [ns] */ static inline JHit_t getTimeDifference(const JHit_t first, const JHit_t second) { return second - first; } /** * Compare time of two hits. * * \param first first value [ns] * \param second second value [ns] * \return true if second hit later; else false */ inline bool operator()(const JHit_t first, const JHit_t second) const { return first < second; } /** * Join two hits. * * Note that this method returns the first hit as-is. * * \param first first hit * \param second second hit * \return joined hit */ static inline JHit_t join(const JHit_t& first, const JHit_t& second) { return first; } }; } #endif