ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
AnalysisCommon
AnalysisUtils
AnalysisUtils
AnalysisMisc.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef ANALYSISUTILS_ANALYSISMISC_H
6
#define ANALYSISUTILS_ANALYSISMISC_H
7
13
14
#include <math.h>
15
#include <vector>
16
#include <algorithm>
17
18
#include "
CxxUtils/fpcompare.h
"
19
#include "
AthContainers/DataVector.h
"
20
#include "
TruthUtils/MagicNumbers.h
"
21
#include <type_traits>
22
23
24
#ifndef XAOD_STANDALONE
25
#include "CLHEP/Vector/LorentzVector.h"
26
#include "
EventKernel/INavigable4Momentum.h
"
27
#endif
28
29
namespace
AnalysisUtils
{
30
31
#ifndef XAOD_STANDALONE
32
35
namespace
Delta
{
36
39
inline
double
phi
(
const
INavigable4Momentum
*p1,
const
INavigable4Momentum
*p2) {
40
double
phi1 = (p1->phi()>
M_PI
) ? p1->phi()-2*
M_PI
: p1->phi();
41
double
phi2 = (p2->phi()>
M_PI
) ? p2->phi()-2*
M_PI
: p2->phi();
42
double
dphi = fabs(phi1-phi2);
43
if
(dphi>
M_PI
) dphi = 2*
M_PI
-dphi;
44
return
dphi;
45
}
46
49
inline
double
R
(
const
INavigable4Momentum
*p1,
const
double
v_eta,
const
double
v_phi) {
50
double
phi1 = (p1->phi()>
M_PI
) ? p1->phi()-2*
M_PI
: p1->phi();
51
double
phi2 = (v_phi>
M_PI
) ? v_phi-2*
M_PI
: v_phi;
52
double
dphi = fabs(phi1-phi2);
53
if
(dphi>
M_PI
) dphi = 2*
M_PI
-dphi;
54
double
deta = p1->eta() - v_eta;
55
return
sqrt(dphi*dphi+deta*deta);
56
}
57
60
inline
double
R
(
const
INavigable4Momentum
*p1,
const
INavigable4Momentum
*p2) {
61
return
R
(p1, p2->eta(), p2->phi());
62
}
63
}
// end of Delta namespace
64
66
69
namespace
Imass
{
70
71
inline
double
two
(
const
INavigable4Momentum
*p1,
const
INavigable4Momentum
*p2) {
72
return
(p1->hlv()+p2->hlv()).m();
73
}
74
75
inline
double
four
(
const
INavigable4Momentum
*p1,
const
INavigable4Momentum
*p2,
76
const
INavigable4Momentum
*p3,
const
INavigable4Momentum
*p4) {
77
return
(p1->hlv()+p2->hlv()+p3->hlv()+p4->
hlv
()).m();
78
}
79
}
// end of Imass namespace
80
82
85
namespace
Match
{
86
92
template
<
class
COLL>
93
inline
bool
R
(
const
double
eta
,
const
double
phi
, COLL *coll,
int
&
index
,
double
&
deltaR
,
const
int
pdg)
94
{
95
deltaR
= 10000.;
// big value
96
bool
l_return =
false
;
97
int
l_idx = 0;
98
typename
COLL::const_iterator it = coll->begin();
99
typename
COLL::const_iterator itE = coll->end();
100
for
(; it != itE; ++it)
101
{
102
if
(((*it)->pdgId()==pdg) || pdg==0 )
103
{
104
double
rtu =
Delta::R
(*it,
eta
,
phi
);
105
if
( rtu <
deltaR
)
106
{
107
index
= l_idx;
108
deltaR
= rtu;
109
l_return =
true
;
110
}
111
}
112
++l_idx;
113
}
114
return
l_return;
115
}
116
122
template
<
class
COLL>
123
inline
bool
R
(
const
double
eta
,
const
double
phi
,
const
double
e, COLL *coll,
124
int
&
index
,
double
&
deltaR
,
const
int
pdg,
double
&deltaE)
125
{
126
deltaR
= 1.0e+20;
// big value
127
deltaE = 1.0e+20;
128
bool
l_return =
false
;
129
int
l_idx = 0;
130
typename
COLL::const_iterator it = coll->begin();
131
typename
COLL::const_iterator itE = coll->end();
132
for
(; it != itE; ++it)
133
{
134
if
(((*it)->pdgId()==pdg) || pdg==0 )
135
{
136
double
rtu =
Delta::R
(*it,
eta
,
phi
);
137
double
dE = fabs( e-(*it)->e() );
138
if
( rtu <
deltaR
&& dE < deltaE)
139
{
140
index
= l_idx;
141
deltaR
= rtu;
142
deltaE = dE;
143
l_return =
true
;
144
}
145
}
146
++l_idx;
147
}
148
return
l_return;
149
}
150
156
template
<
class
COLL>
157
inline
bool
R
(
const
INavigable4Momentum
*t, COLL *coll,
int
&
index
,
double
&
deltaR
,
const
int
pdg)
158
{
159
return
R
(t->eta(), t->phi(), coll,
index
,
deltaR
, pdg);
160
}
161
167
template
<
class
COLL>
168
inline
bool
R
(
const
INavigable4Momentum
*t, COLL *coll,
int
&
index
,
double
&
deltaR
,
169
const
int
pdg,
double
&deltaE)
170
{
171
return
R
(t->eta(), t->phi(), t->e(), coll,
index
,
deltaR
, pdg, deltaE);
172
}
173
177
template
<
class
COLL>
178
inline
bool
R
(
const
double
eta
,
const
double
phi
, COLL *coll,
int
&
index
,
double
&
deltaR
)
179
{
180
deltaR
= 10000.;
// big value
181
bool
l_return =
false
;
182
int
l_idx = 0;
183
typename
COLL::const_iterator it = coll->begin();
184
typename
COLL::const_iterator itE = coll->end();
185
for
(; it != itE; ++it)
186
{
187
double
rtu =
Delta::R
(*it,
eta
,
phi
);
188
if
( rtu <
deltaR
)
189
{
190
index
= l_idx;
191
deltaR
= rtu;
192
l_return =
true
;
193
}
194
++l_idx;
195
}
196
return
l_return;
197
}
198
202
template
<
class
COLL>
203
inline
bool
R
(
const
double
eta
,
const
double
phi
,
const
double
e, COLL *coll,
int
&
index
,
204
double
&
deltaR
,
double
&deltaE)
205
{
206
deltaR
= 1.0e+20;
// big value
207
deltaE = 1.0e+20;
208
bool
l_return =
false
;
209
int
l_idx = 0;
210
typename
COLL::const_iterator it = coll->begin();
211
typename
COLL::const_iterator itE = coll->end();
212
for
(; it != itE; ++it)
213
{
214
double
rtu =
Delta::R
(*it,
eta
,
phi
);
215
double
dE = fabs( e-(*it)->e() );
216
if
( rtu <
deltaR
&& dE < deltaE)
217
{
218
index
= l_idx;
219
deltaR
= rtu;
220
deltaE = dE;
221
l_return =
true
;
222
}
223
++l_idx;
224
}
225
return
l_return;
226
}
227
231
template
<
class
COLL>
232
inline
bool
R
(
const
INavigable4Momentum
*t, COLL *coll,
int
&
index
,
double
&
deltaR
)
233
{
234
return
R
(t->eta(), t->phi(), coll,
index
,
deltaR
);
235
}
236
240
template
<
class
COLL>
241
inline
bool
R
(
const
INavigable4Momentum
*t, COLL *coll,
int
&
index
,
double
&
deltaR
,
double
&deltaE)
242
{
243
return
R
(t->eta(), t->phi(), t->e(), coll,
index
,
deltaR
, deltaE);
244
}
245
246
}
// end of Math namespace
247
249
250
#endif
251
254
namespace
Sort
{
255
256
namespace
Private
{
257
258
using
CxxUtils::fpcompare::greater
;
259
260
// function object for pT sorting
261
template
<
class
T>
inline
bool
compPt
(T
a
, T b)
262
{
263
return
greater (
a
->pt(), b->pt());
264
}
265
266
// function object for e sorting
267
template
<
class
T>
inline
bool
compE
(T
a
, T b)
268
{
269
return
greater (
a
->e(), b->e());
270
}
271
272
// function object for eta sorting
273
template
<
class
T>
inline
bool
compEta
(T
a
, T b)
274
{
275
return
greater (
a
->eta(), b->eta());
276
}
277
278
// function object for phi sorting
279
template
<
class
T>
inline
bool
compPhi
(T
a
, T b)
280
{
281
return
greater (
a
->phi(), b->phi());
282
}
283
284
template
<
bool
b>
285
struct
dosort_imp
286
{
287
template
<
class
COLL,
class
COMP>
288
static
void
dosort
(COLL& coll, COMP comp)
289
{
std::sort
(coll.begin(), coll.end(), comp); }
290
};
291
292
template
<>
293
struct
dosort_imp
<true>
294
{
295
template
<
class
COLL,
class
COMP>
296
static
void
dosort
(COLL& coll, COMP comp)
297
{ coll.sort(comp); }
298
};
299
300
template
<
class
COLL,
class
COMP>
301
inline
void
dosort
(COLL& coll, COMP comp)
302
{
303
typedef
typename
std::remove_pointer<typename COLL::value_type>::type valtype;
304
typedef
DataVector<valtype>
dvtype;
305
const
bool
is_dv = std::is_convertible<COLL&, dvtype&>::value;
306
dosort_imp<is_dv>::dosort
(coll, comp);
307
}
308
309
}
// end of Private namespace
310
315
template
<
class
COLL>
inline
void
pT
(COLL *coll)
316
{
317
// sort
318
Private::dosort
(*coll,
Private::compPt<typename COLL::value_type>
);
319
}
320
325
template
<
class
COLL>
inline
void
e
(COLL *coll)
326
{
327
// sort
328
Private::dosort
(*coll,
Private::compE<typename COLL::value_type>
);
329
}
330
335
template
<
class
COLL>
inline
void
eta
(COLL *coll)
336
{
337
// sort
338
Private::dosort
(*coll,
Private::compEta<typename COLL::value_type>
);
339
}
340
345
template
<
class
COLL>
inline
void
phi
(COLL *coll)
346
{
347
// sort
348
Private::dosort
(*coll,
Private::compPhi<typename COLL::value_type>
);
349
}
350
}
// end of Sort namespace
351
352
#ifndef XAOD_STANDALONE
354
357
namespace
Classify
{
358
365
template
<
class
COLL>
inline
void
charge
(COLL *coll,
366
std::vector<typename COLL::value_type> &pos,
367
std::vector<typename COLL::value_type> &neg)
368
{
369
pos.clear();
370
neg.clear();
371
372
// classify
373
typename
COLL::const_iterator it = coll->begin();
374
typename
COLL::const_iterator itE = coll->end();
375
for
(; it != itE; ++it)
376
{
377
if
((*it)->pdgId() > 0)
378
pos.push_back(*it);
379
else
if
((*it)->pdgId() < 0)
380
neg.push_back(*it);
381
}
382
}
383
}
// end of Classify namespace
384
385
#endif
386
387
}
// end of AnalysisUtils namespace
388
389
#endif
M_PI
#define M_PI
Definition
ActiveFraction.h:14
eta
Scalar eta() const
pseudorapidity method
Definition
AmgMatrixBasePlugin.h:83
deltaR
Scalar deltaR(const MatrixBase< Derived > &vec) const
Definition
AmgMatrixBasePlugin.h:105
phi
Scalar phi() const
phi method
Definition
AmgMatrixBasePlugin.h:67
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
INavigable4Momentum.h
a
static Double_t a
Definition
LArPhysWaveHECTool.cxx:38
MagicNumbers.h
DataVector
Derived DataVector<T>.
Definition
DataVector.h:795
I4Momentum::hlv
virtual CLHEP::HepLorentzVector hlv() const =0
CLHEP HepLorentzVector.
INavigable4Momentum
Definition
INavigable4Momentum.h:21
fpcompare.h
Workaround x86 precision issues for FP inequality comparisons.
AnalysisUtils::Classify
classify
Definition
AnalysisMisc.h:357
AnalysisUtils::Classify::charge
void charge(COLL *coll, std::vector< typename COLL::value_type > &pos, std::vector< typename COLL::value_type > &neg)
classify by charge
Definition
AnalysisMisc.h:365
AnalysisUtils::Delta
compute
Definition
AnalysisMisc.h:35
AnalysisUtils::Delta::R
double R(const INavigable4Momentum *p1, const double v_eta, const double v_phi)
Definition
AnalysisMisc.h:49
AnalysisUtils::Imass
compute Invariant mass
Definition
AnalysisMisc.h:69
AnalysisUtils::Imass::four
double four(const INavigable4Momentum *p1, const INavigable4Momentum *p2, const INavigable4Momentum *p3, const INavigable4Momentum *p4)
Definition
AnalysisMisc.h:75
AnalysisUtils::Imass::two
double two(const INavigable4Momentum *p1, const INavigable4Momentum *p2)
Definition
AnalysisMisc.h:71
AnalysisUtils::Match
find the closest element in a collection to an INavigable4Momentum
Definition
AnalysisMisc.h:85
AnalysisUtils::Match::R
bool R(const double eta, const double phi, COLL *coll, int &index, double &deltaR, const int pdg)
find the closest element in R
Definition
AnalysisMisc.h:93
AnalysisUtils::Sort::Private
Definition
AnalysisMisc.h:256
AnalysisUtils::Sort::Private::dosort
void dosort(COLL &coll, COMP comp)
Definition
AnalysisMisc.h:301
AnalysisUtils::Sort::Private::compPhi
bool compPhi(T a, T b)
Definition
AnalysisMisc.h:279
AnalysisUtils::Sort::Private::compPt
bool compPt(T a, T b)
Definition
AnalysisMisc.h:261
AnalysisUtils::Sort::Private::compEta
bool compEta(T a, T b)
Definition
AnalysisMisc.h:273
AnalysisUtils::Sort::Private::compE
bool compE(T a, T b)
Definition
AnalysisMisc.h:267
AnalysisUtils::Sort
sort
Definition
AnalysisMisc.h:254
AnalysisUtils::Sort::pT
void pT(COLL *coll)
sort by pT
Definition
AnalysisMisc.h:315
AnalysisUtils::Sort::e
void e(COLL *coll)
sort by e
Definition
AnalysisMisc.h:325
AnalysisUtils
utility class to select combination of elements in a collection
Definition
AnalysisCombination.h:16
CxxUtils::fpcompare::greater
bool greater(double a, double b)
Compare two FP numbers, working around x87 precision issues.
Definition
fpcompare.h:140
index
Definition
index.py:1
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition
DVL_algorithms.h:554
AnalysisUtils::Sort::Private::dosort_imp< true >::dosort
static void dosort(COLL &coll, COMP comp)
Definition
AnalysisMisc.h:296
AnalysisUtils::Sort::Private::dosort_imp
Definition
AnalysisMisc.h:286
AnalysisUtils::Sort::Private::dosort_imp::dosort
static void dosort(COLL &coll, COMP comp)
Definition
AnalysisMisc.h:288
Generated on
for ATLAS Offline Software by
1.17.0