Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:18

0001 #ifndef CommonTools_Utils_PtComparator_h
0002 #define CommonTools_Utils_PtComparator_h
0003 /** \class PtComparator
0004  *
0005  * compare by pt
0006  * 
0007  * \author Luca Lista, INFN
0008  *         numeric safe implementation by Fedor Ratnikov, FNAL
0009  *
0010  * \version $Revision: 1.4 $
0011  *
0012  * $Id: PtComparator.h,v 1.4 2007/04/23 20:54:26 llista Exp $
0013  *
0014  */
0015 
0016 template <typename T>
0017 struct LessByPt {
0018   typedef T first_argument_type;
0019   typedef T second_argument_type;
0020   bool operator()(const T& t1, const T& t2) const { return t1.pt() < t2.pt(); }
0021 };
0022 
0023 template <typename T>
0024 struct GreaterByPt {
0025   typedef T first_argument_type;
0026   typedef T second_argument_type;
0027   bool operator()(const T& t1, const T& t2) const { return t1.pt() > t2.pt(); }
0028 };
0029 
0030 #include <limits>
0031 #include <cmath>
0032 
0033 template <class T>
0034 struct NumericSafeLessByPt {
0035   typedef T first_argument_type;
0036   typedef T second_argument_type;
0037   bool operator()(const T& a1, const T& a2) {
0038     return fabs(a1.pt() - a2.pt()) > std::numeric_limits<double>::epsilon()   ? a1.pt() < a2.pt()
0039            : fabs(a1.px() - a2.px()) > std::numeric_limits<double>::epsilon() ? a1.px() < a2.px()
0040                                                                               : a1.pz() < a2.pz();
0041   }
0042 };
0043 
0044 template <class T>
0045 struct NumericSafeGreaterByPt {
0046   typedef T first_argument_type;
0047   typedef T second_argument_type;
0048   bool operator()(const T& a1, const T& a2) {
0049     return fabs(a1.pt() - a2.pt()) > std::numeric_limits<double>::epsilon()   ? a1.pt() > a2.pt()
0050            : fabs(a1.px() - a2.px()) > std::numeric_limits<double>::epsilon() ? a1.px() > a2.px()
0051                                                                               : a1.pz() > a2.pz();
0052   }
0053 };
0054 
0055 #endif