MINT2
UniformBinning.cpp
Go to the documentation of this file.
1 #include "Mint/UniformBinning.h"
2 
3 
5 UniformBinning::UniformBinning(HyperCuboid limits, int nLocalBins) :
6  _limits (limits),
7  _nLocalBins(_limits.getDimension(), nLocalBins)
8 {
9  setBinningType("UniformBinning");
11 
12  WELCOME_LOG << "Hello from the UniformBinning() Constructor";
13 }
14 
15 
16 UniformBinning::UniformBinning(HyperCuboid limits, std::vector<int> nLocalBins) :
17  _limits (limits),
18  _nLocalBins(nLocalBins)
19 {
20  setBinningType("UniformBinning");
22 
23  WELCOME_LOG << "Hello from the UniformBinning() Constructor";
24 }
25 
26 
27 
28 int UniformBinning::getNumLocalBins(int dimension) const{
29  return _nLocalBins.at(dimension);
30 }
31 
33  int nBins = 1;
34  for (int i = 0; i < getDimension(); i++){
35  nBins *= getNumLocalBins(i);
36  }
37  return nBins;
38 }
39 
40 
41 int UniformBinning::getGlobalBinNumber( std::vector<int> localBinNumbers ) const{
42 
43  int dimension = getDimension();
44 
45  int multiplier = 1;
46  int binNumber = 0;
47 
48  for (int i = 0; i < dimension; i++){
49  binNumber += localBinNumbers.at(i)*multiplier;
50  multiplier *= getNumLocalBins(i);
51  }
52 
53  return binNumber;
54 
55 }
56 
57 std::vector<int> UniformBinning::getLocalBinNumbers( int globalBinNumber ) const{
58 
59  int nBins = getNumBins();
60 
61  if ( globalBinNumber >= nBins || globalBinNumber < 0 ){
62  ERROR_LOG << "UniformBinning::getLocalBinNumbers - The global bin number you have given is out of range = " << globalBinNumber << std::endl;
63  }
64 
65  int dimension = getDimension();
66 
67  std::vector<int> localBinNums(dimension, -1.0);
68 
69  int multiplier = nBins;
70 
71  for (int i = dimension - 1; i >= 0; i--){
72 
73  multiplier = multiplier/getNumLocalBins(i);
74 
75  int localBinNum = floor(double(globalBinNumber)/double(multiplier));
76 
77  globalBinNumber -= multiplier*localBinNum;
78 
79  localBinNums.at(i) = localBinNum;
80  }
81 
82  return localBinNums;
83 
84 }
85 
86 double UniformBinning::getLowBinEdgeLocal(int dim, int localBinNum) const{
87 
88  double low = _limits.getLowCorner ().at(dim);
89  double high = _limits.getHighCorner().at(dim);
90  double nbins = _nLocalBins .at(dim);
91  double width = (high - low)/nbins;
92 
93  return low + width*localBinNum;
94 
95 }
96 
97 double UniformBinning::getHighBinEdgeLocal(int dim, int localBinNum) const{
98 
99  double low = _limits.getLowCorner ().at(dim);
100  double high = _limits.getHighCorner().at(dim);
101  double nbins = _nLocalBins .at(dim);
102  double width = (high - low)/nbins;
103 
104  return low + width*(localBinNum + 1.0);
105 
106 }
107 
108 HyperPoint UniformBinning::getLowCorner(int globalBinNum) const{
109  HyperPoint corner(getDimension());
110  std::vector<int> localBinNum = getLocalBinNumbers(globalBinNum);
111  for (int i = 0; i < getDimension(); i++){
112  corner.at( i ) = getLowBinEdgeLocal( i, localBinNum.at(i) );
113  }
114  return corner;
115 }
116 
118  HyperPoint corner(getDimension());
119  std::vector<int> localBinNum = getLocalBinNumbers(globalBinNum);
120  for (int i = 0; i < getDimension(); i++){
121  corner.at( i ) = getHighBinEdgeLocal( i, localBinNum.at(i) );
122  }
123  return corner;
124 }
125 
126 void UniformBinning::load(TString filename, TString option){
127  //not implemented this yet so added these lines to stop
128  //compiler warnings
129  filename = filename;
130  option = option;
131 }
132 
134  return new UniformBinning(*this);
135 }
136 
137 void UniformBinning::save(TString filename) const{
138  //not implemented this yet so added these lines to stop
139  //compiler warnings
140  filename = filename;
141 }
142 
143 void UniformBinning::save() const{
144 
145 }
146 
148  //not implemented this yet so added these lines to stop
149  //compiler warnings
150  other.getDimension();
151 }
152 
153 int UniformBinning::getLocalBinNumber(int dim, double val) const{
154 
155  double low = _limits.getLowCorner ().at(dim);
156  double high = _limits.getHighCorner().at(dim);
157  double nbins = _nLocalBins .at(dim);
158  double width = (high - low)/nbins;
159 
160  return floor( val - low )/width;
161 
162 }
163 
164 std::vector<int> UniformBinning::getLocalBinNumbers(const HyperPoint& coords) const{
165 
166  std::vector<int> localBinNums(getDimension(), -1);
167 
168  for (int i = 0; i < getDimension(); i++){
169  localBinNums.at(i) = getLocalBinNumber(i, coords.at(i));
170  }
171  return localBinNums;
172 
173 }
174 
175 
176 int UniformBinning::getBinNum(const HyperPoint& coords) const{
177 
178  return getGlobalBinNumber( getLocalBinNumbers(coords) );
179 
180 }
181 
183  HyperCuboid cube( getLowCorner(binNumber), getHighCorner(binNumber) );
184  return HyperVolume(cube);
185 }
186 
187 
188 
190 
192  for (int i = 0; i < getDimension(); i++){
193  binwidth.at(i)/= double(getNumLocalBins(i));
194  }
195  return binwidth;
196 
197 }
198 
200  return _limits;
201 }
202 
204 
205 
206 }
207 
208 
double getHighBinEdgeLocal(int dim, int localBinNum) const
virtual TString filename() const
Definition: BinningBase.cpp:57
virtual HyperVolume getBinHyperVolume(int binNumber) const
#define ERROR_LOG
virtual int getBinNum(const HyperPoint &coords) const
int getNumLocalBins(int dimension) const
virtual HyperPoint getAverageBinWidth() const
virtual void setDimension(int dimension)
Definition: BinningBase.cpp:34
HyperCuboid _limits
int getGlobalBinNumber(std::vector< int > localBinNumbers) const
virtual HyperCuboid getLimits() const
const int & getDimension() const
Definition: HyperCuboid.h:45
virtual void save() const
void setBinningType(TString binningType)
Definition: BinningBase.cpp:16
double getLowBinEdgeLocal(int dim, int localBinNum) const
const HyperPoint & getHighCorner() const
Definition: HyperCuboid.h:89
HyperPoint getHighCorner(int globalBinNum) const
std::vector< int > getLocalBinNumbers(int globalBinNumber) const
const int & getDimension() const
Definition: BinningBase.cpp:30
UniformBinning(HyperCuboid limits, int nLocalBins)
The only constructor.
const double & at(int i) const
Definition: HyperPoint.cpp:433
const HyperPoint & getLowCorner() const
Definition: HyperCuboid.h:87
#define WELCOME_LOG
int getLocalBinNumber(int dim, double val) const
virtual ~UniformBinning()
virtual BinningBase * clone() const
HyperPoint getLowCorner(int globalBinNum) const
virtual int getNumBins() const
std::vector< int > _nLocalBins
virtual void mergeBinnings(const BinningBase &other)
virtual void load(TString filename, TString option="READ")