CMS 3D CMS Logo

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 
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>
89 public:
90  int operator()(const T& a1, const T& a2) {
91  if (!a1)
92  return 0;
93  if (!a2)
94  return 1;
96  return comp.operator()(*a1, *a2);
97  }
98 };
99 template <class T>
101 public:
102  int operator()(const T* a1, const T* a2) {
103  if (!a1)
104  return 0;
105  if (!a2)
106  return 1;
108  return comp.operator()(*a1, *a2);
109  }
110 };
111 
112 template <class T>
114 public:
115  int operator()(const T& a1, const T& a2) {
116  if (!a1)
117  return 0;
118  if (!a2)
119  return 1;
121  return comp.operator()(*a1, *a2);
122  }
123 };
124 
125 #endif
GreaterByPtRef::operator()
int operator()(const T &a1, const T &a2)
Definition: JetAlgoHelper.h:90
mps_fire.i
i
Definition: mps_fire.py:355
PtComparator.h
NumericSafeGreaterByEt
Definition: EtComparator.h:45
AlCaHLTBitMon_QueryRunRegistry.comp
comp
Definition: AlCaHLTBitMon_QueryRunRegistry.py:249
testProducerWithPsetDescEmpty_cfi.a2
a2
Definition: testProducerWithPsetDescEmpty_cfi.py:35
GreaterByEtRef::operator()
int operator()(const T &a1, const T &a2)
Definition: JetAlgoHelper.h:115
NumericSafeGreaterByPt
Definition: PtComparator.h:46
GreaterByPtRef
Definition: JetAlgoHelper.h:88
b
double b
Definition: hdecay.h:118
GreaterByPtPtr::operator()
int operator()(const T *a1, const T *a2)
Definition: JetAlgoHelper.h:102
EtComparator.h
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
relativeConstraints.value
value
Definition: relativeConstraints.py:53
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
GreaterByEtRef
Definition: JetAlgoHelper.h:113
GreaterByPtPtr
Definition: JetAlgoHelper.h:100
HEPTopTaggerV2::result
PseudoJet result(const PseudoJet &jet) const override
Definition: HEPTopTaggerWrapperV2.cc:59
HepMCValidationHelper::sortByPt
bool sortByPt(const HepMC::GenParticle *a, const HepMC::GenParticle *b)
Definition: HepMCValidationHelper.h:15