1 | /*
|
---|
2 | * Delphes: a framework for fast simulation of a generic collider experiment
|
---|
3 | * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
|
---|
4 | *
|
---|
5 | * This program is free software: you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef SortableObject_h
|
---|
20 | #define SortableObject_h
|
---|
21 |
|
---|
22 | /** \class SortableObject
|
---|
23 | *
|
---|
24 | * \author P. Demin - UCL, Louvain-la-Neuve
|
---|
25 | *
|
---|
26 | */
|
---|
27 |
|
---|
28 | #include "TObject.h"
|
---|
29 | #include "TRef.h"
|
---|
30 | #include "TRefArray.h"
|
---|
31 |
|
---|
32 | #include "TMath.h"
|
---|
33 |
|
---|
34 | //---------------------------------------------------------------------------
|
---|
35 |
|
---|
36 | class CompBase
|
---|
37 | {
|
---|
38 | public:
|
---|
39 | virtual ~CompBase() {}
|
---|
40 | virtual Bool_t IsSortable(const TObject *) const { return kTRUE; }
|
---|
41 | virtual Int_t Compare(const TObject *obj1, const TObject *obj2) const = 0;
|
---|
42 | };
|
---|
43 |
|
---|
44 | //---------------------------------------------------------------------------
|
---|
45 |
|
---|
46 | class SortableObject: public TObject
|
---|
47 | {
|
---|
48 | public:
|
---|
49 | Bool_t IsSortable() const { return GetCompare() ? GetCompare()->IsSortable(this) : kFALSE; }
|
---|
50 | Int_t Compare(const TObject *obj) const { return GetCompare()->Compare(this, obj); }
|
---|
51 |
|
---|
52 | virtual const CompBase *GetCompare() const = 0;
|
---|
53 |
|
---|
54 | ClassDef(SortableObject, 1)
|
---|
55 | };
|
---|
56 |
|
---|
57 | //---------------------------------------------------------------------------
|
---|
58 | // Standard Comparison Criteria: E, ET, PT, DeltaR
|
---|
59 | //---------------------------------------------------------------------------
|
---|
60 |
|
---|
61 | template <typename T>
|
---|
62 | class CompE: public CompBase
|
---|
63 | {
|
---|
64 | CompE() {}
|
---|
65 |
|
---|
66 | public:
|
---|
67 | static CompE *Instance()
|
---|
68 | {
|
---|
69 | static CompE single;
|
---|
70 | return &single;
|
---|
71 | }
|
---|
72 |
|
---|
73 | Int_t Compare(const TObject *obj1, const TObject *obj2) const
|
---|
74 | {
|
---|
75 | const T *t1 = static_cast<const T *>(obj1);
|
---|
76 | const T *t2 = static_cast<const T *>(obj2);
|
---|
77 | if(t1->E > t2->E)
|
---|
78 | return -1;
|
---|
79 | else if(t1->E < t2->E)
|
---|
80 | return 1;
|
---|
81 | else
|
---|
82 | return 0;
|
---|
83 | }
|
---|
84 | };
|
---|
85 |
|
---|
86 | //---------------------------------------------------------------------------
|
---|
87 |
|
---|
88 | template <typename T>
|
---|
89 | class CompPT: public CompBase
|
---|
90 | {
|
---|
91 | CompPT() {}
|
---|
92 |
|
---|
93 | public:
|
---|
94 | static CompPT *Instance()
|
---|
95 | {
|
---|
96 | static CompPT single;
|
---|
97 | return &single;
|
---|
98 | }
|
---|
99 |
|
---|
100 | Int_t Compare(const TObject *obj1, const TObject *obj2) const
|
---|
101 | {
|
---|
102 | const T *t1 = static_cast<const T *>(obj1);
|
---|
103 | const T *t2 = static_cast<const T *>(obj2);
|
---|
104 | if(t1->PT > t2->PT)
|
---|
105 | return -1;
|
---|
106 | else if(t1->PT < t2->PT)
|
---|
107 | return 1;
|
---|
108 | else
|
---|
109 | return 0;
|
---|
110 | }
|
---|
111 | };
|
---|
112 |
|
---|
113 | //---------------------------------------------------------------------------
|
---|
114 |
|
---|
115 | template <typename T>
|
---|
116 | class CompMomentumPt: public CompBase
|
---|
117 | {
|
---|
118 | CompMomentumPt() {}
|
---|
119 |
|
---|
120 | public:
|
---|
121 | static CompMomentumPt *Instance()
|
---|
122 | {
|
---|
123 | static CompMomentumPt single;
|
---|
124 | return &single;
|
---|
125 | }
|
---|
126 |
|
---|
127 | Int_t Compare(const TObject *obj1, const TObject *obj2) const
|
---|
128 | {
|
---|
129 | const T *t1 = static_cast<const T *>(obj1);
|
---|
130 | const T *t2 = static_cast<const T *>(obj2);
|
---|
131 | if(t1->Momentum.Pt() > t2->Momentum.Pt())
|
---|
132 | return -1;
|
---|
133 | else if(t1->Momentum.Pt() < t2->Momentum.Pt())
|
---|
134 | return 1;
|
---|
135 | else
|
---|
136 | return 0;
|
---|
137 | }
|
---|
138 | };
|
---|
139 |
|
---|
140 | //---------------------------------------------------------------------------
|
---|
141 |
|
---|
142 | template <typename T>
|
---|
143 | class CompET: public CompBase
|
---|
144 | {
|
---|
145 | CompET() {}
|
---|
146 |
|
---|
147 | public:
|
---|
148 | static CompET *Instance()
|
---|
149 | {
|
---|
150 | static CompET single;
|
---|
151 | return &single;
|
---|
152 | }
|
---|
153 |
|
---|
154 | Int_t Compare(const TObject *obj1, const TObject *obj2) const
|
---|
155 | {
|
---|
156 | const T *t1 = static_cast<const T *>(obj1);
|
---|
157 | const T *t2 = static_cast<const T *>(obj2);
|
---|
158 | if(t1->ET > t2->ET)
|
---|
159 | return -1;
|
---|
160 | else if(t1->ET < t2->ET)
|
---|
161 | return 1;
|
---|
162 | else
|
---|
163 | return 0;
|
---|
164 | }
|
---|
165 | };
|
---|
166 |
|
---|
167 | //---------------------------------------------------------------------------
|
---|
168 |
|
---|
169 | template <typename T>
|
---|
170 | class CompSumPT2: public CompBase
|
---|
171 | {
|
---|
172 | CompSumPT2() {}
|
---|
173 |
|
---|
174 | public:
|
---|
175 | static CompSumPT2 *Instance()
|
---|
176 | {
|
---|
177 | static CompSumPT2 single;
|
---|
178 | return &single;
|
---|
179 | }
|
---|
180 |
|
---|
181 | Int_t Compare(const TObject *obj1, const TObject *obj2) const
|
---|
182 | {
|
---|
183 | const T *t1 = static_cast<const T *>(obj1);
|
---|
184 | const T *t2 = static_cast<const T *>(obj2);
|
---|
185 | if(t1->SumPT2 > t2->SumPT2)
|
---|
186 | return -1;
|
---|
187 | else if(t1->SumPT2 < t2->SumPT2)
|
---|
188 | return 1;
|
---|
189 | else
|
---|
190 | return 0;
|
---|
191 | }
|
---|
192 | };
|
---|
193 |
|
---|
194 | //---------------------------------------------------------------------------
|
---|
195 |
|
---|
196 | template <typename T1, typename T2>
|
---|
197 | class CompDeltaR: public CompBase
|
---|
198 | {
|
---|
199 | CompDeltaR(const T2 *obj = 0) :
|
---|
200 | fObj(obj) {}
|
---|
201 |
|
---|
202 | Double_t DeltaPhi(Double_t phi1, Double_t phi2)
|
---|
203 | {
|
---|
204 | Double_t phi = TMath::Abs(phi1 - phi2);
|
---|
205 | return (phi <= TMath::Pi()) ? phi : (2.0 * TMath::Pi()) - phi;
|
---|
206 | }
|
---|
207 |
|
---|
208 | Double_t Sqr(Double_t x) { return x * x; }
|
---|
209 |
|
---|
210 | Double_t SumSqr(Double_t a, Double_t b)
|
---|
211 | {
|
---|
212 | Double_t aAbs = TMath::Abs(a);
|
---|
213 | Double_t bAbs = TMath::Abs(b);
|
---|
214 | if(aAbs > bAbs)
|
---|
215 | return aAbs * TMath::Sqrt(1.0 + Sqr(bAbs / aAbs));
|
---|
216 | else
|
---|
217 | return (bAbs == 0) ? 0.0 : bAbs * TMath::Sqrt(1.0 + Sqr(aAbs / bAbs));
|
---|
218 | };
|
---|
219 |
|
---|
220 | const T2 *fObj;
|
---|
221 |
|
---|
222 | public:
|
---|
223 | static CompDeltaR *Instance(const T2 *obj = 0)
|
---|
224 | {
|
---|
225 | static CompDeltaR single(obj);
|
---|
226 | return &single;
|
---|
227 | }
|
---|
228 |
|
---|
229 | void SetObject(const T2 *obj) { fObj = obj; }
|
---|
230 |
|
---|
231 | Int_t Compare(const TObject *obj1, const TObject *obj2) const
|
---|
232 | {
|
---|
233 | Double_t eta[3], phi[3], deltaR[2];
|
---|
234 | const T1 *t1 = static_cast<const T1 *>(obj1);
|
---|
235 | const T1 *t2 = static_cast<const T1 *>(obj2);
|
---|
236 |
|
---|
237 | eta[0] = fObj->Eta;
|
---|
238 | phi[0] = fObj->Phi;
|
---|
239 |
|
---|
240 | eta[1] = t1->Eta;
|
---|
241 | phi[1] = t1->Phi;
|
---|
242 |
|
---|
243 | eta[2] = t2->Eta;
|
---|
244 | phi[2] = t2->Phi;
|
---|
245 |
|
---|
246 | deltaR[0] = SumSqr(TMath::Abs(eta[0] - eta[1]), DeltaPhi(phi[0], phi[1]));
|
---|
247 | deltaR[1] = SumSqr(TMath::Abs(eta[0] - eta[2]), DeltaPhi(phi[0], phi[2]));
|
---|
248 |
|
---|
249 | if(deltaR[0] < deltaR[1])
|
---|
250 | return -1;
|
---|
251 | else if(deltaR[0] > deltaR[1])
|
---|
252 | return 1;
|
---|
253 | else
|
---|
254 | return 0;
|
---|
255 | }
|
---|
256 | };
|
---|
257 |
|
---|
258 | #endif // SortableObject_h
|
---|