Create an equal frequency (aka equal-statistics) binning.
95 {
96
98
99 unsigned int nEvents = data.size();
100
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]; });
104
105 double sum_weights = 0;
106 for (auto& w : weights)
107 sum_weights += w;
108 double weight_per_bin = sum_weights / nBins;
109
110 unsigned int bin = 1;
111 double current_weight = 0;
112 binning.m_boundaries[0] = data[indices[0]];
113 binning.m_boundaries[nBins] = data[indices[nEvents - 1]];
114
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) {
122 binning.m_boundaries[bin] = data[index];
123 bin++;
124 }
125 }
126 if (isSignal[index]) {
127 binning.m_signal_pdf[bin - 1] += weights[index];
128 } else {
129 binning.m_bckgrd_pdf[bin - 1] += weights[index];
130 }
131 }
132
133 binning.normalizePDFs();
134 binning.calculateCDFsFromPDFs();
135
136 return binning;
137 }
std::vector< std::pair< double, double > > Binning
Bin holder as vector for bin limit pairs: [energy limits, theta limits, phi limits].