Fork me on GitHub

source: git/classes/SortableObject.h@ 0f8390e

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 0f8390e was 1fa50c2, checked in by Pavel Demin <pavel.demin@…>, 10 years ago

fix GPLv3 header

  • Property mode set to 100644
File size: 5.5 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 *
25 * $Date: 2008-06-04 13:57:26 $
26 * $Revision: 1.1 $
27 *
28 *
29 * \author P. Demin - UCL, Louvain-la-Neuve
30 *
31 */
32
33#include "TRef.h"
34#include "TObject.h"
35#include "TRefArray.h"
36
37#include "TMath.h"
38
39//---------------------------------------------------------------------------
40
41class CompBase
42{
43public:
44 virtual ~CompBase() { }
45 virtual Bool_t IsSortable(const TObject *) const { return kTRUE; }
46 virtual Int_t Compare(const TObject *obj1, const TObject *obj2) const = 0;
47};
48
49//---------------------------------------------------------------------------
50
51class SortableObject: public TObject
52{
53public:
54
55 Bool_t IsSortable() const { return GetCompare() ? GetCompare()->IsSortable(this) : kFALSE; }
56 Int_t Compare(const TObject *obj) const { return GetCompare()->Compare(this, obj); }
57
58 virtual const CompBase *GetCompare() const = 0;
59
60 ClassDef(SortableObject, 1)
61};
62
63//---------------------------------------------------------------------------
64// Standard Comparison Criteria: E, ET, PT, DeltaR
65//---------------------------------------------------------------------------
66
67template <typename T>
68class CompE: public CompBase
69{
70 CompE() {}
71public:
72 static CompE *Instance()
73 {
74 static CompE single;
75 return &single;
76 }
77
78 Int_t Compare(const TObject *obj1, const TObject *obj2) const
79 {
80 const T *t1 = static_cast<const T*>(obj1);
81 const T *t2 = static_cast<const T*>(obj2);
82 if(t1->E > t2->E)
83 return -1;
84 else if(t1->E < t2->E)
85 return 1;
86 else
87 return 0;
88 }
89};
90
91//---------------------------------------------------------------------------
92
93template <typename T>
94class CompPT: public CompBase
95{
96 CompPT() {}
97public:
98 static CompPT *Instance()
99 {
100 static CompPT single;
101 return &single;
102 }
103
104 Int_t Compare(const TObject *obj1, const TObject *obj2) const
105 {
106 const T *t1 = static_cast<const T*>(obj1);
107 const T *t2 = static_cast<const T*>(obj2);
108 if(t1->PT > t2->PT)
109 return -1;
110 else if(t1->PT < t2->PT)
111 return 1;
112 else
113 return 0;
114 }
115};
116
117//---------------------------------------------------------------------------
118
119template <typename T>
120class CompMomentumPt: public CompBase
121{
122 CompMomentumPt() {}
123public:
124 static CompMomentumPt *Instance()
125 {
126 static CompMomentumPt single;
127 return &single;
128 }
129
130 Int_t Compare(const TObject *obj1, const TObject *obj2) const
131 {
132 const T *t1 = static_cast<const T*>(obj1);
133 const T *t2 = static_cast<const T*>(obj2);
134 if(t1->Momentum.Pt() > t2->Momentum.Pt())
135 return -1;
136 else if(t1->Momentum.Pt() < t2->Momentum.Pt())
137 return 1;
138 else
139 return 0;
140 }
141};
142
143//---------------------------------------------------------------------------
144
145template <typename T>
146class CompET: public CompBase
147{
148 CompET() {}
149public:
150 static CompET *Instance()
151 {
152 static CompET single;
153 return &single;
154 }
155
156 Int_t Compare(const TObject *obj1, const TObject *obj2) const
157 {
158 const T *t1 = static_cast<const T*>(obj1);
159 const T *t2 = static_cast<const T*>(obj2);
160 if(t1->ET > t2->ET)
161 return -1;
162 else if(t1->ET < t2->ET)
163 return 1;
164 else
165 return 0;
166 }
167};
168
169//---------------------------------------------------------------------------
170
171template <typename T1, typename T2>
172class CompDeltaR: public CompBase
173{
174 CompDeltaR(const T2 *obj = 0) : fObj(obj) {}
175
176 Double_t DeltaPhi(Double_t phi1, Double_t phi2)
177 {
178 Double_t phi = TMath::Abs(phi1 - phi2);
179 return (phi <= TMath::Pi()) ? phi : (2.0*TMath::Pi()) - phi;
180 }
181
182 Double_t Sqr(Double_t x) { return x*x; }
183
184 Double_t SumSqr(Double_t a, Double_t b)
185 {
186 Double_t aAbs = TMath::Abs(a);
187 Double_t bAbs = TMath::Abs(b);
188 if(aAbs > bAbs) return aAbs * TMath::Sqrt(1.0 + Sqr(bAbs / aAbs));
189 else return (bAbs == 0) ? 0.0 : bAbs * TMath::Sqrt(1.0 + Sqr(aAbs / bAbs));
190 };
191
192 const T2 *fObj;
193
194public:
195 static CompDeltaR *Instance(const T2 *obj = 0)
196 {
197 static CompDeltaR single(obj);
198 return &single;
199 }
200
201 void SetObject(const T2 *obj) { fObj = obj; }
202
203 Int_t Compare(const TObject *obj1, const TObject *obj2) const
204 {
205 Double_t eta[3], phi[3], deltaR[2];
206 const T1 *t1 = static_cast<const T1*>(obj1);
207 const T1 *t2 = static_cast<const T1*>(obj2);
208
209 eta[0] = fObj->Eta;
210 phi[0] = fObj->Phi;
211
212 eta[1] = t1->Eta;
213 phi[1] = t1->Phi;
214
215 eta[2] = t2->Eta;
216 phi[2] = t2->Phi;
217
218 deltaR[0] = SumSqr(TMath::Abs(eta[0] - eta[1]), DeltaPhi(phi[0], phi[1]));
219 deltaR[1] = SumSqr(TMath::Abs(eta[0] - eta[2]), DeltaPhi(phi[0], phi[2]));
220
221 if(deltaR[0] < deltaR[1])
222 return -1;
223 else if(deltaR[0] > deltaR[1])
224 return 1;
225 else
226 return 0;
227 }
228};
229
230#endif // SortableObject_h
231
232
Note: See TracBrowser for help on using the repository browser.