ATLAS Offline Software
PhiFilterRange.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 // PhiFilterRange.cxx
7 // Implementation file for class PhiFilterRange
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 {}
29 
32 {
33  if ( this != &range ) {
35  }
36 
37  return *this;
38 }
39 
43 bool PhiFilterRange::isInRange( const double point ) const
44 {
45  // check if point is in range
46  return FilterRange::isInRange( atlasPhi(point) );
47 }
48 
49 double PhiFilterRange::atlasPhi( const double phi ) const
50 {
51  if ( M_PI == std::fabs(phi) ) {
52  return phi;
53  }
54  if ( FLT_MAX != std::fabs(phi) ) {
55  return std::fmod( phi + 3*M_PI, 2*M_PI ) - M_PI;
56  } else {
57  if ( phi > 0. ) {
58  return M_PI;
59  } else {
60  return -M_PI;
61  }
62  }
63 }
64 
68 void PhiFilterRange::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 PhiFilterRange::addRange( const double xMin, const double xMax)
85 {
87  if ( (xMin == -M_PI && xMax == +M_PI ) ||
88  (xMin == -FLT_MAX && xMax == +FLT_MAX ) ) {
89  m_range = std::nullopt;
90  return;
91  }
92 
94  const double phiMin = atlasPhi( xMin );
95  const double phiMax = atlasPhi( xMax );
96 
97  if ( phiMin < phiMax ) {
98  m_range = interval_t( phiMin, phiMax );
99  } else {
100  m_range = interval_t( phiMax, phiMin );
101  }
102 }
103 
105 // Operators
107 bool operator==( const PhiFilterRange& r1, const PhiFilterRange& r2 )
108 {
109  if ( r1.isActive() != r2.isActive() ) {
110  return false;
111  }
112 
113  if ( false == r1.isActive() &&
114  false == r2.isActive() ) {
115  return true;
116  }
117 
118  const double precision = std::min( r1.precision(), r2.precision() );
119 
120  return ( (std::fabs(r1.lower() - r2.lower()) <= precision ) &&
121  (std::fabs(r1.upper() - r2.upper()) <= precision ) );
122 }
123 
124 bool operator!=( const PhiFilterRange& r1, const PhiFilterRange& r2 )
125 {
126  return !( operator==(r1,r2));
127 }
128 
129 bool operator<( const PhiFilterRange& r1, const PhiFilterRange& r2 )
130 {
131  if ( r1.isActive() != r2.isActive() ) {
133  if ( r2.isActive() ) {
134  // case r1 = [-inf, +inf] and r2 = [a,b]
135  return false;
136  } else {
137  // case r1 = [a, b] and r2 = [-inf, +inf]
138  return true;
139  }
140  }
141 
142  if ( false == r1.isActive() &&
143  false == r2.isActive() ) {
144  return false;
145  }
146 
147  return ( r1.upper() < r2.lower() );
148 }
149 
150 bool operator>=( const PhiFilterRange& r1, const PhiFilterRange& r2 )
151 {
152  return !( operator<(r1,r2) );
153 }
154 
155 bool operator>( const PhiFilterRange& r1, const PhiFilterRange& r2 )
156 {
157  if ( r1.isActive() != r2.isActive() ) {
159  if ( r2.isActive() ) {
160  // case r1 = [-inf, +inf] and r2 = [a,b]
161  return true;
162  } else {
163  // case r1 = [a, b] and r2 = [-inf, +inf]
164  return false;
165  }
166  }
167 
168  if ( false == r1.isActive() &&
169  false == r2.isActive() ) {
170  return false;
171  }
172 
173  return ( r1.lower() > r2.upper() );
174 }
175 
176 bool operator<=( const PhiFilterRange& r1, const PhiFilterRange& r2 )
177 {
178  return !( operator>(r1,r2) );
179 }
180 
181 
PhiFilterRange::PhiFilterRange
PhiFilterRange()
Default constructor: it sets the minimum value to -infinity and the maximum value to +infinity.
Definition: PhiFilterRange.h:141
operator>
bool operator>(const PhiFilterRange &r1, const PhiFilterRange &r2)
Definition: PhiFilterRange.cxx:155
PhiFilterRange::operator=
PhiFilterRange & operator=(const PhiFilterRange &obj)
Assignment operator:
Definition: PhiFilterRange.cxx:31
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 PhiFilterRange &r1, const PhiFilterRange &r2)
Definition: PhiFilterRange.cxx:129
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
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
PhiFilterRange::include
void include(const double xMin, const double xMax)
Add [xMin, xMax] interval to existing set of valid ranges.
Definition: PhiFilterRange.cxx:68
operator==
bool operator==(const PhiFilterRange &r1, const PhiFilterRange &r2)
Definition: PhiFilterRange.cxx:107
operator>=
bool operator>=(const PhiFilterRange &r1, const PhiFilterRange &r2)
Definition: PhiFilterRange.cxx:150
M_PI
#define M_PI
Definition: ActiveFraction.h:11
FilterRange
FilterRange implements the range (ie: [min, max]) the filters will use to take their filtering decisi...
Definition: FilterRange.h:35
PhiFilterRange
PhiFilterRange implements the range (ie: [min, max]) the filters will use to take their filtering dec...
Definition: PhiFilterRange.h:30
operator!=
bool operator!=(const PhiFilterRange &r1, const PhiFilterRange &r2)
Definition: PhiFilterRange.cxx:124
PhiFilterRange::isInRange
bool isInRange(const double point) const
Const methods:
Definition: PhiFilterRange.cxx:43
operator<=
bool operator<=(const PhiFilterRange &r1, const PhiFilterRange &r2)
Definition: PhiFilterRange.cxx:176
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
PhiFilterRange::includeAll
void includeAll()
Set full range (from MINUS_INF to PLUS_INF ).
Definition: PhiFilterRange.cxx:75
PhiFilterRange::atlasPhi
double atlasPhi(const double phi) const
Convert a phi angle in the ATLAS conventional range -PI->PI inspired from FourMom package (could also...
Definition: PhiFilterRange.cxx:49
min
#define min(a, b)
Definition: cfImp.cxx:40
PhiFilterRange.h
FilterRange::operator=
FilterRange & operator=(const FilterRange &obj)
Assignment operator:
Definition: FilterRange.cxx:32
PhiFilterRange::addRange
void addRange(double xMin, double xMax)
add a new range [xmin,xmax] deleting previous ranges full contained
Definition: PhiFilterRange.cxx:84