#ifndef __JDETECTOR__JPMTSIMULATOR__ #define __JDETECTOR__JPMTSIMULATOR__ #include #include #include #include "JDetector/JPMTIdentifier.hh" #include "JDetector/JCalibration.hh" #include "JDetector/JTimeRange.hh" #include "Jeep/JStatus.hh" /** * \author mdejong */ namespace JDETECTOR {} namespace JPP { using namespace JDETECTOR; } namespace JDETECTOR { using JEEP::JStatus; /** * Data structure for single photo-electron. */ struct JPhotoElectron { /** * Default constructor. */ JPhotoElectron() : t_ns(0.0) {} /** * Constructor. * * \param __t_ns time [ns] */ JPhotoElectron(const double __t_ns) : t_ns(__t_ns) {} /** * Get end marker. * * \return latest possible photo-electron */ static inline JPhotoElectron getEndMarker() { return JPhotoElectron(std::numeric_limits::max()); } double t_ns; //!< time [ns] }; /** * Less than operator for photo-elecrons. * * \param first first photo-electron * \param second second photo-electron * \return true if first photo-electron earlier than second; else false */ inline bool operator<(const JPhotoElectron& first, const JPhotoElectron& second) { return first.t_ns < second.t_ns; } /** * Data structure for PMT analogue signal. */ struct JPMTSignal { /** * Default constructor. */ JPMTSignal() : t_ns(0.0), npe (0) {} /** * Constructor. * * \param __t_ns time [ns] * \param __npe number of photo-electrons */ JPMTSignal(const double __t_ns, const int __npe) : t_ns(__t_ns), npe (__npe) {} double t_ns; //!< time [ns] int npe; //!< number of photo-electrons }; /** * Less than operator for PMT signals. * * \param first first PMT signal * \param second second PMT signal * \return true if first PMT signal earlier than second; else false */ inline bool operator<(const JPMTSignal& first, const JPMTSignal& second) { return first.t_ns < second.t_ns; } /** * Data structure for PMT digital pulse. */ struct JPMTPulse { /** * Default constructor. */ JPMTPulse() : t_ns (0.0), tot_ns(0.0) {} /** * Constructor. * * \param __t_ns time [ns] * \param __tot_ns time-over-threshold [ns] */ JPMTPulse(const double __t_ns, const double __tot_ns) : t_ns (__t_ns), tot_ns(__tot_ns) {} double t_ns; //!< time [ns] double tot_ns; //!< time-over-threshold [ns] }; /** * Less than operator for PMT pulses. * * \param first first PMT pulse * \param second second PMT pulse * \return true if first PMT pulse earlier than second; else false */ inline bool operator<(const JPMTPulse& first, const JPMTPulse& second) { return first.t_ns < second.t_ns; } /** * Template data structure for PMT I/O. */ template class JPMTData : public std::vector { public: typedef typename std::vector::iterator iterator; typedef typename std::vector::const_iterator const_iterator; typedef typename std::vector::reverse_iterator reverse_iterator; typedef typename std::vector::const_reverse_iterator const_reverse_iterator; /** * Default constructor. */ JPMTData() : std::vector() {} /** * Sort. */ void sort() { std::sort(this->begin(), this->end()); } /** * Insert element whilst maintaining order. * * \param element element */ void insert(const JElement_t& element) { iterator i = std::lower_bound(this->begin(), this->end(), element); std::vector::insert(i, element); } }; /** * Data structure for PMT data corresponding to a detector module. */ class JModuleData : public std::vector< JPMTData > { public: /** * Default constructor. */ JModuleData() : std::vector< JPMTData >() {} /** * Reset buffers. * * \param size number of buffers */ void reset(size_t size) { this->resize(size); for (iterator i = this->begin(); i != this->end(); ++i) { i->clear(); } } }; /** * Interface for PMT simulation. * The input buffer consists of a sorted array of PMT analogue signals JDETECTOR::JPMTSignal and * the output of an array of PMT digital pulses JDETECTOR::JPMTPulse. */ class JPMTSimulator { protected: /** * Default constructor. */ JPMTSimulator() {} public: /** * Virtual destructor. */ virtual ~JPMTSimulator() {} /** * Process hits. * * \param id PMT identifier * \param calibration PMT calibration * \param status PMT status * \param input PMT signals * \param output PMT pulses */ virtual void processHits(const JPMTIdentifier& id, const JCalibration& calibration, const JStatus& status, const JPMTData& input, JPMTData& output) const = 0; }; /** * Get time range (i.e.\ earlist and latest hit time) of PMT data. * * \param input PMT data * \return time range */ inline JTimeRange getTimeRange(const JPMTData& input) { JTimeRange range(JTimeRange::DEFAULT_RANGE); for (JPMTData::const_iterator hit = input.begin(); hit != input.end(); ++hit) { range.include(hit->t_ns); } return range; } /** * Get time range (i.e.\ earlist and latest hit time) of module data. * * \param input module data * \return time range */ inline JTimeRange getTimeRange(const JModuleData& input) { JTimeRange range(JTimeRange::DEFAULT_RANGE); for (JModuleData::const_iterator frame = input.begin(); frame != input.end(); ++frame) { for (JModuleData::value_type::const_iterator hit = frame->begin(); hit != frame->end(); ++hit) { range.include(hit->t_ns); } } return range; } } #endif