Fork me on GitHub

source: git/classes/SortableObject.h@ 3e2bb2b

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 3e2bb2b was 3c46e17, checked in by Michele Selvaggi <michele.selvaggi@…>, 8 years ago

added SumPT2 sorting

  • Property mode set to 100644
File size: 5.9 KB
Line 
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
36class CompBase
37{
38public:
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
46class SortableObject: public TObject
47{
48public:
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
62template <typename T>
63class CompE: public CompBase
64{
65 CompE() {}
66public:
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
88template <typename T>
89class CompPT: public CompBase
90{
91 CompPT() {}
92public:
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
114template <typename T>
115class CompMomentumPt: public CompBase
116{
117 CompMomentumPt() {}
118public:
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
140template <typename T>
141class CompET: public CompBase
142{
143 CompET() {}
144public:
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
166template <typename T>
167class CompSumPT2: public CompBase
168{
169 CompSumPT2() {}
170public:
171 static CompSumPT2 *Instance()
172 {
173 static CompSumPT2 single;
174 return &single;
175 }
176
177 Int_t Compare(const TObject *obj1, const TObject *obj2) const
178 {
179 const T *t1 = static_cast<const T*>(obj1);
180 const T *t2 = static_cast<const T*>(obj2);
181 if(t1->SumPT2 > t2->SumPT2)
182 return -1;
183 else if(t1->SumPT2 < t2->SumPT2)
184 return 1;
185 else
186 return 0;
187 }
188};
189
190//---------------------------------------------------------------------------
191
192template <typename T1, typename T2>
193class CompDeltaR: public CompBase
194{
195 CompDeltaR(const T2 *obj = 0) : fObj(obj) {}
196
197 Double_t DeltaPhi(Double_t phi1, Double_t phi2)
198 {
199 Double_t phi = TMath::Abs(phi1 - phi2);
200 return (phi <= TMath::Pi()) ? phi : (2.0*TMath::Pi()) - phi;
201 }
202
203 Double_t Sqr(Double_t x) { return x*x; }
204
205 Double_t SumSqr(Double_t a, Double_t b)
206 {
207 Double_t aAbs = TMath::Abs(a);
208 Double_t bAbs = TMath::Abs(b);
209 if(aAbs > bAbs) return aAbs * TMath::Sqrt(1.0 + Sqr(bAbs / aAbs));
210 else return (bAbs == 0) ? 0.0 : bAbs * TMath::Sqrt(1.0 + Sqr(aAbs / bAbs));
211 };
212
213 const T2 *fObj;
214
215public:
216 static CompDeltaR *Instance(const T2 *obj = 0)
217 {
218 static CompDeltaR single(obj);
219 return &single;
220 }
221
222 void SetObject(const T2 *obj) { fObj = obj; }
223
224 Int_t Compare(const TObject *obj1, const TObject *obj2) const
225 {
226 Double_t eta[3], phi[3], deltaR[2];
227 const T1 *t1 = static_cast<const T1*>(obj1);
228 const T1 *t2 = static_cast<const T1*>(obj2);
229
230 eta[0] = fObj->Eta;
231 phi[0] = fObj->Phi;
232
233 eta[1] = t1->Eta;
234 phi[1] = t1->Phi;
235
236 eta[2] = t2->Eta;
237 phi[2] = t2->Phi;
238
239 deltaR[0] = SumSqr(TMath::Abs(eta[0] - eta[1]), DeltaPhi(phi[0], phi[1]));
240 deltaR[1] = SumSqr(TMath::Abs(eta[0] - eta[2]), DeltaPhi(phi[0], phi[2]));
241
242 if(deltaR[0] < deltaR[1])
243 return -1;
244 else if(deltaR[0] > deltaR[1])
245 return 1;
246 else
247 return 0;
248 }
249};
250
251#endif // SortableObject_h
252
253
Note: See TracBrowser for help on using the repository browser.