ATLAS Offline Software
FilterRange.h
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // FilterRange.h
8 // Header file for class FilterRange
9 // Author: S.Binet<binet@cern.ch>
11 #ifndef ANALYSISUTILS_FILTERRANGE_H
12 #define ANALYSISUTILS_FILTERRANGE_H
13 
20 // STL includes
21 #include <cfloat>
22 #include <iostream>
23 #include <optional>
24 
25 // Boost includes
26 #include <boost/numeric/interval/interval.hpp>
27 #include <boost/numeric/interval/checking.hpp>
28 #include <boost/numeric/interval/policies.hpp>
29 #include <boost/numeric/interval/compare/certain.hpp>
30 
31 //>Wait for SEAL 1.4.0 and const-correctness
32 //#include "FML/RangeSet.h"
33 
35 {
36 
38  // Public methods:
40  public:
41 
45  FilterRange();
46 
49  FilterRange( const FilterRange& range );
50 
55  FilterRange( const double min, const double max );
56 
59  virtual ~FilterRange();
60 
64 
66  // Const methods:
68 
70  double precision() const;
71 
74  double lower() const;
75 
78  double upper() const;
79 
82  double getMin() const;
83 
86  double getMax() const;
87 
90  double PLUS_INF() const;
91 
94  double MINUS_INF() const;
95 
98  bool isInRange( const double point ) const;
99 
103  bool isActive() const;
104 
106  // Non-const methods:
108  void setPrecision( const double delta );
109  void setRange( const double lower, const double upper );
110  void setMin( const double minValue );
111  void setMax( const double maxValue );
112 
118  void include( const double xMin, const double xMax);
119 
123  void includeAll();
124 
126  // Protected method:
128  protected:
129 
132  void addRange(double xMin, double xMax);
133 
134  // clean ranges present between xmin and xmax
135  //void cleanRanges(double xMin, double xMax);
136 
138  // Protected data:
140  protected:
141 
142  typedef boost::numeric::interval<double> interval_t;
143 
147  std::optional<interval_t> m_range;
148 
151  double m_precision;
152 };
153 
155 // Operators
157 bool operator==( const FilterRange& r1, const FilterRange& r2 );
158 bool operator!=( const FilterRange& r1, const FilterRange& r2 );
159 bool operator <( const FilterRange& r1, const FilterRange& r2 );
160 bool operator >( const FilterRange& r1, const FilterRange& r2 );
161 bool operator<=( const FilterRange& r1, const FilterRange& r2 );
162 bool operator>=( const FilterRange& r1, const FilterRange& r2 );
163 
167 
171  m_range(std::nullopt),
172  m_precision(1e-6)
173 {}
174 
175 inline FilterRange::FilterRange( const double min, const double max ) :
176  m_range( interval_t(min, max) ),
177  m_precision(1e-6)
178 {
179  if ( min == MINUS_INF() && max == PLUS_INF() ) {
180  //std::cout << ">>> You are giving a NO-OP interval : ]"
181  // << min << "; "
182  // << max << "["
183  // << std::endl
184  // << ">>> De-activating this range for optimization purpose."
185  // << std::endl;
186  m_range = std::nullopt;
187  if ( isActive() ) {
188  std::string error = "ERROR : FilterRange is ACTIVE (Should NOT BE !!)";
189  std::cerr << error << std::endl;
190  throw error;
191  }
192  } else {
193  // Do nothing : everything is allright
194  }
195 }
196 
197 // Destructor
200 
202 // Const methods:
204 inline double FilterRange::precision() const
205 {
206  return m_precision;
207 }
208 
209 inline double FilterRange::lower() const
210 {
211  if ( m_range ) {
212  return m_range->lower();
213  }
214 
215  return MINUS_INF();
216 }
217 
218 inline double FilterRange::upper() const
219 {
220  if ( m_range ) {
221  return m_range->upper();
222  }
223 
224  return PLUS_INF();
225 }
226 
227 inline double FilterRange::getMin() const
228 {
229  return lower();
230 }
231 
232 inline double FilterRange::getMax() const
233 {
234  return upper();
235 }
236 
237 inline double FilterRange::PLUS_INF() const
238 {
239  return FLT_MAX;
240 }
241 
242 inline double FilterRange::MINUS_INF() const
243 {
244  return -FLT_MAX;
245 }
246 
247 inline bool FilterRange::isActive() const
248 {
249  if ( m_range ) return true;
250  return false;
251 }
252 
254 // Non-const methods:
256 inline void FilterRange::setPrecision( const double delta )
257 {
258  m_precision = delta;
259 }
260 
261 inline void FilterRange::setMin( const double minValue )
262 {
263  return setRange( minValue, getMax() );
264 }
265 
266 inline void FilterRange::setMax( const double maxValue )
267 {
268  return setRange( getMin(), maxValue );
269 }
270 
271 #endif //> ANALYSISUTILS_FILTERRANGE_H
FilterRange::MINUS_INF
double MINUS_INF() const
Define -infinity according to specific implementation.
Definition: FilterRange.h:242
FilterRange::FilterRange
FilterRange()
Default constructor: it sets the minimum value to -infinity and the maximum value to +infinity.
Definition: FilterRange.h:170
FilterRange::isInRange
bool isInRange(const double point) const
return Return true if the point is in range : min <= point <= max
Definition: FilterRange.cxx:45
FilterRange::isActive
bool isActive() const
return Return true if the range is active (optimize parsing of multiple ranges and returning the fina...
Definition: FilterRange.h:247
FilterRange::interval_t
boost::numeric::interval< double > interval_t
Definition: FilterRange.h:142
FilterRange::m_range
std::optional< interval_t > m_range
The boost interval wrapped by a boost optional.
Definition: FilterRange.h:147
maxValue
#define maxValue(current, test)
Definition: CompoundLayerMaterialCreator.h:22
max
#define max(a, b)
Definition: cfImp.cxx:41
FilterRange
FilterRange implements the range (ie: [min, max]) the filters will use to take their filtering decisi...
Definition: FilterRange.h:35
FilterRange::getMax
double getMax() const
Return the maximum value of the range.
Definition: FilterRange.h:232
FilterRange::include
void include(const double xMin, const double xMax)
Add [xMin, xMax] interval to existing set of valid ranges.
Definition: FilterRange.cxx:68
FilterRange::m_precision
double m_precision
Setup the wanted double precision.
Definition: FilterRange.h:151
m_range
float m_range[NbCaloPart][2]
Definition: CellClusterLinkTool.h:55
FilterRange::PLUS_INF
double PLUS_INF() const
Define +infinity according to specific implementation.
Definition: FilterRange.h:237
operator!=
bool operator!=(const FilterRange &r1, const FilterRange &r2)
Definition: FilterRange.cxx:114
FilterRange::getMin
double getMin() const
Return the minimum value of the range.
Definition: FilterRange.h:227
FilterRange::includeAll
void includeAll()
Set full range (from MINUS_INF to PLUS_INF ).
Definition: FilterRange.cxx:75
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
FilterRange::setRange
void setRange(const double lower, const double upper)
Non-const methods:
Definition: FilterRange.cxx:56
min
#define min(a, b)
Definition: cfImp.cxx:40
operator>=
bool operator>=(const FilterRange &r1, const FilterRange &r2)
Definition: FilterRange.cxx:140
operator<=
bool operator<=(const FilterRange &r1, const FilterRange &r2)
Definition: FilterRange.cxx:166
FilterRange::addRange
void addRange(double xMin, double xMax)
add a new range [xmin,xmax] deleting previous ranges full contained
Definition: FilterRange.cxx:84
FilterRange::operator=
FilterRange & operator=(const FilterRange &obj)
Assignment operator:
Definition: FilterRange.cxx:32
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
FilterRange::setMax
void setMax(const double maxValue)
Definition: FilterRange.h:266
operator>
bool operator>(const FilterRange &r1, const FilterRange &r2)
Definition: FilterRange.cxx:145
FilterRange::precision
double precision() const
Return the double precision for the comparaison of doubles.
Definition: FilterRange.h:204
operator<
bool operator<(const FilterRange &r1, const FilterRange &r2)
Definition: FilterRange.cxx:119
FilterRange::~FilterRange
virtual ~FilterRange()
Destructor:
Definition: FilterRange.h:199
FilterRange::setPrecision
void setPrecision(const double delta)
Definition: FilterRange.h:256
operator==
bool operator==(const FilterRange &r1, const FilterRange &r2)
Definition: FilterRange.cxx:98
get_generator_info.error
error
Definition: get_generator_info.py:40
FilterRange::setMin
void setMin(const double minValue)
Definition: FilterRange.h:261
python.PyAthena.obj
obj
Definition: PyAthena.py:135
error
Definition: IImpactPoint3dEstimator.h:70
minValue
#define minValue(current, test)
Definition: CompoundLayerMaterialCreator.h:21
FilterRange::lower
double lower() const
Return the minimum value of the range.
Definition: FilterRange.h:209
FilterRange::upper
double upper() const
Return the maximum value of the range.
Definition: FilterRange.h:218