Belle II Software  release-06-00-14
Chi2MinimumFinder1D.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 #include <vector>
12 #include <string>
13 #include <memory>
14 #include <TH1F.h>
15 #include <TH1D.h>
16 
17 namespace Belle2 {
22  namespace TOP {
23 
28 
29  public:
30 
34  struct Minimum {
35  double position = 0;
36  double error = 0;
37  double chi2 = 0;
38  bool valid = false;
44  {}
45 
49  Minimum(double pos, double err, double chi2_min, bool valid_flag):
50  position(pos), error(err), chi2(chi2_min), valid(valid_flag)
51  {}
52  };
53 
58  {}
59 
66  Chi2MinimumFinder1D(int nbins, double xmin, double xmax);
67 
71  explicit Chi2MinimumFinder1D(const std::shared_ptr<TH1D> h);
72 
76  void clear();
77 
83  void add(unsigned i, double chi2);
84 
91 
96  double getXmin() const {return m_xmin;}
97 
102  double getXmax() const {return m_xmax;}
103 
108  int getNbins() const {return m_x.size();}
109 
114  double getBinSize() const {return m_dx;}
115 
120  const std::vector<double>& getBinCenters() const {return m_x;}
121 
126  const std::vector<double>& getChi2Values() const {return m_chi2;}
127 
132  int getEntries() const {return m_entries;}
133 
138  {
139  if (!m_searched) {
140  findMinimum();
141  m_searched = true;
142  }
143  return m_minimum;
144  }
145 
151  TH1F getHistogram(std::string name, std::string title) const;
152 
153  private:
154 
158  void findMinimum();
159 
167  Minimum getMinimum(double yLeft, double yCenter, double yRight) const;
168 
169  double m_xmin = 0;
170  double m_xmax = 0;
172  double m_dx = 0;
173  std::vector<double> m_x;
174  std::vector<double> m_chi2;
175  int m_entries = 0;
177  bool m_searched = false;
180  };
181 
182  } // namespace TOP
184 } // namespace Belle2
Minimum finder using tabulated chi^2 values in one dimension.
double m_xmin
lower limit of search region
TH1F getHistogram(std::string name, std::string title) const
Returns chi^2 packed into 1D histogram.
int m_entries
number of entries (counted for bin 0)
Chi2MinimumFinder1D()
Default constructor.
Minimum m_minimum
result: global minimum
double getBinSize() const
Returns bin (or step) size.
void add(unsigned i, double chi2)
Add chi^2 value to bin i.
double m_xmax
upper limit of search region
const Minimum & getMinimum()
Returns parabolic minimum.
int getEntries() const
Returns number of entries (counted for bin 0)
const std::vector< double > & getChi2Values() const
Returns vector of chi^2.
double getXmax() const
Returns upper limit of search region.
std::vector< double > m_chi2
chi^2 values at bin centers
void clear()
Set chi^2 values to zero.
double getXmin() const
Returns lower limit of search region.
std::vector< double > m_x
bin centers
int getNbins() const
Returns number of bins.
const std::vector< double > & getBinCenters() const
Returns vector of bin centers.
Abstract base class for different kinds of events.
Minimum(double pos, double err, double chi2_min, bool valid_flag)
Full constructor.
double position
position of the minimum