#ifndef __ANTARESDAQ_PHYSICSEVENT__ #define __ANTARESDAQ_PHYSICSEVENT__ #include #include #include #include #include #include #include "antares-dataformat/DataTypes.hh" #include "antares-dataformat/Ars.hh" #include "antares-dataformat/EventPreamble.hh" /** * Template hit. */ template class ARS_Hit : public T { public: typedef T data_type; /** LCM identifier */ unsigned short lcm_id; /** ARS identifier */ unsigned char ars_id; /** * Default constructor. */ ARS_Hit() : T(), lcm_id(0), ars_id(0) {} /** * print ASCII * \param out output stream * \param object hit * \return output stream */ friend std::ostream& operator<<(std::ostream& out, const ARS_Hit& object) { using namespace std; out << setw(5) << (int) object. lcm_id << ' ' << setw(2) << (int) object. ars_id << ' '; out << static_cast(object); return out; } ClassDef(ARS_Hit, 2); }; ClassDefT2(ARS_Hit,T); ClassImpT(ARS_Hit,T); /** * SPE hit */ class SPE_Hit : public ARS_Hit { public: /** * Default constructor. */ SPE_Hit() : ARS_Hit() {} ClassDef(SPE_Hit, 2); }; /** * AWF hit */ class AWF_Hit : public ARS_Hit { public: /** * Default constructor. */ AWF_Hit() : ARS_Hit() {} ClassDef(AWF_Hit, 2); }; /** * DWF hit */ class DWF_Hit : public ARS_Hit { public: /** * Default constructor. */ DWF_Hit() : ARS_Hit() {} ClassDef(DWF_Hit, 2); }; /** * Triggered SPE hit */ class TriggeredSPE_Hit : public SPE_Hit { public: /** * Default constructor. */ TriggeredSPE_Hit() : SPE_Hit() {} ClassDef(TriggeredSPE_Hit, 2); }; /** * Physics event */ class PhysicsEvent : public EventPreamble { protected: unsigned int EventType_; unsigned int TriggerCounter_; double MinT_; double MaxT_; float MaxA_; float TotA_; std::vector TriggeredSPEHits_; std::vector SPEHits_; std::vector AWFHits_; std::vector DWFHits_; public: /** * Default constructor. */ PhysicsEvent() : EventPreamble(), EventType_(0), TriggerCounter_(0), MinT_(+std::numeric_limits::max()), MaxT_(-std::numeric_limits::max()), MaxA_(0), TotA_(0) {} /** * Virtual destructor. */ virtual ~PhysicsEvent() {} /** Identifier of processor that created this event */ const unsigned short FrameTarget() const { return frameTarget; } /** most significant word of frametime */ const unsigned int FrameTime1() const { return frameTime1; } /** least significant word of frametime */ const unsigned int FrameTime2() const { return frameTime2; } /** frame index */ const unsigned int FrameIndex() const { return frameIndex; } /** Run number */ const unsigned int RunNumber() const { return runNumber; } /** Type of PhysicsEvent */ const unsigned int EventType() const { return EventType_; } /** Trigger nr. since start of run */ const unsigned int TriggerCounter() const { return TriggerCounter_; } /** time of first hit in event */ const double MinT() const { return MinT_; } /** time of last hit in event */ const double MaxT() const { return MaxT_; } /** amplitude of largest hit in event */ const float MaxA() const { return MaxA_; } /** sum of all amplitudes */ const float TotA() const { return TotA_; } /** Triggered hits */ const std::vector& TriggeredSPEHits() const { return TriggeredSPEHits_; } /** SPE hits */ const std::vector& SPE_Hits() const { return SPEHits_; } /** Waveform hits */ const std::vector& AWF_Hits() const { return AWFHits_; } /** Dynode hits */ const std::vector& DWF_Hits() const { return DWFHits_; } /** * Template vector::iterator */ template class const_iterator : public std::vector::const_iterator { public: const_iterator() : std::vector::const_iterator() {} const_iterator(const typename std::vector::const_iterator& i) : std::vector::const_iterator(i) {} const_iterator& operator=(const typename std::vector::const_iterator& i) { (typename std::vector::const_iterator&) *this = i; return *this; } }; /** template size method for nested vector */ template size_t size() const; /** template begin const_iterator for nested vector */ template typename std::vector::const_iterator begin() const; /** template end const_iterator for nested vector */ template typename std::vector::const_iterator end() const; /** * Print ASCII. * * \param out output stream * \param object physics event * \return output stream */ friend std::ostream& operator<<(std::ostream& out, const PhysicsEvent& object) { using namespace std; out << " +-------------------------------------+ " << endl; out << " | EventType_ " << object.EventType_ << endl; out << " | RunNumber_ " << object.RunNumber() << endl; out << " | TriggerCounter_ " << object.TriggerCounter_ << endl; out << " | FrameTarget_ " << object.FrameTarget() << endl; out << " | FrameTime1_ " << object.FrameTime1() << endl; out << " | FrameTime2_ " << object.FrameTime2() << endl; out << " | FrameIndex_ " << object.FrameIndex() << endl; out << setprecision(11) << setw(14) << " | MinT_ " << object.MinT_ << endl; out << setprecision(11) << setw(14) << " | MaxT_ " << object.MaxT_ << endl; out << setprecision( 6) << setw(10) << " | MaxA_ " << object.MaxA_ << endl; out << setprecision( 6) << setw(10) << " | TotA_ " << object.TotA_ << endl; out << " +-------------------------------------+ " << endl; out << " | Triggered hits " << object.TriggeredSPEHits_.size() << endl; out << " | SPE hits " << object.SPEHits_.size() << endl; out << " | AWF hits " << object.AWFHits_.size() << endl; out << " | DWF hits " << object.DWFHits_.size() << endl; out << " +-------------------------------------+ " << endl; out << endl; return out; } ClassDef(PhysicsEvent, 2); }; /** specialisation for TriggeredSPE_Hit size */ template<> inline size_t PhysicsEvent::size() const { return TriggeredSPEHits_.size(); } /** specialisation for SPE_Hit size */ template<> inline size_t PhysicsEvent::size() const { return SPEHits_.size(); } /** specialisation for AWF_Hit size */ template<> inline size_t PhysicsEvent::size() const { return AWFHits_.size(); } /** specialisation for DWF_Hit size */ template<> inline size_t PhysicsEvent::size() const { return DWFHits_.size(); } /** specialisation for TriggeredSPE_Hit iterator begin */ template<> inline std::vector::const_iterator PhysicsEvent::begin() const { return TriggeredSPEHits_.begin(); } /** specialisation for TriggeredSPE_Hit iterator end */ template<> inline std::vector::const_iterator PhysicsEvent::end() const { return TriggeredSPEHits_.end(); } /** specialisation for SPE_Hit iterator begin */ template<> inline std::vector::const_iterator PhysicsEvent::begin() const { return SPEHits_.begin(); } /** specialisation for SPE_Hit iterator end */ template<> inline std::vector::const_iterator PhysicsEvent::end() const { return SPEHits_.end(); } /** specialisation for AWF_Hit iterator begin */ template<> inline std::vector::const_iterator PhysicsEvent::begin() const { return AWFHits_.begin(); } /** specialisation for AWF_Hit iterator end */ template<> inline std::vector::const_iterator PhysicsEvent::end() const { return AWFHits_.end(); } /** specialisation for DWF_Hit iterator begin */ template<> inline std::vector::const_iterator PhysicsEvent::begin() const { return DWFHits_.begin(); } /** specialisation for DWF_Hit iterator end */ template<> inline std::vector::const_iterator PhysicsEvent::end() const { return DWFHits_.end(); } /** * equal operator for SPE hit. * * \param first SPE hit * \param second SPE hit * \return true if first equals second; else false */ inline bool operator==(const SPE_Hit& first, const SPE_Hit& second) { return (first.lcm_id == second.lcm_id && first.ars_id == second.ars_id && first.timestamp == second.timestamp && first.tvc == second.tvc && first.avc == second.avc); } /** * not-equal operator for SPE hit. * * \param first SPE hit * \param second SPE hit * \return true if first not equals second; else false */ inline bool operator!=(const SPE_Hit& first, const SPE_Hit& second) { return (first.lcm_id != second.lcm_id || first.ars_id != second.ars_id || first.timestamp != second.timestamp || first.tvc != second.tvc || first.avc != second.avc); } /** * equal operator for physics event. * * \param first physics event * \param second physics event * \return true if first equals second; else false */ inline bool operator==(const PhysicsEvent& first, const PhysicsEvent& second) { return (first.MinT() < second.MaxT() && first.MaxT() > second.MinT()); } /** * not-equal operator for physics event. * * \param first physics event * \param second physics event * \return true if first not equals second; else false */ inline bool operator!=(const PhysicsEvent& first, const PhysicsEvent& second) { return (first.MinT() > second.MaxT() || first.MaxT() < second.MinT()); } /** * Comparator for physics event; earliest event first. * * \param first physics event * \param second physics event * \return true if first earlier than second; else false */ inline bool operator<(const PhysicsEvent& first, const PhysicsEvent& second) { return first.MinT() < second.MinT(); } /** * Specialisation of STL distance. * * \param first first position * \param second last position * \return distance */ template inline typename std::vector::difference_type distance(typename std::vector::const_iterator first, typename PhysicsEvent::const_iterator second) { return std::distance(first, (typename std::vector::const_iterator&) second); } #endif