# Project CMSSW displayed by LXR

File indexing completed on 2021-06-12 03:09:05

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