 |
Belle II Software
release-05-01-25
|
11 #include <analysis/dbobjects/PIDPriorsTable.h>
12 #include <framework/logging/Logger.h>
24 auto checkEdges = [](std::vector<float>& edges,
const std::string & axis) {
25 if (edges.size() < 2) {
26 B2WARNING(
"You provided less than 2 bin edges for the " << axis <<
27 " axis. This is not enough to create one bin, so one will be created with range [-FLT_MAX, +FLT_MAX]");
28 edges = { -FLT_MAX, FLT_MAX};
30 auto prevVal = edges[0];
31 for (
int iBin = 1; iBin < static_cast<int>(edges.size()); iBin++) {
32 auto edge = edges[iBin];
34 B2FATAL(
"Null or negative bin size found on the X axis. Please make sure that all the bin edges are sorted and non-equal");
57 if (value > 1. || value < 0.) {
58 B2WARNING(
"The value " << value <<
" you are trying to set for the bin (" << x <<
", " << y <<
59 ") does not look like a probability. The table will be filled, but i will not be usable as a proper prior probability table.");
102 std::cout <<
" --- Prior summary --- " << std::endl;
105 std::cout <<
" X axis: " ;
107 std::cout <<
" " << edge <<
" " ;
109 std::cout <<
" " << std::endl;
110 std::cout <<
" Y axis ";
112 std::cout <<
" " << edge <<
" " ;
114 std::cout <<
" " << std::endl;
115 std::cout <<
" Values " << std::endl;
116 for (
int iY =
m_binEdgesY.size() - 2; iY >= 0; iY--) {
117 for (
int iX = 0; iX < static_cast<int>(
m_binEdgesX.size() - 1); iX++) {
120 std::cout <<
" " << std::endl;
122 std::cout <<
" --- End of prior summary --- " << std::endl;
128 std::cout <<
" --- Error summary --- " << std::endl;
131 std::cout <<
" X axis: " ;
133 std::cout <<
" " << edge <<
" " ;
135 std::cout <<
" " << std::endl;
136 std::cout <<
" Y axis ";
138 std::cout <<
" " << edge <<
" " ;
140 std::cout <<
" " << std::endl;
141 std::cout <<
" Values " << std::endl;
142 for (
int iY =
m_binEdgesY.size() - 2; iY >= 0; iY--) {
143 for (
int iX = 0; iX < static_cast<int>(
m_binEdgesX.size() - 1); iX++) {
146 std::cout <<
" " << std::endl;
148 std::cout <<
" --- End of error summary --- " << std::endl;
155 const float& min = edges.front();
156 const float& max = edges.back();
157 if (val > max || val < min) {
158 B2WARNING(
"PriorsTable: " << text <<
LogVar(
"value", val) <<
LogVar(
"min", min) <<
LogVar(
"max", max));
167 auto it = std::lower_bound(array.cbegin(), array.cend(), val);
168 return std::distance(array.cbegin(), it) - 1;
177 float averageBinSize = (array.back() - array.front()) / (array.size() - 1);
178 short bin = 1 + (short)((val - array[0]) / averageBinSize);
181 while (bin <
static_cast<short>(array.size()) && array[bin] < val) {
185 while (bin - 1 > 0 && array[bin - 1] > val) {
194 float binWidth = (array.back() - array.front()) / (array.size() - 1.);
195 return (
short)((val - array.back()) / binWidth);
std::vector< float > m_binEdgesY
The array containing the bin edges for the Y axis.
float getErrorValue(float x, float y) const
Returns the error on the prior probability for a given value of (x,y).
std::vector< float > m_binEdgesX
The array containing the bin edges for the X axis.
short findBin(float val, std::vector< float > array) const
This function returns the position of a number in a sorted array of bin edges.
short findBinWithFixedWidth(float val, std::vector< float > array) const
This function returns the position of a number in a sorted array of bin edges, assuming that the atte...
void setBinEdges(const std::vector< float > &binEdgesX, const std::vector< float > &binEdgesY)
Sets the bin edges arrays.
float getErrorInBin(int iX, int iY) const
Returns the error on prior probability for a given bin.
void printPrior() const
Prints the content of the table and the axes.
Abstract base class for different kinds of events.
Class to store variables with their name which were sent to the logging service.
void setPriorValue(float x, float y, float value)
Sets the prior value for a single bin.
std::vector< float > m_errors
The the matrix with the errors on the prior probabilities.
bool checkRange(const std::string &text, float val, const std::vector< float > &edges) const
Checks is a values is withing the range of an array.
void setErrorValue(float x, float y, float value)
Sets the error on the prior value for a single bin.
float getPriorInBin(int iX, int iY) const
Returns the prior probability for a given bin.
short findBinFast(float val, std::vector< float > array) const
This function returns the position of a number in a sorted array of bin edges This implementation sho...
std::vector< float > m_priors
The matrix with the prior probabilities.
float getPriorValue(float x, float y) const
Returns the prior probability for a given value of (x,y).
void printError() const
Prints the content of the error table and the axes.