#ifndef __JTRIGGER__JHITL1__ #define __JTRIGGER__JHITL1__ #include #include #include "km3net-dataformat/online/JDAQModuleIdentifier.hh" #include "JTrigger/JHit.hh" #include "JTrigger/JHitL0.hh" #include "JGeometry3D/JRotation3D.hh" #include "JGeometry3D/JVector3D.hh" /** * \file * * Basic data structure for L1 hit. * \author mdejong */ namespace JTRIGGER {} namespace JPP { using namespace JTRIGGER; } namespace JTRIGGER { using KM3NETDAQ::JDAQModuleIdentifier; using JGEOMETRY3D::JRotation3D; using JGEOMETRY3D::JPosition3D; using JGEOMETRY3D::JVector3D; /** * Data structure for L1 hit. */ class JHitL1 : public JDAQModuleIdentifier, public std::vector { public: /** * Default constructor. */ JHitL1() : JDAQModuleIdentifier(), std::vector() {} /** * Constructor. * * \param id module identifier */ JHitL1(const JDAQModuleIdentifier& id) : JDAQModuleIdentifier(id), std::vector() {} /** * Constructor. * * \param hit hit */ JHitL1(const JHitL0& hit) : JDAQModuleIdentifier(hit.getModuleIdentifier()), std::vector(1, hit) {} /** * Constructor. * * \param id module identifier * \param __begin begin of L0 hits * \param __end end of L0 hits */ template JHitL1(const JDAQModuleIdentifier& id, T __begin, T __end) : JDAQModuleIdentifier(id) { for (T i = __begin; i != __end; ++i) { this->push_back(*i); } this->sort(); } /** * Sort L0 hits. * Following the default sort operation, the time slewing implemented in method getT() is applicaple. * * \return this hit */ const JHitL1& sort() { std::sort(this->begin(), this->end(), std::less()); return *this; } /** * Type conversion operator. * * \return position */ operator const JPosition3D& () const { return this->getPosition(); } /** * Get position. * * \return position */ const JPosition3D& getPosition() const { return this->begin()->getPosition(); } /** * Get x position. * The x position is taken from the first L0 hit. * * \return x position [m] */ inline double getX() const { return this->begin()->getX(); } /** * Get y position. * The y position is taken from the first L0 hit. * * \return y position [m] */ inline double getY() const { return this->begin()->getY(); } /** * Get z position. * The z position is taken from the first L0 hit. * * \return z position [m] */ inline double getZ() const { return this->begin()->getZ(); } /** * Get time of hit i. * Note that the time is corrected for the average time slewing. * * \param i index * \return time [ns] */ inline double getT(const unsigned int i) const { static const double t0 = 1.29; // [ns] return at(i).getT() - t0; } /** * Get time. * The time is taken from the first L0 hit corrected for time slewing. * * \return time [ns] */ inline double getT() const { static std::vector t0; if (t0.empty()) { t0.push_back(+0.00); t0.push_back(+0.39); t0.push_back(+0.21); t0.push_back(-0.59); t0.push_back(-1.15); t0.push_back(-1.59); t0.push_back(-1.97); t0.push_back(-2.30); t0.push_back(-2.56); t0.push_back(-2.89); t0.push_back(-3.12); t0.push_back(-3.24); t0.push_back(-3.56); t0.push_back(-3.69); t0.push_back(-4.00); t0.push_back(-4.10); t0.push_back(-4.16); t0.push_back(-4.49); t0.push_back(-4.71); t0.push_back(-4.77); t0.push_back(-4.81); t0.push_back(-4.87); t0.push_back(-4.88); t0.push_back(-4.83); t0.push_back(-5.21); t0.push_back(-5.06); t0.push_back(-5.27); t0.push_back(-5.18); t0.push_back(-5.24); t0.push_back(-5.79); t0.push_back(-6.78); t0.push_back(-6.24); } if (this->size() >= t0.size()) return this->begin()->getT() - t0.back(); else return this->begin()->getT() - t0[this->size()]; } /** * Get overall time over threshold. * * \return time over threshold [ns] */ inline double getToT() const { return JHit(this->begin(), this->end()).getToT(); } /** * Get count. * * \return count */ inline int getN() const { return this->size(); } /** * Get weight.\n * The weight is equal to the number of L0 hits. * * \return weight */ inline double getW() const { return this->size(); } /** * Add position. * * \param pos position * \return this hit */ JHitL1& add(const JVector3D& pos) { for (iterator i = this->begin(); i != this->end(); ++i) { i->add(pos); } return *this; } /** * Subtract position. * * \param pos position * \return this hit */ JHitL1& sub(const JVector3D& pos) { for (iterator i = this->begin(); i != this->end(); ++i) { i->sub(pos); } return *this; } /** * Rotate hit. * * \param R rotation matrix * \return this hit */ JHitL1& rotate(const JRotation3D& R) { for (iterator i = this->begin(); i != this->end(); ++i) { i->rotate(R); } return *this; } /** * Rotate back hit. * * \param R rotation matrix * \return this hit */ JHitL1& rotate_back(const JRotation3D& R) { for (iterator i = this->begin(); i != this->end(); ++i) { i->rotate_back(R); } return *this; } /** * Transform hit. * * \param R rotation matrix * \param pos position of origin (after rotation) */ void transform(const JRotation3D& R, const JVector3D& pos) { for (iterator i = this->begin(); i != this->end(); ++i) { i->transform(R, pos); } } /** * Transform back hit. * * \param R rotation matrix * \param pos position of origin (before rotation) */ void transform_back(const JRotation3D& R, const JVector3D& pos) { for (iterator i = this->begin(); i != this->end(); ++i) { i->transform_back(R, pos); } } /** * 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 JHitL1& first, const JHitL1& second) const { if (first.getModuleID() == second.getModuleID()) return first.getT() < second.getT(); else return first.getModuleID() < second.getModuleID(); } } compare; }; } #endif