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