Belle II Software development
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 <algorithm>
13#include <string>
14#include <memory>
15#include <TH1F.h>
16#include <TH1D.h>
17
18namespace Belle2 {
23 namespace TOP {
24
29
30 public:
31
35 struct Minimum {
36 double position = 0;
37 double error = 0;
38 double chi2 = 0;
39 bool valid = false;
45 {}
46
50 Minimum(double pos, double err, double chi2_min, bool valid_flag):
51 position(pos), error(err), chi2(chi2_min), valid(valid_flag)
52 {}
53 };
54
59 {}
60
67 Chi2MinimumFinder1D(int nbins, double xmin, double xmax);
68
72 explicit Chi2MinimumFinder1D(const std::shared_ptr<TH1D> h);
73
77 void clear();
78
84 void add(unsigned i, double chi2);
85
92
97 double getXmin() const {return m_xmin;}
98
103 double getXmax() const {return m_xmax;}
104
109 int getNbins() const {return m_x.size();}
110
115 double getBinSize() const {return m_dx;}
116
121 const std::vector<double>& getBinCenters() const {return m_x;}
122
127 const std::vector<double>& getChi2Values() const {return m_chi2;}
128
129
134 double getMinChi2() const {return *std::min_element(m_chi2.begin(), m_chi2.end());}
135
140 int getEntries() const {return m_entries;}
141
146 {
147 if (!m_searched) {
148 findMinimum();
149 m_searched = true;
150 }
151 return m_minimum;
152 }
153
159 TH1F getHistogram(std::string name, std::string title) const;
160
161 private:
162
166 void findMinimum();
167
175 Minimum getMinimum(double yLeft, double yCenter, double yRight) const;
176
177 double m_xmin = 0;
178 double m_xmax = 0;
180 double m_dx = 0;
181 std::vector<double> m_x;
182 std::vector<double> m_chi2;
183 int m_entries = 0;
185 bool m_searched = false;
188 };
189
190 } // namespace TOP
192} // namespace Belle2
Minimum finder using tabulated chi^2 values in one dimension.
const std::vector< double > & getBinCenters() const
Returns vector of bin centers.
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 getMinChi2() const
Returns minimum chi2 value.
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
int getEntries() const
Returns number of entries (counted for bin 0)
double getXmax() const
Returns upper limit of search region.
std::vector< double > m_chi2
chi^2 values at bin centers
const Minimum & getMinimum()
Returns parabolic minimum.
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 > & getChi2Values() const
Returns vector of chi^2.
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