Protium
Math and Design Features
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
Histogram.h
Go to the documentation of this file.
1 #ifndef Protium_Histogram_h_
2 #define Protium_Histogram_h_
3 
4 #include <map>
5 
6 namespace Protium{
7 
8  namespace Containers{
9 
10 
11  template<class BinType=double>
12  class Histogram{
13 
14 
15  struct Bin{
16  BinType loweredge;
17  BinType width;
18 
19  bool operator<(const Bin& rhs) const{
20  return (this->loweredge) < (rhs.loweredge) ;
21  }
22 
23  bool operator>(const Bin& rhs) const{
24  return (this->loweredge) > (rhs.loweredge) ;
25  }
26 
27  bool operator==(const Bin& rhs) const{
28  return (this->loweredge) == (rhs.loweredge) ;
29  }
30  };
31 
32  std::map<Bin, unsigned> fContents;
33 
34  public:
36  Histogram( const BinType& lowerEdge, const BinType& upperEdge, const unsigned& nBins){
37  for(unsigned i=0; i<nBins; i++){
38  Bin tempBin;
39  tempBin.width=(upperEdge-lowerEdge)/( (double)nBins );
40  tempBin.loweredge = double(i)* (upperEdge-lowerEdge)/( (double)nBins );
41  fContents.insert(std::make_pair<Bin, unsigned>(tempBin,0) );
42  }
43  }
44 
45  unsigned GetNBins() const{
46  return fContents.size();
47  }
48 
55  void SetNewBin(const BinType& lowerEdge, const BinType& delta ){
56  Bin newBin;
57  newBin.width=delta;
58  newBin.loweredge = lowerEdge;
59  unsigned newContent =0;
60  typename std::map<Bin,unsigned>::iterator hIt = fContents.begin();
61  //move iterator to the first bin intersects with the
62  while( hIt->first < newBin ){hIt++;}
63 
64 
65  fContents[newBin] = newContent;
66  }
67 
68  BinType GetLowerEdgeByI(const int& i) const {
69  int index=0;
70  for(typename std::map<Bin, unsigned>::const_iterator it = fContents.begin(); it!=fContents.end(); ++it){
71  if(i==index++)
72  return (*it).first.loweredge;
73 
74  }
75  }
76 
77  BinType GetBinWidthByI(const int& i) const {
78  int index=0;
79  for(typename std::map<Bin, unsigned>::const_iterator it = fContents.begin(); it!=fContents.end(); ++it){
80  if(i==index++)
81  return (*it).first.width;
82 
83  }
84  }
85 
86  unsigned GetBinContentByI(const int& i) const {
87  int index=0;
88  for(typename std::map<Bin, unsigned>::const_iterator it = fContents.begin(); it!=fContents.end(); ++it){
89  if(i==index++)
90  return (*it).second;
91 
92  }
93  }
94 
95 
96  //Histogram(int nBins, std::vector<double>&binWidths, std::vector<double>& );
97 
98 
99  //BinType GetBinLowerEdgeByI(const int& i);
100  //BinType GetBinLowerEdgeByPos( const BinType& i);
101 
102  //BinType GetBinHigherEdgeByI(const int& i);
103  //BinType GetBinHigherEdgeByPos( const BinType& i);
104 
105  //BinType GetBinWidthByI(const int& i);
106  //BinType GetBinWidthByPos( const BinType& i);
107 
108  //YType GetBinQuantityByI(const int& i);
109  //YType GetBinQuantityByPos( const BinType& i);
110 
111  //void AddBin(const BinType& edge, const BinType& width);
112 
113  //void Initialize(const int& xbins, const int& ybins, const int& zbins, BinType& defaultBinType );
114 
115  //ContentType& IterateBinContent(const BinType& bin );
116 
117  //void SetBinContent(const BinType& bin, const ContentType& content);
118 
119  //void Normalize();
120  };
121 
123  }
124 }
125 
126 
127 #endif //Protium_Histogram_h_
void SetNewBin(const BinType &lowerEdge, const BinType &delta)
Definition: Histogram.h:55
unsigned GetNBins() const
Definition: Histogram.h:45
bool operator>(const Bin &rhs) const
Definition: Histogram.h:23
bool operator==(const Bin &rhs) const
Definition: Histogram.h:27
BinType GetBinWidthByI(const int &i) const
Definition: Histogram.h:77
Histogram< double > Histo1D
Definition: Histogram.h:122
unsigned GetBinContentByI(const int &i) const
Definition: Histogram.h:86
bool operator<(const Bin &rhs) const
Definition: Histogram.h:19
std::map< Bin, unsigned > fContents
Definition: Histogram.h:32
Histogram(const BinType &lowerEdge, const BinType &upperEdge, const unsigned &nBins)
Most Basic Histogram instantiation. Creates uniform size bins.
Definition: Histogram.h:36
BinType GetLowerEdgeByI(const int &i) const
Definition: Histogram.h:68