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 "TRef.h"
|
---|
29 | #include "TObject.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 |
|
---|
50 | Bool_t IsSortable() const { return GetCompare() ? GetCompare()->IsSortable(this) : kFALSE; }
|
---|
51 | Int_t Compare(const TObject *obj) const { return GetCompare()->Compare(this, obj); }
|
---|
52 |
|
---|
53 | virtual const CompBase *GetCompare() const = 0;
|
---|
54 |
|
---|
55 | ClassDef(SortableObject, 1)
|
---|
56 | };
|
---|
57 |
|
---|
58 | //---------------------------------------------------------------------------
|
---|
59 | // Standard Comparison Criteria: E, ET, PT, DeltaR
|
---|
60 | //---------------------------------------------------------------------------
|
---|
61 |
|
---|
62 | template <typename T>
|
---|
63 | class CompE: public CompBase
|
---|
64 | {
|
---|
65 | CompE() {}
|
---|
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 | public:
|
---|
93 | static CompPT *Instance()
|
---|
94 | {
|
---|
95 | static CompPT single;
|
---|
96 | return &single;
|
---|
97 | }
|
---|
98 |
|
---|
99 | Int_t Compare(const TObject *obj1, const TObject *obj2) const
|
---|
100 | {
|
---|
101 | const T *t1 = static_cast<const T*>(obj1);
|
---|
102 | const T *t2 = static_cast<const T*>(obj2);
|
---|
103 | if(t1->PT > t2->PT)
|
---|
104 | return -1;
|
---|
105 | else if(t1->PT < t2->PT)
|
---|
106 | return 1;
|
---|
107 | else
|
---|
108 | return 0;
|
---|
109 | }
|
---|
110 | };
|
---|
111 |
|
---|
112 | //---------------------------------------------------------------------------
|
---|
113 |
|
---|
114 | template <typename T>
|
---|
115 | class CompMomentumPt: public CompBase
|
---|
116 | {
|
---|
117 | CompMomentumPt() {}
|
---|
118 | public:
|
---|
119 | static CompMomentumPt *Instance()
|
---|
120 | {
|
---|
121 | static CompMomentumPt single;
|
---|
122 | return &single;
|
---|
123 | }
|
---|
124 |
|
---|
125 | Int_t Compare(const TObject *obj1, const TObject *obj2) const
|
---|
126 | {
|
---|
127 | const T *t1 = static_cast<const T*>(obj1);
|
---|
128 | const T *t2 = static_cast<const T*>(obj2);
|
---|
129 | if(t1->Momentum.Pt() > t2->Momentum.Pt())
|
---|
130 | return -1;
|
---|
131 | else if(t1->Momentum.Pt() < t2->Momentum.Pt())
|
---|
132 | return 1;
|
---|
133 | else
|
---|
134 | return 0;
|
---|
135 | }
|
---|
136 | };
|
---|
137 |
|
---|
138 | //---------------------------------------------------------------------------
|
---|
139 |
|
---|
140 | template <typename T>
|
---|
141 | class CompET: public CompBase
|
---|
142 | {
|
---|
143 | CompET() {}
|
---|
144 | public:
|
---|
145 | static CompET *Instance()
|
---|
146 | {
|
---|
147 | static CompET 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->ET > t2->ET)
|
---|
156 | return -1;
|
---|
157 | else if(t1->ET < t2->ET)
|
---|
158 | return 1;
|
---|
159 | else
|
---|
160 | return 0;
|
---|
161 | }
|
---|
162 | };
|
---|
163 |
|
---|
164 | //---------------------------------------------------------------------------
|
---|
165 |
|
---|
166 | template <typename T1, typename T2>
|
---|
167 | class CompDeltaR: public CompBase
|
---|
168 | {
|
---|
169 | CompDeltaR(const T2 *obj = 0) : fObj(obj) {}
|
---|
170 |
|
---|
171 | Double_t DeltaPhi(Double_t phi1, Double_t phi2)
|
---|
172 | {
|
---|
173 | Double_t phi = TMath::Abs(phi1 - phi2);
|
---|
174 | return (phi <= TMath::Pi()) ? phi : (2.0*TMath::Pi()) - phi;
|
---|
175 | }
|
---|
176 |
|
---|
177 | Double_t Sqr(Double_t x) { return x*x; }
|
---|
178 |
|
---|
179 | Double_t SumSqr(Double_t a, Double_t b)
|
---|
180 | {
|
---|
181 | Double_t aAbs = TMath::Abs(a);
|
---|
182 | Double_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 CompDeltaR *Instance(const T2 *obj = 0)
|
---|
191 | {
|
---|
192 | static CompDeltaR 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 | Double_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 // SortableObject_h
|
---|
226 |
|
---|
227 |
|
---|