Fork me on GitHub

source: svn/trunk/Utilities/ExRootAnalysis/interface/BlockCompare.h@ 337

Last change on this file since 337 was 220, checked in by Xavier Rouby, 16 years ago

include statements have been cleaned

File size: 4.7 KB
RevLine 
[3]1#ifndef BLOCKCOMPARE_H
2#define BLOCKCOMPARE_H
3
4/** \class BlockCompare
5 *
6 * Definition of comparison object functions for block classes
7 *
[220]8 * $Date: 2009-02-02 11:32:12 $
9 * $Revision: 1.2 $
[3]10 *
11 *
12 * \author S. Ovyn - UCL, Louvain-la-Neuve
13 *
14 */
15
16#include "Rtypes.h"
17#include "TMath.h"
18
19//------------------------------------------------------------------------------
20
21class TObject;
22
23class TCompare
24{
25public:
26 virtual Bool_t IsSortable(const TObject *obj) const { return kTRUE; }
27 virtual Int_t Compare(const TObject *obj1, const TObject *obj2) const = 0;
28 virtual ~TCompare() {};
29};
30
31//---------------------------------------------------------------------------
32
33template <typename T>
34class TCompareE: public TCompare
35{
36 TCompareE() {}
37public:
38 static TCompareE *Instance()
39 {
40 static TCompareE single;
41 return &single;
42 }
43
44 Int_t Compare(const TObject *obj1, const TObject *obj2) const
45 {
46 const T *t1 = static_cast<const T*>(obj1);
47 const T *t2 = static_cast<const T*>(obj2);
48 if(t1->E > t2->E)
49 return -1;
50 else if(t1->E < t2->E)
51 return 1;
52 else
53 return 0;
54 }
55};
56
57//---------------------------------------------------------------------------
58
59template <typename T>
60class TComparePT: public TCompare
61{
62 TComparePT() {}
63public:
64 static TComparePT *Instance()
65 {
66 static TComparePT single;
67 return &single;
68 }
69
70 Int_t Compare(const TObject *obj1, const TObject *obj2) const
71 {
72 const T *t1 = static_cast<const T*>(obj1);
73 const T *t2 = static_cast<const T*>(obj2);
74 if(t1->PT > t2->PT)
75 return -1;
76 else if(t1->PT < t2->PT)
77 return 1;
78 else
79 return 0;
80 }
81};
82
83//---------------------------------------------------------------------------
84
85template <typename T>
86class TCompareET: public TCompare
87{
88 TCompareET() {}
89public:
90 static TCompareET *Instance()
91 {
92 static TCompareET single;
93 return &single;
94 }
95
96 Int_t Compare(const TObject *obj1, const TObject *obj2) const
97 {
98 const T *t1 = static_cast<const T*>(obj1);
99 const T *t2 = static_cast<const T*>(obj2);
100 if(t1->ET > t2->ET)
101 return -1;
102 else if(t1->ET < t2->ET)
103 return 1;
104 else
105 return 0;
106 }
107};
108
109//---------------------------------------------------------------------------
110
111template <typename T>
112class TCompareCalPT: public TCompare
113{
114 TCompareCalPT() {}
115public:
116 static TCompareCalPT *Instance()
117 {
118 static TCompareCalPT single;
119 return &single;
120 }
121
122 Int_t Compare(const TObject *obj1, const TObject *obj2) const
123 {
124 const T *t1 = static_cast<const T*>(obj1);
125 const T *t2 = static_cast<const T*>(obj2);
126 if(t1->CalPT > t2->CalPT)
127 return -1;
128 else if(t1->CalPT < t2->CalPT)
129 return 1;
130 else
131 return 0;
132 }
133};
134
135
136//---------------------------------------------------------------------------
137
138template <typename T>
139class TCompareCalET: public TCompare
140{
141 TCompareCalET() {}
142public:
143 static TCompareCalET *Instance()
144 {
145 static TCompareCalET single;
146 return &single;
147 }
148
149 Int_t Compare(const TObject *obj1, const TObject *obj2) const
150 {
151 const T *t1 = static_cast<const T*>(obj1);
152 const T *t2 = static_cast<const T*>(obj2);
153 if(t1->CalET > t2->CalET)
154 return -1;
155 else if(t1->CalET < t2->CalET)
156 return 1;
157 else
158 return 0;
159 }
160};
161
162//---------------------------------------------------------------------------
163
164template <typename T1, typename T2>
165class TCompareDeltaR: public TCompare
166{
167 TCompareDeltaR(const T2 *obj = 0) : fObj(obj) {}
168
169 Float_t DeltaPhi(Float_t phi1, Float_t phi2)
170 {
171 Float_t phi = TMath::Abs(phi1 - phi2);
172 return (phi <= TMath::Pi()) ? phi : (2.0*TMath::Pi()) - phi;
173 }
174
175 Float_t Sqr(Float_t x) { return x*x; }
176
177 Float_t SumSqr(Float_t a, Float_t b)
178 {
179 Float_t aAbs = TMath::Abs(a);
180 Float_t bAbs = TMath::Abs(b);
181 if(aAbs > bAbs) return aAbs * TMath::Sqrt(1.0 + Sqr(bAbs / aAbs));
182 else return (bAbs == 0) ? 0.0 : bAbs * TMath::Sqrt(1.0 + Sqr(aAbs / bAbs));
183 };
184
185 const T2 *fObj;
186
187public:
188 static TCompareDeltaR *Instance(const T2 *obj = 0)
189 {
190 static TCompareDeltaR single(obj);
191 return &single;
192 }
193
194 void SetObject(const T2 *obj) { fObj = obj; }
195
196 Int_t Compare(const TObject *obj1, const TObject *obj2) const
197 {
198 Float_t eta[3], phi[3], deltaR[2];
199 const T1 *t1 = static_cast<const T1*>(obj1);
200 const T1 *t2 = static_cast<const T1*>(obj2);
201
202 eta[0] = fObj->Eta;
203 phi[0] = fObj->Phi;
204
205 eta[1] = t1->Eta;
206 phi[1] = t1->Phi;
207
208 eta[2] = t2->Eta;
209 phi[2] = t2->Phi;
210
211 deltaR[0] = SumSqr(TMath::Abs(eta[0] - eta[1]), DeltaPhi(phi[0], phi[1]));
212 deltaR[1] = SumSqr(TMath::Abs(eta[0] - eta[2]), DeltaPhi(phi[0], phi[2]));
213
214 if(deltaR[0] < deltaR[1])
215 return -1;
216 else if(deltaR[0] > deltaR[1])
217 return 1;
218 else
219 return 0;
220 }
221};
222
223#endif // BLOCKCOMPARE_H
Note: See TracBrowser for help on using the repository browser.