Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
JHistogramMap.hh
Go to the documentation of this file.
1 #ifndef __JTOOLS__JHISTOGRAMMAP__
2 #define __JTOOLS__JHISTOGRAMMAP__
3 
4 #include "JLang/JClass.hh"
5 #include "JTools/JHistogram.hh"
6 #include "JTools/JDistance.hh"
7 
8 
9 /**
10  * \author mdejong
11  */
12 
13 namespace JTOOLS {}
14 namespace JPP { using namespace JTOOLS; }
15 
16 namespace JTOOLS {
17 
18 
19  /**
20  * Histogram map.
21  *
22  * This class implements the JHistogram interface.
23  */
24  template<class JAbscissa_t,
25  class JContents_t,
26  template<class, class, class> class JMap_t,
27  class JDistance_t = JDistance<JAbscissa_t> >
28  class JHistogramMap :
29  public JMap_t<JAbscissa_t, JContents_t, JDistance_t>,
30  public JHistogram<JAbscissa_t, typename JContents_t::contents_type>
31  {
32  public:
33 
34  typedef JMap_t<JAbscissa_t, JContents_t, JDistance_t> collection_type;
36 
37  typedef typename collection_type::abscissa_type abscissa_type;
38  typedef typename collection_type::ordinate_type ordinate_type;
39  typedef typename collection_type::value_type value_type;
40 
41  typedef typename collection_type::const_iterator const_iterator;
42  typedef typename collection_type::const_reverse_iterator const_reverse_iterator;
43  typedef typename collection_type::iterator iterator;
44  typedef typename collection_type::reverse_iterator reverse_iterator;
45 
46  //typedef typename histogram_type::abscissa_type abscissa_type;
48 
49 
50  /**
51  * Default constructor.
52  */
54  {}
55 
56 
57  /**
58  * Fill histogram.
59  *
60  * \param pX pointer to abscissa values
61  * \param w weight
62  */
63  virtual void evaluate(const abscissa_type* pX,
65  {
66  const abscissa_type x = *pX;
67 
68  iterator p = this->lower_bound(x);
69 
70  this->integral += w;
71 
72  if (p == this->begin())
73  this->underflow += w;
74  else if (p == this->end())
75  this->overflow += w;
76  else
77  (--p)->getY().evaluate(++pX, w);
78  }
79 
80 
81  /**
82  * Scale contents.
83  *
84  * \param factor multiplication factor
85  * \return this histogram
86  */
88  {
89  collection_type::mul(factor);
90  histogram_type ::mul(factor);
91 
92  return *this;
93  }
94 
95 
96  /**
97  * Scale contents.
98  *
99  * \param factor division factor
100  * \return this histogram
101  */
103  {
104  collection_type::div(factor);
105  histogram_type ::div(factor);
106 
107  return *this;
108  }
109 
110 
111  /**
112  * Read histogram map from input.
113  *
114  * \param in reader
115  * \param object histogram map
116  * \return reader
117  */
118  friend inline JReader& operator>>(JReader& in, JHistogramMap& object)
119  {
120  in >> static_cast<histogram_type&> (object);
121  in >> static_cast<collection_type&>(object);
122 
123  return in;
124  }
125 
126 
127  /**
128  * Write histogram map to output.
129  *
130  * \param out writer
131  * \param object histogram map
132  * \return writer
133  */
134  friend inline JWriter& operator<<(JWriter& out, const JHistogramMap& object)
135  {
136  out << static_cast<const histogram_type&> (object);
137  out << static_cast<const collection_type&>(object);
138 
139  return out;
140  }
141  };
142 }
143 
144 #endif
Interface for binary input.
Interface for binary output.
virtual void evaluate(const abscissa_type *pX, typename JLANG::JClass< contents_type >::argument_type w)
Fill histogram.
collection_type::reverse_iterator reverse_iterator
collection_type::iterator iterator
JMap_t< JAbscissa_t, JContents_t, JDistance_t > collection_type
JHistogram< JAbscissa_t, typename JContents_t::contents_type > histogram_type
collection_type::abscissa_type abscissa_type
friend JWriter & operator<<(JWriter &out, const JHistogramMap &object)
Write histogram map to output.
JHistogramMap()
Default constructor.
histogram_type::contents_type contents_type
collection_type::const_reverse_iterator const_reverse_iterator
JHistogramMap & div(typename JLANG::JClass< contents_type >::argument_type factor)
Scale contents.
friend JReader & operator>>(JReader &in, JHistogramMap &object)
Read histogram map from input.
collection_type::value_type value_type
collection_type::const_iterator const_iterator
collection_type::ordinate_type ordinate_type
JHistogramMap & mul(typename JLANG::JClass< contents_type >::argument_type factor)
Scale contents.
Template definition of histogram object interface.
Definition: JHistogram.hh:28
JContents_t contents_type
Definition: JHistogram.hh:43
JHistogram & div(double value)
Scale histogram.
Definition: JHistogram.hh:128
JHistogram & mul(const double value)
Scale histogram.
Definition: JHistogram.hh:112
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
data_type w[N+1][M+1]
Definition: JPolint.hh:867
JArgument< T >::argument_type argument_type
Definition: JClass.hh:82
Template class for distance evaluation.
Definition: JDistance.hh:24