CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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<limits>
8 #include <iostream>
9 #include <cmath>
10 
13 
14 namespace {
15 
16  struct SortObject {
17  double value;
18  unsigned index;
19  };
20 
21  inline bool so_lt (const SortObject& a, const SortObject& b) {return a.value < b.value;}
22  inline bool so_gt (const SortObject& a, const SortObject& b) {return a.value > b.value;}
23 
24  template <class T> struct GetPt {inline double getValue (const T& a) {return a.pt();}};
25  template <class T> struct GetEt {inline double getValue (const T& a) {return a.et();}};
26  template <class T> struct GetPtRef {inline double getValue (const T& a) {return a->pt();}};
27  template <class T> struct GetEtRef {inline double getValue (const T& a) {return a->et();}};
28 
29  template <class T, class GetValue>
30  inline void sortGreater (std::vector <T>* container) {
31  std::vector <SortObject> sortable (container->size());
32  bool sorted = true;
33  GetValue getter;
34  for (unsigned i = 0; i < container->size(); i++) {
35  sortable[i].value = getter.getValue ((*container)[i]);
36  sortable[i].index = i;
37  if (sorted && i && so_lt (sortable[i-1], sortable[i])) sorted = false;
38  }
39  if (!sorted) { // needs sorting
40  std::sort (sortable.begin(), sortable.end(), so_gt);
41  std::vector <T> result;
42  result.reserve(container->size());
43  for (unsigned i = 0; i < container->size(); i++) {
44  result.push_back ((*container)[sortable[i].index]);
45  }
46  container->swap (result);
47  }
48  }
49 
50  template <class T>
51  inline void sortByPt (std::vector <T>* container) {
52  sortGreater <T, GetPt<T> > (container);
53  }
54 
55  template <class T>
56  inline void sortByEt (std::vector <T>* container) {
57  sortGreater <T, GetEt<T> > (container);
58  }
59 
60 
61  template <class T>
62  inline void sortByPtRef (std::vector <T>* container) {
63  sortGreater <T, GetPtRef<T> > (container);
64  }
65 
66  template <class T>
67  inline void sortByEtRef (std::vector <T>* container) {
68  sortGreater <T, GetEtRef<T> > (container);
69  }
70 
71 }
72 
73 template <class T>
75  public:
76  int operator()(const T& a1, const T& a2) {
77  if (!a1) return 0;
78  if (!a2) return 1;
80  return comp.operator () (*a1, *a2);
81  }
82 };
83 template <class T>
85  public:
86  int operator()(const T* a1, const T* a2) {
87  if (!a1) return 0;
88  if (!a2) return 1;
90  return comp.operator () (*a1, *a2);
91  }
92 };
93 
94 template <class T>
96  public:
97  int operator()(const T& a1, const T& a2) {
98  if (!a1) return 0;
99  if (!a2) return 1;
101  return comp.operator () (*a1, *a2);
102  }
103 };
104 
105 #endif
int i
Definition: DBlmapReader.cc:9
int operator()(const T &a1, const T &a2)
Definition: JetAlgoHelper.h:97
bool sortByPt(const HepMC::GenParticle *a, const HepMC::GenParticle *b)
virtual PseudoJet result(const PseudoJet &jet) const
double b
Definition: hdecay.h:120
int operator()(const T *a1, const T *a2)
Definition: JetAlgoHelper.h:86
double a
Definition: hdecay.h:121
const JetExtendedData & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
long double T
int operator()(const T &a1, const T &a2)
Definition: JetAlgoHelper.h:76