#ifndef __JHISTOGRAMMAP__ #define __JHISTOGRAMMAP__ #include "JTools/JGridBounds.hh" namespace JTOOLS { /** * Template definition of histogram map. */ template class JMap_t> class JHistogramMap; /** * Template specialisation of histogram map. * This class implements the JHistogram::Fill() method. */ template class JMap_t> class JHistogramMap : public virtual JHistogram, public JMap_t { public: typedef typename JHistogram_t::argument_type argument_type; typedef typename JHistogram_t::result_type result_type; typedef JMap_t JCollection_t; typedef typename JCollection_t::key_type key_type; typedef typename JCollection_t::mapped_type mapped_type; typedef typename JCollection_t::value_type value_type; typedef typename JCollection_t::const_iterator const_iterator; typedef typename JCollection_t::const_reverse_iterator const_reverse_iterator; typedef typename JCollection_t::iterator iterator; typedef typename JCollection_t::reverse_iterator reverse_iterator; friend class JGridConfigureHelper; // helper class for configuration. using JCollection_t::insert; /** * Default constructor. */ JHistogramMap() : JCollection_t(), lowerLimitValue(0.0), upperLimitValue(0.0) {} /** * Constructor. * * \param bounds grid bounds */ JHistogramMap(const JAbstractGridBounds& bounds) : JCollection_t(), lowerLimitValue(0.0), upperLimitValue(0.0) { configure(bounds); } /** * Constructor. * * \param __begin begin of x-values * \param __end end of x-values */ template JHistogramMap(T __begin, T __end) : JCollection_t(), lowerLimitValue(0.0), upperLimitValue(0.0) { configure(__begin, __end); } /** * Configure histogram map. * * \param bounds grid bounds */ void configure(const JAbstractGridBounds& bounds) { for (unsigned int i = 0; i != bounds.getNumberOfKeys(); ++i) { const argument_type x = bounds.getKey(i); this->insert(value_type(x, mapped_type())); } } /** * Configure histogram map. * * \param __begin begin of x-values * \param __end end of x-values */ template void configure(T __begin, T __end) { for (T i = __begin; i != __end; ++i) { const argument_type x = *i; this->insert(value_type(x, mapped_type())); } } /** * Insert bin. * * \param x x-value */ void insert(const argument_type& x) { this->insert(value_type(x, mapped_type())); } /** * Fill histogram. * * \param pX pointer to key list * \param y value */ void Fill(const argument_type* pX, const result_type& y) { const argument_type x = *pX; iterator i = this->lower_bound(x); if (i == this->begin()) lowerLimitValue += y; else if (i == this->end()) upperLimitValue += y; else (--i)->second.Fill(++pX,y); } result_type lowerLimitValue; result_type upperLimitValue; }; } #endif