CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/CommonTools/Utils/interface/PtComparator.h

Go to the documentation of this file.
00001 #ifndef CommonTools_Utils_PtComparator_h
00002 #define CommonTools_Utils_PtComparator_h
00003 
00016 template<typename T>
00017 struct LessByPt {
00018   typedef T first_argument_type;
00019   typedef T second_argument_type;
00020   bool operator()( const T & t1, const T & t2 ) const {
00021     return t1.pt() < t2.pt();
00022   }
00023 };
00024 
00025 template<typename T>
00026 struct GreaterByPt {
00027   typedef T first_argument_type;
00028   typedef T second_argument_type;
00029   bool operator()( const T & t1, const T & t2 ) const {
00030     return t1.pt() > t2.pt();
00031   }
00032 };
00033 
00034 #include<limits>
00035 #include <cmath>
00036 
00037 template <class T>
00038 struct NumericSafeLessByPt {
00039   typedef T first_argument_type;
00040   typedef T second_argument_type;
00041   bool operator()(const T& a1, const T& a2) {
00042     return
00043       fabs (a1.pt()-a2.pt()) > std::numeric_limits<double>::epsilon() ? a1.pt() < a2.pt() :
00044       fabs (a1.px()-a2.px()) > std::numeric_limits<double>::epsilon() ? a1.px() < a2.px() :
00045       a1.pz() < a2.pz();
00046   }
00047 };
00048 
00049 template <class T>
00050 struct NumericSafeGreaterByPt {
00051   typedef T first_argument_type;
00052   typedef T second_argument_type;
00053   bool operator()(const T& a1, const T& a2) {
00054     return
00055       fabs (a1.pt()-a2.pt()) > std::numeric_limits<double>::epsilon() ? a1.pt() > a2.pt() :
00056       fabs (a1.px()-a2.px()) > std::numeric_limits<double>::epsilon() ? a1.px() > a2.px() :
00057       a1.pz() > a2.pz();
00058   }
00059 };
00060 
00061 #endif