#ifndef __JTRIGGER__JHITR1__ #define __JTRIGGER__JHITR1__ #include "km3net-dataformat/online/JDAQModuleIdentifier.hh" #include "JGeometry3D/JPosition3D.hh" #include "JTrigger/JHit.hh" #include "JTrigger/JHitL0.hh" #include "JTrigger/JHitL1.hh" #include "km3net-dataformat/online/JDAQPMTIdentifier.hh" /** * \file * * Reduced data structure for L1 hit. * \author mdejong */ namespace JTRIGGER {} namespace JPP { using namespace JTRIGGER; } namespace JTRIGGER { using KM3NETDAQ::JDAQModuleIdentifier; using KM3NETDAQ::JDAQPMTIdentifier; using JGEOMETRY3D::JPosition3D; /** * Reduced data structure for L1 hit. */ class JHitR1 : public JDAQModuleIdentifier, public JPosition3D, public JHit { public: /** * Default constructor. */ JHitR1() : JDAQModuleIdentifier(), JPosition3D (), JHit(), __n (0), __w (0.0) {} /** * Constructor. * * \param id module identifier * \param pos position */ JHitR1(const JDAQModuleIdentifier& id, const JPosition3D& pos) : JDAQModuleIdentifier(id), JPosition3D (pos), JHit(), __n (0), __w (0.0) {} /** * Constructor. * * \param id module identifier * \param pos position * \param hit hit * \param weight weight */ JHitR1(const JDAQModuleIdentifier& id, const JPosition3D& pos, const JHit& hit, const double weight = 1.0) : JDAQModuleIdentifier(id), JPosition3D (pos), JHit(hit), __n (1), __w (weight) {} /** * Constructor. * * \param hit hit * \param weight weight */ JHitR1(const JHitL0& hit, const double weight = 1.0) : JDAQModuleIdentifier(hit.getModuleIdentifier()), JPosition3D (hit.getPosition()), JHit (hit.getHit()), __n (1), __w (weight) {} /** * Constructor. * * \param hit hit */ JHitR1(const JHitL1& hit) : JDAQModuleIdentifier(hit.getModuleIdentifier()), JPosition3D (hit.getPosition()), JHit(hit.getT(), hit.getToT()), __n (hit.size()), __w (hit.getW()) {} /** * Set hit. * * Note that: * - JHitR1::count is set to one; * - JHitR1::weight is set to given weight; * * \param hit hit * \param weight weight */ void set(const JHit& hit, const double weight = 1.0) { static_cast(*this) = hit; this->__n = 1; this->__w = weight; } /** * Add hit. * * Note that: * - time of this hit is set to the earliest leading edge of the two hits; * - time over threshold is set to the difference between the latest trailing and earliest leading edge of two hits; * - JHitR1::count is incremented by one; * - JHitR1::weight is incremented by given weight; * * \param hit hit * \param weight weight * \return this hit */ JHitR1& add(const JHit& hit, const double weight = 1.0) { double t1 = this->t; double t2 = this->t + this->tot; if (t1 > hit.getT()) { t1 = hit.getT(); } if (t2 < hit.getT() + hit.getToT()) { t2 = hit.getT() + hit.getToT(); } this->t = t1; this->tot = t2 - t1; this->__n += 1; this->__w += weight; return static_cast(*this); } /** * Get PMT identifier. * Note that the PMT address is set to -1. * * \return PMT identifier */ JDAQPMTIdentifier getPMTIdentifier() const { return JDAQPMTIdentifier(this->getModuleIdentifier(), -1); } /** * Get count. * * \return count */ inline int getN() const { return __n; } /** * Get weight. * * \return weight */ inline double getW() const { return __w; } /** * Auxiliary data structure for sorting of hits. */ static const struct compare { /** * Compare hits by module identifier and time. * * \param first first hit * \param second second hit * \return true if first before second; else false */ bool operator()(const JHitR1& first, const JHitR1& second) const { if (first.getModuleID() == second.getModuleID()) return first.getT() < second.getT(); else return first.getModuleID() < second.getModuleID(); } } compare; protected: int __n; double __w; }; } #endif