Belle II Software  release-05-02-19
MinMax.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jakob Lettenbichler (jakob.lettenbichler@oeaw.ac.at) *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <string>
14 #include <utility> // std::pair
15 #include <limits> // std::numeric_limits
16 
17 
18 namespace Belle2 {
25  class MinMax {
26  protected:
27  std::pair<double, double> m_minMax;
28  public:
29 
31  MinMax() :
32  m_minMax( {std::numeric_limits< double >::max(), -std::numeric_limits< double >::max()}) {}
33 
35  void reset() { m_minMax = {std::numeric_limits< double >::max(), -std::numeric_limits< double >::max()}; }
36 
38  bool checkAndReplaceIfMinMax(double newVal)
39  {
40  bool wasAdded = false;
41  if (newVal < m_minMax.first) { m_minMax.first = newVal; wasAdded = true; }
42  if (m_minMax.second < newVal) { m_minMax.second = newVal; wasAdded = true; }
43  return wasAdded;
44  }
45 
46  double getMin() const { return m_minMax.first; }
48  double getMax() const { return m_minMax.second; }
50  std::string print() const
51  {
52  std::string min = m_minMax.first == std::numeric_limits< double >::max() ? "max<double>" : std::to_string(m_minMax.first);
53  std::string max = m_minMax.second == -std::numeric_limits< double >::max() ? "min<double>" : std::to_string(m_minMax.second);
54  return "min: " + min + ", max: " + max;
55  }
56  };
58 }
59 
Belle2::MinMax::reset
void reset()
reset to start values.
Definition: MinMax.h:43
Belle2::MinMax::m_minMax
std::pair< double, double > m_minMax
.first is min, .second is .max.
Definition: MinMax.h:35
Belle2::MinMax::MinMax
MinMax()
construtor, starts with max for min and min for max (will later be replaced by valid entries).
Definition: MinMax.h:39
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MinMax::checkAndReplaceIfMinMax
bool checkAndReplaceIfMinMax(double newVal)
checks value and replaces old ones if new one is better.
Definition: MinMax.h:46