ATLAS Offline Software
FilterRange.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // FilterRange.cxx
7 // Implementation file for class FilterRange
8 // Author: S.Binet <binet@cern.ch>
10 
11 
12 // STL includes
13 #include <cmath>
14 
15 // Boost includes
16 #include <boost/numeric/interval/compare/explicit.hpp>
17 
18 // AnalysisUtils includes
20 
24 
28  m_precision( range.m_precision )
29 {}
30 
33 {
34  if ( this != &range ) {
35  m_range = interval_t( range.lower(), range.upper() );
36  m_precision = range.m_precision;
37  }
38 
39  return *this;
40 }
41 
45 bool FilterRange::isInRange( const double point ) const
46 {
47  // check if point is in range
48  if ( ( ( lower() - point ) <= +m_precision ) &&
49  ( ( upper() - point ) >= -m_precision ) ) return true;
50  return false;
51 }
52 
56 void FilterRange::setRange( const double lower, const double upper )
57 {
59  if ( lower == MINUS_INF() && upper == PLUS_INF() ) {
60  m_range = std::nullopt;
61  return;
62  }
63 
66 }
67 
68 void FilterRange::include(double xMin, double xMax)
69 {
72  addRange(xMin,xMax);
73 }
74 
76 {
77  m_range = std::nullopt;
78  return;
79 }
80 
82 // Protected methods:
84 void FilterRange::addRange( const double xMin, const double xMax)
85 {
87  if ( xMin == MINUS_INF() && xMax == PLUS_INF() ) {
88  m_range = std::nullopt;
89  return;
90  }
91 
92  m_range = interval_t( xMin, xMax );
93 }
94 
96 // Operators
98 bool operator==( const FilterRange& r1, const FilterRange& r2 )
99 {
100  if ( r1.isActive() != r2.isActive() ) {
101  return false;
102  }
103 
104  if ( false == r1.isActive() &&
105  false == r2.isActive() ) {
106  return true;
107  }
108  const double precision = std::min( r1.precision(), r2.precision() );
109 
110  return ( ( std::fabs(r1.lower() - r2.lower()) <= precision ) &&
111  ( std::fabs(r1.upper() - r2.upper()) <= precision ) );
112 }
113 
114 bool operator!=( const FilterRange& r1, const FilterRange& r2 )
115 {
116  return !( operator==(r1,r2));
117 }
118 
119 bool operator<( const FilterRange& r1, const FilterRange& r2 )
120 {
121  if ( r1.isActive() != r2.isActive() ) {
123  if ( r2.isActive() ) {
124  // case r1 = [-inf, +inf] and r2 = [a,b]
125  return false;
126  } else {
127  // case r1 = [a, b] and r2 = [-inf, +inf]
128  return true;
129  }
130  }
131 
132  if ( false == r1.isActive() &&
133  false == r2.isActive() ) {
134  return false;
135  }
136 
137  return ( r1.upper() < r2.lower() );
138 }
139 
140 bool operator>=( const FilterRange& r1, const FilterRange& r2 )
141 {
142  return !( operator<(r1,r2) );
143 }
144 
145 bool operator>( const FilterRange& r1, const FilterRange& r2 )
146 {
147  if ( r1.isActive() != r2.isActive() ) {
149  if ( r2.isActive() ) {
150  // case r1 = [-inf, +inf] and r2 = [a,b]
151  return true;
152  } else {
153  // case r1 = [a, b] and r2 = [-inf, +inf]
154  return false;
155  }
156  }
157 
158  if ( false == r1.isActive() &&
159  false == r2.isActive() ) {
160  return false;
161  }
162 
163  return ( r1.lower() > r2.upper() );
164 }
165 
166 bool operator<=( const FilterRange& r1, const FilterRange& r2 )
167 {
168  return !( operator>(r1,r2) );
169 }
170 
171 
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
operator==
bool operator==(const FilterRange &r1, const FilterRange &r2)
Definition: FilterRange.cxx:98
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
operator<=
bool operator<=(const FilterRange &r1, const FilterRange &r2)
Definition: FilterRange.cxx:166
FilterRange
FilterRange implements the range (ie: [min, max]) the filters will use to take their filtering decisi...
Definition: FilterRange.h:35
FilterRange::include
void include(const double xMin, const double xMax)
Add [xMin, xMax] interval to existing set of valid ranges.
Definition: FilterRange.cxx:68
upper
int upper(int c)
Definition: LArBadChannelParser.cxx:49
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.h
FilterRange::includeAll
void includeAll()
Set full range (from MINUS_INF to PLUS_INF ).
Definition: FilterRange.cxx:75
operator<
bool operator<(const FilterRange &r1, const FilterRange &r2)
Definition: FilterRange.cxx:119
operator>
bool operator>(const FilterRange &r1, const FilterRange &r2)
Definition: FilterRange.cxx:145
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
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
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