93 Binning Binning::CreateEqualFrequency(
const std::vector<float>& data,
const std::vector<float>& weights,
94 const std::vector<bool>& isSignal,
unsigned int nBins)
99 unsigned int nEvents = data.size();
101 std::vector<unsigned int> indices(nEvents);
102 std::iota(indices.begin(), indices.end(), 0);
103 std::sort(indices.begin(), indices.end(), [&](
unsigned int i,
unsigned int j) {return data[i] < data[j]; });
105 double sum_weights = 0;
106 for (
auto& w : weights)
108 double weight_per_bin = sum_weights / nBins;
110 unsigned int bin = 1;
111 double current_weight = 0;
113 binning.
m_boundaries[nBins] = data[indices[nEvents - 1]];
115 for (
unsigned int iEvent = 0; iEvent < nEvents; ++iEvent) {
116 unsigned int index = indices[iEvent];
117 current_weight += weights[index];
118 if (current_weight >= weight_per_bin and bin < nBins and binning.
m_boundaries[bin - 1] < data[index]) {
119 auto number_of_bins =
static_cast<unsigned int>(current_weight / weight_per_bin);
120 current_weight -= weight_per_bin * number_of_bins;
121 for (
unsigned int i = 0; i < number_of_bins; ++i) {
126 if (isSignal[index]) {
139 Binning Binning::CreateEquidistant(
const std::vector<float>& data,
const std::vector<float>& weights,
140 const std::vector<bool>& isSignal,
unsigned int nBins)
145 auto minmax = std::minmax_element(data.begin(), data.end());
146 float min = *(minmax.first);
147 float max = *(minmax.second);
148 float step = (max - min) / nBins;
150 for (
unsigned int iBin = 0; iBin <= nBins; ++iBin) {
154 for (
unsigned int iEvent = 0; iEvent < data.size(); ++iEvent) {
155 unsigned int bin = binning.
getBin(data[iEvent]);
157 if (isSignal[iEvent])