Belle II Software  release-05-02-19
Chi2MinimumFinder1D.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2018 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Marko Staric *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <vector>
14 #include <string>
15 #include <memory>
16 #include <TH1F.h>
17 #include <TH1D.h>
18 
19 namespace Belle2 {
24  namespace TOP {
25 
29  class Chi2MinimumFinder1D {
30 
31  public:
32 
36  struct Minimum {
37  double position = 0;
38  double error = 0;
39  double chi2 = 0;
40  bool valid = false;
46  {}
47 
51  Minimum(double pos, double err, double chi2_min, bool valid_flag):
52  position(pos), error(err), chi2(chi2_min), valid(valid_flag)
53  {}
54  };
55 
60  {}
61 
68  Chi2MinimumFinder1D(int nbins, double xmin, double xmax);
69 
73  explicit Chi2MinimumFinder1D(const std::shared_ptr<TH1D> h);
74 
78  void clear();
79 
85  void add(unsigned i, double chi2);
86 
93 
98  double getXmin() const {return m_xmin;}
99 
104  double getXmax() const {return m_xmax;}
105 
110  int getNbins() const {return m_x.size();}
111 
116  double getBinSize() const {return m_dx;}
117 
122  const std::vector<double>& getBinCenters() const {return m_x;}
123 
128  const std::vector<double>& getChi2Values() const {return m_chi2;}
129 
134  int getEntries() const {return m_entries;}
135 
139  const Minimum& getMinimum()
140  {
141  if (!m_searched) {
143  m_searched = true;
144  }
145  return m_minimum;
146  }
147 
153  TH1F getHistogram(std::string name, std::string title) const;
154 
155  private:
156 
160  void findMinimum();
161 
169  Minimum getMinimum(double yLeft, double yCenter, double yRight) const;
170 
171  double m_xmin = 0;
172  double m_xmax = 0;
174  double m_dx = 0;
175  std::vector<double> m_x;
176  std::vector<double> m_chi2;
177  int m_entries = 0;
179  bool m_searched = false;
182  };
183 
184  } // namespace TOP
186 } // namespace Belle2
Belle2::TOP::Chi2MinimumFinder1D::m_minimum
Minimum m_minimum
result: global minimum
Definition: Chi2MinimumFinder1D.h:188
Belle2::TOP::Chi2MinimumFinder1D::Minimum::valid
bool valid
valid minimum found
Definition: Chi2MinimumFinder1D.h:48
Belle2::TOP::Chi2MinimumFinder1D::findMinimum
void findMinimum()
Finds minimum.
Definition: Chi2MinimumFinder1D.cc:102
Belle2::TOP::Chi2MinimumFinder1D::getHistogram
TH1F getHistogram(std::string name, std::string title) const
Returns chi^2 packed into 1D histogram.
Definition: Chi2MinimumFinder1D.cc:135
Belle2::TOP::Chi2MinimumFinder1D::m_dx
double m_dx
bin size
Definition: Chi2MinimumFinder1D.h:182
Belle2::TOP::Chi2MinimumFinder1D::m_chi2
std::vector< double > m_chi2
chi^2 values at bin centers
Definition: Chi2MinimumFinder1D.h:184
Belle2::TOP::Chi2MinimumFinder1D::getEntries
int getEntries() const
Returns number of entries (counted for bin 0)
Definition: Chi2MinimumFinder1D.h:142
Belle2::TOP::Chi2MinimumFinder1D::getBinCenters
const std::vector< double > & getBinCenters() const
Returns vector of bin centers.
Definition: Chi2MinimumFinder1D.h:130
Belle2::TOP::Chi2MinimumFinder1D::Minimum::position
double position
position of the minimum
Definition: Chi2MinimumFinder1D.h:45
Belle2::TOP::Chi2MinimumFinder1D::getXmax
double getXmax() const
Returns upper limit of search region.
Definition: Chi2MinimumFinder1D.h:112
Belle2::TOP::Chi2MinimumFinder1D
Minimum finder using tabulated chi^2 values in one dimension.
Definition: Chi2MinimumFinder1D.h:37
Belle2::TOP::Chi2MinimumFinder1D::getChi2Values
const std::vector< double > & getChi2Values() const
Returns vector of chi^2.
Definition: Chi2MinimumFinder1D.h:136
Belle2::TOP::Chi2MinimumFinder1D::Minimum
Result of minimum finder.
Definition: Chi2MinimumFinder1D.h:44
Belle2::TOP::Chi2MinimumFinder1D::getMinimum
const Minimum & getMinimum()
Returns parabolic minimum.
Definition: Chi2MinimumFinder1D.h:147
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TOP::Chi2MinimumFinder1D::m_entries
int m_entries
number of entries (counted for bin 0)
Definition: Chi2MinimumFinder1D.h:185
Belle2::TOP::Chi2MinimumFinder1D::Chi2MinimumFinder1D
Chi2MinimumFinder1D()
Default constructor.
Definition: Chi2MinimumFinder1D.h:67
Belle2::TOP::Chi2MinimumFinder1D::m_x
std::vector< double > m_x
bin centers
Definition: Chi2MinimumFinder1D.h:183
Belle2::TOP::Chi2MinimumFinder1D::Minimum::error
double error
error on the position
Definition: Chi2MinimumFinder1D.h:46
Belle2::TOP::Chi2MinimumFinder1D::m_xmax
double m_xmax
upper limit of search region
Definition: Chi2MinimumFinder1D.h:180
Belle2::TOP::Chi2MinimumFinder1D::add
void add(unsigned i, double chi2)
Add chi^2 value to bin i.
Definition: Chi2MinimumFinder1D.cc:72
Belle2::TOP::Chi2MinimumFinder1D::getBinSize
double getBinSize() const
Returns bin (or step) size.
Definition: Chi2MinimumFinder1D.h:124
Belle2::TOP::Chi2MinimumFinder1D::m_xmin
double m_xmin
lower limit of search region
Definition: Chi2MinimumFinder1D.h:179
Belle2::TOP::Chi2MinimumFinder1D::clear
void clear()
Set chi^2 values to zero.
Definition: Chi2MinimumFinder1D.cc:64
Belle2::TOP::Chi2MinimumFinder1D::getXmin
double getXmin() const
Returns lower limit of search region.
Definition: Chi2MinimumFinder1D.h:106
Belle2::TOP::Chi2MinimumFinder1D::getNbins
int getNbins() const
Returns number of bins.
Definition: Chi2MinimumFinder1D.h:118
Belle2::TOP::Chi2MinimumFinder1D::Minimum::chi2
double chi2
chi2 at minimum
Definition: Chi2MinimumFinder1D.h:47
Belle2::TOP::Chi2MinimumFinder1D::m_searched
bool m_searched
internal flag
Definition: Chi2MinimumFinder1D.h:187
Belle2::TOP::Chi2MinimumFinder1D::Minimum::Minimum
Minimum()
Default constructor.
Definition: Chi2MinimumFinder1D.h:53