39 binvalues.at(ibin) += 1;
46 binvalues.at(ibin) += weight;
50 void BinnedDataSet::collectBins() {
55 binsizes.push_back(var.getNumBins());
60 std::vector<size_t> locals = convertValuesToBins(vals);
61 return localToGlobal(locals);
64 size_t BinnedDataSet::localToGlobal(
const std::vector<size_t> &locals)
const {
65 unsigned int priorMatrixSize = 1;
69 size_t localBin = locals[i];
70 ret += localBin * priorMatrixSize;
71 priorMatrixSize *= binsizes[i];
77 std::vector<size_t> BinnedDataSet::globalToLocal(
size_t global)
const {
78 std::vector<size_t> locals;
85 size_t localBin = global % binsizes[i];
86 locals.push_back(localBin);
87 global /= binsizes[i];
93 std::vector<size_t> locals = globalToLocal(bin);
94 size_t localBin = locals.at(ivar);
97 ret *= (localBin + 0.5);
122 if(0 == binerrors.size())
123 return sqrt(binvalues.at(bin));
125 return binerrors.at(bin);
129 if(0 == binerrors.size())
130 binerrors.resize(binvalues.size());
132 binerrors.at(bin) = error;
136 return std::accumulate(std::begin(binsizes), std::end(binsizes), 1, std::multiplies<size_t>());
140 return std::accumulate(std::begin(binvalues), std::end(binvalues), 0);
143 std::vector<size_t> BinnedDataSet::convertValuesToBins(
const std::vector<fptype> &vals)
const {
147 std::vector<size_t> localBins;
151 if(currval != betval)
152 GOOFIT_INFO(
"Warning: Value {} outside {} range [{},{}] - clamping to {}",
158 localBins.push_back(static_cast<size_t>(floor((betval -
observables[i].getLowerLimit()) /
getBinSize(i))));
Thrown when a general error is encountered.
std::vector< Observable > observables
fptype getBinSize(size_t ivar) const
Get the size of a bin.
void checkAllVars() const
Throw an error if any variables are out of range, call in addEvent.
Special class for observables. Used in DataSets.
BinnedDataSet(const Observable &var, std::string n="")
std::string getName() const
size_t indexOfVariable(const Observable &var) const
fptype getBinError(size_t bin) const
fptype getNumWeightedEvents() const
This includes weights.
fptype getBinCenter(size_t ivar, size_t bin) const
void addWeightedEvent(double weight) override
size_t getBinNumber() const
std::vector< fptype > getCurrentValues() const
fptype getBinVolume(size_t bin) const
size_t getNumBins() const
void setBinError(unsigned int bin, fptype value)