Belle II Software  release-05-02-19
PIDPriorsTable.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2018 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Umberto Tamponi (tamponi@to.infn.it) *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <vector>
14 #include <string>
15 
16 namespace Belle2 {
29  class PIDPriorsTable {
30 
31  public:
32 
39  void setBinEdges(const std::vector<float>& binEdgesX, const std::vector<float>& binEdgesY);
40 
41 
46  void setPriorsTable(const std::vector<float>& priors)
47  {
48  m_priors = priors;
49  return;
50  };
51 
52 
57  void setErrorsTable(const std::vector<float>& errors)
58  {
59  m_errors = errors;
60  return;
61  };
62 
63 
70  void setPriorValue(float x, float y, float value);
71 
72 
79  void setErrorValue(float x, float y, float value);
80 
81 
87  void setAxisLabels(const std::string& labelX, const std::string& labelY)
88  {
89  m_xAxisLabel = labelX;
90  m_yAxisLabel = labelY;
91  return ;
92  }
93 
94 
101  float getPriorInBin(int iX, int iY) const
102  {
103  return m_priors[iX + (m_binEdgesX.size() - 1) * iY];
104  };
105 
106 
113  float getErrorInBin(int iX, int iY) const
114  {
115  return m_errors[iX + (m_binEdgesX.size() - 1) * iY];
116  };
117 
118 
125  float getPriorValue(float x, float y) const;
126 
127 
134  float getErrorValue(float x, float y) const;
135 
136 
141  std::string getXAxisLabel() const
142  {
143  return m_xAxisLabel;
144  };
145 
150  std::string getYAxisLabel() const
151  {
152  return m_yAxisLabel;
153  };
154 
155 
159  void printPrior() const;
160 
164  void printError() const;
165 
166 
167  private:
168 
169  std::vector<float> m_binEdgesX = {};
170  std::vector<float> m_binEdgesY = {};
171  std::vector<float> m_priors;
172  std::vector<float> m_errors;
173  std::string m_xAxisLabel = "" ;
174  std::string m_yAxisLabel = "" ;
183  bool checkRange(const std::string& text, float val, const std::vector<float>& edges) const;
184 
191  short findBin(float val, std::vector<float> array) const;
192 
203  // cppcheck-suppress unusedPrivateFunction
204  short findBinFast(float val, std::vector<float> array) const;
205 
213  // cppcheck-suppress unusedPrivateFunction
214  short findBinWithFixedWidth(float val, std::vector<float> array) const;
215 
216 
217  };
219 } // Belle2 namespace
Belle2::PIDPriorsTable::m_binEdgesY
std::vector< float > m_binEdgesY
The array containing the bin edges for the Y axis.
Definition: PIDPriorsTable.h:178
Belle2::PIDPriorsTable::setAxisLabels
void setAxisLabels(const std::string &labelX, const std::string &labelY)
Sets axes lables.
Definition: PIDPriorsTable.h:95
Belle2::PIDPriorsTable::getXAxisLabel
std::string getXAxisLabel() const
Returns the X axis label.
Definition: PIDPriorsTable.h:149
Belle2::PIDPriorsTable::getYAxisLabel
std::string getYAxisLabel() const
Returns the Y axis label.
Definition: PIDPriorsTable.h:158
Belle2::PIDPriorsTable::getErrorValue
float getErrorValue(float x, float y) const
Returns the error on the prior probability for a given value of (x,y).
Definition: PIDPriorsTable.cc:90
Belle2::PIDPriorsTable::m_binEdgesX
std::vector< float > m_binEdgesX
The array containing the bin edges for the X axis.
Definition: PIDPriorsTable.h:177
Belle2::PIDPriorsTable::findBin
short findBin(float val, std::vector< float > array) const
This function returns the position of a number in a sorted array of bin edges.
Definition: PIDPriorsTable.cc:165
Belle2::PIDPriorsTable::m_yAxisLabel
std::string m_yAxisLabel
label of the Y axis, indicating which variable is represented here
Definition: PIDPriorsTable.h:182
Belle2::PIDPriorsTable::findBinWithFixedWidth
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...
Definition: PIDPriorsTable.cc:192
Belle2::PIDPriorsTable::setBinEdges
void setBinEdges(const std::vector< float > &binEdgesX, const std::vector< float > &binEdgesY)
Sets the bin edges arrays.
Definition: PIDPriorsTable.cc:18
Belle2::PIDPriorsTable::setPriorsTable
void setPriorsTable(const std::vector< float > &priors)
Sets the priors table from a 2D std::vector.
Definition: PIDPriorsTable.h:54
Belle2::PIDPriorsTable::getErrorInBin
float getErrorInBin(int iX, int iY) const
Returns the error on prior probability for a given bin.
Definition: PIDPriorsTable.h:121
Belle2::PIDPriorsTable::printPrior
void printPrior() const
Prints the content of the table and the axes.
Definition: PIDPriorsTable.cc:100
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::PIDPriorsTable::setPriorValue
void setPriorValue(float x, float y, float value)
Sets the prior value for a single bin.
Definition: PIDPriorsTable.cc:53
Belle2::PIDPriorsTable::m_errors
std::vector< float > m_errors
The the matrix with the errors on the prior probabilities.
Definition: PIDPriorsTable.h:180
Belle2::PIDPriorsTable::m_xAxisLabel
std::string m_xAxisLabel
label of the X axis, indicating which variable is represented here
Definition: PIDPriorsTable.h:181
Belle2::PIDPriorsTable::setErrorsTable
void setErrorsTable(const std::vector< float > &errors)
Sets the priors error table from a 2D std::vector.
Definition: PIDPriorsTable.h:65
Belle2::PIDPriorsTable::checkRange
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.
Definition: PIDPriorsTable.cc:153
Belle2::PIDPriorsTable::setErrorValue
void setErrorValue(float x, float y, float value)
Sets the error on the prior value for a single bin.
Definition: PIDPriorsTable.cc:68
Belle2::PIDPriorsTable::getPriorInBin
float getPriorInBin(int iX, int iY) const
Returns the prior probability for a given bin.
Definition: PIDPriorsTable.h:109
Belle2::PIDPriorsTable::findBinFast
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...
Definition: PIDPriorsTable.cc:172
Belle2::PIDPriorsTable::m_priors
std::vector< float > m_priors
The matrix with the prior probabilities.
Definition: PIDPriorsTable.h:179
Belle2::PIDPriorsTable::getPriorValue
float getPriorValue(float x, float y) const
Returns the prior probability for a given value of (x,y).
Definition: PIDPriorsTable.cc:80
Belle2::PIDPriorsTable::printError
void printError() const
Prints the content of the error table and the axes.
Definition: PIDPriorsTable.cc:126