Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:04

0001 #ifndef MuonIsolation_Range_H
0002 #define MuonIsolation_Range_H
0003 
0004 /** \class muonisolation::Range
0005  *  Define a range [aMin,aMax] 
0006  */
0007 
0008 #include <iostream>
0009 #include <utility>
0010 #include <algorithm>
0011 
0012 namespace muonisolation {
0013 
0014   template <class T>
0015   class Range : public std::pair<T, T> {
0016   public:
0017     Range() {}
0018 
0019     Range(const T& aMin, const T& aMax) : std::pair<T, T>(aMin, aMax) {}
0020 
0021     Range(const std::pair<T, T>& aPair) : std::pair<T, T>(aPair) {}
0022 
0023     const T& min() const { return this->first; }
0024 
0025     const T& max() const { return this->second; }
0026 
0027     T mean() const { return (this->first + this->second) / 2.; }
0028 
0029     bool empty() const { return (this->second < this->first); }
0030 
0031     bool inside(const T& value) const {
0032       if (value < this->first || this->second < value)
0033         return false;
0034       else
0035         return true;
0036     }
0037 
0038     void sort() {
0039       if (empty())
0040         std::swap(this->first, this->second);
0041     }
0042   };
0043 
0044 }  // namespace muonisolation
0045 
0046 template <class T>
0047 std::ostream& operator<<(std::ostream& out, const muonisolation::Range<T>& r) {
0048   return out << "(" << r.min() << "," << r.max() << ")";
0049 }
0050 
0051 #endif