Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:51

0001 #ifndef PixelRecoRange_H
0002 #define PixelRecoRange_H
0003 
0004 /** Define a range [aMin,aMax] */
0005 
0006 #include <ostream>
0007 #include <utility>
0008 #include <algorithm>
0009 
0010 #include "TrackingTools/DetLayers/interface/rangesIntersect.h"
0011 #include "RecoTracker/TkMSParametrization/interface/rangeIntersection.h"
0012 
0013 template <class T>
0014 class PixelRecoRange : public std::pair<T, T> {
0015 public:
0016   PixelRecoRange() {}
0017 
0018   template <class U>
0019   PixelRecoRange(PixelRecoRange<U> other) : std::pair<T, T>(other.min(), other.max()) {}
0020 
0021   PixelRecoRange(T aMin, T aMax) : std::pair<T, T>(aMin, aMax) {}
0022 
0023   PixelRecoRange(const std::pair<T, T>& aPair) : std::pair<T, T>(aPair) {}
0024 
0025   T min() const { return this->first; }
0026   T max() const { return this->second; }
0027   T mean() const { return T(0.5) * (this->first + this->second); }
0028 
0029   bool empty() const { return (this->second < this->first); }
0030 
0031   PixelRecoRange<T>& swap() {
0032     std::swap(this->second, this->first);
0033     return *this;
0034   }
0035 
0036   bool inside(const T& value) const { return !((value < this->first) | (this->second < value)); }
0037 
0038   bool hasIntersection(const PixelRecoRange<T>& r) const { return rangesIntersect(*this, r); }
0039 
0040   PixelRecoRange<T> intersection(const PixelRecoRange<T>& r) const { return rangeIntersection(*this, r); }
0041 
0042   PixelRecoRange<T> sum(const PixelRecoRange<T>& r) const {
0043     if (this->empty())
0044       return r;
0045     else if (r.empty())
0046       return *this;
0047     else
0048       return PixelRecoRange(std::min(min(), r.min()), std::max(max(), r.max()));
0049   }
0050 
0051   PixelRecoRange<T>& sort() {
0052     if (empty())
0053       std::swap(this->first, this->second);
0054     return *this;
0055   }
0056 };
0057 
0058 template <class T>
0059 std::ostream& operator<<(std::ostream& out, const PixelRecoRange<T>& r) {
0060   return out << "(" << r.min() << "," << r.max() << ")";
0061 }
0062 #endif