1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#ifndef CommonTools_Utils_PtComparator_h
#define CommonTools_Utils_PtComparator_h
/** \class PtComparator
*
* compare by pt
*
* \author Luca Lista, INFN
* numeric safe implementation by Fedor Ratnikov, FNAL
*
* \version $Revision: 1.4 $
*
* $Id: PtComparator.h,v 1.4 2007/04/23 20:54:26 llista Exp $
*
*/
template <typename T>
struct LessByPt {
typedef T first_argument_type;
typedef T second_argument_type;
bool operator()(const T& t1, const T& t2) const { return t1.pt() < t2.pt(); }
};
template <typename T>
struct GreaterByPt {
typedef T first_argument_type;
typedef T second_argument_type;
bool operator()(const T& t1, const T& t2) const { return t1.pt() > t2.pt(); }
};
#include <limits>
#include <cmath>
template <class T>
struct NumericSafeLessByPt {
typedef T first_argument_type;
typedef T second_argument_type;
bool operator()(const T& a1, const T& a2) {
return fabs(a1.pt() - a2.pt()) > std::numeric_limits<double>::epsilon() ? a1.pt() < a2.pt()
: fabs(a1.px() - a2.px()) > std::numeric_limits<double>::epsilon() ? a1.px() < a2.px()
: a1.pz() < a2.pz();
}
};
template <class T>
struct NumericSafeGreaterByPt {
typedef T first_argument_type;
typedef T second_argument_type;
bool operator()(const T& a1, const T& a2) {
return fabs(a1.pt() - a2.pt()) > std::numeric_limits<double>::epsilon() ? a1.pt() > a2.pt()
: fabs(a1.px() - a2.px()) > std::numeric_limits<double>::epsilon() ? a1.px() > a2.px()
: a1.pz() > a2.pz();
}
};
#endif
|