CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/CommonTools/Utils/interface/EtComparator.h

Go to the documentation of this file.
00001 #ifndef CommonTools_Utils_EtComparator_h
00002 #define CommonTools_Utils_EtComparator_h
00003 
00015 template<typename T>
00016 struct LessByEt {
00017   typedef T first_argument_type;
00018   typedef T second_argument_type;
00019   bool operator()( const T & t1, const T & t2 ) const {
00020     return t1.et() < t2.et();
00021   }
00022 };
00023 
00024 template<typename T>
00025 struct GreaterByEt {
00026   typedef T first_argument_type;
00027   typedef T second_argument_type;
00028   bool operator()( const T & t1, const T & t2 ) const {
00029     return t1.et() > t2.et();
00030   }
00031 };
00032 
00033 
00034 #include<limits>
00035 #include <cmath>
00036 
00037 template <class T>
00038 struct NumericSafeLessByEt {
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.et()-a2.et()) > std::numeric_limits<double>::epsilon() ? a1.et() < a2.et() :
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 NumericSafeGreaterByEt {
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.et()-a2.et()) > std::numeric_limits<double>::epsilon() ? a1.et() > a2.et() :
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