src
RecoJets
JetAlgorithms
interface
JetAlgoHelper.h
Go to the documentation of this file.
1
#ifndef JetAlgorithms_JetAlgoHelper_h
2
#define JetAlgorithms_JetAlgoHelper_h
3
4
// Various simple tools
5
// F.Ratnikov, UMd
6
7
#include <algorithm>
8
#include <limits>
9
#include <iostream>
10
#include <cmath>
11
#include <vector>
12
13
#include "
CommonTools/Utils/interface/PtComparator.h
"
14
#include "
CommonTools/Utils/interface/EtComparator.h
"
15
16
namespace
{
17
18
struct
SortObject {
19
double
value
;
20
unsigned
index
;
21
};
22
23
inline
bool
so_lt(
const
SortObject&
a
,
const
SortObject&
b
) {
return
a
.value <
b
.value; }
24
inline
bool
so_gt(
const
SortObject&
a
,
const
SortObject&
b
) {
return
a
.value >
b
.value; }
25
26
template
<
class
T>
27
struct
GetPt {
28
inline
double
getValue
(
const
T
&
a
) {
return
a
.pt(); }
29
};
30
template
<
class
T>
31
struct
GetEt {
32
inline
double
getValue
(
const
T
&
a
) {
return
a
.et(); }
33
};
34
template
<
class
T>
35
struct
GetPtRef {
36
inline
double
getValue
(
const
T
&
a
) {
return
a
->pt(); }
37
};
38
template
<
class
T>
39
struct
GetEtRef {
40
inline
double
getValue
(
const
T
&
a
) {
return
a
->et(); }
41
};
42
43
template
<
class
T,
class
GetValue>
44
inline
void
sortGreater(std::vector<T>* container) {
45
std::vector<SortObject>
sortable
(container->size());
46
bool
sorted =
true
;
47
GetValue getter;
48
for
(
unsigned
i
= 0;
i
< container->size();
i
++) {
49
sortable
[
i
].value = getter.getValue((*container)[
i
]);
50
sortable
[
i
].index =
i
;
51
if
(sorted &&
i
&& so_lt(
sortable
[
i
- 1],
sortable
[
i
]))
52
sorted =
false
;
53
}
54
if
(!sorted) {
// needs sorting
55
std::sort
(
sortable
.begin(),
sortable
.end(), so_gt);
56
std::vector<T>
result
;
57
result
.reserve(container->size());
58
for
(
unsigned
i
= 0;
i
< container->size();
i
++) {
59
result
.push_back((*container)[
sortable
[
i
].
index
]);
60
}
61
container->swap(
result
);
62
}
63
}
64
65
template
<
class
T>
66
inline
void
sortByPt
(std::vector<T>* container) {
67
sortGreater<T, GetPt<T> >(container);
68
}
69
70
template
<
class
T>
71
inline
void
sortByEt(std::vector<T>* container) {
72
sortGreater<T, GetEt<T> >(container);
73
}
74
75
template
<
class
T>
76
inline
void
sortByPtRef
(std::vector<T>* container) {
77
sortGreater<T, GetPtRef<T> >(container);
78
}
79
80
template
<
class
T>
81
inline
void
sortByEtRef(std::vector<T>* container) {
82
sortGreater<T, GetEtRef<T> >(container);
83
}
84
85
}
// namespace
86
87
template
<
class
T>
88
class
GreaterByPtRef
{
89
public
:
90
int
operator()
(
const
T
& a1,
const
T
&
a2
) {
91
if
(!a1)
92
return
0;
93
if
(!
a2
)
94
return
1;
95
NumericSafeGreaterByPt<typename T::value_type>
comp
;
96
return
comp
.operator()(*a1, *
a2
);
97
}
98
};
99
template
<
class
T>
100
class
GreaterByPtPtr
{
101
public
:
102
int
operator()
(
const
T
* a1,
const
T
*
a2
) {
103
if
(!a1)
104
return
0;
105
if
(!
a2
)
106
return
1;
107
NumericSafeGreaterByPt<T>
comp
;
108
return
comp
.operator()(*a1, *
a2
);
109
}
110
};
111
112
template
<
class
T>
113
class
GreaterByEtRef
{
114
public
:
115
int
operator()
(
const
T
& a1,
const
T
&
a2
) {
116
if
(!a1)
117
return
0;
118
if
(!
a2
)
119
return
1;
120
NumericSafeGreaterByEt<typename T::value_type>
comp
;
121
return
comp
.operator()(*a1, *
a2
);
122
}
123
};
124
125
#endif
GreaterByPtRef
Definition:
JetAlgoHelper.h:88
jetUpdater_cfi.sort
sort
Definition:
jetUpdater_cfi.py:30
mps_fire.i
i
Definition:
mps_fire.py:429
HEPTopTaggerV2::result
PseudoJet result(const PseudoJet &jet) const override
Definition:
HEPTopTaggerWrapperV2.cc:59
GreaterByEtRef::operator()
int operator()(const T &a1, const T &a2)
Definition:
JetAlgoHelper.h:115
HepMCValidationHelper::sortByPt
bool sortByPt(const HepMC::GenParticle *a, const HepMC::GenParticle *b)
Definition:
HepMCValidationHelper.h:15
NumericSafeGreaterByEt
Definition:
EtComparator.h:44
EtComparator.h
AlCaHLTBitMon_QueryRunRegistry.comp
string comp
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:249
HepMCValidationHelper::sortByPtRef
bool sortByPtRef(const T lhs, const T rhs)
Definition:
HepMCValidationHelper.h:20
PtComparator.h
GreaterByEtRef
Definition:
JetAlgoHelper.h:113
AlignmentPI::index
index
Definition:
AlignmentPayloadInspectorHelper.h:71
NumericSafeGreaterByPt
Definition:
PtComparator.h:45
GreaterByPtPtr
Definition:
JetAlgoHelper.h:100
postprocess-scan-build.sortable
sortable
Definition:
postprocess-scan-build.py:19
testProducerWithPsetDescEmpty_cfi.a2
a2
Definition:
testProducerWithPsetDescEmpty_cfi.py:35
relativeConstraints.value
value
Definition:
relativeConstraints.py:53
b
double b
Definition:
hdecay.h:118
GreaterByPtPtr::operator()
int operator()(const T *a1, const T *a2)
Definition:
JetAlgoHelper.h:102
a
double a
Definition:
hdecay.h:119
reco::JetExtendedAssociation::getValue
const JetExtendedData & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
Definition:
JetExtendedAssociation.cc:50
T
long double T
Definition:
Basic3DVectorLD.h:48
GreaterByPtRef::operator()
int operator()(const T &a1, const T &a2)
Definition:
JetAlgoHelper.h:90
Generated for CMSSW Reference Manual by
1.8.14