CMS 3D CMS Logo

PixelRecoRange.h
Go to the documentation of this file.
1 #ifndef PixelRecoRange_H
2 #define PixelRecoRange_H
3 
6 #include <ostream>
7 #include <utility>
8 #include <algorithm>
9 
12 
13 template<class T> class PixelRecoRange : public std::pair<T,T> {
14 public:
15 
17 
18 
19  template<class U>
21  std::pair<T,T> (other.min(),other.max()) { }
22 
23 
24  PixelRecoRange(T aMin, T aMax)
25  : std::pair<T,T> (aMin,aMax) { }
26 
27  PixelRecoRange(const std::pair<T,T> & aPair )
28  : std::pair<T,T> (aPair) { }
29 
30  T min() const { return this->first; }
31  T max() const { return this->second; }
32  T mean() const { return T(0.5)*(this->first+this->second); }
33 
34  bool empty() const { return (this->second < this->first); }
35 
36  PixelRecoRange<T> & swap() { std::swap(this->second,this->first); return *this;}
37 
38 
39  bool inside(const T & value) const {
40  return !( (value < this->first) | (this->second < value) );
41  }
42 
43  bool hasIntersection( const PixelRecoRange<T> & r) const {
44  return rangesIntersect(*this,r);
45  }
46 
48  return rangeIntersection(*this,r);
49  }
50 
52  if( this->empty()) return r;
53  else if( r.empty()) return *this;
54  else return
56  std::max( max(),r.max())
57  );
58  }
59 
60  PixelRecoRange<T> & sort() { if (empty() ) std::swap(this->first,this->second); return *this;}
61 
62 };
63 
64 template <class T> std::ostream & operator<<(
65  std::ostream& out, const PixelRecoRange<T>& r)
66 {
67  return out << "("<<r.min()<<","<<r.max()<<")";
68 }
69 #endif
PixelRecoRange(const std::pair< T, T > &aPair)
T max() const
PixelRecoRange< T > & sort()
PixelRecoRange< T > & swap()
PixelRecoRange< T > sum(const PixelRecoRange< T > &r) const
bool empty() const
T min() const
PixelRecoRange(PixelRecoRange< U > other)
U second(std::pair< T, U > const &p)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
bool rangesIntersect(const Range &a, const Range &b)
Definition: value.py:1
T min(T a, T b)
Definition: MathUtil.h:58
T mean() const
bool inside(const T &value) const
PixelRecoRange< T > intersection(const PixelRecoRange< T > &r) const
std::ostream & operator<<(std::ostream &out, const PixelRecoRange< T > &r)
bool hasIntersection(const PixelRecoRange< T > &r) const
Range rangeIntersection(const Range &a, const Range &b)
PixelRecoRange(T aMin, T aMax)
long double T